diff --git a/src/main/java/pl/norbit/discordmc/DiscordMc.java b/src/main/java/pl/norbit/discordmc/DiscordMc.java index 0d07adb..5d38c4e 100644 --- a/src/main/java/pl/norbit/discordmc/DiscordMc.java +++ b/src/main/java/pl/norbit/discordmc/DiscordMc.java @@ -1,6 +1,7 @@ package pl.norbit.discordmc; import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.MessageChannel; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.core.Logger; @@ -28,6 +29,8 @@ public final class DiscordMc extends JavaPlugin { private static Long timeServer; private static DiscordMc instance; + private static Guild guild; + private static ConsoleCommandSender commandSender; private static JDA jda; @@ -68,7 +71,9 @@ private boolean start() throws InterruptedException { jda = discordBot.getJda(); - if(jda.awaitReady().getGuildById(PluginConfig.SERVER_ID) == null) { + guild = jda.awaitReady().getGuildById(PluginConfig.SERVER_ID); + + if(guild == null) { sendMessage("&c[ERROR] Wrong discord server ID"); sendMessage("&cHow to get discord server id?"); sendMessage("&chttps://github.com/Norbit4/DiscordMc/wiki/Configuration#id"); @@ -208,4 +213,8 @@ public static DiscordMc getInstance() { public static JDA getJda() { return jda; } + + public static Guild getGuild(){ + return guild; + } } diff --git a/src/main/java/pl/norbit/discordmc/bot/embed/Embed.java b/src/main/java/pl/norbit/discordmc/bot/embed/Embed.java index ced3bd1..6775947 100644 --- a/src/main/java/pl/norbit/discordmc/bot/embed/Embed.java +++ b/src/main/java/pl/norbit/discordmc/bot/embed/Embed.java @@ -53,13 +53,12 @@ public static EmbedBuilder getConsoleMessage(String tittle, String message, Colo } public static EmbedBuilder getProfileMessage(){ - EmbedBuilder embedBuilder = getBuilder(PluginConfig.EMBED_PROFILE_TITLE, "", + return getBuilder(PluginConfig.EMBED_PROFILE_TITLE, "", new Color( PluginConfig.EMBED_PROFILE_R, PluginConfig.EMBED_PROFILE_G, PluginConfig.EMBED_PROFILE_B), false, ""); - return embedBuilder; } public static boolean isUsernamePremium(String username) throws IOException { URL url = new URL("https://api.mojang.com/users/profiles/minecraft/"+ username); diff --git a/src/main/java/pl/norbit/discordmc/discord/DiscordUserUpdateTask.java b/src/main/java/pl/norbit/discordmc/discord/DiscordUserUpdateTask.java index 3bdeb9c..048ce99 100644 --- a/src/main/java/pl/norbit/discordmc/discord/DiscordUserUpdateTask.java +++ b/src/main/java/pl/norbit/discordmc/discord/DiscordUserUpdateTask.java @@ -15,7 +15,7 @@ public class DiscordUserUpdateTask { private static final Queue queue = new LinkedList<>(); public static void start(){ - if(!PluginConfig.SYNC_RANK_ENABLE) return; + if(!PluginConfig.SYNC_PERM_ENABLE) return; new BukkitRunnable() { @Override public void run() { diff --git a/src/main/java/pl/norbit/discordmc/server/commands/args/SyncClearCommand.java b/src/main/java/pl/norbit/discordmc/server/commands/args/SyncClearCommand.java index 0f6b8f7..9ef20f6 100644 --- a/src/main/java/pl/norbit/discordmc/server/commands/args/SyncClearCommand.java +++ b/src/main/java/pl/norbit/discordmc/server/commands/args/SyncClearCommand.java @@ -55,6 +55,7 @@ public void run() { if (PluginConfig.EXECUTE_COMMAND_ON_SYNC_CLEAR) ConsoleUtil.executeCommand(p, PluginConfig.COMMANDS_ON_SYNC_CLEAR.toArray(new String[0])); + instance.getServer().getPluginManager().callEvent(new SyncClearEvent(playerUUID, discordId)); } }.runTaskLater(DiscordMc.getInstance(), 4); diff --git a/src/main/java/pl/norbit/discordmc/serverinfo/InfoUpdater.kt b/src/main/java/pl/norbit/discordmc/serverinfo/InfoUpdater.kt index cd88bb5..e4954b3 100644 --- a/src/main/java/pl/norbit/discordmc/serverinfo/InfoUpdater.kt +++ b/src/main/java/pl/norbit/discordmc/serverinfo/InfoUpdater.kt @@ -22,7 +22,7 @@ class InfoUpdater { PluginConfig.MESSAGE_RELOAD_TIME } - var messageID: String + val messageID: String val textChannel = jda?.awaitReady()?.getTextChannelById(PluginConfig.CHANNEL_INFO_ID) val color = Color(PluginConfig.EMBED_INFO_R, PluginConfig.EMBED_INFO_G, PluginConfig.EMBED_INFO_B) @@ -51,8 +51,6 @@ class InfoUpdater { PluginConfig.EMBED_INFO_ARGS ) - if(messageID == null) return - textChannel.editMessageById(messageID, "*").setEmbeds(message?.build()).queue() } }.runTaskTimerAsynchronously(DiscordMc.getInstance(), 20 * 6, reloadTime.toLong() * 20) diff --git a/src/main/java/pl/norbit/discordmc/sync/SyncTimerTask.java b/src/main/java/pl/norbit/discordmc/sync/SyncTimerTask.java index 137e657..33314c6 100644 --- a/src/main/java/pl/norbit/discordmc/sync/SyncTimerTask.java +++ b/src/main/java/pl/norbit/discordmc/sync/SyncTimerTask.java @@ -14,15 +14,11 @@ public static void runTaskTimer(JavaPlugin javaPlugin) { new BukkitRunnable() { @Override public void run() { - if(!syncPlayerList.isEmpty()) { + if(syncPlayerList.isEmpty()) return; - syncPlayerList.forEach(syncPlayer -> { - - if(syncPlayer.time() == 1){ - removeSyncPlayer(syncPlayer); - } - }); - } + syncPlayerList.forEach(syncPlayer -> { + if(syncPlayer.time() == 1) removeSyncPlayer(syncPlayer); + }); } }.runTaskTimerAsynchronously(javaPlugin, 0, 20); } @@ -32,10 +28,9 @@ public static void addSyncPlayer(SyncPlayer syncPlayer){ } public static SyncPlayer getSyncPlayer(UUID playerUUID){ - Optional optionalSyncPlayer = syncPlayerList.stream() + return syncPlayerList.stream() .filter(syncPlayer1 -> syncPlayer1.getPlayer().getUniqueId().equals(playerUUID)) - .findFirst(); - return optionalSyncPlayer.orElse(null); + .findFirst().orElse(null); } public static void removeSyncPlayer(SyncPlayer syncPlayer){ diff --git a/src/main/java/pl/norbit/discordmc/utils/PermissionUtil.java b/src/main/java/pl/norbit/discordmc/utils/PermissionUtil.java index 01ae4f9..2ec1abc 100644 --- a/src/main/java/pl/norbit/discordmc/utils/PermissionUtil.java +++ b/src/main/java/pl/norbit/discordmc/utils/PermissionUtil.java @@ -17,7 +17,7 @@ public PermissionUtil(Player p) { }); } - public boolean hasPermission(String [] perms) { + public boolean hasPermission(String... perms) { for (String perm : perms) {