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.JsonParser;
import lombok.val;
import org.bukkit.configuration.file.YamlConfiguration;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IMessage;
import java.io.File;
import java.util.List;
public class AnnouncerModule extends Component {
@ -27,7 +29,7 @@ public class AnnouncerModule extends Component {
* Set to 0 or >50 to disable
*/
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() {
@ -57,10 +59,11 @@ public class AnnouncerModule extends Component {
} catch (InterruptedException ignore) {
}
});
val yc = YamlConfiguration.loadConfiguration(new File("plugins/DiscordPlugin", "config.yml")); //Name change
if (lastannouncementtime().get() == 0) //Load old data
lastannouncementtime().set(getConfig().getConfig().getRoot().getLong("lastannouncementtime"));
lastannouncementtime().set(yc.getLong("lastannouncementtime"));
if (lastseentime().get() == 0)
lastseentime().set(getConfig().getConfig().getLong("lastseentime"));
lastseentime().set(yc.getLong("lastseentime"));
new Thread(this::AnnouncementGetterThreadMethod).start();
}

View file

@ -138,6 +138,11 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
if (task != null)
task.cancel();
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
DiscordCommandBase.registerCommands();
@ -169,26 +174,10 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
}
TBMCCoreAPI.SendUnsentExceptions();
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);
for (IListener<?> listener : CommonListeners.getListeners())
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);
TBMCChatAPI.AddCommands(this, DiscordMCCommandBase.class);
TBMCCoreAPI.RegisterUserClass(DiscordPlayer.class);
@ -206,11 +195,7 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
public static boolean Restart;
@Override
public void pluginDisable() {
MCChatPrivate.logoutAll();
getConfig().set("serverup", false);
saveConfig();
public void pluginPreDisable() {
EmbedObject embed;
if (ResetMCCommand.resetting)
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);
ChromaBot.getInstance().updatePlayerList();
}
@Override
public void pluginDisable() {
MCChatPrivate.logoutAll();
getConfig().set("serverup", false);
saveConfig();
try {
SafeMode = true; // Stop interacting with Discord
ChromaBot.delete();