Only showing join/leave/etc. messages if not hooked

This commit is contained in:
Norbi Peti 2017-11-28 23:07:34 +01:00
parent 0c9dd6f49a
commit 20ff9cc3e6
3 changed files with 26 additions and 5 deletions

View file

@ -0,0 +1,11 @@
package buttondevteam.discordplugin;
import lombok.Getter;
public class ChromaBot {
/**
* May be null if it's not initialized
*/
public @Getter ChromaBot instance;
// TODO
}

View file

@ -44,14 +44,21 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
public static DiscordPlugin plugin; public static DiscordPlugin plugin;
public static boolean SafeMode = true; public static boolean SafeMode = true;
public static List<String> GameRoles; public static List<String> GameRoles;
public static boolean hooked = false;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void onEnable() { public void onEnable() {
try { try {
Bukkit.getLogger().info("Initializing DiscordPlugin..."); Bukkit.getLogger().info("Initializing DiscordPlugin...");
try {
PlayerListWatcher.hookUp(); PlayerListWatcher.hookUp();
hooked = true;
Bukkit.getLogger().info("Finished hooking into the player list"); Bukkit.getLogger().info("Finished hooking into the player list");
} catch (Throwable e) {
e.printStackTrace();
Bukkit.getLogger().warning("Couldn't hook into the player list!");
}
plugin = this; plugin = this;
lastannouncementtime = getConfig().getLong("lastannouncementtime"); lastannouncementtime = getConfig().getLong("lastannouncementtime");
lastseentime = getConfig().getLong("lastseentime"); lastseentime = getConfig().getLong("lastseentime");

View file

@ -68,6 +68,7 @@ public class MCListener implements Listener {
+ " do /discord accept"); + " do /discord accept");
p.sendMessage("§bIf it wasn't you, do /discord decline"); p.sendMessage("§bIf it wasn't you, do /discord decline");
} }
if (!DiscordPlugin.hooked)
MCChatListener.sendSystemMessageToChat(e.GetPlayer().PlayerName().get() + " joined the game"); MCChatListener.sendSystemMessageToChat(e.GetPlayer().PlayerName().get() + " joined the game");
MCChatListener.ListC = 0; MCChatListener.ListC = 0;
DiscordPlugin.updatePlayerList(); DiscordPlugin.updatePlayerList();
@ -83,6 +84,7 @@ public class MCListener implements Listener {
() -> MCChatListener.ConnectedSenders.values().stream() () -> MCChatListener.ConnectedSenders.values().stream()
.filter(s -> s.getUniqueId().equals(e.getPlayer().getUniqueId())).findAny() .filter(s -> s.getUniqueId().equals(e.getPlayer().getUniqueId())).findAny()
.ifPresent(dcp -> callEventExcludingSome(new PlayerJoinEvent(dcp, "")))); .ifPresent(dcp -> callEventExcludingSome(new PlayerJoinEvent(dcp, ""))));
if (!DiscordPlugin.hooked)
MCChatListener.sendSystemMessageToChat(e.GetPlayer().PlayerName().get() + " left the game"); MCChatListener.sendSystemMessageToChat(e.GetPlayer().PlayerName().get() + " left the game");
Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, DiscordPlugin::updatePlayerList, 5); Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, DiscordPlugin::updatePlayerList, 5);
} }
@ -105,6 +107,7 @@ public class MCListener implements Listener {
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void onPlayerDeath(PlayerDeathEvent e) { public void onPlayerDeath(PlayerDeathEvent e) {
if (!DiscordPlugin.hooked)
MCChatListener.sendSystemMessageToChat(e.getDeathMessage()); MCChatListener.sendSystemMessageToChat(e.getDeathMessage());
} }