Server start/stop msg + announcer fix

Announcer data migration fix (which won't be needed because I'm gonna copy the new config over)
The server start/stop messages show up again
This commit is contained in:
Norbi Peti 2019-01-30 23:41:52 +01:00
parent 2659170c4d
commit abd4050786
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 44 additions and 48 deletions

View file

@ -9,9 +9,11 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import lombok.val; import lombok.val;
import org.bukkit.configuration.file.YamlConfiguration;
import sx.blah.discord.handle.obj.IChannel; import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IMessage; import sx.blah.discord.handle.obj.IMessage;
import java.io.File;
import java.util.List; import java.util.List;
public class AnnouncerModule extends Component { public class AnnouncerModule extends Component {
@ -27,7 +29,7 @@ public class AnnouncerModule extends Component {
* Set to 0 or >50 to disable * Set to 0 or >50 to disable
*/ */
public ConfigData<Short> keepPinned() { public ConfigData<Short> keepPinned() {
return getConfig().getData("keepPinned", (short) 40, i -> ((Integer) i).shortValue(), Short::intValue); return getConfig().getData("keepPinned", (short) 40);
} }
private ConfigData<Long> lastannouncementtime() { private ConfigData<Long> lastannouncementtime() {
@ -57,10 +59,11 @@ public class AnnouncerModule extends Component {
} catch (InterruptedException ignore) { } catch (InterruptedException ignore) {
} }
}); });
val yc = YamlConfiguration.loadConfiguration(new File("plugins/DiscordPlugin", "config.yml")); //Name change
if (lastannouncementtime().get() == 0) //Load old data if (lastannouncementtime().get() == 0) //Load old data
lastannouncementtime().set(getConfig().getConfig().getRoot().getLong("lastannouncementtime")); lastannouncementtime().set(yc.getLong("lastannouncementtime"));
if (lastseentime().get() == 0) if (lastseentime().get() == 0)
lastseentime().set(getConfig().getConfig().getLong("lastseentime")); lastseentime().set(yc.getLong("lastseentime"));
new Thread(this::AnnouncementGetterThreadMethod).start(); new Thread(this::AnnouncementGetterThreadMethod).start();
} }

View file

@ -138,6 +138,11 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
if (task != null) if (task != null)
task.cancel(); task.cancel();
if (!sent) { if (!sent) {
Component.registerComponent(this, new GeneralEventBroadcasterModule());
Component.registerComponent(this, new MinecraftChatModule());
Component.registerComponent(this, new ExceptionListenerModule());
Component.registerComponent(this, new GameRoleModule()); //Needs the mainServer to be set
Component.registerComponent(this, new AnnouncerModule());
new ChromaBot(this).updatePlayerList(); //Initialize ChromaBot - The MCCHatModule is tested to be enabled new ChromaBot(this).updatePlayerList(); //Initialize ChromaBot - The MCCHatModule is tested to be enabled
DiscordCommandBase.registerCommands(); DiscordCommandBase.registerCommands();
@ -169,26 +174,10 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
} }
TBMCCoreAPI.SendUnsentExceptions(); TBMCCoreAPI.SendUnsentExceptions();
TBMCCoreAPI.SendUnsentDebugMessages(); TBMCCoreAPI.SendUnsentDebugMessages();
/*if (!TBMCCoreAPI.IsTestServer()) {
final Calendar currentCal = Calendar.getInstance();
final Calendar newCal = Calendar.getInstance();
currentCal.set(currentCal.get(Calendar.YEAR), currentCal.get(Calendar.MONTH),
currentCal.get(Calendar.DAY_OF_MONTH), 4, 10);
if (currentCal.get(Calendar.DAY_OF_MONTH) % 9 == 0 && currentCal.before(newCal)) {
Random rand = new Random();
sendMessageToChannel(dc.getChannels().get(rand.nextInt(dc.getChannels().size())),
"You could make a religion out of this");
}
}*/
} }
}, 0, 10); }, 0, 10);
for (IListener<?> listener : CommonListeners.getListeners()) for (IListener<?> listener : CommonListeners.getListeners())
dc.getDispatcher().registerListener(listener); dc.getDispatcher().registerListener(listener);
Component.registerComponent(this, new GeneralEventBroadcasterModule());
Component.registerComponent(this, new MinecraftChatModule());
Component.registerComponent(this, new ExceptionListenerModule());
Component.registerComponent(this, new GameRoleModule());
Component.registerComponent(this, new AnnouncerModule());
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(), this); TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(), this);
TBMCChatAPI.AddCommands(this, DiscordMCCommandBase.class); TBMCChatAPI.AddCommands(this, DiscordMCCommandBase.class);
TBMCCoreAPI.RegisterUserClass(DiscordPlayer.class); TBMCCoreAPI.RegisterUserClass(DiscordPlayer.class);
@ -206,11 +195,7 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
public static boolean Restart; public static boolean Restart;
@Override @Override
public void pluginDisable() { public void pluginPreDisable() {
MCChatPrivate.logoutAll();
getConfig().set("serverup", false);
saveConfig();
EmbedObject embed; EmbedObject embed;
if (ResetMCCommand.resetting) if (ResetMCCommand.resetting)
embed = new EmbedBuilder().withColor(Color.ORANGE).withTitle("Discord plugin restarting").build(); embed = new EmbedBuilder().withColor(Color.ORANGE).withTitle("Discord plugin restarting").build();
@ -235,6 +220,14 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
} }
}, ChannelconBroadcast.RESTART, false); }, ChannelconBroadcast.RESTART, false);
ChromaBot.getInstance().updatePlayerList(); ChromaBot.getInstance().updatePlayerList();
}
@Override
public void pluginDisable() {
MCChatPrivate.logoutAll();
getConfig().set("serverup", false);
saveConfig();
try { try {
SafeMode = true; // Stop interacting with Discord SafeMode = true; // Stop interacting with Discord
ChromaBot.delete(); ChromaBot.delete();