From 09927ed970e53349e245cbc4232942ef37b386bb Mon Sep 17 00:00:00 2001 From: Christopher White <18whitechristop@gmail.com> Date: Sat, 31 May 2025 14:54:44 -0700 Subject: [PATCH] Add compatibility interfaces Signed-off-by: Christopher White <18whitechristop@gmail.com> --- .../java/dev/pgm/community/Community.java | 2 +- .../assistance/menu/ReportReasonsMenu.java | 2 +- .../pgm/community/freeze/FreezeManager.java | 36 ++-- .../pgm/community/menu/MapSelectionMenu.java | 125 ++++-------- .../menu/PlayerSelectionProvider.java | 3 +- .../dev/pgm/community/mobs/MobCommand.java | 190 ++++++++--------- .../tools/buttons/types/GamemodeButton.java | 15 +- .../types/ObserverVisibilityButton.java | 3 +- .../tools/menu/ModerationToolsMenu.java | 41 ++-- .../moderation/tools/types/LookupSign.java | 3 +- .../pgm/community/mutations/MutationType.java | 30 +-- .../mutations/menu/MutationOptionsMenu.java | 25 ++- .../mutations/menu/MutationToggleMenu.java | 25 +-- .../types/arrows/WebSlingersMutation.java | 61 +++--- .../mutations/types/items/BreadMutation.java | 187 ++++++++--------- .../types/items/CannonSuppliesMutation.java | 36 ++-- .../types/items/ExplosionMutation.java | 132 ++++++------ .../types/items/FireworkMutation.java | 7 +- .../mapdev/ProximityEffectsMutation.java | 61 +++--- .../types/mechanics/KnockbackMutation.java | 2 +- .../types/mechanics/MobMutation.java | 3 +- .../dev/pgm/community/party/MapPartyType.java | 2 +- .../party/menu/MapPartyMainMenu.java | 103 ++++------ .../community/party/menu/MapPartyMenu.java | 32 ++- .../community/party/menu/hosts/HostMenu.java | 39 ++-- .../community/party/menu/maps/MapAddMenu.java | 166 +++++---------- .../community/party/menu/maps/MapMenu.java | 43 ++-- .../menu/settings/MapPartySettingsMenu.java | 191 ++++++++---------- .../party/settings/MapPartySettings.java | 40 ++-- .../commands/sponsor/SponsorCommands.java | 2 +- .../community/requests/menu/SponsorMenu.java | 24 +-- .../dev/pgm/community/utils/PGMUtils.java | 29 +++ .../dev/pgm/community/utils/SkullUtils.java | 10 +- .../utils/compatibility/Enchantments.java | 13 ++ .../utils/compatibility/EntityTypes.java | 12 ++ .../utils/compatibility/Materials.java | 45 +++++ .../utils/compatibility/PotionEffects.java | 18 ++ 37 files changed, 822 insertions(+), 936 deletions(-) create mode 100644 core/src/main/java/dev/pgm/community/utils/compatibility/Enchantments.java create mode 100644 core/src/main/java/dev/pgm/community/utils/compatibility/EntityTypes.java create mode 100644 core/src/main/java/dev/pgm/community/utils/compatibility/Materials.java create mode 100644 core/src/main/java/dev/pgm/community/utils/compatibility/PotionEffects.java diff --git a/core/src/main/java/dev/pgm/community/Community.java b/core/src/main/java/dev/pgm/community/Community.java index 99c10d92..ac5dce94 100644 --- a/core/src/main/java/dev/pgm/community/Community.java +++ b/core/src/main/java/dev/pgm/community/Community.java @@ -9,8 +9,8 @@ import dev.pgm.community.utils.PGMUtils; import fr.minuskube.inv.InventoryManager; import java.util.Random; -import net.md_5.bungee.api.ChatColor; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; import tc.oc.pgm.api.integration.Integration; diff --git a/core/src/main/java/dev/pgm/community/assistance/menu/ReportReasonsMenu.java b/core/src/main/java/dev/pgm/community/assistance/menu/ReportReasonsMenu.java index d69ccd76..922b168b 100644 --- a/core/src/main/java/dev/pgm/community/assistance/menu/ReportReasonsMenu.java +++ b/core/src/main/java/dev/pgm/community/assistance/menu/ReportReasonsMenu.java @@ -4,7 +4,7 @@ import dev.pgm.community.menu.CommunityInventoryProvider; import fr.minuskube.inv.content.InventoryContents; import java.util.function.Consumer; -import net.md_5.bungee.api.ChatColor; +import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; diff --git a/core/src/main/java/dev/pgm/community/freeze/FreezeManager.java b/core/src/main/java/dev/pgm/community/freeze/FreezeManager.java index 8e2016fd..5c78c2a8 100644 --- a/core/src/main/java/dev/pgm/community/freeze/FreezeManager.java +++ b/core/src/main/java/dev/pgm/community/freeze/FreezeManager.java @@ -26,7 +26,7 @@ import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.title.Title.Times; import net.kyori.adventure.util.Ticks; -import net.md_5.bungee.api.ChatColor; +import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -95,11 +95,10 @@ public void setFrozen( // Don't allow freezing if player is exempt if (freezee.hasPermission(CommunityPermissions.FREEZE_EXEMPT) && !freezer.getSender().hasPermission(CommunityPermissions.FREEZE_FORCE)) { - freezer.sendWarning( - text() - .append(PlayerComponent.player(freezee, NameStyle.FANCY)) - .append(text(" can not be frozen")) - .build()); + freezer.sendWarning(text() + .append(PlayerComponent.player(freezee, NameStyle.FANCY)) + .append(text(" can not be frozen")) + .build()); return; } @@ -138,11 +137,10 @@ private void freeze(Player freezee, Component senderName, boolean silent) { Audience.get(freezee).sendWarning(freezeTitle.build()); } else { Audience.get(freezee) - .showTitle( - title( - empty(), - freezeTitle.build(), - Times.of(Ticks.duration(5), Ticks.duration(9999), Ticks.duration(5)))); + .showTitle(title( + empty(), + freezeTitle.build(), + Times.of(Ticks.duration(5), Ticks.duration(9999), Ticks.duration(5)))); } Audience.get(freezee).playSound(FREEZE_SOUND); @@ -172,15 +170,13 @@ private void thaw(Player freezee, Component senderName, boolean silent) { private Component createInteractiveBroadcast( Component senderName, Player freezee, boolean frozen) { return text() - .append( - translatable( - String.format("moderation.freeze.broadcast.%s", frozen ? "frozen" : "thaw"), - NamedTextColor.GRAY, - senderName, - PlayerComponent.player(freezee, NameStyle.FANCY))) - .hoverEvent( - HoverEvent.showText( - translatable("moderation.freeze.broadcast.hover", NamedTextColor.GRAY))) + .append(translatable( + String.format("moderation.freeze.broadcast.%s", frozen ? "frozen" : "thaw"), + NamedTextColor.GRAY, + senderName, + PlayerComponent.player(freezee, NameStyle.FANCY))) + .hoverEvent(HoverEvent.showText( + translatable("moderation.freeze.broadcast.hover", NamedTextColor.GRAY))) .clickEvent(ClickEvent.runCommand("/f " + freezee.getName())) .build(); } diff --git a/core/src/main/java/dev/pgm/community/menu/MapSelectionMenu.java b/core/src/main/java/dev/pgm/community/menu/MapSelectionMenu.java index 8fd7ed19..302d3d9d 100644 --- a/core/src/main/java/dev/pgm/community/menu/MapSelectionMenu.java +++ b/core/src/main/java/dev/pgm/community/menu/MapSelectionMenu.java @@ -1,11 +1,14 @@ package dev.pgm.community.menu; +import static dev.pgm.community.utils.PGMUtils.mapTagMaterial; import static net.kyori.adventure.text.Component.text; import static tc.oc.pgm.util.bukkit.BukkitUtils.colorize; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import dev.pgm.community.Community; +import dev.pgm.community.utils.compatibility.Enchantments; +import dev.pgm.community.utils.compatibility.Materials; import fr.minuskube.inv.ClickableItem; import fr.minuskube.inv.SmartInventory; import fr.minuskube.inv.content.InventoryContents; @@ -20,7 +23,6 @@ import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.DyeColor; import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; @@ -57,12 +59,11 @@ public MapSelectionMenu(String title, List maps, Player viewer) { } public SmartInventory getInventory(SmartInventory parent) { - SmartInventory.Builder builder = - SmartInventory.builder() - .title(colorize(title)) - .provider(this) - .manager(Community.get().getInventory()) - .size(ROWS, 9); + SmartInventory.Builder builder = SmartInventory.builder() + .title(colorize(title)) + .provider(this) + .manager(Community.get().getInventory()) + .size(ROWS, 9); if (parent != null) { builder.parent(parent); @@ -136,7 +137,8 @@ public Material getMapMaterial(MapInfo map) { return map.getTags().isEmpty() || !map.getTags().stream().filter(tag -> tag.isGamemode()).findAny().isPresent() ? Material.MAP - : getMapTagMaterial(map.getTags().stream().filter(tag -> tag.isGamemode()).findAny().get()); + : mapTagMaterial( + map.getTags().stream().filter(tag -> tag.isGamemode()).findAny().get()); } private List getMapItems(List maps) { @@ -144,47 +146,41 @@ private List getMapItems(List maps) { } private List getFilteredMapItems() { - return getMapItems( - maps.stream() - .filter( - map -> { - if (viewAll) return true; - - Collection tags = map.getTags(); - return tags != null && tags.contains(getFilterTag()); - }) - .collect(Collectors.toList())); + return getMapItems(maps.stream() + .filter(map -> { + if (viewAll) return true; + + Collection tags = map.getTags(); + return tags != null && tags.contains(getFilterTag()); + }) + .collect(Collectors.toList())); } private ClickableItem getNoMapsIcon() { - return ClickableItem.empty( - new ItemBuilder() - .material(Material.STAINED_GLASS_PANE) - .color(DyeColor.RED) - .name(colorize("&cNo Maps found")) - .lore(colorize("&7Check &b/maps &7for details")) - .flags(ItemFlag.values()) - .build()); + return ClickableItem.empty(new ItemBuilder() + .material(Materials.STAINED_GLASS_PANE) + .color(DyeColor.RED) + .name(colorize("&cNo Maps found")) + .lore(colorize("&7Check &b/maps &7for details")) + .flags(ItemFlag.values()) + .build()); } private ClickableItem getAllIcon() { - ItemBuilder allItemBuilder = - new ItemBuilder() - .material(Material.BOOKSHELF) - .name(colorize((viewAll ? "&a" : "&c") + "View All")) - .lore(colorize(viewAll ? "&7Click to filter by map tags" : "&7Click to view all maps")) - .flags(ItemFlag.values()); + ItemBuilder allItemBuilder = new ItemBuilder() + .material(Material.BOOKSHELF) + .name(colorize((viewAll ? "&a" : "&c") + "View All")) + .lore(colorize(viewAll ? "&7Click to filter by map tags" : "&7Click to view all maps")) + .flags(ItemFlag.values()); if (viewAll) { - allItemBuilder.enchant(Enchantment.LUCK, 1); + allItemBuilder.enchant(Enchantments.LUCK_OF_THE_SEA, 1); } - return ClickableItem.of( - allItemBuilder.build(), - c -> { - this.viewAll = !viewAll; - getInventory().open(getViewer(), 0); - }); + return ClickableItem.of(allItemBuilder.build(), c -> { + this.viewAll = !viewAll; + getInventory().open(getViewer(), 0); + }); } private ClickableItem getFilterIcon() { @@ -194,13 +190,13 @@ private ClickableItem getFilterIcon() { return ClickableItem.of( new ItemBuilder() - .material(getMapTagMaterial(getFilterTag())) + .material(mapTagMaterial(getFilterTag())) .name(TextTranslations.translateLegacy(getFilterTag().getName(), getViewer())) .lore( colorize("&7Filter: &b" + (filterIndex + 1) + " &7/&3 " + tags.size()), colorize( "&7Total Maps: &a" + getFilteredMapItems().size() + " &7/&2 " + maps.size())) - .enchant(Enchantment.LUCK, 1) + .enchant(Enchantments.LUCK_OF_THE_SEA, 1) .flags(ItemFlag.values()) .build(), c -> { @@ -233,53 +229,6 @@ protected Component renderMapTags(MapInfo map) { NamedTextColor.GRAY); } - private Material getMapTagMaterial(MapTag mapTag) { - switch (mapTag.getId()) { - case "2teams": - return Material.LEATHER; - case "ffa": - return Material.DIAMOND_SWORD; - case "border": - return Material.IRON_BARDING; - case "wool": - return Material.WOOL; - case "controlpoint": - return Material.BEACON; - case "flag": - return Material.BANNER; - case "classes": - return Material.FISHING_ROD; - case "deathmatch": - return Material.STONE_SWORD; - case "monument": - return Material.DIAMOND_PICKAXE; - case "4teams": - return Material.TRAP_DOOR; - case "timelimit": - return Material.WATCH; - case "autotnt": - return Material.TNT; - case "core": - return Material.OBSIDIAN; - case "blitz": - return Material.EGG; - case "scorebox": - return Material.WEB; - case "6teams": - return Material.BED; - case "rage": - return Material.BOW; - case "3teams": - return Material.WORKBENCH; - case "terrain": - return Material.GRASS; - case "8teams": - return Material.INK_SACK; - default: - return Material.MAP; - } - } - private MapTag getFilterTag() { return tags.get(filterIndex); } diff --git a/core/src/main/java/dev/pgm/community/menu/PlayerSelectionProvider.java b/core/src/main/java/dev/pgm/community/menu/PlayerSelectionProvider.java index a7d8efe3..0b42bfe9 100644 --- a/core/src/main/java/dev/pgm/community/menu/PlayerSelectionProvider.java +++ b/core/src/main/java/dev/pgm/community/menu/PlayerSelectionProvider.java @@ -4,6 +4,7 @@ import static tc.oc.pgm.util.nms.NMSHacks.NMS_HACKS; import static tc.oc.pgm.util.nms.PlayerUtils.PLAYER_UTILS; +import dev.pgm.community.utils.compatibility.Materials; import fr.minuskube.inv.ClickableItem; import fr.minuskube.inv.SmartInventory; import fr.minuskube.inv.content.InventoryContents; @@ -111,7 +112,7 @@ private ClickableItem getPlayerItem( } private ItemStack getPlayerHead(Player viewer, Player player) { - ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3); + ItemStack head = new ItemStack(Materials.SKULL_ITEM, 1, (byte) 3); SkullMeta meta = (SkullMeta) head.getItemMeta(); meta.setDisplayName(player.getDisplayName()); meta.setLore(getPlayerLore(viewer, player)); diff --git a/core/src/main/java/dev/pgm/community/mobs/MobCommand.java b/core/src/main/java/dev/pgm/community/mobs/MobCommand.java index 4c7337d1..13e99c59 100644 --- a/core/src/main/java/dev/pgm/community/mobs/MobCommand.java +++ b/core/src/main/java/dev/pgm/community/mobs/MobCommand.java @@ -12,7 +12,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; -import org.apache.commons.lang3.text.WordUtils; +import org.apache.commons.lang.WordUtils; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -40,11 +40,10 @@ public MobCommand() { public void viewMobs(CommandAudience audience, Player sender) { List ownedMobs = mobs.getOwnedMobs(sender); if (!ownedMobs.isEmpty()) { - audience.sendMessage( - TextFormatter.horizontalLineHeading( - sender, - text("Mobs", NamedTextColor.GREEN, TextDecoration.BOLD), - NamedTextColor.DARK_GREEN)); + audience.sendMessage(TextFormatter.horizontalLineHeading( + sender, + text("Mobs", NamedTextColor.GREEN, TextDecoration.BOLD), + NamedTextColor.DARK_GREEN)); sendEntityTotals(audience, ownedMobs); } else { @@ -52,36 +51,22 @@ public void viewMobs(CommandAudience audience, Player sender) { return; } - Component mobActions = - text() - .append( - button( - "Teleport", - NamedTextColor.GREEN, - "/mobs tphere", - "Click to teleport mobs here")) - .append(space()) - .append(button("Clear", NamedTextColor.RED, "/mobs clear", "Click to remove all mobs")) - .append(space()) - .append(button("Heal", NamedTextColor.LIGHT_PURPLE, "/mobs heal", "Click to heal mobs")) - .build(); - - Component mobModes = - text() - .append( - button( - "Follow", - NamedTextColor.DARK_GREEN, - "/mobs follow", - "Click to toggle follow mode")) - .append(space()) - .append( - button( - "Attack", - NamedTextColor.DARK_RED, - "/mobs attack", - "Click to toggle mob targeting")) - .build(); + Component mobActions = text() + .append( + button("Teleport", NamedTextColor.GREEN, "/mobs tphere", "Click to teleport mobs here")) + .append(space()) + .append(button("Clear", NamedTextColor.RED, "/mobs clear", "Click to remove all mobs")) + .append(space()) + .append(button("Heal", NamedTextColor.LIGHT_PURPLE, "/mobs heal", "Click to heal mobs")) + .build(); + + Component mobModes = text() + .append(button( + "Follow", NamedTextColor.DARK_GREEN, "/mobs follow", "Click to toggle follow mode")) + .append(space()) + .append(button( + "Attack", NamedTextColor.DARK_RED, "/mobs attack", "Click to toggle mob targeting")) + .build(); audience.sendMessage(empty()); audience.sendMessage(text("Actions:", NamedTextColor.GRAY)); audience.sendMessage(mobActions); @@ -95,24 +80,20 @@ private void sendEntityTotals(CommandAudience audience, List mobs) for (EntityType type : EntityType.values()) { long typeTotal = mobs.stream().filter(le -> le.getType().equals(type)).count(); if (typeTotal > 0) { - audience.sendMessage( - text() - .append( - text( - WordUtils.capitalizeFully(type.toString().toLowerCase()), - NamedTextColor.DARK_AQUA)) - .append(text(" : ", NamedTextColor.GREEN)) - .append(text(typeTotal, NamedTextColor.YELLOW)) - .build()); + audience.sendMessage(text() + .append(text( + WordUtils.capitalizeFully(type.toString().toLowerCase()), NamedTextColor.DARK_AQUA)) + .append(text(" : ", NamedTextColor.GREEN)) + .append(text(typeTotal, NamedTextColor.YELLOW)) + .build()); } total += typeTotal; } - audience.sendMessage( - text() - .append(text("Total mobs spawned", NamedTextColor.GRAY)) - .append(text(" : ", NamedTextColor.GREEN)) - .append(text(total, NamedTextColor.GOLD)) - .build()); + audience.sendMessage(text() + .append(text("Total mobs spawned", NamedTextColor.GRAY)) + .append(text(" : ", NamedTextColor.GREEN)) + .append(text(total, NamedTextColor.GOLD)) + .build()); } @Command("spawn [amount]") @@ -129,14 +110,13 @@ public void mob( return; } mobs.spawn(sender, type, amount, !canDie); - audience.sendMessage( - text() - .append(text("Spawned ")) - .append(text(amount, NamedTextColor.YELLOW)) - .append(text(" ")) - .append(text(WordUtils.capitalize(type.toString().toLowerCase()), NamedTextColor.GREEN)) - .color(NamedTextColor.GRAY) - .build()); + audience.sendMessage(text() + .append(text("Spawned ")) + .append(text(amount, NamedTextColor.YELLOW)) + .append(text(" ")) + .append(text(WordUtils.capitalize(type.toString().toLowerCase()), NamedTextColor.GREEN)) + .color(NamedTextColor.GRAY) + .build()); } @Command("clear") @@ -144,13 +124,12 @@ public void mob( @Permission(CommunityPermissions.MOB_SPAWN) public void clear(CommandAudience audience, Player sender) { int mobsRemoved = mobs.remove(audience.getPlayer()); - audience.sendMessage( - text() - .append(text("Removed ")) - .append(text(mobsRemoved, NamedTextColor.RED)) - .append(text(" mob" + (mobsRemoved != 1 ? "s" : ""))) - .color(NamedTextColor.GRAY) - .build()); + audience.sendMessage(text() + .append(text("Removed ")) + .append(text(mobsRemoved, NamedTextColor.RED)) + .append(text(" mob" + (mobsRemoved != 1 ? "s" : ""))) + .color(NamedTextColor.GRAY) + .build()); } @Command("tphere|tph") @@ -158,13 +137,12 @@ public void clear(CommandAudience audience, Player sender) { @Permission(CommunityPermissions.MOB_SPAWN) public void tphere(CommandAudience audience, Player sender) { int mobsTeleported = mobs.tphere(audience.getPlayer()); - audience.sendMessage( - text() - .append(text("Teleported ")) - .append(text(mobsTeleported, NamedTextColor.GREEN)) - .append(text(" mob" + (mobsTeleported != 1 ? "s" : "") + " to your location")) - .color(NamedTextColor.GRAY) - .build()); + audience.sendMessage(text() + .append(text("Teleported ")) + .append(text(mobsTeleported, NamedTextColor.GREEN)) + .append(text(" mob" + (mobsTeleported != 1 ? "s" : "") + " to your location")) + .color(NamedTextColor.GRAY) + .build()); } @Command("heal") @@ -172,13 +150,12 @@ public void tphere(CommandAudience audience, Player sender) { @Permission(CommunityPermissions.MOB_SPAWN) public void heal(CommandAudience audience, Player sender) { int mobsHealed = mobs.heal(audience.getPlayer()); - audience.sendMessage( - text() - .append(text("Healed ")) - .append(text(mobsHealed, NamedTextColor.GREEN)) - .append(text(" mob" + (mobsHealed != 1 ? "s" : ""))) - .color(NamedTextColor.GRAY) - .build()); + audience.sendMessage(text() + .append(text("Healed ")) + .append(text(mobsHealed, NamedTextColor.GREEN)) + .append(text(" mob" + (mobsHealed != 1 ? "s" : ""))) + .color(NamedTextColor.GRAY) + .build()); } @Command("attack [target]") @@ -188,23 +165,19 @@ public void heal(CommandAudience audience, Player sender) { public void attack(CommandAudience audience, Player sender, @Argument("target") Player target) { if (target != null) { mobs.attack(sender, target); - audience.sendMessage( - text() - .append(text("Spawned mobs will now attack ", NamedTextColor.GRAY)) - .append(PlayerComponent.player(target, NameStyle.FANCY)) - .build()); + audience.sendMessage(text() + .append(text("Spawned mobs will now attack ", NamedTextColor.GRAY)) + .append(PlayerComponent.player(target, NameStyle.FANCY)) + .build()); } else { boolean autoEnabled = mobs.toggleAutoAttack(sender); - audience.sendMessage( - text() - .append( - text() - .append(text("Hostile targeting has been ", NamedTextColor.GRAY)) - .append( - text( - autoEnabled ? "Enabled" : "Disabled", - autoEnabled ? NamedTextColor.GREEN : NamedTextColor.RED))) - .build()); + audience.sendMessage(text() + .append(text() + .append(text("Hostile targeting has been ", NamedTextColor.GRAY)) + .append(text( + autoEnabled ? "Enabled" : "Disabled", + autoEnabled ? NamedTextColor.GREEN : NamedTextColor.RED))) + .build()); } } @@ -213,16 +186,13 @@ public void attack(CommandAudience audience, Player sender, @Argument("target") @Permission(CommunityPermissions.MOB_SPAWN) public void follow(CommandAudience audience, Player sender) { boolean following = mobs.toggleFollow(audience.getPlayer()); - audience.sendMessage( - text() - .append( - text() - .append(text("Mob following has been ", NamedTextColor.GRAY)) - .append( - text( - following ? "Enabled" : "Disabled", - following ? NamedTextColor.GREEN : NamedTextColor.RED))) - .build()); + audience.sendMessage(text() + .append(text() + .append(text("Mob following has been ", NamedTextColor.GRAY)) + .append(text( + following ? "Enabled" : "Disabled", + following ? NamedTextColor.GREEN : NamedTextColor.RED))) + .build()); } @Command("speed ") @@ -230,11 +200,9 @@ public void follow(CommandAudience audience, Player sender) { @Permission(CommunityPermissions.MOB_SPAWN) public void speed(CommandAudience audience, @Argument("speed") float speed) { mobs.setSpeed(speed); - audience.sendMessage( - text() - .append( - text("Follow speed has been set to ", NamedTextColor.GRAY) - .append(text(speed, NamedTextColor.GREEN))) - .build()); + audience.sendMessage(text() + .append(text("Follow speed has been set to ", NamedTextColor.GRAY) + .append(text(speed, NamedTextColor.GREEN))) + .build()); } } diff --git a/core/src/main/java/dev/pgm/community/moderation/tools/buttons/types/GamemodeButton.java b/core/src/main/java/dev/pgm/community/moderation/tools/buttons/types/GamemodeButton.java index fb014a80..6c11ddfe 100644 --- a/core/src/main/java/dev/pgm/community/moderation/tools/buttons/types/GamemodeButton.java +++ b/core/src/main/java/dev/pgm/community/moderation/tools/buttons/types/GamemodeButton.java @@ -9,7 +9,7 @@ import java.util.function.Consumer; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import org.apache.commons.lang3.text.WordUtils; +import org.apache.commons.lang.WordUtils; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; @@ -39,10 +39,8 @@ public Component getLoreComponent() { // TODO: This is broken for some reason? Investigate later // String gamemode = TextTranslations.translate("gameMode." + // getViewer().getGameMode().name().toLowerCase(), getViewer()); - Component gamemode = - text( - WordUtils.capitalize(getViewer().getGameMode().name().toLowerCase()), - NamedTextColor.AQUA); + Component gamemode = text( + WordUtils.capitalize(getViewer().getGameMode().name().toLowerCase()), NamedTextColor.AQUA); return translatable("setting.gamemode.lore", NamedTextColor.GRAY, gamemode); } @@ -70,10 +68,9 @@ private void toggleObserverGameMode() { } private Component getToggleMessage() { - Component command = - text("/tools", NamedTextColor.AQUA) - .hoverEvent(showText(translatable("setting.gamemode.hover", NamedTextColor.GRAY))) - .clickEvent(runCommand("/tools")); + Component command = text("/tools", NamedTextColor.AQUA) + .hoverEvent(showText(translatable("setting.gamemode.hover", NamedTextColor.GRAY))) + .clickEvent(runCommand("/tools")); return translatable("setting.gamemode.warning", NamedTextColor.GRAY, command); } diff --git a/core/src/main/java/dev/pgm/community/moderation/tools/buttons/types/ObserverVisibilityButton.java b/core/src/main/java/dev/pgm/community/moderation/tools/buttons/types/ObserverVisibilityButton.java index b8fbce87..0940096d 100644 --- a/core/src/main/java/dev/pgm/community/moderation/tools/buttons/types/ObserverVisibilityButton.java +++ b/core/src/main/java/dev/pgm/community/moderation/tools/buttons/types/ObserverVisibilityButton.java @@ -3,6 +3,7 @@ import static net.kyori.adventure.text.Component.translatable; import dev.pgm.community.moderation.tools.buttons.TranslatableToolButton; +import dev.pgm.community.utils.compatibility.Materials; import java.util.function.Consumer; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -19,7 +20,7 @@ public class ObserverVisibilityButton extends TranslatableToolButton { private static final String NAME_KEY = "setting.visibility"; private static final String LORE_KEY = NAME_KEY + ".lore"; - private static final Material ON_MATERIAL = Material.EYE_OF_ENDER; + private static final Material ON_MATERIAL = Materials.EYE_OF_ENDER; private static final Material OFF_MATERIAL = Material.ENDER_PEARL; private static final NamedTextColor COLOR = NamedTextColor.YELLOW; private static final NamedTextColor ON_COLOR = NamedTextColor.GREEN; diff --git a/core/src/main/java/dev/pgm/community/moderation/tools/menu/ModerationToolsMenu.java b/core/src/main/java/dev/pgm/community/moderation/tools/menu/ModerationToolsMenu.java index a7f0345f..ce226b1f 100644 --- a/core/src/main/java/dev/pgm/community/moderation/tools/menu/ModerationToolsMenu.java +++ b/core/src/main/java/dev/pgm/community/moderation/tools/menu/ModerationToolsMenu.java @@ -7,6 +7,7 @@ import dev.pgm.community.moderation.tools.buttons.types.NightVisionButton; import dev.pgm.community.moderation.tools.buttons.types.ObserverVisibilityButton; import dev.pgm.community.moderation.tools.buttons.types.SpeedButton; +import dev.pgm.community.utils.compatibility.Materials; import fr.minuskube.inv.ClickableItem; import fr.minuskube.inv.SmartInventory; import fr.minuskube.inv.content.InventoryContents; @@ -14,7 +15,6 @@ import java.util.Random; import org.bukkit.ChatColor; import org.bukkit.DyeColor; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; @@ -27,13 +27,12 @@ public class ModerationToolsMenu implements InventoryProvider { private Random random; public ModerationToolsMenu() { - this.inventory = - SmartInventory.builder() - .manager(Community.get().getInventory()) - .size(4, 9) - .title(colorize("&aModeration Tools")) - .provider(this) - .build(); + this.inventory = SmartInventory.builder() + .manager(Community.get().getInventory()) + .size(4, 9) + .title(colorize("&aModeration Tools")) + .provider(this) + .build(); this.random = new Random(); } @@ -50,13 +49,12 @@ public void init(Player player, InventoryContents contents) { contents.fillRow( 1, - ClickableItem.empty( - new ItemBuilder() - .material(Material.STAINED_GLASS_PANE) - .color(DyeColor.BLACK) - .name(colorize("&4 Coming Soon")) - .flags(ItemFlag.values()) - .build())); + ClickableItem.empty(new ItemBuilder() + .material(Materials.STAINED_GLASS_PANE) + .color(DyeColor.BLACK) + .name(colorize("&4 Coming Soon")) + .flags(ItemFlag.values()) + .build())); } private void addItem(Player player, ItemStack item) { @@ -76,12 +74,11 @@ public void update(Player player, InventoryContents contents) { contents.fillRow( 1, - ClickableItem.empty( - new ItemBuilder() - .material(Material.STAINED_GLASS_PANE) - .color(DyeColor.values()[color]) - .name(colorize(cColor + "&lMore tools coming soon!")) - .flags(ItemFlag.values()) - .build())); + ClickableItem.empty(new ItemBuilder() + .material(Materials.STAINED_GLASS_PANE) + .color(DyeColor.values()[color]) + .name(colorize(cColor + "&lMore tools coming soon!")) + .flags(ItemFlag.values()) + .build())); } } diff --git a/core/src/main/java/dev/pgm/community/moderation/tools/types/LookupSign.java b/core/src/main/java/dev/pgm/community/moderation/tools/types/LookupSign.java index e6e28d77..6b92a846 100644 --- a/core/src/main/java/dev/pgm/community/moderation/tools/types/LookupSign.java +++ b/core/src/main/java/dev/pgm/community/moderation/tools/types/LookupSign.java @@ -2,6 +2,7 @@ import com.google.common.collect.Lists; import dev.pgm.community.moderation.tools.ToolBase; +import dev.pgm.community.utils.compatibility.Materials; import java.util.List; import org.bukkit.Material; import tc.oc.pgm.api.player.MatchPlayer; @@ -9,7 +10,7 @@ public class LookupSign extends ToolBase { - private static final Material MATERIAL = Material.SIGN; + private static final Material MATERIAL = Materials.SIGN; private static final String NAME = "&c&lLookup Sign"; private static final List LORE = diff --git a/core/src/main/java/dev/pgm/community/mutations/MutationType.java b/core/src/main/java/dev/pgm/community/mutations/MutationType.java index 83ac2955..591edfbd 100644 --- a/core/src/main/java/dev/pgm/community/mutations/MutationType.java +++ b/core/src/main/java/dev/pgm/community/mutations/MutationType.java @@ -2,12 +2,13 @@ import static net.kyori.adventure.text.Component.text; +import dev.pgm.community.utils.compatibility.Enchantments; +import dev.pgm.community.utils.compatibility.Materials; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.ChatColor; import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import tc.oc.pgm.util.inventory.ItemBuilder; @@ -15,24 +16,24 @@ public enum MutationType { RAGE("Rage", "Instant death", Material.BOW), BLITZ("Blitz", "A limited number of lives", Material.EGG), - EXPLOSION("Explosion", "TNT, Fireballs, and random explosions", Material.SULPHUR), + EXPLOSION("Explosion", "TNT, Fireballs, and random explosions", Materials.SULPHUR), FLY("Fly", "Everyone can fly", Material.FEATHER), JUMP("Jump", "Double jump", Material.SLIME_BLOCK), - FIREWORK("Firework", "Celebrate with fireworks!", Material.FIREWORK), + FIREWORK("Firework", "Celebrate with fireworks!", Materials.FIREWORK), POTION("Potion", "Random potions everywhere", Material.POTION), BREAD("Bread", "Bread with powerful enchantments or attributes", Material.BREAD), BLIND("Blindness", "Lights out", Material.COAL), - HEALTH("Health", "Double health", Material.RED_ROSE), + HEALTH("Health", "Double health", Materials.RED_ROSE), GHOST("Ghost", "Everyone turns invisible", Material.GLASS), STORM("Storm", "Stormy weather with lots of lightning", Material.WATER_BUCKET), FRIENDLY("Friendly Fire", "Kill whoever you like", Material.ROTTEN_FLESH), ENDERPEARL("Enderpearl", "All projectiles are enderpearls", Material.ENDER_PEARL), BLOCK_DECAY("Block Decay", "Blocks placed decay after some time", Material.SOUL_SAND), KNOCKBACK("Knockback", "Knockback applied to everything", Material.FISHING_ROD), - WEB_SLINGERS("Web Slingers", "Shoot webs like a spider", Material.WEB), - MOBS("Mob", "Attack of the mobs", Material.MOB_SPAWNER), + WEB_SLINGERS("Web Slingers", "Shoot webs like a spider", Materials.WEB), + MOBS("Mob", "Attack of the mobs", Materials.MOB_SPAWNER), TNT_BOW("TNT Bow", "All projectiles are TNT", Material.TNT), - FIREBALL_BOW("Fireball Bow", "All projectiles are fireballs", Material.FIREBALL), + FIREBALL_BOW("Fireball Bow", "All projectiles are fireballs", Materials.FIREBALL), CANNON_SUPPLIES("Cannon Supplies", "Supplies for making TNT cannons", Material.REDSTONE), GRAPPLING_HOOK("Grappling Hook", "Everyone can use a grappling hook", Material.FISHING_ROD), NO_SPAWN_KIT("No Spawn Kit", "No Spawn Kits!", Material.BARRIER), @@ -64,16 +65,15 @@ public Material getMaterial() { } public ItemStack getIcon(boolean enabled) { - ItemBuilder item = - new ItemBuilder() - .material(getMaterial()) - .name((enabled ? ChatColor.GREEN : ChatColor.RED) + getDisplayName()) - .lore(ChatColor.GRAY + getDescription()) - .amount(1) - .flags(ItemFlag.values()); + ItemBuilder item = new ItemBuilder() + .material(getMaterial()) + .name((enabled ? ChatColor.GREEN : ChatColor.RED) + getDisplayName()) + .lore(ChatColor.GRAY + getDescription()) + .amount(1) + .flags(ItemFlag.values()); if (enabled) { - item.enchant(Enchantment.LUCK, 0); + item.enchant(Enchantments.LUCK_OF_THE_SEA, 0); } return item.build(); diff --git a/core/src/main/java/dev/pgm/community/mutations/menu/MutationOptionsMenu.java b/core/src/main/java/dev/pgm/community/mutations/menu/MutationOptionsMenu.java index 3d959506..f9545725 100644 --- a/core/src/main/java/dev/pgm/community/mutations/menu/MutationOptionsMenu.java +++ b/core/src/main/java/dev/pgm/community/mutations/menu/MutationOptionsMenu.java @@ -8,12 +8,13 @@ import dev.pgm.community.mutations.options.MutationListOption; import dev.pgm.community.mutations.options.MutationOption; import dev.pgm.community.mutations.options.MutationRangeOption; +import dev.pgm.community.utils.compatibility.Materials; import fr.minuskube.inv.ClickableItem; import fr.minuskube.inv.content.InventoryContents; import fr.minuskube.inv.content.InventoryProvider; import java.util.List; import java.util.stream.Collectors; -import net.md_5.bungee.api.ChatColor; +import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; @@ -40,11 +41,10 @@ public void update(Player player, InventoryContents contents) { private void render(Player player, InventoryContents contents) { contents.fill(null); - List options = - mutations.getMutations().stream() - .map(Mutation::getOptions) - .flatMap(mo -> mo.stream()) - .collect(Collectors.toList()); + List options = mutations.getMutations().stream() + .map(Mutation::getOptions) + .flatMap(mo -> mo.stream()) + .collect(Collectors.toList()); if (options.isEmpty()) { contents.set(1, 4, getNoMutationsIcon()); @@ -58,13 +58,12 @@ private void render(Player player, InventoryContents contents) { } private ClickableItem getNoMutationsIcon() { - return ClickableItem.empty( - new ItemBuilder() - .material(Material.SIGN) - .name(colorize("&c&lNo mutation options found!")) - .lore(colorize("&7Options only display when mutation is enabled")) - .flags(ItemFlag.values()) - .build()); + return ClickableItem.empty(new ItemBuilder() + .material(Materials.SIGN) + .name(colorize("&c&lNo mutation options found!")) + .lore(colorize("&7Options only display when mutation is enabled")) + .flags(ItemFlag.values()) + .build()); } private ClickableItem getReturnIcon(Player viewer) { diff --git a/core/src/main/java/dev/pgm/community/mutations/menu/MutationToggleMenu.java b/core/src/main/java/dev/pgm/community/mutations/menu/MutationToggleMenu.java index c74e5bcd..d6649aff 100644 --- a/core/src/main/java/dev/pgm/community/mutations/menu/MutationToggleMenu.java +++ b/core/src/main/java/dev/pgm/community/mutations/menu/MutationToggleMenu.java @@ -4,12 +4,12 @@ import dev.pgm.community.mutations.MutationType; import dev.pgm.community.mutations.feature.MutationFeature; import dev.pgm.community.utils.CommandAudience; +import dev.pgm.community.utils.compatibility.Materials; import fr.minuskube.inv.ClickableItem; import fr.minuskube.inv.content.InventoryContents; import fr.minuskube.inv.content.InventoryProvider; import java.util.Optional; import org.bukkit.ChatColor; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; import tc.oc.pgm.util.inventory.ItemBuilder; @@ -27,18 +27,15 @@ public void init(Player player, InventoryContents contents) { CommandAudience viewer = new CommandAudience(player); for (MutationType type : MutationType.values()) { Optional mutation = mutations.getMutation(type); - contents.add( - ClickableItem.of( - type.getIcon(mutation.isPresent()), - e -> { - if (!mutations.hasMutation(type)) { - mutations.addMutation(viewer, type, true); - } else { - mutations.removeMutation(viewer, type); - } - e.setCancelled(true); - e.setCurrentItem(type.getIcon(mutations.getMutation(type).isPresent())); - })); + contents.add(ClickableItem.of(type.getIcon(mutation.isPresent()), e -> { + if (!mutations.hasMutation(type)) { + mutations.addMutation(viewer, type, true); + } else { + mutations.removeMutation(viewer, type); + } + e.setCancelled(true); + e.setCurrentItem(type.getIcon(mutations.getMutation(type).isPresent())); + })); } contents.set(3, 4, getOptionIcon(player)); @@ -47,7 +44,7 @@ public void init(Player player, InventoryContents contents) { private ClickableItem getOptionIcon(Player player) { return ClickableItem.of( new ItemBuilder() - .material(Material.WORKBENCH) + .material(Materials.WORKBENCH) .name(ChatColor.GOLD + "Options") .lore(ChatColor.GRAY + "Click to view active mutation options") .flags(ItemFlag.values()) diff --git a/core/src/main/java/dev/pgm/community/mutations/types/arrows/WebSlingersMutation.java b/core/src/main/java/dev/pgm/community/mutations/types/arrows/WebSlingersMutation.java index 3985f34c..1c1628d5 100644 --- a/core/src/main/java/dev/pgm/community/mutations/types/arrows/WebSlingersMutation.java +++ b/core/src/main/java/dev/pgm/community/mutations/types/arrows/WebSlingersMutation.java @@ -10,6 +10,8 @@ import dev.pgm.community.mutations.options.MutationRangeOption; import dev.pgm.community.mutations.types.BowMutation; import dev.pgm.community.mutations.types.KitMutationBase; +import dev.pgm.community.utils.compatibility.Enchantments; +import dev.pgm.community.utils.compatibility.Materials; import java.util.Collection; import java.util.Iterator; import java.util.Map; @@ -18,7 +20,6 @@ import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.FallingBlock; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -33,15 +34,14 @@ public class WebSlingersMutation extends KitMutationBase implements BowMutation { - private static MutationRangeOption WEB_LIFE = - new MutationRangeOption( - "Web Life", - "Length of time before webs are removed", - MutationType.WEB_SLINGERS.getMaterial(), - false, - 10, - 1, - 60); + private static MutationRangeOption WEB_LIFE = new MutationRangeOption( + "Web Life", + "Length of time before webs are removed", + MutationType.WEB_SLINGERS.getMaterial(), + false, + 10, + 1, + 60); private int cleanupTask; @@ -60,11 +60,10 @@ public Collection getOptions() { @Override public void enable() { super.enable(); - this.cleanupTask = - Community.get() - .getServer() - .getScheduler() - .scheduleSyncRepeatingTask(Community.get(), this::cleanup, 0L, 20L); + this.cleanupTask = Community.get() + .getServer() + .getScheduler() + .scheduleSyncRepeatingTask(Community.get(), this::cleanup, 0L, 20L); } @Override @@ -94,11 +93,10 @@ public void onShootWeb(final EntityShootBowEvent event) { ItemStack bow = event.getBow(); if (!bow.isSimilar(getWebBow())) return; - FallingBlock web = - event - .getEntity() - .getWorld() - .spawnFallingBlock(event.getProjectile().getLocation(), Material.WEB, (byte) 0); + FallingBlock web = event + .getEntity() + .getWorld() + .spawnFallingBlock(event.getProjectile().getLocation(), Materials.WEB, (byte) 0); web.setDropItem(false); web.setVelocity(event.getProjectile().getVelocity()); event.setProjectile(web); @@ -108,10 +106,10 @@ public void onShootWeb(final EntityShootBowEvent event) { public void onWebLand(final EntityChangeBlockEvent event) { if (!(event.getEntity() instanceof FallingBlock)) return; FallingBlock block = (FallingBlock) event.getEntity(); - if (block.getMaterial() != Material.WEB) return; + if (block.getMaterial() != Materials.WEB) return; Location location = block.getLocation(); - location.getBlock().setType(Material.WEB); + location.getBlock().setType(Materials.WEB); webLocations.put(location, getDelayedTime(WEB_LIFE.getValue())); } @@ -127,7 +125,7 @@ private void cleanup() { } private void revertBlock(Location location) { - if (location.getBlock().getType() == Material.WEB) { + if (location.getBlock().getType() == Materials.WEB) { location.getBlock().setType(Material.AIR); } } @@ -138,15 +136,14 @@ private static ItemKit getWebBowKit() { } private static ItemStack getWebBow() { - ItemStack bow = - new ItemBuilder() - .material(Material.BOW) - .enchant(Enchantment.ARROW_INFINITE, 1) - .name(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Web-Slinger") - .lore(ChatColor.GRAY + "Use to launch webs") - .flags(ItemFlag.values()) - .unbreakable(true) - .build(); + ItemStack bow = new ItemBuilder() + .material(Material.BOW) + .enchant(Enchantments.INFINITY, 1) + .name(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Web-Slinger") + .lore(ChatColor.GRAY + "Use to launch webs") + .flags(ItemFlag.values()) + .unbreakable(true) + .build(); ItemTags.PREVENT_SHARING.set(bow, true); diff --git a/core/src/main/java/dev/pgm/community/mutations/types/items/BreadMutation.java b/core/src/main/java/dev/pgm/community/mutations/types/items/BreadMutation.java index c773a066..de634345 100644 --- a/core/src/main/java/dev/pgm/community/mutations/types/items/BreadMutation.java +++ b/core/src/main/java/dev/pgm/community/mutations/types/items/BreadMutation.java @@ -7,6 +7,7 @@ import dev.pgm.community.mutations.Mutation; import dev.pgm.community.mutations.MutationType; import dev.pgm.community.mutations.types.KitMutationBase; +import dev.pgm.community.utils.compatibility.PotionEffects; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -49,36 +50,33 @@ import tc.oc.pgm.util.inventory.ItemBuilder; public class BreadMutation extends KitMutationBase { - static final ImmutableMap BAD_POTION_MAP = - new ImmutableMap.Builder() - .put(PotionEffectType.WEAKNESS, 10.0) - .put(PotionEffectType.SLOW, 10.0) - .put(PotionEffectType.POISON, 10.0) - .put(PotionEffectType.WITHER, 10.0) - .put(PotionEffectType.BLINDNESS, 5.0) - .put(PotionEffectType.HUNGER, 5.0) - .put(PotionEffectType.CONFUSION, 5.0) - .build(); + static final ImmutableMap BAD_POTION_MAP = new ImmutableMap.Builder< + PotionEffectType, Double>() + .put(PotionEffectType.WEAKNESS, 10.0) + .put(PotionEffects.SLOWNESS, 10.0) + .put(PotionEffectType.POISON, 10.0) + .put(PotionEffectType.WITHER, 10.0) + .put(PotionEffectType.BLINDNESS, 5.0) + .put(PotionEffectType.HUNGER, 5.0) + .put(PotionEffects.NAUSEA, 5.0) + .build(); private static final ItemStack POTION_BREAD = - preventSharing( - new ItemBuilder(new ItemStack(Material.BREAD)) - .unbreakable(true) - .name("Potion Bread") - .build()); + preventSharing(new ItemBuilder(new ItemStack(Material.BREAD)) + .unbreakable(true) + .name("Potion Bread") + .build()); private static final ItemStack ARMORED_BREAD = - preventSharing( - new ItemBuilder(new ItemStack(Material.BREAD)) - .unbreakable(true) - .name("Armored Bread") - .build()); + preventSharing(new ItemBuilder(new ItemStack(Material.BREAD)) + .unbreakable(true) + .name("Armored Bread") + .build()); private static final ItemStack TELEPORT_BREAD = - preventSharing( - new ItemBuilder(new ItemStack(Material.BREAD)) - .unbreakable(true) - .name("Teleport Bread") - .build()); + preventSharing(new ItemBuilder(new ItemStack(Material.BREAD)) + .unbreakable(true) + .name("Teleport Bread") + .build()); static final ImmutableMap BREADS_MAP = getBreadsMap(); static final ImmutableMap BAD_BREADS_MAP = getBadBreadsMap(); private final WeightedRandomChooser breadChooser; @@ -102,59 +100,53 @@ public BreadMutation(Match match) { static ImmutableMap getBreadsMap() { - ItemStack ironBread = - preventSharing(new ItemBuilder(new ItemStack(Material.BREAD)).name("Iron Bread").build()); + ItemStack ironBread = preventSharing( + new ItemBuilder(new ItemStack(Material.BREAD)).name("Iron Bread").build()); ItemMeta ironBreadMeta = ironBread.getItemMeta(); ironBreadMeta.addAttributeModifier( Attribute.GENERIC_KNOCKBACK_RESISTANCE, new AttributeModifier( - Attribute.GENERIC_KNOCKBACK_RESISTANCE.getName(), + Attribute.GENERIC_KNOCKBACK_RESISTANCE.name(), 1, AttributeModifier.Operation.ADD_NUMBER)); ironBread.setItemMeta(ironBreadMeta); - ItemStack fastBread = - preventSharing(new ItemBuilder(new ItemStack(Material.BREAD)).name("Fast Bread").build()); + ItemStack fastBread = preventSharing( + new ItemBuilder(new ItemStack(Material.BREAD)).name("Fast Bread").build()); ItemMeta speedBreadMeta = fastBread.getItemMeta(); speedBreadMeta.addAttributeModifier( Attribute.GENERIC_MOVEMENT_SPEED, new AttributeModifier( - Attribute.GENERIC_MOVEMENT_SPEED.getName(), - 0.3, - AttributeModifier.Operation.ADD_SCALAR)); + Attribute.GENERIC_MOVEMENT_SPEED.name(), 0.3, AttributeModifier.Operation.ADD_SCALAR)); fastBread.setItemMeta(speedBreadMeta); - ItemStack veryFastBread = - preventSharing( - new ItemBuilder(new ItemStack(Material.BREAD)).name("Very Fast Bread").build()); + ItemStack veryFastBread = preventSharing( + new ItemBuilder(new ItemStack(Material.BREAD)).name("Very Fast Bread").build()); ItemMeta veryFastBreadMeta = veryFastBread.getItemMeta(); veryFastBreadMeta.addAttributeModifier( Attribute.GENERIC_MOVEMENT_SPEED, new AttributeModifier( - Attribute.GENERIC_MOVEMENT_SPEED.getName(), 1, AttributeModifier.Operation.ADD_SCALAR)); + Attribute.GENERIC_MOVEMENT_SPEED.name(), 1, AttributeModifier.Operation.ADD_SCALAR)); veryFastBread.setItemMeta(veryFastBreadMeta); return new ImmutableMap.Builder() .put( - preventSharing( - new ItemBuilder(new ItemStack(Material.BREAD)) - .enchant(Enchantment.FIRE_ASPECT, 1) - .name("Hot Bread") - .build()), + preventSharing(new ItemBuilder(new ItemStack(Material.BREAD)) + .enchant(Enchantment.FIRE_ASPECT, 1) + .name("Hot Bread") + .build()), 20.0) .put( - preventSharing( - new ItemBuilder(new ItemStack(Material.BREAD)) - .enchant(Enchantment.DAMAGE_ALL, 5) - .name("Sharp Bread") - .build()), + preventSharing(new ItemBuilder(new ItemStack(Material.BREAD)) + .enchant(Enchantment.DAMAGE_ALL, 5) + .name("Sharp Bread") + .build()), 20.0) .put( - preventSharing( - new ItemBuilder(new ItemStack(Material.BREAD)) - .enchant(Enchantment.KNOCKBACK, 2) - .name("Bouncy Bread") - .build()), + preventSharing(new ItemBuilder(new ItemStack(Material.BREAD)) + .enchant(Enchantment.KNOCKBACK, 2) + .name("Bouncy Bread") + .build()), 20.0) .put(ironBread, 10.0) .put(fastBread, 10.0) @@ -163,46 +155,40 @@ static ImmutableMap getBreadsMap() { .put(TELEPORT_BREAD, 3.0) .put(veryFastBread, 3.0) .put( - preventSharing( - new ItemBuilder(new ItemStack(Material.BREAD)) - .enchant(Enchantment.DAMAGE_ALL, 10) - .name("Very Sharp Bread") - .build()), + preventSharing(new ItemBuilder(new ItemStack(Material.BREAD)) + .enchant(Enchantment.DAMAGE_ALL, 10) + .name("Very Sharp Bread") + .build()), 3.0) .put( - preventSharing( - new ItemBuilder(new ItemStack(Material.BREAD)) - .enchant(Enchantment.FIRE_ASPECT, 10) - .name("Very Hot Bread") - .build()), + preventSharing(new ItemBuilder(new ItemStack(Material.BREAD)) + .enchant(Enchantment.FIRE_ASPECT, 10) + .name("Very Hot Bread") + .build()), 2.0) .put( - preventSharing( - new ItemBuilder(new ItemStack(Material.BREAD)) - .enchant(Enchantment.KNOCKBACK, 10) - .name("Very Bouncy Bread") - .build()), + preventSharing(new ItemBuilder(new ItemStack(Material.BREAD)) + .enchant(Enchantment.KNOCKBACK, 10) + .name("Very Bouncy Bread") + .build()), 1.0) .put( - preventSharing( - new ItemBuilder(new ItemStack(Material.BREAD)) - .enchant(Enchantment.DAMAGE_ALL, 20) - .name("Insanely Sharp Bread") - .build()), + preventSharing(new ItemBuilder(new ItemStack(Material.BREAD)) + .enchant(Enchantment.DAMAGE_ALL, 20) + .name("Insanely Sharp Bread") + .build()), 1.0) .put( - preventSharing( - new ItemBuilder(new ItemStack(Material.BREAD)) - .enchant(Enchantment.FIRE_ASPECT, 100) - .name("Insanely Hot Bread") - .build()), + preventSharing(new ItemBuilder(new ItemStack(Material.BREAD)) + .enchant(Enchantment.FIRE_ASPECT, 100) + .name("Insanely Hot Bread") + .build()), 1.0) .put( - preventSharing( - new ItemBuilder(new ItemStack(Material.BREAD)) - .enchant(Enchantment.KNOCKBACK, 100) - .name("Insanely Bouncy Bread") - .build()), + preventSharing(new ItemBuilder(new ItemStack(Material.BREAD)) + .enchant(Enchantment.KNOCKBACK, 100) + .name("Insanely Bouncy Bread") + .build()), 1.0) .build(); } @@ -210,25 +196,22 @@ static ImmutableMap getBreadsMap() { static ImmutableMap getBadBreadsMap() { return new ImmutableMap.Builder() .put( - preventSharing( - new ItemBuilder(new ItemStack(Material.BREAD)) - .enchant(Enchantment.FIRE_ASPECT, 1) - .name("Hot Bread") - .build()), + preventSharing(new ItemBuilder(new ItemStack(Material.BREAD)) + .enchant(Enchantment.FIRE_ASPECT, 1) + .name("Hot Bread") + .build()), 20.0) .put( - preventSharing( - new ItemBuilder(new ItemStack(Material.BREAD)) - .enchant(Enchantment.DAMAGE_ALL, 5) - .name("Sharp Bread") - .build()), + preventSharing(new ItemBuilder(new ItemStack(Material.BREAD)) + .enchant(Enchantment.DAMAGE_ALL, 5) + .name("Sharp Bread") + .build()), 20.0) .put( - preventSharing( - new ItemBuilder(new ItemStack(Material.BREAD)) - .enchant(Enchantment.KNOCKBACK, 2) - .name("Bouncy Bread") - .build()), + preventSharing(new ItemBuilder(new ItemStack(Material.BREAD)) + .enchant(Enchantment.KNOCKBACK, 2) + .name("Bouncy Bread") + .build()), 20.0) .build(); } @@ -257,9 +240,8 @@ public void onPlayerDamageByEntity(EntityDamageByEntityEvent event) { ItemStack itemInHand = ((Player) event.getDamager()).getItemInHand(); Player hitPlayer = (Player) event.getEntity(); if (itemInHand.isSimilar(POTION_BREAD)) { - hitPlayer.addPotionEffect( - new PotionEffect( - potionChooser.choose(random), 20 * random.nextInt(7) + 3, random.nextInt(2) + 1)); + hitPlayer.addPotionEffect(new PotionEffect( + potionChooser.choose(random), 20 * random.nextInt(7) + 3, random.nextInt(2) + 1)); } else if (itemInHand.isSimilar(TELEPORT_BREAD)) { performBreadTeleport(hitPlayer); } @@ -291,9 +273,8 @@ private void performBreadTeleport(Player hitPlayer) { // Check if the player can physically walk into the area? if (isSafe(nextLocation, y < 0 ? 2 - y : 2) && isSafe(previousLocation, y == 1 ? 3 : 2)) { // Check if pgm will deny entry - PlayerCoarseMoveEvent event = - new PlayerCoarseMoveEvent( - new PlayerMoveEvent(hitPlayer, previousLocation, nextLocation)); + PlayerCoarseMoveEvent event = new PlayerCoarseMoveEvent( + new PlayerMoveEvent(hitPlayer, previousLocation, nextLocation)); pluginManager.callEvent(event); if (!event.isCancelled()) { diff --git a/core/src/main/java/dev/pgm/community/mutations/types/items/CannonSuppliesMutation.java b/core/src/main/java/dev/pgm/community/mutations/types/items/CannonSuppliesMutation.java index 0cacd3d2..26ddbe2e 100644 --- a/core/src/main/java/dev/pgm/community/mutations/types/items/CannonSuppliesMutation.java +++ b/core/src/main/java/dev/pgm/community/mutations/types/items/CannonSuppliesMutation.java @@ -5,6 +5,7 @@ import dev.pgm.community.mutations.Mutation; import dev.pgm.community.mutations.MutationType; import dev.pgm.community.mutations.types.KitMutationBase; +import dev.pgm.community.utils.compatibility.Materials; import java.util.List; import java.util.Set; import org.bukkit.Material; @@ -27,25 +28,22 @@ public CannonSuppliesMutation(Match match) { // Order is to allow partial kits to build functional cannons. The more items the player receives // the more complicated the cannons they can build - static List spawnKit = - Lists.newArrayList( - new ItemKit( - Maps.newHashMap(), - preventSharing( - Lists.newArrayList( - new ItemStack(Material.TNT, 64), - new ItemStack(Material.WATER_BUCKET), - new ItemStack(Material.STONE_BUTTON, 32), - new ItemStack(Material.LADDER, 32), - new ItemStack(Material.TNT, 64), - new ItemStack(Material.REDSTONE, 64), - new ItemStack(Material.WATER_BUCKET), - new ItemStack(Material.FENCE, 32), - new ItemStack(Material.WOOD_STEP, 64), - new ItemStack(Material.TNT, 64), - new ItemStack(Material.WOOD, 64), - new ItemStack(Material.TNT, 64), - new ItemStack(Material.DIODE, 64))))); + static List spawnKit = Lists.newArrayList(new ItemKit( + Maps.newHashMap(), + preventSharing(Lists.newArrayList( + new ItemStack(Material.TNT, 64), + new ItemStack(Material.WATER_BUCKET), + new ItemStack(Material.STONE_BUTTON, 32), + new ItemStack(Material.LADDER, 32), + new ItemStack(Material.TNT, 64), + new ItemStack(Material.REDSTONE, 64), + new ItemStack(Material.WATER_BUCKET), + new ItemStack(Materials.FENCE, 32), + new ItemStack(Materials.WOOD_STEP, 64), + new ItemStack(Material.TNT, 64), + new ItemStack(Materials.WOOD, 64), + new ItemStack(Material.TNT, 64), + new ItemStack(Materials.DIODE, 64))))); @Override public List getKits() { diff --git a/core/src/main/java/dev/pgm/community/mutations/types/items/ExplosionMutation.java b/core/src/main/java/dev/pgm/community/mutations/types/items/ExplosionMutation.java index 74aa401d..f5608f16 100644 --- a/core/src/main/java/dev/pgm/community/mutations/types/items/ExplosionMutation.java +++ b/core/src/main/java/dev/pgm/community/mutations/types/items/ExplosionMutation.java @@ -12,6 +12,7 @@ import dev.pgm.community.mutations.options.MutationOption; import dev.pgm.community.mutations.options.MutationRangeOption; import dev.pgm.community.mutations.types.KitMutationBase; +import dev.pgm.community.utils.compatibility.Materials; import java.util.Collection; import java.util.List; import java.util.Map; @@ -49,55 +50,50 @@ /** ExplosionMutation - TNT, Fireballs, and random explosions when mining blocks * */ public class ExplosionMutation extends KitMutationBase { - private static MutationRangeOption FIREBALL_POWER = - new MutationRangeOption( - "Fireball Power", - "Power of fireball explosion", - MutationType.EXPLOSION.getMaterial(), - false, - 0, - 0, - 10); - - private static MutationBooleanOption FIREBALL_FIRE = - new MutationBooleanOption( - "Fireball Fire", - "Whether fireballs are incendiary", - MutationType.EXPLOSION.getMaterial(), - true, - false); - - private static MutationRangeOption LAUNCH_COOLDOWN = - new MutationRangeOption( - "Explosive Cooldown", - "Delay between fireball or TNT shots", - MutationType.EXPLOSION.getMaterial(), - false, - 4, - 0, - 60); - - private static MutationBooleanOption MYSTERY_TNT = - new MutationBooleanOption( - "Mystery TNT", - "Whether TNT should have a random effect", - MutationType.EXPLOSION.getMaterial(), - true, - false); - - private static MutationRangeOption TNT_SIZE = - new MutationRangeOption( - "TNT Amount", - "Amount of TNT given per player", - MutationType.EXPLOSION.getMaterial(), - false, - 6, - 1, - 64); + private static MutationRangeOption FIREBALL_POWER = new MutationRangeOption( + "Fireball Power", + "Power of fireball explosion", + MutationType.EXPLOSION.getMaterial(), + false, + 0, + 0, + 10); + + private static MutationBooleanOption FIREBALL_FIRE = new MutationBooleanOption( + "Fireball Fire", + "Whether fireballs are incendiary", + MutationType.EXPLOSION.getMaterial(), + true, + false); + + private static MutationRangeOption LAUNCH_COOLDOWN = new MutationRangeOption( + "Explosive Cooldown", + "Delay between fireball or TNT shots", + MutationType.EXPLOSION.getMaterial(), + false, + 4, + 0, + 60); + + private static MutationBooleanOption MYSTERY_TNT = new MutationBooleanOption( + "Mystery TNT", + "Whether TNT should have a random effect", + MutationType.EXPLOSION.getMaterial(), + true, + false); + + private static MutationRangeOption TNT_SIZE = new MutationRangeOption( + "TNT Amount", + "Amount of TNT given per player", + MutationType.EXPLOSION.getMaterial(), + false, + 6, + 1, + 64); private static final double EXPLODE_CHANCE = 0.05; private static final int FIREBALL_COUNT = 5; - private static final Material TNT_LAUNCHER_MATERIAL = Material.NETHER_BRICK_ITEM; + private static final Material TNT_LAUNCHER_MATERIAL = Materials.NETHER_BRICK_ITEM; private static final String EXPLOSION_METADATA = "mutation_explosion"; private static final ItemTag EXPLOSION_KIT = ItemTag.newString(EXPLOSION_METADATA); @@ -191,7 +187,7 @@ public void onExplosiveLaunch(PlayerInteractEvent event) { if (!isParticipant(player)) return; if (item == null || item.getType() == Material.AIR) return; - if (item.getType() != Material.FIREBALL && item.getType() != TNT_LAUNCHER_MATERIAL) return; + if (item.getType() != Materials.FIREBALL && item.getType() != TNT_LAUNCHER_MATERIAL) return; if (item.getType() == TNT_LAUNCHER_MATERIAL && !isFromKit(item)) return; if (!launchExplosive(event.getPlayer(), item.getType())) return; @@ -257,19 +253,17 @@ public ItemStack[] getAllItems() { } private static List getTNTItems() { - List items = - Lists.newArrayList( - getTNTItem(), new ItemStack(Material.REDSTONE_TORCH_ON, TNT_SIZE.getValue())); + List items = Lists.newArrayList( + getTNTItem(), new ItemStack(Materials.REDSTONE_TORCH_ON, TNT_SIZE.getValue())); items = items.stream().map(ExplosionMutation::applyLore).collect(Collectors.toList()); return items; } private static ItemStack getTNTItem() { - ItemBuilder builder = - new ItemBuilder() - .material(Material.TNT) - .amount(TNT_SIZE.getValue()) - .name(colorize(MYSTERY_TNT.getValue() ? "&d&lMystery TNT" : "&c&lTNT")); + ItemBuilder builder = new ItemBuilder() + .material(Material.TNT) + .amount(TNT_SIZE.getValue()) + .name(colorize(MYSTERY_TNT.getValue() ? "&d&lMystery TNT" : "&c&lTNT")); if (MYSTERY_TNT.getValue()) { builder.lore(colorize("&7This TNT may have a special effect when placed!")); } @@ -277,24 +271,22 @@ private static ItemStack getTNTItem() { } private static ItemStack getTNTLauncherItem() { - ItemStack item = - new ItemBuilder() - .material(TNT_LAUNCHER_MATERIAL) - .amount(TNT_SIZE.getValue()) - .name(colorize("&4&lTNT Launcher")) - .lore("&7Click to launch TNT in the direction you are facing") - .build(); + ItemStack item = new ItemBuilder() + .material(TNT_LAUNCHER_MATERIAL) + .amount(TNT_SIZE.getValue()) + .name(colorize("&4&lTNT Launcher")) + .lore("&7Click to launch TNT in the direction you are facing") + .build(); return applyLore(item); } private static ItemStack getFireballItem() { - ItemStack item = - new ItemBuilder() - .material(Material.FIREBALL) - .amount(FIREBALL_COUNT) - .name(colorize("&4&lFireball")) - .lore(colorize("&7Click to launch fireball")) - .build(); + ItemStack item = new ItemBuilder() + .material(Materials.FIREBALL) + .amount(FIREBALL_COUNT) + .name(colorize("&4&lFireball")) + .lore(colorize("&7Click to launch fireball")) + .build(); return applyLore(item); } @@ -324,7 +316,7 @@ private boolean launchExplosive(Player player, Material type) { } } - if (type == Material.FIREBALL) { + if (type == Materials.FIREBALL) { launchFireball(player); } diff --git a/core/src/main/java/dev/pgm/community/mutations/types/items/FireworkMutation.java b/core/src/main/java/dev/pgm/community/mutations/types/items/FireworkMutation.java index fa9bfc26..f89b256b 100644 --- a/core/src/main/java/dev/pgm/community/mutations/types/items/FireworkMutation.java +++ b/core/src/main/java/dev/pgm/community/mutations/types/items/FireworkMutation.java @@ -9,6 +9,8 @@ import dev.pgm.community.mutations.Mutation; import dev.pgm.community.mutations.MutationType; import dev.pgm.community.mutations.types.KitMutationBase; +import dev.pgm.community.utils.compatibility.Materials; +import dev.pgm.community.utils.compatibility.PotionEffects; import java.util.Iterator; import java.util.List; import java.util.Random; @@ -32,7 +34,6 @@ import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; import org.jetbrains.annotations.Nullable; import tc.oc.pgm.api.match.Match; @@ -105,7 +106,7 @@ private void fling(Firework firework) { Player player = (Player) firework.getPassenger(); Vector velocity = player.getLocation().getDirection().multiply(7).setY(0); player.setVelocity(velocity); - player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20 * 5, 5)); + player.addPotionEffect(new PotionEffect(PotionEffects.RESISTANCE, 20 * 5, 5)); } } @@ -153,7 +154,7 @@ private static ItemKit getFireworkKit() { private static ItemStack getFirework(@Nullable Color color, Type type, int power) { Random random = Community.get().getRandom(); - ItemStack firework = new ItemStack(Material.FIREWORK); + ItemStack firework = new ItemStack(Materials.FIREWORK); FireworkMeta meta = (FireworkMeta) firework.getItemMeta(); meta.addEffect(FireworkEffect.builder() .withColor( diff --git a/core/src/main/java/dev/pgm/community/mutations/types/mapdev/ProximityEffectsMutation.java b/core/src/main/java/dev/pgm/community/mutations/types/mapdev/ProximityEffectsMutation.java index 8520b5f4..e1575a71 100644 --- a/core/src/main/java/dev/pgm/community/mutations/types/mapdev/ProximityEffectsMutation.java +++ b/core/src/main/java/dev/pgm/community/mutations/types/mapdev/ProximityEffectsMutation.java @@ -8,6 +8,8 @@ import dev.pgm.community.mutations.options.MutationOption; import dev.pgm.community.mutations.options.MutationRangeOption; import dev.pgm.community.mutations.types.ScheduledMutationBase; +import dev.pgm.community.utils.compatibility.Materials; +import dev.pgm.community.utils.compatibility.PotionEffects; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -40,20 +42,18 @@ public class ProximityEffectsMutation extends ScheduledMutationBase { - MutationListOption attackerDistanceOption = - new MutationListOption<>( - "Attacker Distance", - "Radius where potion effects are applied", - Material.COMPASS, - true, - Lists.newArrayList(0, 5, 10, 15, 20, 30, 40, 50, 75, 100, 150, 200)); - MutationListOption defenderDistanceOption = - new MutationListOption<>( - "Defender Distance", - "Radius where potion effects are applied", - Material.EMPTY_MAP, - true, - Lists.newArrayList(0, 5, 10, 15, 20, 30, 40, 50, 75, 100, 150, 200)); + MutationListOption attackerDistanceOption = new MutationListOption<>( + "Attacker Distance", + "Radius where potion effects are applied", + Material.COMPASS, + true, + Lists.newArrayList(0, 5, 10, 15, 20, 30, 40, 50, 75, 100, 150, 200)); + MutationListOption defenderDistanceOption = new MutationListOption<>( + "Defender Distance", + "Radius where potion effects are applied", + Materials.EMPTY_MAP, + true, + Lists.newArrayList(0, 5, 10, 15, 20, 30, 40, 50, 75, 100, 150, 200)); Map attackerOptions; Map defenderOptions; @@ -85,7 +85,7 @@ static Map buildOptions(String prefix) { HashMap effectOptionMap = new HashMap<>(); effectOptionMap.put( - PotionEffectType.FAST_DIGGING, + PotionEffects.HASTE, new MutationRangeOption( prefix + " Haste", prefix + " Haste Amount", Material.DIAMOND_PICKAXE, true, 0, 0, 5)); effectOptionMap.put( @@ -93,7 +93,7 @@ static Map buildOptions(String prefix) { new MutationRangeOption( prefix + " Speed", prefix + " Speed Amount", Material.SUGAR, true, 0, 0, 5)); effectOptionMap.put( - PotionEffectType.INCREASE_DAMAGE, + PotionEffects.STRENGTH, new MutationRangeOption( prefix + " Strength", prefix + " Strength Amount", @@ -103,7 +103,7 @@ static Map buildOptions(String prefix) { 0, 5)); effectOptionMap.put( - PotionEffectType.JUMP, + PotionEffects.JUMP_BOOST, new MutationRangeOption( prefix + " Jump Boost", prefix + " Jump Boost Amount", @@ -123,23 +123,29 @@ static Map buildOptions(String prefix) { 0, 5)); effectOptionMap.put( - PotionEffectType.SLOW_DIGGING, + PotionEffects.MINING_FATIGUE, new MutationRangeOption( prefix + " Mining Fatigue", prefix + " Mining Fatigue Amount", - Material.WOOD_PICKAXE, + Materials.WOOD_PICKAXE, true, 0, 0, 5)); effectOptionMap.put( - PotionEffectType.SLOW, + PotionEffects.SLOWNESS, new MutationRangeOption( - prefix + " Slowness", prefix + " Slowness Amount", Material.WEB, true, 0, 0, 5)); + prefix + " Slowness", prefix + " Slowness Amount", Materials.WEB, true, 0, 0, 5)); effectOptionMap.put( PotionEffectType.WEAKNESS, new MutationRangeOption( - prefix + " Weakness", prefix + " Weakness Amount", Material.WOOD_SWORD, true, 0, 0, 5)); + prefix + " Weakness", + prefix + " Weakness Amount", + Materials.WOOD_SWORD, + true, + 0, + 0, + 5)); return effectOptionMap; } @@ -196,10 +202,8 @@ private void findADLocations( if (destroyableMatchModule.isPresent()) { for (Destroyable destroyable : destroyableMatchModule.get().getDestroyables()) { if (!destroyable.isCompleted()) { - ownedLocationsMap.add( - new Pair<>( - destroyable.getBlockRegion().getBounds().getCenterPoint(), - destroyable.getOwner())); + ownedLocationsMap.add(new Pair<>( + destroyable.getBlockRegion().getBounds().getCenterPoint(), destroyable.getOwner())); } } } @@ -232,9 +236,8 @@ private void applyPotionEffects( for (Map.Entry entry : options.entrySet()) { int level = entry.getValue().getValue(); if (level > 0) { - PotionKit potionKit = - new PotionKit( - Collections.singleton(new PotionEffect(entry.getKey(), 5 * 20, level - 1))); + PotionKit potionKit = new PotionKit( + Collections.singleton(new PotionEffect(entry.getKey(), 5 * 20, level - 1))); for (MatchPlayer defender : players) { defender.applyKit(potionKit, true); } diff --git a/core/src/main/java/dev/pgm/community/mutations/types/mechanics/KnockbackMutation.java b/core/src/main/java/dev/pgm/community/mutations/types/mechanics/KnockbackMutation.java index e1aa036d..4ad62316 100644 --- a/core/src/main/java/dev/pgm/community/mutations/types/mechanics/KnockbackMutation.java +++ b/core/src/main/java/dev/pgm/community/mutations/types/mechanics/KnockbackMutation.java @@ -7,10 +7,10 @@ import org.bukkit.entity.Entity; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerAttackEntityEvent; import org.bukkit.util.Vector; import tc.oc.pgm.api.match.Match; import tc.oc.pgm.api.player.MatchPlayer; +import tc.oc.pgm.util.event.player.PlayerAttackEntityEvent; public class KnockbackMutation extends MutationBase { diff --git a/core/src/main/java/dev/pgm/community/mutations/types/mechanics/MobMutation.java b/core/src/main/java/dev/pgm/community/mutations/types/mechanics/MobMutation.java index 933f85b2..490f71c3 100644 --- a/core/src/main/java/dev/pgm/community/mutations/types/mechanics/MobMutation.java +++ b/core/src/main/java/dev/pgm/community/mutations/types/mechanics/MobMutation.java @@ -8,6 +8,7 @@ import dev.pgm.community.mutations.options.MutationListOption; import dev.pgm.community.mutations.options.MutationOption; import dev.pgm.community.mutations.types.ScheduledMutationBase; +import dev.pgm.community.utils.compatibility.EntityTypes; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -104,7 +105,7 @@ private RandomPointProvider getPointProvider() { EntityType.SKELETON, EntityType.SPIDER, EntityType.ENDERMAN, - EntityType.PIG_ZOMBIE, + EntityTypes.PIG_ZOMBIE, EntityType.CREEPER, EntityType.WITCH }; diff --git a/core/src/main/java/dev/pgm/community/party/MapPartyType.java b/core/src/main/java/dev/pgm/community/party/MapPartyType.java index 291db713..931f470e 100644 --- a/core/src/main/java/dev/pgm/community/party/MapPartyType.java +++ b/core/src/main/java/dev/pgm/community/party/MapPartyType.java @@ -1,6 +1,6 @@ package dev.pgm.community.party; -import org.apache.commons.lang3.text.WordUtils; +import org.apache.commons.lang.WordUtils; import org.bukkit.Material; public enum MapPartyType { diff --git a/core/src/main/java/dev/pgm/community/party/menu/MapPartyMainMenu.java b/core/src/main/java/dev/pgm/community/party/menu/MapPartyMainMenu.java index 527105dd..00fe951e 100644 --- a/core/src/main/java/dev/pgm/community/party/menu/MapPartyMainMenu.java +++ b/core/src/main/java/dev/pgm/community/party/menu/MapPartyMainMenu.java @@ -13,6 +13,7 @@ import dev.pgm.community.party.menu.settings.MapPartySettingsMenu; import dev.pgm.community.party.presets.MapPartyPreset; import dev.pgm.community.utils.SkullUtils; +import dev.pgm.community.utils.compatibility.Materials; import fr.minuskube.inv.ClickableItem; import fr.minuskube.inv.content.InventoryContents; import java.util.List; @@ -47,16 +48,15 @@ private void render(Player player, InventoryContents contents) { MapParty party = getFeature().getParty(); // Info item - ItemStack info = - new ItemBuilder() - .material(Material.CAKE) - .name(colorize(party.getName())) - .lore( - colorize(" &f* &7Description: &6" + party.getDescription()), - colorize(" &f* &7Type: &6" + party.getEventType()), - colorize(" &f* &7Started: " + (party.isRunning() ? "&aYes" : "&cNo")), - colorize(" &f* &7Time Remaining: &a" + MapPartyMessages.formatTime(party))) - .build(); + ItemStack info = new ItemBuilder() + .material(Material.CAKE) + .name(colorize(party.getName())) + .lore( + colorize(" &f* &7Description: &6" + party.getDescription()), + colorize(" &f* &7Type: &6" + party.getEventType()), + colorize(" &f* &7Started: " + (party.isRunning() ? "&aYes" : "&cNo")), + colorize(" &f* &7Time Remaining: &a" + MapPartyMessages.formatTime(party))) + .build(); ClickableItem infoIcon = ClickableItem.empty(info); @@ -126,47 +126,34 @@ private Optional getParty() { } private ClickableItem getStartIcon() { - return ClickableItem.of( - START_ITEM, - c -> { - getParty() - .ifPresent( - party -> { - Bukkit.dispatchCommand( - getViewer(), "event start " + (c.isLeftClick() ? "false" : "true")); - }); - }); + return ClickableItem.of(START_ITEM, c -> { + getParty().ifPresent(party -> { + Bukkit.dispatchCommand(getViewer(), "event start " + (c.isLeftClick() ? "false" : "true")); + }); + }); } private ClickableItem getRestartIcon() { - return ClickableItem.of( - RESTART_ITEM, - c -> { - getParty() - .ifPresent( - party -> { - Bukkit.dispatchCommand(getViewer(), "event restart"); - }); - }); + return ClickableItem.of(RESTART_ITEM, c -> { + getParty().ifPresent(party -> { + Bukkit.dispatchCommand(getViewer(), "event restart"); + }); + }); } private ClickableItem getEndIcon() { - return ClickableItem.of( - END_ITEM, - c -> { - getParty() - .ifPresent( - party -> { - Bukkit.dispatchCommand(getViewer(), "event stop"); - close(); - }); - }); + return ClickableItem.of(END_ITEM, c -> { + getParty().ifPresent(party -> { + Bukkit.dispatchCommand(getViewer(), "event stop"); + close(); + }); + }); } private ClickableItem getHostIcon(MapPartyHosts hosts) { return ClickableItem.of( new ItemBuilder() - .material(Material.SKULL_ITEM) + .material(Materials.SKULL_ITEM) .durability(3) .name(colorize("&a&lHosts")) .lore(colorize("&7Click to manage party hosts")) @@ -182,9 +169,8 @@ private ClickableItem getMapsIcon(MapPartyType type) { new ItemBuilder() .material(Material.MAP) .name(colorize(type == MapPartyType.REGULAR ? "&6&lPool" : "&6&lMaps")) - .lore( - colorize( - "&7Click to manage party " + (type == MapPartyType.REGULAR ? "pool" : "maps"))) + .lore(colorize( + "&7Click to manage party " + (type == MapPartyType.REGULAR ? "pool" : "maps"))) .flags(ItemFlag.values()) .build(), c -> { @@ -195,7 +181,7 @@ private ClickableItem getMapsIcon(MapPartyType type) { private ClickableItem getSettingsIcon() { return ClickableItem.of( new ItemBuilder() - .material(Material.REDSTONE_COMPARATOR) + .material(Materials.REDSTONE_COMPARATOR) .name(colorize("&3&lSettings")) .lore(colorize("&7Click to manage party settings")) .flags(ItemFlag.values()) @@ -234,7 +220,7 @@ private ClickableItem getPresetIcon(MapPartyPreset preset) { return ClickableItem.of( new ItemBuilder() - .material(Material.STAINED_GLASS_PANE) + .material(Materials.STAINED_GLASS_PANE) .color(DyeColor.CYAN) .name(colorize(preset.getName())) .lore(lore.toArray(new String[lore.size()])) @@ -245,12 +231,11 @@ private ClickableItem getPresetIcon(MapPartyPreset preset) { } private ClickableItem getEmptyItem(int i) { - return ClickableItem.empty( - new ItemBuilder() - .material(Material.STAINED_GLASS_PANE) - .color(DyeColor.GRAY) - .name(colorize("&cEmpty Preset #" + (i + 1))) - .build()); + return ClickableItem.empty(new ItemBuilder() + .material(Materials.STAINED_GLASS_PANE) + .color(DyeColor.GRAY) + .name(colorize("&cEmpty Preset #" + (i + 1))) + .build()); } private static final String START_PARTY_SKIN = @@ -260,16 +245,14 @@ private ClickableItem getEmptyItem(int i) { private static final String END_PARTY_SKIN = "http://textures.minecraft.net/texture/e9cdb9af38cf41daa53bc8cda7665c509632d14e678f0f19f263f46e541d8a30"; - private static final ItemStack START_ITEM = - SkullUtils.customSkull( - START_PARTY_SKIN, - "&a&lStart Event", - "&2Left-Click&7 to start the event now", - "&2Right-Click&7 to start event after current match ends"); + private static final ItemStack START_ITEM = SkullUtils.customSkull( + START_PARTY_SKIN, + "&a&lStart Event", + "&2Left-Click&7 to start the event now", + "&2Right-Click&7 to start event after current match ends"); - private static final ItemStack RESTART_ITEM = - SkullUtils.customSkull( - RESTART_PARTY_SKIN, "&2&lRestart Event", "&7Click to restart the event"); + private static final ItemStack RESTART_ITEM = SkullUtils.customSkull( + RESTART_PARTY_SKIN, "&2&lRestart Event", "&7Click to restart the event"); private static final ItemStack END_ITEM = SkullUtils.customSkull(END_PARTY_SKIN, "&4&lEnd Event", "&7Click to end the event"); diff --git a/core/src/main/java/dev/pgm/community/party/menu/MapPartyMenu.java b/core/src/main/java/dev/pgm/community/party/menu/MapPartyMenu.java index 606b8d0a..5f048f37 100644 --- a/core/src/main/java/dev/pgm/community/party/menu/MapPartyMenu.java +++ b/core/src/main/java/dev/pgm/community/party/menu/MapPartyMenu.java @@ -7,6 +7,7 @@ import dev.pgm.community.Community; import dev.pgm.community.CommunityPermissions; import dev.pgm.community.party.feature.MapPartyFeature; +import dev.pgm.community.utils.compatibility.Materials; import fr.minuskube.inv.ClickableItem; import fr.minuskube.inv.SmartInventory; import fr.minuskube.inv.content.InventoryContents; @@ -27,7 +28,7 @@ public abstract class MapPartyMenu implements InventoryProvider { - protected static final Material BORDER_MATERIAL = Material.STAINED_GLASS_PANE; + protected static final Material BORDER_MATERIAL = Materials.STAINED_GLASS_PANE; private final String title; private final int rows; @@ -99,12 +100,11 @@ public SmartInventory getInventory() { } public SmartInventory getInventory(SmartInventory parent) { - SmartInventory.Builder builder = - SmartInventory.builder() - .title(colorize(title)) - .provider(this) - .manager(Community.get().getInventory()) - .size(rows, 9); + SmartInventory.Builder builder = SmartInventory.builder() + .title(colorize(title)) + .provider(this) + .manager(Community.get().getInventory()) + .size(rows, 9); if (parent != null) { builder.parent(parent); @@ -114,13 +114,12 @@ public SmartInventory getInventory(SmartInventory parent) { } protected ClickableItem getBorderItem() { - return ClickableItem.empty( - new ItemBuilder() - .material(BORDER_MATERIAL) - .color(getBorderColor()) - .name(" ") - .flags(ItemFlag.values()) - .build()); + return ClickableItem.empty(new ItemBuilder() + .material(BORDER_MATERIAL) + .color(getBorderColor()) + .name(" ") + .flags(ItemFlag.values()) + .build()); } protected static final String ADD_SKIN = @@ -134,15 +133,14 @@ protected DyeColor getBorderColor() { protected ClickableItem getMainMenuIcon() { return ClickableItem.of( - getNamedItem("&7Return to &dMap Party Manager", Material.CAKE, 1), - c -> { + getNamedItem("&7Return to &dMap Party Manager", Material.CAKE, 1), c -> { Bukkit.dispatchCommand(getViewer(), "event"); }); } protected ItemStack getPlayerHead( String displayName, String name, List lore, UUID playerId, Skin skin) { - ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3); + ItemStack head = new ItemStack(Materials.SKULL_ITEM, 1, (byte) 3); SkullMeta meta = (SkullMeta) head.getItemMeta(); meta.setDisplayName(displayName); meta.setLore(lore); diff --git a/core/src/main/java/dev/pgm/community/party/menu/hosts/HostMenu.java b/core/src/main/java/dev/pgm/community/party/menu/hosts/HostMenu.java index 25ebcd21..7decf1a3 100644 --- a/core/src/main/java/dev/pgm/community/party/menu/hosts/HostMenu.java +++ b/core/src/main/java/dev/pgm/community/party/menu/hosts/HostMenu.java @@ -7,6 +7,7 @@ import dev.pgm.community.party.hosts.MapPartyHosts; import dev.pgm.community.party.menu.MapPartyMenu; import dev.pgm.community.utils.SkullUtils; +import dev.pgm.community.utils.compatibility.Materials; import fr.minuskube.inv.ClickableItem; import fr.minuskube.inv.content.InventoryContents; import fr.minuskube.inv.content.Pagination; @@ -17,7 +18,6 @@ import java.util.stream.Collectors; import org.bukkit.Bukkit; import org.bukkit.DyeColor; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; @@ -44,10 +44,9 @@ public void render(Player player, InventoryContents contents) { // Main host contents.set(1, 4, getMainHostIcon(hosts)); - Set players = - hosts.getSubHostIds().stream() - .map(id -> getSubHostIcon(hosts, id)) - .collect(Collectors.toSet()); + Set players = hosts.getSubHostIds().stream() + .map(id -> getSubHostIcon(hosts, id)) + .collect(Collectors.toSet()); Pagination page = contents.pagination(); page.setItems(players.toArray(new ClickableItem[players.size()])); @@ -75,8 +74,7 @@ public void render(Player player, InventoryContents contents) { 4, 4, ClickableItem.of( - SkullUtils.customSkull(ADD_SKIN, "&a&lAdd Host", "&7Click to add event host"), - c -> { + SkullUtils.customSkull(ADD_SKIN, "&a&lAdd Host", "&7Click to add event host"), c -> { new HostAddMenu(hosts).open(getViewer()); })); @@ -96,13 +94,11 @@ public void update(Player player, InventoryContents contents) { } private ClickableItem getSubHostIcon(MapPartyHosts hosts, UUID playerId) { - return ClickableItem.of( - getHostHead(hosts, playerId), - c -> { - close(); - String name = hosts.getCachedName(playerId); - Bukkit.dispatchCommand(getViewer(), "event hosts remove " + name); - }); + return ClickableItem.of(getHostHead(hosts, playerId), c -> { + close(); + String name = hosts.getCachedName(playerId); + Bukkit.dispatchCommand(getViewer(), "event hosts remove " + name); + }); } private ClickableItem getMainHostIcon(MapPartyHosts hosts) { @@ -110,14 +106,13 @@ private ClickableItem getMainHostIcon(MapPartyHosts hosts) { } private ClickableItem getNoPlayersIcon() { - return ClickableItem.empty( - new ItemBuilder() - .material(Material.STAINED_GLASS_PANE) - .color(DyeColor.RED) - .name(colorize("&cNo hosts found")) - .lore(colorize("&7Add hosts using the button below")) - .flags(ItemFlag.values()) - .build()); + return ClickableItem.empty(new ItemBuilder() + .material(Materials.STAINED_GLASS_PANE) + .color(DyeColor.RED) + .name(colorize("&cNo hosts found")) + .lore(colorize("&7Add hosts using the button below")) + .flags(ItemFlag.values()) + .build()); } private ItemStack getHostHead(MapPartyHosts hosts, UUID playerId) { diff --git a/core/src/main/java/dev/pgm/community/party/menu/maps/MapAddMenu.java b/core/src/main/java/dev/pgm/community/party/menu/maps/MapAddMenu.java index 45b4ba61..088970f6 100644 --- a/core/src/main/java/dev/pgm/community/party/menu/maps/MapAddMenu.java +++ b/core/src/main/java/dev/pgm/community/party/menu/maps/MapAddMenu.java @@ -1,5 +1,6 @@ package dev.pgm.community.party.menu.maps; +import static dev.pgm.community.utils.PGMUtils.mapTagMaterial; import static net.kyori.adventure.text.Component.text; import static tc.oc.pgm.util.bukkit.BukkitUtils.colorize; @@ -7,6 +8,8 @@ import com.google.common.collect.Sets; import dev.pgm.community.party.feature.MapPartyFeature; import dev.pgm.community.party.menu.MapPartyMenu; +import dev.pgm.community.utils.compatibility.Enchantments; +import dev.pgm.community.utils.compatibility.Materials; import fr.minuskube.inv.ClickableItem; import fr.minuskube.inv.content.InventoryContents; import fr.minuskube.inv.content.Pagination; @@ -20,7 +23,6 @@ import org.bukkit.Bukkit; import org.bukkit.DyeColor; import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; import tc.oc.pgm.api.PGM; @@ -94,34 +96,26 @@ private void render(Player player, InventoryContents contents) { } // Return to party menu - contents.set( - 5, - 4, - ClickableItem.of( - getNamedItem("&7Return to &6Maps", Material.CAKE, 1), - c -> { - Bukkit.dispatchCommand(player, "event maps"); - })); + contents.set(5, 4, ClickableItem.of(getNamedItem("&7Return to &6Maps", Material.CAKE, 1), c -> { + Bukkit.dispatchCommand(player, "event maps"); + })); } private ClickableItem getAllIcon() { - ItemBuilder allItemBuilder = - new ItemBuilder() - .material(Material.BOOKSHELF) - .name(colorize((viewAll ? "&a" : "&c") + "View All")) - .lore(colorize(viewAll ? "&7Click to filter by map tags" : "&7Click to view all maps")) - .flags(ItemFlag.values()); + ItemBuilder allItemBuilder = new ItemBuilder() + .material(Material.BOOKSHELF) + .name(colorize((viewAll ? "&a" : "&c") + "View All")) + .lore(colorize(viewAll ? "&7Click to filter by map tags" : "&7Click to view all maps")) + .flags(ItemFlag.values()); if (viewAll) { - allItemBuilder.enchant(Enchantment.LUCK, 1); + allItemBuilder.enchant(Enchantments.LUCK_OF_THE_SEA, 1); } - return ClickableItem.of( - allItemBuilder.build(), - c -> { - this.viewAll = !viewAll; - getInventory().open(getViewer(), 0); - }); + return ClickableItem.of(allItemBuilder.build(), c -> { + this.viewAll = !viewAll; + getInventory().open(getViewer(), 0); + }); } private ClickableItem getFilterIcon() { @@ -131,13 +125,13 @@ private ClickableItem getFilterIcon() { return ClickableItem.of( new ItemBuilder() - .material(getMapTagMaterial(getFilterTag())) + .material(mapTagMaterial(getFilterTag())) .name(TextTranslations.translateLegacy(getFilterTag().getName(), getViewer())) .lore( colorize("&7Filter: &b" + (filterIndex + 1) + " &7/&3 " + tags.size()), colorize( "&7Total Maps: &a" + getFilteredMapItems().size() + " &7/&2 " + maps.size())) - .enchant(Enchantment.LUCK, 1) + .enchant(Enchantments.LUCK_OF_THE_SEA, 1) .flags(ItemFlag.values()) .build(), c -> { @@ -182,60 +176,53 @@ private List getMapItems(List maps) { } private List getFilteredMapItems() { - return getMapItems( - maps.stream() - .filter( - map -> { - if (viewAll) return true; - - Collection tags = map.getTags(); - return tags != null && tags.contains(getFilterTag()); - }) - .collect(Collectors.toList())); + return getMapItems(maps.stream() + .filter(map -> { + if (viewAll) return true; + + Collection tags = map.getTags(); + return tags != null && tags.contains(getFilterTag()); + }) + .collect(Collectors.toList())); } private ClickableItem getMapIcon(MapInfo map) { boolean isAdded = getFeature().getParty().isMapAdded(map); - Material icon = - map.getTags().isEmpty() - || !map.getTags().stream().filter(t -> t.isGamemode()).findAny().isPresent() - ? Material.MAP - : getMapTagMaterial( - map.getTags().stream().filter(tag -> tag.isGamemode()).findAny().get()); - - ItemBuilder builder = - new ItemBuilder() - .material(icon) - .name(colorize("&6" + map.getName())) - .lore( - colorize( - "&7Max Players: &e" + map.getMaxPlayers().stream().reduce(0, Integer::sum)), - colorize( - "&7Tags: " + TextTranslations.translateLegacy(renderMapTags(map), getViewer())), - colorize(isAdded ? "&cAlready added" : "&aClick to add map")) // TODO: - .flags(ItemFlag.values()); + Material icon; + icon = map.getTags().isEmpty() + || !map.getTags().stream().filter(t -> t.isGamemode()).findAny().isPresent() + ? Material.MAP + : mapTagMaterial( + map.getTags().stream().filter(tag -> tag.isGamemode()).findAny().get()); + + ItemBuilder builder = new ItemBuilder() + .material(icon) + .name(colorize("&6" + map.getName())) + .lore( + colorize("&7Max Players: &e" + map.getMaxPlayers().stream().reduce(0, Integer::sum)), + colorize( + "&7Tags: " + TextTranslations.translateLegacy(renderMapTags(map), getViewer())), + colorize(isAdded ? "&cAlready added" : "&aClick to add map")) // TODO: + .flags(ItemFlag.values()); if (isAdded) { - builder.enchant(Enchantment.LUCK, 1); + builder.enchant(Enchantments.LUCK_OF_THE_SEA, 1); } - return ClickableItem.of( - builder.build(), - c -> { - Bukkit.dispatchCommand(getViewer(), "event addmap " + map.getName()); - }); + return ClickableItem.of(builder.build(), c -> { + Bukkit.dispatchCommand(getViewer(), "event addmap " + map.getName()); + }); } private ClickableItem getNoMapsIcon() { - return ClickableItem.empty( - new ItemBuilder() - .material(Material.STAINED_GLASS_PANE) - .color(DyeColor.RED) - .name(colorize("&cNo Maps found")) - .lore(colorize("&7Check &b/maps &7for details")) - .flags(ItemFlag.values()) - .build()); + return ClickableItem.empty(new ItemBuilder() + .material(Materials.STAINED_GLASS_PANE) + .color(DyeColor.RED) + .name(colorize("&cNo Maps found")) + .lore(colorize("&7Check &b/maps &7for details")) + .flags(ItemFlag.values()) + .build()); } private Component renderMapTags(MapInfo map) { @@ -245,51 +232,4 @@ private Component renderMapTags(MapInfo map) { .collect(Collectors.toList()), NamedTextColor.GRAY); } - - private Material getMapTagMaterial(MapTag mapTag) { - switch (mapTag.getId()) { - case "2teams": - return Material.LEATHER; - case "ffa": - return Material.DIAMOND_SWORD; - case "border": - return Material.IRON_BARDING; - case "wool": - return Material.WOOL; - case "controlpoint": - return Material.BEACON; - case "flag": - return Material.BANNER; - case "classes": - return Material.FISHING_ROD; - case "deathmatch": - return Material.STONE_SWORD; - case "monument": - return Material.DIAMOND_PICKAXE; - case "4teams": - return Material.TRAP_DOOR; - case "timelimit": - return Material.WATCH; - case "autotnt": - return Material.TNT; - case "core": - return Material.OBSIDIAN; - case "blitz": - return Material.EGG; - case "scorebox": - return Material.WEB; - case "6teams": - return Material.BED; - case "rage": - return Material.BOW; - case "3teams": - return Material.WORKBENCH; - case "terrain": - return Material.GRASS; - case "8teams": - return Material.INK_SACK; - default: - return Material.MAP; - } - } } diff --git a/core/src/main/java/dev/pgm/community/party/menu/maps/MapMenu.java b/core/src/main/java/dev/pgm/community/party/menu/maps/MapMenu.java index 751fd8a0..b01d7bec 100644 --- a/core/src/main/java/dev/pgm/community/party/menu/maps/MapMenu.java +++ b/core/src/main/java/dev/pgm/community/party/menu/maps/MapMenu.java @@ -8,6 +8,8 @@ import dev.pgm.community.party.types.RegularPoolParty; import dev.pgm.community.utils.PGMUtils; import dev.pgm.community.utils.SkullUtils; +import dev.pgm.community.utils.compatibility.Enchantments; +import dev.pgm.community.utils.compatibility.Materials; import fr.minuskube.inv.ClickableItem; import fr.minuskube.inv.content.InventoryContents; import fr.minuskube.inv.content.Pagination; @@ -18,7 +20,6 @@ import org.bukkit.Bukkit; import org.bukkit.DyeColor; import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; import tc.oc.pgm.api.map.MapInfo; @@ -128,34 +129,30 @@ private ClickableItem getMapIcon(MapInfo map) { } private ClickableItem getPoolIcon(MapPool pool, boolean active) { - ItemBuilder icon = - new ItemBuilder() - .material(Material.MAP) - .name(colorize("&6" + StringUtils.capitalize(pool.getName()))) - .lore( - colorize("&7Maps: &b" + pool.getMaps().size()), - colorize(active ? "&aSelected Pool" : "&7Click to set")) - .flags(ItemFlag.values()); + ItemBuilder icon = new ItemBuilder() + .material(Material.MAP) + .name(colorize("&6" + StringUtils.capitalize(pool.getName()))) + .lore( + colorize("&7Maps: &b" + pool.getMaps().size()), + colorize(active ? "&aSelected Pool" : "&7Click to set")) + .flags(ItemFlag.values()); if (active) { - icon.enchant(Enchantment.LUCK, 1); + icon.enchant(Enchantments.LUCK_OF_THE_SEA, 1); } - return ClickableItem.of( - icon.build(), - c -> { - Bukkit.dispatchCommand(getViewer(), "event setpool " + pool.getName()); - }); + return ClickableItem.of(icon.build(), c -> { + Bukkit.dispatchCommand(getViewer(), "event setpool " + pool.getName()); + }); } private ClickableItem getNoMapsIcon() { - return ClickableItem.empty( - new ItemBuilder() - .material(Material.STAINED_GLASS_PANE) - .color(DyeColor.RED) - .name(colorize("&cNo Maps found")) - .lore(colorize("&7Add maps using the button below")) - .flags(ItemFlag.values()) - .build()); + return ClickableItem.empty(new ItemBuilder() + .material(Materials.STAINED_GLASS_PANE) + .color(DyeColor.RED) + .name(colorize("&cNo Maps found")) + .lore(colorize("&7Add maps using the button below")) + .flags(ItemFlag.values()) + .build()); } private static String getTitle(MapPartyFeature feature) { diff --git a/core/src/main/java/dev/pgm/community/party/menu/settings/MapPartySettingsMenu.java b/core/src/main/java/dev/pgm/community/party/menu/settings/MapPartySettingsMenu.java index 139611f6..d7fe744a 100644 --- a/core/src/main/java/dev/pgm/community/party/menu/settings/MapPartySettingsMenu.java +++ b/core/src/main/java/dev/pgm/community/party/menu/settings/MapPartySettingsMenu.java @@ -11,6 +11,7 @@ import dev.pgm.community.party.settings.MapPartySettings; import dev.pgm.community.party.settings.PartyBooleanSetting; import dev.pgm.community.party.types.CustomPoolParty; +import dev.pgm.community.utils.compatibility.Materials; import fr.minuskube.inv.ClickableItem; import fr.minuskube.inv.content.InventoryContents; import java.time.Duration; @@ -75,61 +76,52 @@ public void update(Player player, InventoryContents contents) { private ClickableItem getTimelimitItem(MapParty party) { boolean hasLimit = party.getLength() != null; - Component limitRender = - !hasLimit - ? text("No limit", NamedTextColor.YELLOW) - : duration(party.getLength(), NamedTextColor.YELLOW); - - ItemStack item = - new ItemBuilder() - .material(Material.WATCH) - .name(colorize("&2&lTimelimit")) - .lore( - colorize( - "&7Current: " - + TextTranslations.translateLegacy( - limitRender.color(NamedTextColor.GRAY), getViewer())), - colorize("&7Click to edit")) - .flags(ItemFlag.values()) - .build(); - - return ClickableItem.of( - item, - c -> { - close(); - Audience viewer = Audience.get(getViewer()); - viewer.sendMessage( - text() - .append(text("Current party timelimit: ")) - .append(limitRender) - .color(NamedTextColor.GRAY)); - - // TODO: make presets customizable via config? - // [30 minutes] [1 hour] [3 hours] [Custom] - Component preset1 = renderTimePreset(Duration.ofMinutes(30)); - Component preset2 = renderTimePreset(Duration.ofHours(1)); - Component preset3 = renderTimePreset(Duration.ofHours(3)); - Component custom = - text() - .append(text("[")) - .append(text("Custom", NamedTextColor.YELLOW, TextDecoration.BOLD)) - .append(text("]")) - .color(NamedTextColor.GRAY) - .hoverEvent( - HoverEvent.showText( - text("Click to set a custom timelimit", NamedTextColor.GRAY))) - .clickEvent(ClickEvent.suggestCommand("/event timelimit ")) - .build(); - viewer.sendMessage( - text() - .append(preset1) - .append(space()) - .append(preset2) - .append(space()) - .append(preset3) - .append(space()) - .append(custom)); - }); + Component limitRender = !hasLimit + ? text("No limit", NamedTextColor.YELLOW) + : duration(party.getLength(), NamedTextColor.YELLOW); + + ItemStack item = new ItemBuilder() + .material(Materials.WATCH) + .name(colorize("&2&lTimelimit")) + .lore( + colorize("&7Current: " + + TextTranslations.translateLegacy( + limitRender.color(NamedTextColor.GRAY), getViewer())), + colorize("&7Click to edit")) + .flags(ItemFlag.values()) + .build(); + + return ClickableItem.of(item, c -> { + close(); + Audience viewer = Audience.get(getViewer()); + viewer.sendMessage(text() + .append(text("Current party timelimit: ")) + .append(limitRender) + .color(NamedTextColor.GRAY)); + + // TODO: make presets customizable via config? + // [30 minutes] [1 hour] [3 hours] [Custom] + Component preset1 = renderTimePreset(Duration.ofMinutes(30)); + Component preset2 = renderTimePreset(Duration.ofHours(1)); + Component preset3 = renderTimePreset(Duration.ofHours(3)); + Component custom = text() + .append(text("[")) + .append(text("Custom", NamedTextColor.YELLOW, TextDecoration.BOLD)) + .append(text("]")) + .color(NamedTextColor.GRAY) + .hoverEvent( + HoverEvent.showText(text("Click to set a custom timelimit", NamedTextColor.GRAY))) + .clickEvent(ClickEvent.suggestCommand("/event timelimit ")) + .build(); + viewer.sendMessage(text() + .append(preset1) + .append(space()) + .append(preset2) + .append(space()) + .append(preset3) + .append(space()) + .append(custom)); + }); } private Component renderTimePreset(Duration time) { @@ -145,53 +137,44 @@ private Component renderTimePreset(Duration time) { } private ClickableItem getNameItem(MapParty party) { - ItemStack item = - new ItemBuilder() - .material(Material.NAME_TAG) - .name(colorize("&3&lParty Name")) - .lore(colorize("&7Current: " + party.getName()), colorize("&7Click to edit")) - .flags(ItemFlag.values()) - .build(); - - return ClickableItem.of( - item, - c -> { - close(); - Audience viewer = Audience.get(getViewer()); - Component edit = - text() - .append(text(" [")) - .append(text("Edit", NamedTextColor.YELLOW, TextDecoration.BOLD)) - .append(text("]")) - .color(NamedTextColor.GRAY) - .hoverEvent( - HoverEvent.showText(text("Click to edit party name", NamedTextColor.GRAY))) - .clickEvent(ClickEvent.suggestCommand("/event setname ")) - .build(); - viewer.sendMessage( - text() - .append(text("Current party name: ", NamedTextColor.GRAY)) - .append(party.getStyledName()) - .append(edit) - .build()); - }); + ItemStack item = new ItemBuilder() + .material(Material.NAME_TAG) + .name(colorize("&3&lParty Name")) + .lore(colorize("&7Current: " + party.getName()), colorize("&7Click to edit")) + .flags(ItemFlag.values()) + .build(); + + return ClickableItem.of(item, c -> { + close(); + Audience viewer = Audience.get(getViewer()); + Component edit = text() + .append(text(" [")) + .append(text("Edit", NamedTextColor.YELLOW, TextDecoration.BOLD)) + .append(text("]")) + .color(NamedTextColor.GRAY) + .hoverEvent(HoverEvent.showText(text("Click to edit party name", NamedTextColor.GRAY))) + .clickEvent(ClickEvent.suggestCommand("/event setname ")) + .build(); + viewer.sendMessage(text() + .append(text("Current party name: ", NamedTextColor.GRAY)) + .append(party.getStyledName()) + .append(edit) + .build()); + }); } private ClickableItem getPoolModeItem(CustomPoolParty party) { - ItemBuilder builder = - new ItemBuilder() - .material(party.isVoted() ? Material.PAPER : Material.RAILS) - .name(colorize("&d&lPool Mode")) - .lore( - colorize("&7Current: &6" + (party.isVoted() ? "Voted" : "Rotation")), - colorize("&7Click to toggle mode")) - .flags(ItemFlag.values()); - - return ClickableItem.of( - builder.build(), - c -> { - Bukkit.dispatchCommand(getViewer(), "event mode"); - }); + ItemBuilder builder = new ItemBuilder() + .material(party.isVoted() ? Material.PAPER : Materials.RAILS) + .name(colorize("&d&lPool Mode")) + .lore( + colorize("&7Current: &6" + (party.isVoted() ? "Voted" : "Rotation")), + colorize("&7Click to toggle mode")) + .flags(ItemFlag.values()); + + return ClickableItem.of(builder.build(), c -> { + Bukkit.dispatchCommand(getViewer(), "event mode"); + }); } private ClickableItem getSettingItem(PartyBooleanSetting setting) { @@ -199,12 +182,10 @@ private ClickableItem getSettingItem(PartyBooleanSetting setting) { } private ClickableItem getAutoScalingItem(PartyBooleanSetting setting) { - return ClickableItem.of( - settingItemBuilder(setting), - c -> { - setting.toggle(); - Bukkit.dispatchCommand(getViewer(), "event autoscaling " + setting.getValue()); - }); + return ClickableItem.of(settingItemBuilder(setting), c -> { + setting.toggle(); + Bukkit.dispatchCommand(getViewer(), "event autoscaling " + setting.getValue()); + }); } private static ItemStack settingItemBuilder(PartyBooleanSetting setting) { diff --git a/core/src/main/java/dev/pgm/community/party/settings/MapPartySettings.java b/core/src/main/java/dev/pgm/community/party/settings/MapPartySettings.java index 79028019..fb887c50 100644 --- a/core/src/main/java/dev/pgm/community/party/settings/MapPartySettings.java +++ b/core/src/main/java/dev/pgm/community/party/settings/MapPartySettings.java @@ -1,6 +1,7 @@ package dev.pgm.community.party.settings; import dev.pgm.community.party.MapPartyConfig; +import dev.pgm.community.utils.compatibility.Materials; import org.bukkit.Material; public class MapPartySettings { @@ -10,27 +11,24 @@ public class MapPartySettings { private PartyBooleanSetting autoscalingTeams; public MapPartySettings(MapPartyConfig config) { - this.showLoginMessage = - new PartyBooleanSetting( - "Login Message", - "Display a login welcome when party is active", - config.showLoginMessage(), - Material.SIGN, - Material.BARRIER); - this.showPartyNotifications = - new PartyBooleanSetting( - "Notification", - "Broadcast announcements related to party", - config.showPartyNotifications(), - Material.BOOK_AND_QUILL, - Material.BARRIER); - this.autoscalingTeams = - new PartyBooleanSetting( - "Autoscaling Teams", - "Automatically resize teams on match cycle", - true, - Material.GOLD_PLATE, - Material.WOOD_PLATE); + this.showLoginMessage = new PartyBooleanSetting( + "Login Message", + "Display a login welcome when party is active", + config.showLoginMessage(), + Material.SIGN, + Material.BARRIER); + this.showPartyNotifications = new PartyBooleanSetting( + "Notification", + "Broadcast announcements related to party", + config.showPartyNotifications(), + Materials.BOOK_AND_QUILL, + Material.BARRIER); + this.autoscalingTeams = new PartyBooleanSetting( + "Autoscaling Teams", + "Automatically resize teams on match cycle", + true, + Materials.GOLD_PLATE, + Materials.WOOD_PLATE); } public PartyBooleanSetting getShowLoginMessage() { diff --git a/core/src/main/java/dev/pgm/community/requests/commands/sponsor/SponsorCommands.java b/core/src/main/java/dev/pgm/community/requests/commands/sponsor/SponsorCommands.java index 65ba7637..a51a0985 100644 --- a/core/src/main/java/dev/pgm/community/requests/commands/sponsor/SponsorCommands.java +++ b/core/src/main/java/dev/pgm/community/requests/commands/sponsor/SponsorCommands.java @@ -36,7 +36,7 @@ import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; -import net.md_5.bungee.api.ChatColor; +import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import tc.oc.pgm.api.map.Contributor; diff --git a/core/src/main/java/dev/pgm/community/requests/menu/SponsorMenu.java b/core/src/main/java/dev/pgm/community/requests/menu/SponsorMenu.java index 1dbf342a..a4f452d2 100644 --- a/core/src/main/java/dev/pgm/community/requests/menu/SponsorMenu.java +++ b/core/src/main/java/dev/pgm/community/requests/menu/SponsorMenu.java @@ -3,6 +3,7 @@ import static tc.oc.pgm.util.bukkit.BukkitUtils.colorize; import dev.pgm.community.menu.MapSelectionMenu; +import dev.pgm.community.utils.compatibility.Materials; import fr.minuskube.inv.ClickableItem; import fr.minuskube.inv.SmartInventory; import java.util.List; @@ -37,23 +38,20 @@ public ClickableItem getCloseButton() { @Override public ClickableItem getBorderItem() { - return ClickableItem.empty( - new ItemBuilder() - .material(Material.STAINED_GLASS_PANE) - .color(DyeColor.YELLOW) - .name(" ") - .flags(ItemFlag.values()) - .build()); + return ClickableItem.empty(new ItemBuilder() + .material(Materials.STAINED_GLASS_PANE) + .color(DyeColor.YELLOW) + .name(" ") + .flags(ItemFlag.values()) + .build()); } @Override public ClickableItem getMapIcon(MapInfo map) { - return ClickableItem.of( - getMapItem(map), - c -> { - Bukkit.dispatchCommand(getViewer(), "sponsor request " + map.getName()); - getViewer().closeInventory(); - }); + return ClickableItem.of(getMapItem(map), c -> { + Bukkit.dispatchCommand(getViewer(), "sponsor request " + map.getName()); + getViewer().closeInventory(); + }); } private ItemStack getMapItem(MapInfo map) { diff --git a/core/src/main/java/dev/pgm/community/utils/PGMUtils.java b/core/src/main/java/dev/pgm/community/utils/PGMUtils.java index 45fee40e..ed3db150 100644 --- a/core/src/main/java/dev/pgm/community/utils/PGMUtils.java +++ b/core/src/main/java/dev/pgm/community/utils/PGMUtils.java @@ -1,16 +1,19 @@ package dev.pgm.community.utils; import com.google.common.collect.Lists; +import dev.pgm.community.utils.compatibility.Materials; import java.time.Duration; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; import tc.oc.pgm.api.PGM; import tc.oc.pgm.api.map.MapInfo; +import tc.oc.pgm.api.map.MapTag; import tc.oc.pgm.api.match.Match; import tc.oc.pgm.api.match.MatchPhase; import tc.oc.pgm.api.player.MatchPlayer; @@ -184,4 +187,30 @@ public static List getPlayers(String permissionFilter) { .filter(mp -> mp.getBukkit().hasPermission(permissionFilter)) .collect(Collectors.toList()); } + + public static Material mapTagMaterial(MapTag mapTag) { + return switch (mapTag.getId()) { + case "2teams" -> Material.LEATHER; + case "ffa" -> Material.DIAMOND_SWORD; + case "border" -> Materials.IRON_BARDING; + case "wool" -> Materials.WOOL; + case "controlpoint" -> Material.BEACON; + case "flag" -> Materials.BANNER; + case "classes" -> Material.FISHING_ROD; + case "deathmatch" -> Material.STONE_SWORD; + case "monument" -> Material.DIAMOND_PICKAXE; + case "4teams" -> Materials.TRAP_DOOR; + case "timelimit" -> Materials.WATCH; + case "autotnt" -> Material.TNT; + case "core" -> Material.OBSIDIAN; + case "blitz" -> Material.EGG; + case "scorebox" -> Materials.WEB; + case "6teams" -> Materials.BED; + case "rage" -> Material.BOW; + case "3teams" -> Materials.WORKBENCH; + case "terrain" -> Materials.GRASS; + case "8teams" -> Materials.DYE; + default -> Material.MAP; + }; + } } diff --git a/core/src/main/java/dev/pgm/community/utils/SkullUtils.java b/core/src/main/java/dev/pgm/community/utils/SkullUtils.java index 88d377b1..dfbfe933 100644 --- a/core/src/main/java/dev/pgm/community/utils/SkullUtils.java +++ b/core/src/main/java/dev/pgm/community/utils/SkullUtils.java @@ -3,11 +3,11 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; +import dev.pgm.community.utils.compatibility.Materials; import java.lang.reflect.Field; import java.util.Arrays; +import java.util.Base64; import java.util.UUID; -import org.apache.commons.codec.binary.Base64; -import org.bukkit.Material; import org.bukkit.SkullType; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; @@ -17,7 +17,7 @@ public class SkullUtils { public static ItemStack customSkull(String url, String displayName, String... lore) { - ItemStack head = new ItemStack(Material.SKULL_ITEM); + ItemStack head = new ItemStack(Materials.SKULL_ITEM); head.setDurability((short) SkullType.PLAYER.ordinal()); if (url.isEmpty()) { return head; @@ -47,8 +47,8 @@ private static GameProfile createGameProfile(String url) { return null; } - byte[] encodedData = - new Base64().encode(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes()); + byte[] encodedData = Base64.getEncoder() + .encode(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes()); propertyMap.put("textures", new Property("textures", new String(encodedData))); return profile; diff --git a/core/src/main/java/dev/pgm/community/utils/compatibility/Enchantments.java b/core/src/main/java/dev/pgm/community/utils/compatibility/Enchantments.java new file mode 100644 index 00000000..fa14a44b --- /dev/null +++ b/core/src/main/java/dev/pgm/community/utils/compatibility/Enchantments.java @@ -0,0 +1,13 @@ +package dev.pgm.community.utils.compatibility; + +import org.bukkit.enchantments.Enchantment; +import tc.oc.pgm.util.bukkit.BukkitUtils; + +public interface Enchantments { + Enchantment INFINITY = parse("ARROW_INFINITE", "infinity"); + Enchantment LUCK_OF_THE_SEA = parse("LUCK", "luck_of_the_sea"); + + private static Enchantment parse(String... names) { + return BukkitUtils.parse(Enchantment::getByName, names); + } +} diff --git a/core/src/main/java/dev/pgm/community/utils/compatibility/EntityTypes.java b/core/src/main/java/dev/pgm/community/utils/compatibility/EntityTypes.java new file mode 100644 index 00000000..ee97fef6 --- /dev/null +++ b/core/src/main/java/dev/pgm/community/utils/compatibility/EntityTypes.java @@ -0,0 +1,12 @@ +package dev.pgm.community.utils.compatibility; + +import org.bukkit.entity.EntityType; +import tc.oc.pgm.util.bukkit.BukkitUtils; + +public interface EntityTypes { + EntityType PIG_ZOMBIE = parse("PIG_ZOMBIE", "ZOMBIFIED_PIGLIN"); + + private static EntityType parse(String... names) { + return BukkitUtils.parse(EntityType::valueOf, names); + } +} diff --git a/core/src/main/java/dev/pgm/community/utils/compatibility/Materials.java b/core/src/main/java/dev/pgm/community/utils/compatibility/Materials.java new file mode 100644 index 00000000..6793c935 --- /dev/null +++ b/core/src/main/java/dev/pgm/community/utils/compatibility/Materials.java @@ -0,0 +1,45 @@ +package dev.pgm.community.utils.compatibility; + +import org.bukkit.Material; +import tc.oc.pgm.util.bukkit.BukkitUtils; + +public interface Materials { + + Material WOOL = parse("WOOL", "LEGACY_WOOL"); + Material WEB = parse("WEB", "COBWEB"); + Material SIGN = parse("SIGN", "OAK_SIGN"); + Material BOOK_AND_QUILL = parse("BOOK_AND_QUILL", "WRITABLE_BOOK"); + Material EYE_OF_ENDER = parse("EYE_OF_ENDER", "ENDER_EYE"); + Material FIREWORK = parse("FIREWORK", "FIREWORK_ROCKET"); + Material WATCH = parse("WATCH", "CLOCK"); + Material DYE = parse("INK_SACK", "BLACK_DYE"); + Material WORKBENCH = parse("WORKBENCH", "CRAFTING_TABLE"); + Material IRON_BARDING = parse("IRON_BARDING", "IRON_HORSE_ARMOR"); + Material BANNER = parse("BANNER", "WHITE_BANNER"); + Material TRAP_DOOR = parse("TRAP_DOOR", "OAK_TRAPDOOR"); + Material BED = parse("BED", "RED_BED"); + Material GRASS = parse("GRASS", "GRASS_BLOCK"); + Material GOLD_PLATE = parse("GOLD_PLATE", "HEAVY_WEIGHTED_PRESSURE_PLATE"); + Material WOOD_PLATE = parse("WOOD_PLATE", "OAK_PRESSURE_PLATE"); + Material FENCE = parse("FENCE", "OAK_FENCE"); + Material WOOD_STEP = parse("WOOD_STEP", "OAK_SLAB"); + Material WOOD = parse("WOOD", "OAK_PLANKS"); + Material DIODE = parse("DIODE", "REPEATER"); + Material SKULL_ITEM = parse("SKULL_ITEM", "PLAYER_HEAD"); + Material NETHER_BRICK_ITEM = parse("NETHER_BRICK_ITEM", "NETHER_BRICK"); + Material FIREBALL = parse("FIREBALL", "FIRE_CHARGE"); + Material REDSTONE_TORCH_ON = parse("REDSTONE_TORCH_ON", "REDSTONE_TORCH"); + Material MOB_SPAWNER = parse("MOB_SPAWNER", "SPAWNER"); + Material RED_ROSE = parse("RED_ROSE", "POPPY"); + Material SULPHUR = parse("SULPHUR", "GUNPOWDER"); + Material STAINED_GLASS_PANE = parse("STAINED_GLASS_PANE", "LEGACY_STAINED_GLASS_PANE"); + Material WOOD_SWORD = parse("WOOD_SWORD", "WOODEN_SWORD"); + Material WOOD_PICKAXE = parse("WOOD_PICKAXE", "WOODEN_PICKAXE"); + Material EMPTY_MAP = parse("EMPTY_MAP", "MAP"); + Material REDSTONE_COMPARATOR = parse("REDSTONE_COMPARATOR", "COMPARATOR"); + Material RAILS = parse("RAILS", "RAIL"); + + static Material parse(String... names) { + return BukkitUtils.parse(Material::valueOf, names); + } +} diff --git a/core/src/main/java/dev/pgm/community/utils/compatibility/PotionEffects.java b/core/src/main/java/dev/pgm/community/utils/compatibility/PotionEffects.java new file mode 100644 index 00000000..1b6aed2d --- /dev/null +++ b/core/src/main/java/dev/pgm/community/utils/compatibility/PotionEffects.java @@ -0,0 +1,18 @@ +package dev.pgm.community.utils.compatibility; + +import org.bukkit.potion.PotionEffectType; +import tc.oc.pgm.util.bukkit.BukkitUtils; + +public interface PotionEffects { + PotionEffectType NAUSEA = parse("CONFUSION", "nausea"); + PotionEffectType RESISTANCE = parse("DAMAGE_RESISTANCE", "resistance"); + PotionEffectType HASTE = parse("FAST_DIGGING", "HASTE"); + PotionEffectType STRENGTH = parse("INCREASE_DAMAGE", "strength"); + PotionEffectType JUMP_BOOST = parse("JUMP", "jump_boost"); + PotionEffectType SLOWNESS = parse("SLOW", "slowness"); + PotionEffectType MINING_FATIGUE = parse("SLOW_DIGGING", "mining_fatigue"); + + private static PotionEffectType parse(String... names) { + return BukkitUtils.parse(PotionEffectType::getByName, names); + } +}