diff --git a/.gitignore b/.gitignore index f259fc0..6511395 100644 --- a/.gitignore +++ b/.gitignore @@ -290,3 +290,5 @@ target/classes/com/songoda/ultimatemoderation/command/commands/CommandSlowMode\. target/classes/com/songoda/ultimatemoderation/listeners/ChatListener\$Log\.class target/classes/com/songoda/ultimatemoderation/tasks/SlowModeTask\.class + +target/classes/com/songoda/ultimatemoderation/utils/ServerVersion\.class diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 047b67e..a8d6ae7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "ultimatemoderation" path: "/builds/Songoda/$name" - version: "1 B3" + version: "1" build: stage: build diff --git a/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java b/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java index 7fe21bd..c9a4ff9 100644 --- a/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java +++ b/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java @@ -21,8 +21,10 @@ import com.songoda.ultimatemoderation.tickets.TicketResponse; import com.songoda.ultimatemoderation.tickets.TicketStatus; import com.songoda.ultimatemoderation.utils.Methods; import com.songoda.ultimatemoderation.utils.Metrics; +import com.songoda.ultimatemoderation.utils.ServerVersion; import com.songoda.ultimatemoderation.utils.SettingsManager; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; +import org.apache.commons.lang.ArrayUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -35,6 +37,8 @@ public class UltimateModeration extends JavaPlugin { private static UltimateModeration INSTANCE; private References references; + private ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName()); + private TicketManager ticketManager; private TemplateManager templateManager; private SettingsManager settingsManager; @@ -49,29 +53,10 @@ public class UltimateModeration extends JavaPlugin { return INSTANCE; } - private boolean checkVersion() { - int workingVersion = 13; - int currentVersion = Integer.parseInt(Bukkit.getServer().getClass() - .getPackage().getName().split("\\.")[3].split("_")[1]); - - if (currentVersion < workingVersion) { - Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> { - Bukkit.getConsoleSender().sendMessage(""); - Bukkit.getConsoleSender().sendMessage(String.format("%sYou installed the 1.%s only version of %s on a 1.%s server. Since you are on the wrong version we disabled the plugin for you. Please install correct version to continue using %s.", ChatColor.RED, workingVersion, this.getDescription().getName(), currentVersion, this.getDescription().getName())); - Bukkit.getConsoleSender().sendMessage(""); - }, 20L); - return false; - } - return true; - } - @Override public void onEnable() { INSTANCE = this; - // Check to make sure the Bukkit version is compatible. - if (!checkVersion()) return; - console.sendMessage(Methods.formatText("&a=============================")); console.sendMessage(Methods.formatText("&7UltimateModeration " + this.getDescription().getVersion() + " by &5Songoda <3!")); console.sendMessage(Methods.formatText("&7Action: &aEnabling&7...")); @@ -209,6 +194,21 @@ public class UltimateModeration extends JavaPlugin { storage.doSave(); } + public ServerVersion getServerVersion() { + return serverVersion; + } + + public boolean isServerVersion(ServerVersion version) { + return serverVersion == version; + } + public boolean isServerVersion(ServerVersion... versions) { + return ArrayUtils.contains(versions, serverVersion); + } + + public boolean isServerVersionAtLeast(ServerVersion version) { + return serverVersion.ordinal() >= version.ordinal(); + } + private void setupConfig() { settingsManager.updateSettings(); this.getConfig().options().copyDefaults(true); diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandSpy.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandSpy.java index acf24d0..82b1776 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandSpy.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandSpy.java @@ -2,6 +2,7 @@ package com.songoda.ultimatemoderation.command.commands; import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.command.AbstractCommand; +import com.songoda.ultimatemoderation.utils.ServerVersion; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.OfflinePlayer; @@ -21,6 +22,11 @@ public class CommandSpy extends AbstractCommand { public static void spy(OfflinePlayer oPlayer, Player senderP) { UltimateModeration instance = UltimateModeration.getInstance(); + if (!UltimateModeration.getInstance().isServerVersionAtLeast(ServerVersion.V1_12)) { + senderP.sendMessage(instance.getReferences().getPrefix() + "This feature is not compatible with this version of spigot."); + return; + } + Player player = oPlayer.getPlayer(); if (player == null) { diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandVanish.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandVanish.java index 0a5950e..74da610 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandVanish.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandVanish.java @@ -3,6 +3,7 @@ package com.songoda.ultimatemoderation.command.commands; import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.command.AbstractCommand; import com.songoda.ultimatemoderation.utils.Methods; +import com.songoda.ultimatemoderation.utils.ServerVersion; import com.songoda.ultimatemoderation.utils.SettingsManager; import org.bukkit.Bukkit; import org.bukkit.Particle; @@ -64,7 +65,8 @@ public class CommandVanish extends AbstractCommand { float xx = (float) (0 + (Math.random() * 1)); float yy = (float) (0 + (Math.random() * 2)); float zz = (float) (0 + (Math.random() * 1)); - player.getWorld().spawnParticle(Particle.valueOf(SettingsManager.Setting.VANISH_PARTICLE.getString()), player.getLocation().add(0, 1, 0), 35, xx, yy, zz, 0); + if (instance.isServerVersionAtLeast(ServerVersion.V1_12)) + player.getWorld().spawnParticle(Particle.valueOf(SettingsManager.Setting.VANISH_PARTICLE.getString()), player.getLocation().add(0, 1, 0), 35, xx, yy, zz, 0); } for (Player p : Bukkit.getOnlinePlayers()) { diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/GUIModerate.java b/src/main/java/com/songoda/ultimatemoderation/gui/GUIModerate.java index 2a2b205..019cd90 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/GUIModerate.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/GUIModerate.java @@ -4,6 +4,7 @@ import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.command.commands.CommandFreeze; import com.songoda.ultimatemoderation.command.commands.CommandRevive; import com.songoda.ultimatemoderation.command.commands.CommandSpy; +import com.songoda.ultimatemoderation.utils.ServerVersion; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import org.bukkit.Material; import org.bukkit.OfflinePlayer; @@ -28,14 +29,14 @@ public class GUIModerate extends AbstractGUI { @Override protected void constructGUI() { - createButton(8, Material.OAK_DOOR, "Back"); + createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.OAK_DOOR : Material.valueOf("WOOD_DOOR"), "Back"); - createButton(10, Material.BLUE_ICE, "&6&lFreeze", "&7Stop this player from moving.", "", "&7Currently:&6 " + (CommandFreeze.isFrozen(toModerate) ? "Frozen" : "Unfrozen")); + createButton(10, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.BLUE_ICE : Material.valueOf("PACKED_ICE"), "&6&lFreeze", "&7Stop this player from moving.", "", "&7Currently:&6 " + (CommandFreeze.isFrozen(toModerate) ? "Frozen" : "Unfrozen")); createButton(12, Material.SADDLE, "&6&lSpy", "&7Spy on this player"); createButton(14, Material.CHEST, "&c&lInventory", "&7Access this players Inventory."); createButton(16, Material.ENDER_CHEST, "&a&lEnderchest", "&7Access this players Enderchest"); - createButton(28, Material.SPLASH_POTION, "&c&lRevive", "&7Revive this player."); + createButton(28, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.SPLASH_POTION : Material.valueOf("POTION"), "&c&lRevive", "&7Revive this player."); } @Override diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/GUINotesManager.java b/src/main/java/com/songoda/ultimatemoderation/gui/GUINotesManager.java index 2ae9f51..5f8de8c 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/GUINotesManager.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/GUINotesManager.java @@ -3,6 +3,7 @@ package com.songoda.ultimatemoderation.gui; import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.punish.PunishmentNote; import com.songoda.ultimatemoderation.utils.AbstractChatConfirm; +import com.songoda.ultimatemoderation.utils.ServerVersion; import com.songoda.ultimatemoderation.utils.gui.AbstractAnvilGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import org.bukkit.Bukkit; @@ -41,7 +42,7 @@ public class GUINotesManager extends AbstractGUI { registerClickables(); for (int i = 0; i < 9; i++) - createButton(9 + i, Material.GRAY_STAINED_GLASS_PANE, "&1"); + createButton(9 + i, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1"); int numNotes = plugin.getPunishmentManager().getPlayer(toModerate).getNotes().size(); int maxPage = (int) Math.floor(numNotes / 36.0); @@ -65,7 +66,7 @@ public class GUINotesManager extends AbstractGUI { })); } - createButton(8, Material.OAK_DOOR, plugin.getLocale().getMessage("gui.general.back")); + createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.OAK_DOOR : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back")); createButton(6, Material.REDSTONE, plugin.getLocale().getMessage("gui.notes.create")); diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/GUIPlayer.java b/src/main/java/com/songoda/ultimatemoderation/gui/GUIPlayer.java index 0c33f2a..73602d2 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/GUIPlayer.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/GUIPlayer.java @@ -1,6 +1,7 @@ package com.songoda.ultimatemoderation.gui; import com.songoda.ultimatemoderation.UltimateModeration; +import com.songoda.ultimatemoderation.utils.ServerVersion; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import org.bukkit.Material; import org.bukkit.OfflinePlayer; @@ -24,14 +25,17 @@ public class GUIPlayer extends AbstractGUI { @Override protected void constructGUI() { - ItemStack head = new ItemStack(Material.PLAYER_HEAD); + ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3); SkullMeta meta = ((SkullMeta) head.getItemMeta()); - meta.setOwningPlayer(toModerate); + if (plugin.isServerVersionAtLeast(ServerVersion.V1_13)) + meta.setOwningPlayer(toModerate); + else + meta.setOwner(toModerate.getName()); head.setItemMeta(meta); createButton(13, head, "&7&l" + toModerate.getName()); - createButton(8, Material.OAK_DOOR, plugin.getLocale().getMessage("gui.general.back")); + createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.OAK_DOOR : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back")); createButton(38, Material.ANVIL, plugin.getLocale().getMessage("gui.player.punish")); createButton(30, Material.CHEST, plugin.getLocale().getMessage("gui.player.tickets")); diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/GUIPlayers.java b/src/main/java/com/songoda/ultimatemoderation/gui/GUIPlayers.java index b24e3e5..979c212 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/GUIPlayers.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/GUIPlayers.java @@ -4,6 +4,7 @@ import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.player.PlayerPunishData; import com.songoda.ultimatemoderation.tickets.TicketStatus; +import com.songoda.ultimatemoderation.utils.ServerVersion; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -64,9 +65,12 @@ public class GUIPlayers extends AbstractGUI { PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(pl); - ItemStack head = new ItemStack(Material.PLAYER_HEAD); + ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3); SkullMeta meta = ((SkullMeta) head.getItemMeta()); - meta.setOwningPlayer(pl); + if (plugin.isServerVersionAtLeast(ServerVersion.V1_13)) + meta.setOwningPlayer(pl); + else + meta.setOwner(pl.getName()); head.setItemMeta(meta); ArrayList<String> lore = new ArrayList<>(); @@ -102,7 +106,7 @@ public class GUIPlayers extends AbstractGUI { } for (int i = 0; i < 9; i++) - createButton(36 + i, Material.GRAY_STAINED_GLASS_PANE, "&1"); + createButton(36 + i, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1"); createButton(51, Material.CHEST, "&7Tickets"); createButton(52, Material.MAP, plugin.getLocale().getMessage("gui.players.button.templatemanager")); diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/GUIPunish.java b/src/main/java/com/songoda/ultimatemoderation/gui/GUIPunish.java index c120cc6..e8c2898 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/GUIPunish.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/GUIPunish.java @@ -5,6 +5,7 @@ import com.songoda.ultimatemoderation.punish.Punishment; import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.template.Template; import com.songoda.ultimatemoderation.utils.Methods; +import com.songoda.ultimatemoderation.utils.ServerVersion; import com.songoda.ultimatemoderation.utils.gui.AbstractAnvilGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import org.bukkit.Bukkit; @@ -54,9 +55,12 @@ public class GUIPunish extends AbstractGUI { @Override protected void constructGUI() { inventory.clear(); - ItemStack head = new ItemStack(Material.PLAYER_HEAD); + ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3); SkullMeta meta = ((SkullMeta) head.getItemMeta()); - meta.setOwningPlayer(toModerate); + if (plugin.isServerVersionAtLeast(ServerVersion.V1_13)) + meta.setOwningPlayer(toModerate); + else + meta.setOwner(toModerate.getName()); head.setItemMeta(meta); if (toModerate != null) @@ -64,7 +68,7 @@ public class GUIPunish extends AbstractGUI { createButton(22, Material.EMERALD_BLOCK, plugin.getLocale().getMessage("gui.punish.submit")); - createButton(8, Material.OAK_DOOR, plugin.getLocale().getMessage("gui.general.back")); + createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.OAK_DOOR : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back")); createButton(28, Material.ANVIL, plugin.getLocale().getMessage("gui.punish.type.punishment"), "&7" + type.getTranslation(), @@ -86,7 +90,7 @@ public class GUIPunish extends AbstractGUI { } if (type != PunishmentType.KICK) { - createButton(32, Material.CLOCK, plugin.getLocale().getMessage("gui.punish.type.duration"), + createButton(32, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"), plugin.getLocale().getMessage("gui.punish.type.duration"), plugin.getLocale().getMessage("gui.punish.type.duration.leftclick"), plugin.getLocale().getMessage("gui.punish.type.duration.rightclick"), "", @@ -106,7 +110,7 @@ public class GUIPunish extends AbstractGUI { return; } - Material material = Material.WHITE_WOOL; + Material material = plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.WHITE_WOOL : Material.valueOf("WOOL"); String name = plugin.getLocale().getMessage("gui.punish.template.create"); ArrayList<String> lore = new ArrayList<>(); lore.add(plugin.getLocale().getMessage("gui.punish.template.create2")); @@ -119,7 +123,7 @@ public class GUIPunish extends AbstractGUI { lore.add(plugin.getLocale().getMessage("gui.punish.template.rightclick")); } - if (inventory.getItem(4) != null && inventory.getItem(4).getType() == Material.WHITE_WOOL) + if (plugin.isServerVersionAtLeast(ServerVersion.V1_13) && inventory.getItem(4) != null && inventory.getItem(4).getType() == Material.WHITE_WOOL) material = Material.YELLOW_WOOL; createButton(4, material, name, lore); diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/GUIPunishments.java b/src/main/java/com/songoda/ultimatemoderation/gui/GUIPunishments.java index 3cd632e..d1b802f 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/GUIPunishments.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/GUIPunishments.java @@ -7,11 +7,13 @@ import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.player.PlayerPunishData; import com.songoda.ultimatemoderation.tickets.TicketResponse; import com.songoda.ultimatemoderation.utils.Methods; +import com.songoda.ultimatemoderation.utils.ServerVersion; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import org.omg.PortableInterceptor.ACTIVE; import java.util.*; @@ -87,13 +89,13 @@ public class GUIPunishments extends AbstractGUI { })); } - createButton(8, Material.OAK_DOOR, plugin.getLocale().getMessage("gui.general.back")); + createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.OAK_DOOR : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back")); createButton(3, Material.APPLE, Methods.formatText("&6" + currentActivity.getTranslation())); createButton(4, Material.DIAMOND_SWORD, Methods.formatText("&6" + punishmentType.name())); for (int i = 0; i < 9; i++) - createButton(9 + i, Material.GRAY_STAINED_GLASS_PANE, "&1"); + createButton(9 + i, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1"); int currentSlot = 18; for (PunishmentHolder punishmentHolder : punishments) { diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/GUITemplateManager.java b/src/main/java/com/songoda/ultimatemoderation/gui/GUITemplateManager.java index ed0d78f..25d69e6 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/GUITemplateManager.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/GUITemplateManager.java @@ -5,10 +5,12 @@ import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.template.Template; import com.songoda.ultimatemoderation.tickets.TicketResponse; import com.songoda.ultimatemoderation.utils.Methods; +import com.songoda.ultimatemoderation.utils.ServerVersion; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.List; @@ -59,12 +61,12 @@ public class GUITemplateManager extends AbstractGUI { createButton(3 ,Material.DIAMOND_SWORD, Methods.formatText("&6" + punishmentType.name())); - createButton(8, Material.OAK_DOOR, plugin.getLocale().getMessage("gui.general.back")); + createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.OAK_DOOR : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back")); createButton(7, Material.REDSTONE, plugin.getLocale().getMessage("gui.templatemanager.create")); for (int i = 0; i < 9; i++) - createButton(9 + i, Material.GRAY_STAINED_GLASS_PANE, "&1"); + createButton(9 + i, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1"); if (punishmentType != PunishmentType.ALL) templates.removeIf(template -> template.getPunishmentType() != punishmentType); diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/GUITemplateSelector.java b/src/main/java/com/songoda/ultimatemoderation/gui/GUITemplateSelector.java index ef7efe5..fef070d 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/GUITemplateSelector.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/GUITemplateSelector.java @@ -4,9 +4,11 @@ import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.template.Template; import com.songoda.ultimatemoderation.utils.Methods; +import com.songoda.ultimatemoderation.utils.ServerVersion; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import java.util.ArrayList; @@ -25,10 +27,10 @@ public class GUITemplateSelector extends AbstractGUI { @Override protected void constructGUI() { - createButton(8, Material.OAK_DOOR, plugin.getLocale().getMessage("gui.general.back")); + createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.OAK_DOOR : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back")); for (int i = 0; i < 9; i++) - createButton(9 + i, Material.GRAY_STAINED_GLASS_PANE, "&1"); + createButton(9 + i, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1"); ArrayList<Template> templates = new ArrayList<>(plugin.getTemplateManager().getTemplates().values()); for (int i = 0; i < templates.size(); i++) { diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/GUITicket.java b/src/main/java/com/songoda/ultimatemoderation/gui/GUITicket.java index 3540cce..553e0a7 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/GUITicket.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/GUITicket.java @@ -5,6 +5,7 @@ import com.songoda.ultimatemoderation.tickets.Ticket; import com.songoda.ultimatemoderation.tickets.TicketResponse; import com.songoda.ultimatemoderation.tickets.TicketStatus; import com.songoda.ultimatemoderation.utils.AbstractChatConfirm; +import com.songoda.ultimatemoderation.utils.ServerVersion; import com.songoda.ultimatemoderation.utils.gui.AbstractAnvilGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import org.bukkit.Bukkit; @@ -69,7 +70,7 @@ public class GUITicket extends AbstractGUI { if (player.hasPermission("um.ticket.openclose")) createButton(5, Material.REDSTONE, "&6" + ticket.getStatus().getStatus()); - createButton(8, Material.OAK_DOOR, plugin.getLocale().getMessage("gui.general.back")); + createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.OAK_DOOR : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back")); if (player.hasPermission("um.ticket.clicktotele") && ticket.getLocation() != null) createButton(7, Material.REDSTONE, plugin.getLocale().getMessage("gui.ticket.clicktotele")); @@ -77,7 +78,7 @@ public class GUITicket extends AbstractGUI { createButton(6, Material.REDSTONE, plugin.getLocale().getMessage("gui.ticket.respond")); for (int i = 0; i < 9; i++) - createButton(9 + i, Material.GRAY_STAINED_GLASS_PANE, "&1"); + createButton(9 + i, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1"); for (int i = 0; i < responses.size(); i++) { TicketResponse ticketResponse = responses.get(i); diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/GUITicketManager.java b/src/main/java/com/songoda/ultimatemoderation/gui/GUITicketManager.java index a9b4ebb..4fe3cae 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/GUITicketManager.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/GUITicketManager.java @@ -7,6 +7,7 @@ import com.songoda.ultimatemoderation.tickets.TicketResponse; import com.songoda.ultimatemoderation.tickets.TicketStatus; import com.songoda.ultimatemoderation.utils.AbstractChatConfirm; import com.songoda.ultimatemoderation.utils.Methods; +import com.songoda.ultimatemoderation.utils.ServerVersion; import com.songoda.ultimatemoderation.utils.gui.AbstractAnvilGUI; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; import org.bukkit.Bukkit; @@ -75,10 +76,10 @@ public class GUITicketManager extends AbstractGUI { createButton(7, Material.REDSTONE, plugin.getLocale().getMessage("gui.tickets.create")); if (player.hasPermission("um.ticket")) - createButton(8, Material.OAK_DOOR, plugin.getLocale().getMessage("gui.general.back")); + createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.OAK_DOOR : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back")); for (int i = 0; i < 9; i++) - createButton(9 + i, Material.GRAY_STAINED_GLASS_PANE, "&1"); + createButton(9 + i, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1"); for (int i = 0; i < tickets.size(); i++) { Ticket ticket = tickets.get(i); diff --git a/src/main/java/com/songoda/ultimatemoderation/tasks/SlowModeTask.java b/src/main/java/com/songoda/ultimatemoderation/tasks/SlowModeTask.java index c5a74e3..6be5417 100644 --- a/src/main/java/com/songoda/ultimatemoderation/tasks/SlowModeTask.java +++ b/src/main/java/com/songoda/ultimatemoderation/tasks/SlowModeTask.java @@ -3,6 +3,7 @@ package com.songoda.ultimatemoderation.tasks; import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.listeners.ChatListener; import com.songoda.ultimatemoderation.utils.Methods; +import com.songoda.ultimatemoderation.utils.ServerVersion; import com.songoda.ultimatemoderation.utils.SettingsManager; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; @@ -48,6 +49,7 @@ public class SlowModeTask extends BukkitRunnable { if ((System.currentTimeMillis() - last.getSent()) < (slowmode + 1000)) { int remaining = (int)((slowmode / 1000) - (System.currentTimeMillis() - last.getSent()) / 1000); + if (plugin.isServerVersionAtLeast(ServerVersion.V1_9)) player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(remaining == 0 ? plugin.getLocale().getMessage("event.slowmode.done") : plugin.getLocale().getMessage("event.slowmode.wait", remaining))); } diff --git a/src/main/java/com/songoda/ultimatemoderation/utils/Methods.java b/src/main/java/com/songoda/ultimatemoderation/utils/Methods.java index 5767829..7d206a7 100644 --- a/src/main/java/com/songoda/ultimatemoderation/utils/Methods.java +++ b/src/main/java/com/songoda/ultimatemoderation/utils/Methods.java @@ -33,9 +33,11 @@ public class Methods { int randomNum = 1 + (int) (Math.random() * 6); ItemStack glass; if (rainbow) { - glass = new ItemStack(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) randomNum); + glass = new ItemStack(UltimateModeration.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? + Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) randomNum); } else { - glass = new ItemStack(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) type); + glass = new ItemStack(UltimateModeration.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? + Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) type); } ItemMeta glassmeta = glass.getItemMeta(); glassmeta.setDisplayName("§l"); diff --git a/src/main/java/com/songoda/ultimatemoderation/utils/ServerVersion.java b/src/main/java/com/songoda/ultimatemoderation/utils/ServerVersion.java new file mode 100644 index 0000000..66be358 --- /dev/null +++ b/src/main/java/com/songoda/ultimatemoderation/utils/ServerVersion.java @@ -0,0 +1,26 @@ +package com.songoda.ultimatemoderation.utils; + +public enum ServerVersion { + + UNKNOWN("unknown_server_version"), + V1_7("org.bukkit.craftbukkit.v1_7"), + V1_8("org.bukkit.craftbukkit.v1_8"), + V1_9("org.bukkit.craftbukkit.v1_9"), + V1_10("org.bukkit.craftbukkit.v1_10"), + V1_11("org.bukkit.craftbukkit.v1_11"), + V1_12("org.bukkit.craftbukkit.v1_12"), + V1_13("org.bukkit.craftbukkit.v1_13"); + + + private final String packagePrefix; + + private ServerVersion(String packagePrefix) { + this.packagePrefix = packagePrefix; + } + + public static ServerVersion fromPackageName(String packageName) { + for (ServerVersion version : values()) + if (packageName.startsWith(version.packagePrefix)) return version; + return ServerVersion.UNKNOWN; + } +} \ No newline at end of file diff --git a/src/main/java/com/songoda/ultimatemoderation/utils/SettingsManager.java b/src/main/java/com/songoda/ultimatemoderation/utils/SettingsManager.java index 6a4435c..f024bdb 100644 --- a/src/main/java/com/songoda/ultimatemoderation/utils/SettingsManager.java +++ b/src/main/java/com/songoda/ultimatemoderation/utils/SettingsManager.java @@ -113,7 +113,7 @@ public class SettingsManager implements Listener { int slot = 10; for (String key : instance.getConfig().getDefaultSection().getKeys(false)) { - ItemStack item = new ItemStack(Material.WHITE_WOOL, 1, (byte) (slot - 9)); //ToDo: Make this function as it was meant to. + ItemStack item = new ItemStack(instance.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.WHITE_WOOL : Material.valueOf("WOOL"), 1, (byte) (slot - 9)); //ToDo: Make this function as it was meant to. ItemMeta meta = item.getItemMeta(); meta.setLore(Collections.singletonList(Methods.formatText("&6Click To Edit This Category."))); meta.setDisplayName(Methods.formatText("&f&l" + key)); @@ -144,7 +144,7 @@ public class SettingsManager implements Listener { item.setType(Material.PAPER); lore.add(Methods.formatText("&9" + config.getString(fKey))); } else if (config.isInt(fKey)) { - item.setType(Material.CLOCK); + item.setType(instance.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH")); lore.add(Methods.formatText("&5" + config.getInt(fKey))); } diff --git a/src/main/java/com/songoda/ultimatemoderation/utils/gui/AbstractAnvilGUI.java b/src/main/java/com/songoda/ultimatemoderation/utils/gui/AbstractAnvilGUI.java index f00d0a6..5dbeb2d 100644 --- a/src/main/java/com/songoda/ultimatemoderation/utils/gui/AbstractAnvilGUI.java +++ b/src/main/java/com/songoda/ultimatemoderation/utils/gui/AbstractAnvilGUI.java @@ -1,6 +1,7 @@ package com.songoda.ultimatemoderation.utils.gui; import com.songoda.ultimatemoderation.UltimateModeration; +import com.songoda.ultimatemoderation.utils.ServerVersion; import com.songoda.ultimatemoderation.utils.version.NMSUtil; import org.bukkit.Bukkit; import org.bukkit.Sound; @@ -37,7 +38,7 @@ public class AbstractAnvilGUI { private Inventory inv; private Listener listener; - private Sound closeSound = Sound.ENTITY_PLAYER_LEVELUP; + private Sound closeSound = UltimateModeration.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? Sound.ENTITY_PLAYER_LEVELUP : Sound.valueOf("LEVEL_UP"); public AbstractAnvilGUI(final Player player, final AnvilClickEventHandler handler) { loadClasses(); diff --git a/src/main/java/com/songoda/ultimatemoderation/utils/gui/AbstractGUI.java b/src/main/java/com/songoda/ultimatemoderation/utils/gui/AbstractGUI.java index 8ca569a..e6eb1dc 100644 --- a/src/main/java/com/songoda/ultimatemoderation/utils/gui/AbstractGUI.java +++ b/src/main/java/com/songoda/ultimatemoderation/utils/gui/AbstractGUI.java @@ -163,6 +163,13 @@ public abstract class AbstractGUI implements Listener { return createButton(slot, inventory, item, name, lore); } + protected ItemStack createButton(int slot, Object item, String name, String... lore) { + if (item instanceof ItemStack) + return createButton(slot, inventory, (ItemStack)item, name, lore); + else + return createButton(slot, inventory, (Material)item, name, lore); + } + protected ItemStack createButton(int slot, Inventory inventory, Material material, String name, String... lore) { return createButton(slot, inventory, new ItemStack(material), name, lore); } diff --git a/src/main/java/com/songoda/ultimatemoderation/utils/gui/Range.java b/src/main/java/com/songoda/ultimatemoderation/utils/gui/Range.java index 43f9e96..d5b46a1 100644 --- a/src/main/java/com/songoda/ultimatemoderation/utils/gui/Range.java +++ b/src/main/java/com/songoda/ultimatemoderation/utils/gui/Range.java @@ -1,5 +1,7 @@ package com.songoda.ultimatemoderation.utils.gui; +import com.songoda.ultimatemoderation.UltimateModeration; +import com.songoda.ultimatemoderation.utils.ServerVersion; import org.bukkit.Sound; import org.bukkit.event.inventory.ClickType; @@ -9,13 +11,14 @@ public class Range { private int max; private ClickType clickType; private boolean bottom; - private Sound onClickSound = Sound.UI_BUTTON_CLICK; + private Sound onClickSound; public Range(int min, int max, ClickType clickType, boolean bottom) { this.min = min; this.max = max; this.clickType = clickType; this.bottom = bottom; + if (UltimateModeration.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) onClickSound = Sound.UI_BUTTON_CLICK; } public Range(int min, int max, Sound onClickSound, ClickType clickType, boolean bottom) {