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);
@ -205,36 +194,40 @@ 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(); EmbedObject embed;
getConfig().set("serverup", false); if (ResetMCCommand.resetting)
embed = new EmbedBuilder().withColor(Color.ORANGE).withTitle("Discord plugin restarting").build();
else
embed = new EmbedBuilder().withColor(Restart ? Color.ORANGE : Color.RED)
.withTitle(Restart ? "Server restarting" : "Server stopping")
.withDescription(
Bukkit.getOnlinePlayers().size() > 0
? (DPUtils
.sanitizeString(Bukkit.getOnlinePlayers().stream()
.map(Player::getDisplayName).collect(Collectors.joining(", ")))
+ (Bukkit.getOnlinePlayers().size() == 1 ? " was " : " were ")
+ "kicked the hell out.") //TODO: Make configurable
: "") //If 'restart' is disabled then this isn't shown even if joinleave is enabled
.build();
MCChatUtils.forCustomAndAllMCChat(ch -> {
try {
DiscordPlugin.sendMessageToChannelWait(ch, "",
embed, 5, TimeUnit.SECONDS);
} catch (TimeoutException | InterruptedException e) {
e.printStackTrace();
}
}, ChannelconBroadcast.RESTART, false);
ChromaBot.getInstance().updatePlayerList();
}
saveConfig(); @Override
EmbedObject embed; public void pluginDisable() {
if (ResetMCCommand.resetting) MCChatPrivate.logoutAll();
embed = new EmbedBuilder().withColor(Color.ORANGE).withTitle("Discord plugin restarting").build(); getConfig().set("serverup", false);
else
embed = new EmbedBuilder().withColor(Restart ? Color.ORANGE : Color.RED) saveConfig();
.withTitle(Restart ? "Server restarting" : "Server stopping")
.withDescription(
Bukkit.getOnlinePlayers().size() > 0
? (DPUtils
.sanitizeString(Bukkit.getOnlinePlayers().stream()
.map(Player::getDisplayName).collect(Collectors.joining(", ")))
+ (Bukkit.getOnlinePlayers().size() == 1 ? " was " : " were ")
+ "kicked the hell out.") //TODO: Make configurable
: "") //If 'restart' is disabled then this isn't shown even if joinleave is enabled
.build();
MCChatUtils.forCustomAndAllMCChat(ch -> {
try {
DiscordPlugin.sendMessageToChannelWait(ch, "",
embed, 5, TimeUnit.SECONDS);
} catch (TimeoutException | InterruptedException e) {
e.printStackTrace();
}
}, ChannelconBroadcast.RESTART, false);
ChromaBot.getInstance().updatePlayerList();
try { try {
SafeMode = true; // Stop interacting with Discord SafeMode = true; // Stop interacting with Discord
ChromaBot.delete(); ChromaBot.delete();