From 9db77ecd5651e0cb5147daf6b864007884b81818 Mon Sep 17 00:00:00 2001 From: EinfachBeez Date: Mon, 8 Jul 2024 00:26:38 +0200 Subject: [PATCH] implement spigot 1.21 api & fix experimental items, minecraft name mappings --- .../action/impl/HealEntityAction.java | 5 +- .../action/impl/ModifyMaxHealthAction.java | 6 +- .../trigger/impl/ConsumeItemTrigger.java | 3 +- .../impl/StandsNotOnSpecificBlockTrigger.java | 3 +- .../challenge/BlockRandomizerChallenge.java | 16 ++-- .../CraftingRandomizerChallenge.java | 5 +- .../challenge/FiveHundredBlocksChallenge.java | 4 +- .../challenge/ForceBlockChallenge.java | 3 +- .../challenge/ForceItemChallenge.java | 3 +- .../challenge/FreezeChallenge.java | 15 ++-- .../challenge/InfectionChallenge.java | 7 +- .../challenge/JumpAndRunChallenge.java | 4 +- .../challenge/LowDropRateChallenge.java | 3 +- .../challenge/MissingItemsChallenge.java | 3 +- .../challenge/MobRandomizerChallenge.java | 31 ++++---- .../PermanentEffectOnDamageChallenge.java | 16 ++-- .../challenge/RandomEventChallenge.java | 3 +- .../RandomPotionEffectChallenge.java | 5 +- .../goal/CollectAllItemsGoal.java | 3 +- .../goal/CollectMostItemsGoal.java | 3 +- .../implementation/goal/CollectWoodGoal.java | 3 +- .../goal/KillSnowGolemGoal.java | 7 +- .../implementation/goal/RaceGoal.java | 8 +- .../goal/forcebattle/targets/BlockTarget.java | 3 +- .../goal/forcebattle/targets/ItemTarget.java | 3 +- .../setting/BastionSpawnSetting.java | 3 +- .../setting/DeathMessageSetting.java | 4 +- .../setting/DifficultySetting.java | 6 +- .../setting/PositionSetting.java | 4 +- .../setting/RespawnSetting.java | 12 +-- .../implementation/setting/SoupSetting.java | 7 +- .../type/abstraction/HydraChallenge.java | 8 +- .../type/helper/SubSettingsHelper.java | 5 +- .../ChooseMultipleItemGenerator.java | 15 ++-- .../categorised/SettingCategory.java | 4 +- .../implementation/TimerMenuGenerator.java | 4 +- .../custom/InfoMenuGenerator.java | 3 +- .../custom/MaterialMenuGenerator.java | 3 +- .../management/server/ServerManager.java | 4 +- .../plugin/spigot/command/SearchCommand.java | 3 +- .../listener/PlayerConnectionListener.java | 10 +-- .../plugin/utils/item/DefaultItem.java | 6 +- .../plugin/utils/misc/ColorConversions.java | 7 +- .../plugin/utils/misc/ExperimentalUtils.java | 59 ++++++++++++++ .../plugin/utils/misc/InventoryUtils.java | 2 +- .../utils/misc/MinecraftNameWrapper.java | 77 +++++++++++++++++++ .../plugin/utils/misc/ParticleUtils.java | 2 +- pom.xml | 2 +- 48 files changed, 289 insertions(+), 126 deletions(-) create mode 100644 plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/ExperimentalUtils.java create mode 100644 plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/MinecraftNameWrapper.java diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/custom/settings/action/impl/HealEntityAction.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/custom/settings/action/impl/HealEntityAction.java index 646adc981..6e0f923d3 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/custom/settings/action/impl/HealEntityAction.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/custom/settings/action/impl/HealEntityAction.java @@ -1,10 +1,10 @@ package net.codingarea.challenges.plugin.challenges.custom.settings.action.impl; -import net.anweisen.utilities.bukkit.utils.item.MaterialWrapper; import net.codingarea.challenges.plugin.challenges.custom.settings.action.EntityTargetAction; import net.codingarea.challenges.plugin.challenges.type.helper.SubSettingsHelper; import net.codingarea.challenges.plugin.utils.item.DefaultItem; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import org.bukkit.Material; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; @@ -24,7 +24,8 @@ public HealEntityAction(String name) { String prefix = DefaultItem.getItemPrefix(); for (int i = 1; i < 21; i++) { builder.addSetting( - String.valueOf(i), new ItemBuilder(MaterialWrapper.RED_DYE, prefix + "§7" + (i / 2f) + " §c❤").setAmount(i).build()); + String.valueOf(i), new ItemBuilder( + MinecraftNameWrapper.RED_DYE, prefix + "§7" + (i / 2f) + " §c❤").setAmount(i).build()); } })); } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/custom/settings/action/impl/ModifyMaxHealthAction.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/custom/settings/action/impl/ModifyMaxHealthAction.java index ddd6d2bd3..7075c9e34 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/custom/settings/action/impl/ModifyMaxHealthAction.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/custom/settings/action/impl/ModifyMaxHealthAction.java @@ -1,6 +1,5 @@ package net.codingarea.challenges.plugin.challenges.custom.settings.action.impl; -import net.anweisen.utilities.bukkit.utils.item.MaterialWrapper; import net.codingarea.challenges.plugin.challenges.custom.settings.action.PlayerTargetAction; import net.codingarea.challenges.plugin.challenges.implementation.setting.MaxHealthSetting; import net.codingarea.challenges.plugin.challenges.type.abstraction.AbstractChallenge; @@ -8,6 +7,7 @@ import net.codingarea.challenges.plugin.challenges.type.helper.SubSettingsHelper; import net.codingarea.challenges.plugin.content.Message; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -23,7 +23,7 @@ public ModifyMaxHealthAction(String name) { super(name, SubSettingsHelper.createEntityTargetSettingsBuilder(false, true) .createValueChild().fill(builder -> { builder.addModifierSetting("health_offset", - new ItemBuilder(MaterialWrapper.RED_DYE, + new ItemBuilder(MinecraftNameWrapper.RED_DYE, Message.forName("item-custom-action-max_health-offset")), 0, -20, 20, integer -> "", integer -> "HP §8(§e" + (integer / 2f) + " §c❤§8)"); @@ -32,7 +32,7 @@ public ModifyMaxHealthAction(String name) { @Override public Material getMaterial() { - return MaterialWrapper.RED_DYE; + return MinecraftNameWrapper.RED_DYE; } @Override diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/custom/settings/trigger/impl/ConsumeItemTrigger.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/custom/settings/trigger/impl/ConsumeItemTrigger.java index 32d66ad68..b86324d7a 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/custom/settings/trigger/impl/ConsumeItemTrigger.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/custom/settings/trigger/impl/ConsumeItemTrigger.java @@ -6,6 +6,7 @@ import net.codingarea.challenges.plugin.utils.bukkit.misc.BukkitStringUtils; import net.codingarea.challenges.plugin.utils.item.DefaultItem; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -19,7 +20,7 @@ public class ConsumeItemTrigger extends ChallengeTrigger { public ConsumeItemTrigger(String name) { super(name, SubSettingsBuilder.createChooseMultipleItem(SubSettingsHelper.ITEM).fill(builder -> { - for (Material material : Material.values()) { + for (Material material : ExperimentalUtils.getMaterials()) { if (material.isEdible()) { builder.addSetting(material.name(), new ItemBuilder(material, DefaultItem.getItemPrefix() + BukkitStringUtils.getItemName(material).toPlainText()).build()); } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/custom/settings/trigger/impl/StandsNotOnSpecificBlockTrigger.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/custom/settings/trigger/impl/StandsNotOnSpecificBlockTrigger.java index 2f00b5718..fd880281e 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/custom/settings/trigger/impl/StandsNotOnSpecificBlockTrigger.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/custom/settings/trigger/impl/StandsNotOnSpecificBlockTrigger.java @@ -3,6 +3,7 @@ import net.codingarea.challenges.plugin.challenges.custom.settings.trigger.ChallengeTrigger; import net.codingarea.challenges.plugin.challenges.type.helper.SubSettingsHelper; import net.codingarea.challenges.plugin.utils.misc.BlockUtils; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.event.EventHandler; @@ -37,7 +38,7 @@ public void onMove(PlayerMoveEvent event) { Material type = blockBelow.getType(); - List materials = new LinkedList<>(Arrays.asList(Material.values())); + List materials = new LinkedList<>(Arrays.asList(ExperimentalUtils.getMaterials())); materials.remove(type); materials.removeIf(material -> !material.isBlock() || !material.isItem()); diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/BlockRandomizerChallenge.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/BlockRandomizerChallenge.java index 3bf430cf4..d3629f0d9 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/BlockRandomizerChallenge.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/BlockRandomizerChallenge.java @@ -1,6 +1,9 @@ package net.codingarea.challenges.plugin.challenges.implementation.challenge; -import net.codingarea.challenges.plugin.utils.item.ItemUtils; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.annotation.Nonnull; import net.anweisen.utilities.bukkit.utils.misc.BukkitReflectionUtils; import net.codingarea.challenges.plugin.Challenges; import net.codingarea.challenges.plugin.challenges.type.abstraction.RandomizerSetting; @@ -9,13 +12,10 @@ import net.codingarea.challenges.plugin.management.blocks.BlockDropManager.DropPriority; import net.codingarea.challenges.plugin.management.menu.MenuType; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.item.ItemUtils; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import org.bukkit.Material; -import javax.annotation.Nonnull; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - /** * @author anweisen | https://github.com/anweisen * @since 2.0 @@ -36,11 +36,11 @@ public ItemBuilder createDisplayItem() { protected void reloadRandomization() { BlockDropManager manager = Challenges.getInstance().getBlockDropManager(); - List blocks = new ArrayList<>(Arrays.asList(Material.values())); + List blocks = new ArrayList<>(Arrays.asList(ExperimentalUtils.getMaterials())); blocks.removeIf(material -> !ItemUtils.isObtainableInSurvival(material) || !material.isBlock() || BukkitReflectionUtils.isAir(material)); random.shuffle(blocks); - List drops = new ArrayList<>(Arrays.asList(Material.values())); + List drops = new ArrayList<>(Arrays.asList(ExperimentalUtils.getMaterials())); drops.removeIf(material -> !material.isItem() || !ItemUtils.isObtainableInSurvival(material)); random.shuffle(drops); diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/CraftingRandomizerChallenge.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/CraftingRandomizerChallenge.java index a03c15b65..48387e2a6 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/CraftingRandomizerChallenge.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/CraftingRandomizerChallenge.java @@ -5,6 +5,7 @@ import net.codingarea.challenges.plugin.content.Message; import net.codingarea.challenges.plugin.management.menu.MenuType; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -35,11 +36,11 @@ public ItemBuilder createDisplayItem() { @Override protected void reloadRandomization() { - List from = new ArrayList<>(Arrays.asList(Material.values())); + List from = new ArrayList<>(Arrays.asList(ExperimentalUtils.getMaterials())); from.removeIf(material -> !material.isItem() || !ItemUtils.isObtainableInSurvival(material)); random.shuffle(from); - List to = new ArrayList<>(Arrays.asList(Material.values())); + List to = new ArrayList<>(Arrays.asList(ExperimentalUtils.getMaterials())); to.removeIf(material -> !material.isItem() || !ItemUtils.isObtainableInSurvival(material)); random.shuffle(to); diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/FiveHundredBlocksChallenge.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/FiveHundredBlocksChallenge.java index e9b0cde8b..50773a756 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/FiveHundredBlocksChallenge.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/FiveHundredBlocksChallenge.java @@ -1,6 +1,5 @@ package net.codingarea.challenges.plugin.challenges.implementation.challenge; -import net.anweisen.utilities.bukkit.utils.item.MaterialWrapper; import net.anweisen.utilities.common.annotations.Since; import net.anweisen.utilities.common.config.Document; import net.codingarea.challenges.plugin.Challenges; @@ -12,6 +11,7 @@ import net.codingarea.challenges.plugin.utils.item.ItemBuilder; import net.codingarea.challenges.plugin.utils.misc.BlockUtils; import net.codingarea.challenges.plugin.utils.misc.InventoryUtils; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; @@ -84,7 +84,7 @@ protected void onDisable() { @NotNull @Override public ItemBuilder createDisplayItem() { - return new ItemBuilder(MaterialWrapper.SIGN, Message.forName("item-five-hundred-blocks-challenges")); + return new ItemBuilder(MinecraftNameWrapper.SIGN, Message.forName("item-five-hundred-blocks-challenges")); } @Override diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/ForceBlockChallenge.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/ForceBlockChallenge.java index 8fde92173..febee0eab 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/ForceBlockChallenge.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/ForceBlockChallenge.java @@ -13,6 +13,7 @@ import net.codingarea.challenges.plugin.management.server.scoreboard.ChallengeBossBar.BossBarInstance; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; import net.codingarea.challenges.plugin.utils.misc.BlockUtils; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import net.codingarea.challenges.plugin.utils.misc.NameHelper; import org.bukkit.Material; import org.bukkit.boss.BarColor; @@ -95,7 +96,7 @@ protected void broadcastSuccessMessage() { @Override protected void chooseForcing() { - Material[] materials = Arrays.stream(Material.values()) + Material[] materials = Arrays.stream(ExperimentalUtils.getMaterials()) .filter(Material::isBlock) .filter(ItemUtils::isObtainableInSurvival) .filter(material -> !BlockUtils.isTooHardToGet(material)) diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/ForceItemChallenge.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/ForceItemChallenge.java index 4428789d2..1e1de5779 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/ForceItemChallenge.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/ForceItemChallenge.java @@ -16,6 +16,7 @@ import net.codingarea.challenges.plugin.spigot.events.PlayerPickupItemEvent; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; import net.codingarea.challenges.plugin.utils.misc.BlockUtils; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import net.codingarea.challenges.plugin.utils.misc.NameHelper; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -93,7 +94,7 @@ protected void broadcastSuccessMessage(@Nonnull Player player) { @Override protected void chooseForcing() { - List items = new ArrayList<>(Arrays.asList(Material.values())); + List items = new ArrayList<>(Arrays.asList(ExperimentalUtils.getMaterials())); items.removeIf(material -> !ItemUtils.isObtainableInSurvival(material)); items.removeIf(material -> !material.isItem()); items.removeIf(BlockUtils::isTooHardToGet); diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/FreezeChallenge.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/FreezeChallenge.java index 8e332add7..beacbaf11 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/FreezeChallenge.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/FreezeChallenge.java @@ -1,5 +1,7 @@ package net.codingarea.challenges.plugin.challenges.implementation.challenge; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import net.anweisen.utilities.common.annotations.Since; import net.codingarea.challenges.plugin.challenges.type.abstraction.SettingModifier; import net.codingarea.challenges.plugin.challenges.type.helper.ChallengeHelper; @@ -7,6 +9,7 @@ import net.codingarea.challenges.plugin.management.menu.MenuType; import net.codingarea.challenges.plugin.management.menu.generator.categorised.SettingCategory; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import org.bukkit.Material; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -15,10 +18,6 @@ import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; /** * @author KxmischesDomi | https://github.com/kxmischesdomi @@ -63,19 +62,19 @@ public void onMove(@Nonnull PlayerMoveEvent event) { if (event.getTo() == null) return; if (event.getTo().getY() == event.getFrom().getY() && event.getTo().getX() == event.getFrom().getX() && event.getTo().getZ() == event.getFrom().getZ()) return; - PotionEffect effect = event.getPlayer().getPotionEffect(PotionEffectType.SLOW); + PotionEffect effect = event.getPlayer().getPotionEffect(MinecraftNameWrapper.SLOWNESS); if (effect == null || effect.getAmplifier() != 255) return; event.setCancelled(true); } public void setFreeze(LivingEntity entity, double damage) { int time = (int) (damage * getValue() * 20 / 2); - PotionEffect effect = entity.getPotionEffect(PotionEffectType.SLOW); - entity.removePotionEffect(PotionEffectType.SLOW); + PotionEffect effect = entity.getPotionEffect(MinecraftNameWrapper.SLOWNESS); + entity.removePotionEffect(MinecraftNameWrapper.SLOWNESS); if (effect != null && effect.getAmplifier() == 255) time += effect.getDuration(); - entity.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, time, 255)); + entity.addPotionEffect(new PotionEffect(MinecraftNameWrapper.SLOWNESS, time, 255)); } } \ No newline at end of file diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/InfectionChallenge.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/InfectionChallenge.java index 80521b38e..3f3e72e95 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/InfectionChallenge.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/InfectionChallenge.java @@ -6,6 +6,7 @@ import net.codingarea.challenges.plugin.management.menu.generator.categorised.SettingCategory; import net.codingarea.challenges.plugin.management.scheduler.task.ScheduledTask; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; @@ -58,7 +59,7 @@ private void updateSickness(@Nonnull Player player) { List entities = getNearbyTargets(player, 2); if (entities.isEmpty()) { - player.removePotionEffect(PotionEffectType.CONFUSION); + player.removePotionEffect(MinecraftNameWrapper.NAUSEA); return; } @@ -67,7 +68,7 @@ private void updateSickness(@Nonnull Player player) { if (player.getLocation().distance(currentEntity.getLocation()) <= 1.5) value = 2; } - player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, Integer.MAX_VALUE, 15)); + player.addPotionEffect(new PotionEffect(MinecraftNameWrapper.NAUSEA, Integer.MAX_VALUE, 15)); if (value == 1) { if (!player.hasPotionEffect(PotionEffectType.WITHER)) { player.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 5 * 20, 2)); @@ -80,7 +81,7 @@ private void updateSickness(@Nonnull Player player) { } private void removeEffects(@Nonnull Player player) { - player.removePotionEffect(PotionEffectType.CONFUSION); + player.removePotionEffect(MinecraftNameWrapper.NAUSEA); player.removePotionEffect(PotionEffectType.POISON); player.removePotionEffect(PotionEffectType.WITHER); } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/JumpAndRunChallenge.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/JumpAndRunChallenge.java index 7cacc020c..8d0d6bdaf 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/JumpAndRunChallenge.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/JumpAndRunChallenge.java @@ -17,6 +17,7 @@ import net.codingarea.challenges.plugin.utils.bukkit.jumpgeneration.RandomJumpGenerator; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; import net.codingarea.challenges.plugin.utils.misc.BlockUtils; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import net.codingarea.challenges.plugin.utils.misc.NameHelper; import net.codingarea.challenges.plugin.utils.misc.ParticleUtils; import org.bukkit.*; @@ -207,7 +208,8 @@ public void loadGameState(@Nonnull Document document) { @ScheduledTask(ticks = 20, timerPolicy = TimerPolicy.ALWAYS, worldPolicy = ExtraWorldPolicy.USED) public void spawnParticles() { if (targetBlock == null) return; - ParticleUtils.spawnParticleCircle(targetBlock.getLocation().add(0.5, 1.05, 0.5), Particle.SPELL_INSTANT, 13, 0.35); + ParticleUtils.spawnParticleCircle(targetBlock.getLocation().add(0.5, 1.05, 0.5), + MinecraftNameWrapper.INSTANT_EFFECT, 13, 0.35); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/LowDropRateChallenge.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/LowDropRateChallenge.java index ea2e70bb4..f903284d1 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/LowDropRateChallenge.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/LowDropRateChallenge.java @@ -8,6 +8,7 @@ import net.codingarea.challenges.plugin.management.blocks.BlockDropManager.DropPriority; import net.codingarea.challenges.plugin.management.menu.MenuType; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import org.bukkit.Material; import javax.annotation.Nonnull; @@ -61,7 +62,7 @@ protected void onDisable() { } protected void reloadChances() { - Arrays.stream(Material.values()).filter(Material::isBlock).forEach(block -> { + Arrays.stream(ExperimentalUtils.getMaterials()).filter(Material::isBlock).forEach(block -> { Challenges.getInstance().getBlockDropManager().setDropChance(block, DropPriority.CHANCE, () -> random.nextInt(10) < getValue()); }); } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/MissingItemsChallenge.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/MissingItemsChallenge.java index 2ca7d1328..e24753a54 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/MissingItemsChallenge.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/MissingItemsChallenge.java @@ -16,6 +16,7 @@ import net.codingarea.challenges.plugin.management.menu.generator.categorised.SettingCategory; import net.codingarea.challenges.plugin.utils.bukkit.command.PlayerCommand; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import net.codingarea.challenges.plugin.utils.misc.InventoryUtils; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.ClickEvent; @@ -77,7 +78,7 @@ public ItemBuilder createDisplayItem() { @Override protected void onEnable() { - materials = Arrays.stream(Material.values()) + materials = Arrays.stream(ExperimentalUtils.getMaterials()) .filter(Material::isItem) .filter(ItemUtils::isObtainableInSurvival) .collect(Collectors.toList()); diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/MobRandomizerChallenge.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/MobRandomizerChallenge.java index 6353ca097..5534d16dc 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/MobRandomizerChallenge.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/MobRandomizerChallenge.java @@ -1,5 +1,10 @@ package net.codingarea.challenges.plugin.challenges.implementation.challenge; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Nonnull; import net.anweisen.utilities.bukkit.utils.misc.MinecraftVersion; import net.anweisen.utilities.common.annotations.Since; import net.codingarea.challenges.plugin.ChallengeAPI; @@ -9,24 +14,26 @@ import net.codingarea.challenges.plugin.management.menu.MenuType; import net.codingarea.challenges.plugin.management.scheduler.task.TimerTask; import net.codingarea.challenges.plugin.management.scheduler.timer.TimerStatus; -import net.codingarea.challenges.plugin.management.server.GameWorldStorage; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import net.codingarea.challenges.plugin.utils.misc.ListBuilder; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.entity.*; +import org.bukkit.entity.Animals; +import org.bukkit.entity.Drowned; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Guardian; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Monster; +import org.bukkit.entity.SpawnCategory; +import org.bukkit.entity.WaterMob; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntitySpawnEvent; -import javax.annotation.Nonnull; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - /** * @author KxmischesDomi | https://github.com/kxmischesdomi * @since 2.0 @@ -117,7 +124,7 @@ protected void reloadRandomization() { } public List getSpawnAbleEntities() { - ListBuilder builder = new ListBuilder<>(EntityType.values()) + ListBuilder builder = new ListBuilder<>(ExperimentalUtils.getEntityTypes()) .removeIf(type -> !type.isSpawnable()) .removeIf(type -> !type.isAlive()) .remove(EntityType.ENDER_DRAGON) @@ -125,12 +132,6 @@ public List getSpawnAbleEntities() { .remove(EntityType.GIANT) .remove(EntityType.ILLUSIONER); - try { - builder.removeIf(type -> !type.isEnabledByFeature(plugin.getGameWorldStorage().getWorld(World.Environment.NORMAL))); - } catch (Exception e) { - // OLD VERSION - } - return builder.build(); } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/PermanentEffectOnDamageChallenge.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/PermanentEffectOnDamageChallenge.java index 0991fab98..bedd6ccb5 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/PermanentEffectOnDamageChallenge.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/PermanentEffectOnDamageChallenge.java @@ -1,5 +1,12 @@ package net.codingarea.challenges.plugin.challenges.implementation.challenge; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Random; +import java.util.UUID; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import net.anweisen.utilities.bukkit.utils.logging.Logger; import net.anweisen.utilities.common.annotations.Since; import net.anweisen.utilities.common.collection.pair.Tuple; @@ -14,6 +21,7 @@ import net.codingarea.challenges.plugin.management.scheduler.timer.TimerStatus; import net.codingarea.challenges.plugin.utils.item.DefaultItem; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import net.codingarea.challenges.plugin.utils.misc.TriConsumer; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -29,10 +37,6 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.*; - /** * @author KxmischesDomi | https://github.com/kxmischesdomi * @since 2.0 @@ -155,8 +159,8 @@ private void applyNewEffect(@Nonnull Player player, @Nonnull PotionEffectType po @Nullable private PotionEffectType getNewRandomEffect() { ArrayList possibleEffects = new ArrayList<>(Arrays.asList(PotionEffectType.values())); - possibleEffects.remove(PotionEffectType.HEAL); - possibleEffects.remove(PotionEffectType.HARM); + possibleEffects.remove(MinecraftNameWrapper.INSTANT_HEALTH); + possibleEffects.remove(MinecraftNameWrapper.INSTANT_DAMAGE); return possibleEffects.get(random.nextInt(possibleEffects.size())); } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/RandomEventChallenge.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/RandomEventChallenge.java index 6110f42df..65e0e559d 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/RandomEventChallenge.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/RandomEventChallenge.java @@ -10,6 +10,7 @@ import net.codingarea.challenges.plugin.management.menu.MenuType; import net.codingarea.challenges.plugin.management.menu.generator.categorised.SettingCategory; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -183,7 +184,7 @@ public Message getActivationMessage() { @Override public void run(@Nonnull Player player) { - player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 7 * 20, 0)); + player.addPotionEffect(new PotionEffect(MinecraftNameWrapper.NAUSEA, 7 * 20, 0)); player.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 3 * 20, 1)); player.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 5 * 20, 1)); } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/RandomPotionEffectChallenge.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/RandomPotionEffectChallenge.java index 8a74d49ed..13f549b34 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/RandomPotionEffectChallenge.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/challenge/RandomPotionEffectChallenge.java @@ -8,6 +8,7 @@ import net.codingarea.challenges.plugin.management.menu.generator.categorised.SettingCategory; import net.codingarea.challenges.plugin.management.scheduler.task.ScheduledTask; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.LivingEntity; @@ -72,8 +73,8 @@ public static PotionEffectType getNewRandomEffect(@Nonnull LivingEntity entity) ArrayList possibleEffects = new ArrayList<>(Arrays.asList(PotionEffectType.values())); possibleEffects.removeAll(activeEffects); - possibleEffects.remove(PotionEffectType.HEAL); - possibleEffects.remove(PotionEffectType.HARM); + possibleEffects.remove(MinecraftNameWrapper.INSTANT_HEALTH); + possibleEffects.remove(MinecraftNameWrapper.INSTANT_DAMAGE); return possibleEffects.get(IRandom.threadLocal().nextInt(possibleEffects.size())); } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/CollectAllItemsGoal.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/CollectAllItemsGoal.java index f3d8c85d0..b5ba68447 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/CollectAllItemsGoal.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/CollectAllItemsGoal.java @@ -14,6 +14,7 @@ import net.codingarea.challenges.plugin.spigot.events.PlayerPickupItemEvent; import net.codingarea.challenges.plugin.utils.bukkit.command.SenderCommand; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import net.codingarea.challenges.plugin.utils.misc.NameHelper; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -57,7 +58,7 @@ public ItemBuilder createDisplayItem() { } private void reloadItemsToFind() { - allItemsToFind = new ArrayList<>(Arrays.asList(Material.values())); + allItemsToFind = new ArrayList<>(Arrays.asList(ExperimentalUtils.getMaterials())); allItemsToFind.removeIf(material -> !material.isItem()); allItemsToFind.removeIf(material -> !ItemUtils.isObtainableInSurvival(material)); Collections.shuffle(allItemsToFind, random); diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/CollectMostItemsGoal.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/CollectMostItemsGoal.java index f443f9d46..6eb21782a 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/CollectMostItemsGoal.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/CollectMostItemsGoal.java @@ -7,6 +7,7 @@ import net.codingarea.challenges.plugin.content.Prefix; import net.codingarea.challenges.plugin.management.menu.generator.categorised.SettingCategory; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -24,7 +25,7 @@ public class CollectMostItemsGoal extends CollectionGoal { public CollectMostItemsGoal() { - super(Material.values()); + super(ExperimentalUtils.getMaterials()); setCategory(SettingCategory.SCORE_POINTS); } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/CollectWoodGoal.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/CollectWoodGoal.java index 0b04bbf1b..4ed755a9c 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/CollectWoodGoal.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/CollectWoodGoal.java @@ -11,6 +11,7 @@ import net.codingarea.challenges.plugin.spigot.events.PlayerPickupItemEvent; import net.codingarea.challenges.plugin.utils.item.DefaultItem; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import net.codingarea.challenges.plugin.utils.misc.ListBuilder; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -80,7 +81,7 @@ protected void onValueChange() { @Nonnull private Object[] getWoodMaterials() { return new ListBuilder().fill(builder -> { - for (Material material : Material.values()) { + for (Material material : ExperimentalUtils.getMaterials()) { if (isSearched(material)) builder.add(material); } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/KillSnowGolemGoal.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/KillSnowGolemGoal.java index 884c8f84b..cfe230402 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/KillSnowGolemGoal.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/KillSnowGolemGoal.java @@ -1,16 +1,15 @@ package net.codingarea.challenges.plugin.challenges.implementation.goal; +import javax.annotation.Nonnull; import net.anweisen.utilities.bukkit.utils.animation.SoundSample; import net.anweisen.utilities.common.annotations.Since; import net.codingarea.challenges.plugin.challenges.type.abstraction.KillEntityGoal; import net.codingarea.challenges.plugin.content.Message; import net.codingarea.challenges.plugin.management.menu.generator.categorised.SettingCategory; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import org.bukkit.Material; import org.bukkit.Sound; -import org.bukkit.entity.EntityType; - -import javax.annotation.Nonnull; /** * @author anweisen | https://github.com/anweisen @@ -20,7 +19,7 @@ public class KillSnowGolemGoal extends KillEntityGoal { public KillSnowGolemGoal() { - super(EntityType.SNOWMAN); + super(MinecraftNameWrapper.SNOW_GOLEM); setCategory(SettingCategory.KILL_ENTITY); this.killerNeeded = true; } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/RaceGoal.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/RaceGoal.java index 0ae60463b..d8d5a3dcb 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/RaceGoal.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/RaceGoal.java @@ -15,6 +15,7 @@ import net.codingarea.challenges.plugin.management.server.ChallengeEndCause; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; import net.codingarea.challenges.plugin.utils.misc.BlockUtils; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import net.codingarea.challenges.plugin.utils.misc.NameHelper; import net.codingarea.challenges.plugin.utils.misc.ParticleUtils; import org.bukkit.*; @@ -112,12 +113,13 @@ public void onSecond() { Location relativeGoal = goal.clone(); relativeGoal.setY(player.getLocation().getY()); relativeGoal.add(0.5, 0, 0.5); - ParticleUtils.drawLine(player, player.getLocation(), relativeGoal, Particle.REDSTONE, new DustOptions( + ParticleUtils.drawLine(player, player.getLocation(), relativeGoal, MinecraftNameWrapper.REDSTONE_DUST, new DustOptions( Color.LIME, 1), 1, 0.5, 50); if (player.getWorld() != goal.getWorld()) return; if (player.getLocation().distance(relativeGoal) > 20) return; - ParticleUtils.spawnParticleCircleAroundRadius(Challenges.getInstance(), relativeGoal, Particle.SPELL_INSTANT, 0.75, 0.5); + ParticleUtils.spawnParticleCircleAroundRadius(Challenges.getInstance(), relativeGoal, + MinecraftNameWrapper.INSTANT_EFFECT, 0.75, 0.5); }); } @@ -131,7 +133,7 @@ public void onMove(PlayerMoveEvent event) { if (BlockUtils.isSameBlockLocationIgnoreHeight(event.getTo(), goal)) { Message.forName("race-goal-reached").broadcast(Prefix.CHALLENGES, NameHelper.getName(event.getPlayer())); ChallengeAPI.endChallenge(ChallengeEndCause.GOAL_REACHED, () -> Collections.singletonList(event.getPlayer())); - ParticleUtils.spawnParticleCircleAroundRadius(Challenges.getInstance(), event.getTo(), Particle.SPELL_MOB, 0.75, 2); + ParticleUtils.spawnParticleCircleAroundRadius(Challenges.getInstance(), event.getTo(), MinecraftNameWrapper.ENTITY_EFFECT, 0.75, 2); } } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/forcebattle/targets/BlockTarget.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/forcebattle/targets/BlockTarget.java index 767ac2202..585c5acb1 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/forcebattle/targets/BlockTarget.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/forcebattle/targets/BlockTarget.java @@ -5,6 +5,7 @@ import net.codingarea.challenges.plugin.content.Message; import net.codingarea.challenges.plugin.utils.bukkit.misc.BukkitStringUtils; import net.codingarea.challenges.plugin.utils.misc.EntityUtils; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -28,7 +29,7 @@ public boolean check(Player player) { } public static List getPossibleBlocks() { - List materials = new ArrayList<>(Arrays.asList(Material.values())); + List materials = new ArrayList<>(Arrays.asList(ExperimentalUtils.getMaterials())); materials.removeIf(material -> !ItemUtils.blockIsAvailableInSurvival(material)); return materials; } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/forcebattle/targets/ItemTarget.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/forcebattle/targets/ItemTarget.java index 8afab590d..a407974ec 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/forcebattle/targets/ItemTarget.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/goal/forcebattle/targets/ItemTarget.java @@ -4,6 +4,7 @@ import net.codingarea.challenges.plugin.challenges.implementation.goal.forcebattle.ExtremeForceBattleGoal; import net.codingarea.challenges.plugin.content.Message; import net.codingarea.challenges.plugin.utils.bukkit.misc.BukkitStringUtils; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -27,7 +28,7 @@ public boolean check(Player player) { } public static List getPossibleItems() { - List materials = new ArrayList<>(Arrays.asList(Material.values())); + List materials = new ArrayList<>(Arrays.asList(ExperimentalUtils.getMaterials())); materials.removeIf(material -> !material.isItem()); materials.removeIf(material -> !ItemUtils.isObtainableInSurvival(material)); return materials; diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/BastionSpawnSetting.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/BastionSpawnSetting.java index d9462bdde..0cd7cb3a7 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/BastionSpawnSetting.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/BastionSpawnSetting.java @@ -7,6 +7,7 @@ import net.codingarea.challenges.plugin.management.challenges.annotations.RequireVersion; import net.codingarea.challenges.plugin.management.menu.MenuType; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import org.bukkit.Material; import org.bukkit.StructureType; @@ -24,7 +25,7 @@ public class BastionSpawnSetting extends NetherPortalSpawnSetting { public BastionSpawnSetting() { super(MenuType.SETTINGS, StructureType.BASTION_REMNANT, "unable-to-find-bastion", - Arrays.stream(Material.values()).filter(material -> material.name().contains("BASALT")).collect(Collectors.toList())); + Arrays.stream(ExperimentalUtils.getMaterials()).filter(material -> material.name().contains("BASALT")).collect(Collectors.toList())); } @Nonnull diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/DeathMessageSetting.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/DeathMessageSetting.java index 3b3995526..a6f8d4d99 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/DeathMessageSetting.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/DeathMessageSetting.java @@ -1,6 +1,5 @@ package net.codingarea.challenges.plugin.challenges.implementation.setting; -import net.anweisen.utilities.bukkit.utils.item.MaterialWrapper; import net.codingarea.challenges.plugin.challenges.type.abstraction.Modifier; import net.codingarea.challenges.plugin.challenges.type.helper.ChallengeHelper; import net.codingarea.challenges.plugin.content.Message; @@ -8,6 +7,7 @@ import net.codingarea.challenges.plugin.management.menu.MenuType; import net.codingarea.challenges.plugin.utils.item.DefaultItem; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import net.codingarea.challenges.plugin.utils.misc.NameHelper; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -50,7 +50,7 @@ public ItemBuilder createSettingsItem() { case ENABLED: return DefaultItem.enabled(); case VANILLA: - return DefaultItem.create(MaterialWrapper.SIGN, Message.forName("item-death-message-setting-vanilla")); + return DefaultItem.create(MinecraftNameWrapper.SIGN, Message.forName("item-death-message-setting-vanilla")); } } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/DifficultySetting.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/DifficultySetting.java index 7d2c67536..aeb0167f5 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/DifficultySetting.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/DifficultySetting.java @@ -1,6 +1,5 @@ package net.codingarea.challenges.plugin.challenges.implementation.setting; -import net.anweisen.utilities.bukkit.utils.item.MaterialWrapper; import net.anweisen.utilities.common.config.Document; import net.codingarea.challenges.plugin.ChallengeAPI; import net.codingarea.challenges.plugin.challenges.type.abstraction.Modifier; @@ -12,6 +11,7 @@ import net.codingarea.challenges.plugin.utils.bukkit.misc.BukkitStringUtils; import net.codingarea.challenges.plugin.utils.item.DefaultItem; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TranslatableComponent; @@ -59,11 +59,11 @@ public ItemBuilder createSettingsItem() { case 0: return DefaultItem.create(Material.LIME_DYE, getDifficultyName()); case 1: - return DefaultItem.create(MaterialWrapper.GREEN_DYE, getDifficultyName()); + return DefaultItem.create(MinecraftNameWrapper.GREEN_DYE, getDifficultyName()); case 2: return DefaultItem.create(Material.ORANGE_DYE, getDifficultyName()); default: - return DefaultItem.create(MaterialWrapper.RED_DYE, getDifficultyName()); + return DefaultItem.create(MinecraftNameWrapper.RED_DYE, getDifficultyName()); } } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/PositionSetting.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/PositionSetting.java index 2bd0bf7c0..78a4b5c5b 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/PositionSetting.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/PositionSetting.java @@ -11,6 +11,7 @@ import net.codingarea.challenges.plugin.management.menu.MenuType; import net.codingarea.challenges.plugin.utils.bukkit.command.PlayerCommand; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import net.codingarea.challenges.plugin.utils.misc.NameHelper; import net.codingarea.challenges.plugin.utils.misc.ParticleUtils; import net.codingarea.challenges.plugin.utils.misc.Utils; @@ -149,7 +150,8 @@ private void playParticleLine(@Nonnull Player player, @Nonnull Location position Bukkit.getScheduler().runTaskTimer(plugin, task -> { current[0]++; if (current[0] >= 10) task.cancel(); - ParticleUtils.drawLine(player, player.getLocation(), target, Particle.REDSTONE, new DustOptions(Color.LIME, 1), 1, 0.5, 50); + ParticleUtils.drawLine(player, player.getLocation(), target, + MinecraftNameWrapper.REDSTONE_DUST, new DustOptions(Color.LIME, 1), 1, 0.5, 50); }, 0, 10); } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/RespawnSetting.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/RespawnSetting.java index 69f4ae316..fa4fd7d3f 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/RespawnSetting.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/RespawnSetting.java @@ -1,5 +1,8 @@ package net.codingarea.challenges.plugin.challenges.implementation.setting; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import javax.annotation.Nonnull; import net.anweisen.utilities.bukkit.utils.animation.SoundSample; import net.codingarea.challenges.plugin.ChallengeAPI; import net.codingarea.challenges.plugin.Challenges; @@ -8,21 +11,17 @@ import net.codingarea.challenges.plugin.management.menu.MenuType; import net.codingarea.challenges.plugin.management.server.ChallengeEndCause; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import net.codingarea.challenges.plugin.utils.misc.ParticleUtils; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.Particle; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerRespawnEvent; -import javax.annotation.Nonnull; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - /** * @author anweisen | https://github.com/anweisen * @since 1.0 @@ -54,7 +53,8 @@ public void onPlayerDeath(@Nonnull PlayerDeathEvent event) { checkAllPlayersDead(); } - ParticleUtils.spawnUpGoingParticleCircle(Challenges.getInstance(), player.getLocation(), Particle.SPELL_WITCH, 17, 1, 2); + ParticleUtils.spawnUpGoingParticleCircle(Challenges.getInstance(), player.getLocation(), + MinecraftNameWrapper.WITCH_EFFECT, 17, 1, 2); } public void checkAllPlayersDead() { diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/SoupSetting.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/SoupSetting.java index ecf8fc2fb..ab5ea73de 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/SoupSetting.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/implementation/setting/SoupSetting.java @@ -1,10 +1,12 @@ package net.codingarea.challenges.plugin.challenges.implementation.setting; +import javax.annotation.Nonnull; import net.anweisen.utilities.bukkit.utils.animation.SoundSample; import net.codingarea.challenges.plugin.challenges.type.abstraction.Setting; import net.codingarea.challenges.plugin.content.Message; import net.codingarea.challenges.plugin.management.menu.MenuType; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -12,9 +14,6 @@ import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -import javax.annotation.Nonnull; /** * @author anweisen | https://github.com/anweisen @@ -44,7 +43,7 @@ public void onInteract(PlayerInteractEvent event) { if (player.getGameMode() == GameMode.CREATIVE) return; if (player.getHealth() == player.getMaxHealth()) return; - player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 1)); + player.addPotionEffect(new PotionEffect(MinecraftNameWrapper.INSTANT_HEALTH, 1, 1)); player.getInventory().setItemInMainHand(new ItemBuilder(Material.BOWL).build()); player.updateInventory(); SoundSample.EAT.play(player); diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/type/abstraction/HydraChallenge.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/type/abstraction/HydraChallenge.java index e6a0d91d6..80884d628 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/type/abstraction/HydraChallenge.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/type/abstraction/HydraChallenge.java @@ -1,19 +1,18 @@ package net.codingarea.challenges.plugin.challenges.type.abstraction; +import javax.annotation.Nonnull; import net.codingarea.challenges.plugin.Challenges; import net.codingarea.challenges.plugin.challenges.type.helper.ChallengeHelper; import net.codingarea.challenges.plugin.management.menu.MenuType; import net.codingarea.challenges.plugin.spigot.events.EntityDeathByPlayerEvent; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import net.codingarea.challenges.plugin.utils.misc.ParticleUtils; -import org.bukkit.Particle; import org.bukkit.entity.EnderDragon; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import javax.annotation.Nonnull; - /** * @author KxmischesDomi | https://github.com/kxmischesdomi * @since 2.0 @@ -41,7 +40,8 @@ public void onEntityDamageByEntity(@Nonnull EntityDeathByPlayerEvent event) { for (int i = 0; i < mobsCount; i++) { event.getEntity().getWorld().spawnEntity(event.getEntity().getLocation(), event.getEntityType()); } - ParticleUtils.spawnUpGoingParticleCircle(Challenges.getInstance(), event.getEntity().getLocation(), Particle.SPELL_MOB, 2, 17, 1); + ParticleUtils.spawnUpGoingParticleCircle(Challenges.getInstance(), event.getEntity().getLocation(), + MinecraftNameWrapper.ENTITY_EFFECT, 2, 17, 1); } } \ No newline at end of file diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/type/helper/SubSettingsHelper.java b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/type/helper/SubSettingsHelper.java index 8beaec9e1..f8390f8db 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/type/helper/SubSettingsHelper.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/challenges/type/helper/SubSettingsHelper.java @@ -10,6 +10,7 @@ import net.codingarea.challenges.plugin.utils.bukkit.misc.BukkitStringUtils; import net.codingarea.challenges.plugin.utils.item.DefaultItem; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import net.codingarea.challenges.plugin.utils.misc.StructureUtils; import org.bukkit.Material; import org.bukkit.StructureType; @@ -58,7 +59,7 @@ public static ChooseMultipleItemSubSettingBuilder createEntityTypeSettingsBuilde public static ChooseMultipleItemSubSettingBuilder createBlockSettingsBuilder() { return SubSettingsBuilder.createChooseMultipleItem(BLOCK).fill(builder -> { builder.addSetting(ANY, new ItemBuilder(Material.NETHER_STAR, Message.forName("item-custom-setting-block-any")).build()); - for (Material material : Material.values()) { + for (Material material : ExperimentalUtils.getMaterials()) { if (material.isBlock() && material.isItem() && !BukkitReflectionUtils.isAir(material)) { builder.addSetting(material.name(), new ItemBuilder(material, DefaultItem.getItemPrefix() + BukkitStringUtils.getItemName(material).toPlainText()).build()); } @@ -69,7 +70,7 @@ public static ChooseMultipleItemSubSettingBuilder createBlockSettingsBuilder() { public static ChooseMultipleItemSubSettingBuilder createItemSettingsBuilder() { return SubSettingsBuilder.createChooseMultipleItem(ITEM).fill(builder -> { builder.addSetting(ANY, new ItemBuilder(Material.NETHER_STAR, Message.forName("item-custom-setting-item-any")).build()); - for (Material material : Material.values()) { + for (Material material : ExperimentalUtils.getMaterials()) { if (material.isItem() && !BukkitReflectionUtils.isAir(material)) { builder.addSetting(material.name(), new ItemBuilder(material, DefaultItem.getItemPrefix() + BukkitStringUtils.getItemName(material).toPlainText()).build()); } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/ChooseMultipleItemGenerator.java b/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/ChooseMultipleItemGenerator.java index 22cd2eab4..99ef204a9 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/ChooseMultipleItemGenerator.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/ChooseMultipleItemGenerator.java @@ -1,5 +1,10 @@ package net.codingarea.challenges.plugin.management.menu.generator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import javax.annotation.Nonnegative; +import javax.annotation.Nonnull; import net.anweisen.utilities.bukkit.utils.animation.SoundSample; import net.anweisen.utilities.bukkit.utils.menu.MenuClickInfo; import net.anweisen.utilities.bukkit.utils.menu.MenuPosition; @@ -11,18 +16,12 @@ import net.codingarea.challenges.plugin.utils.item.DefaultItem; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; import net.codingarea.challenges.plugin.utils.misc.InventoryUtils; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -import javax.annotation.Nonnegative; -import javax.annotation.Nonnull; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; - /** * @author KxmischesDomi | https://github.com/kxmischesdomi * @since 2.1.0 @@ -126,7 +125,7 @@ public void generatePage(@Nonnull Inventory inventory, int page) { itemBuilder.hideAttributes(); if (selectedKeys.contains(key)) { - itemBuilder.addEnchantment(Enchantment.DURABILITY, 1); + itemBuilder.addEnchantment(MinecraftNameWrapper.UNBREAKING, 1); itemBuilder.appendName(" §8┃ §2§l✔"); } else { itemBuilder.appendName(" §8┃ §c✖"); diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/categorised/SettingCategory.java b/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/categorised/SettingCategory.java index d59192dae..87b064286 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/categorised/SettingCategory.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/categorised/SettingCategory.java @@ -1,8 +1,8 @@ package net.codingarea.challenges.plugin.management.menu.generator.categorised; -import net.anweisen.utilities.bukkit.utils.item.MaterialWrapper; import net.codingarea.challenges.plugin.content.Message; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import org.bukkit.Material; import java.util.function.Supplier; @@ -18,7 +18,7 @@ public class SettingCategory { public static final SettingCategory RANDOMIZER = new SettingCategory(1, Material.COMMAND_BLOCK, () -> Message.forName("category-randomizer")); public static final SettingCategory FORCE = new SettingCategory(2, Material.BLUE_BANNER, () -> Message.forName("category-force")); public static final SettingCategory ENTITIES = new SettingCategory(3, Material.PIG_SPAWN_EGG, () -> Message.forName("category-entities")); - public static final SettingCategory DAMAGE = new SettingCategory(4, MaterialWrapper.RED_DYE, () -> Message.forName("category-damage")); + public static final SettingCategory DAMAGE = new SettingCategory(4, MinecraftNameWrapper.RED_DYE, () -> Message.forName("category-damage")); public static final SettingCategory EFFECT = new SettingCategory(5, Material.FERMENTED_SPIDER_EYE, () -> Message.forName("category-effect")); public static final SettingCategory WORLD = new SettingCategory(6, Material.TNT, () -> Message.forName("category-world")); public static final SettingCategory INVENTORY = new SettingCategory(7, Material.CHEST, () -> Message.forName("category-inventory")); diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/implementation/TimerMenuGenerator.java b/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/implementation/TimerMenuGenerator.java index 06c5b2eee..3aeaaca2c 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/implementation/TimerMenuGenerator.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/implementation/TimerMenuGenerator.java @@ -1,7 +1,6 @@ package net.codingarea.challenges.plugin.management.menu.generator.implementation; import net.anweisen.utilities.bukkit.utils.animation.SoundSample; -import net.anweisen.utilities.bukkit.utils.item.MaterialWrapper; import net.anweisen.utilities.bukkit.utils.menu.MenuClickInfo; import net.anweisen.utilities.bukkit.utils.menu.MenuPosition; import net.codingarea.challenges.plugin.ChallengeAPI; @@ -16,6 +15,7 @@ import net.codingarea.challenges.plugin.management.scheduler.timer.TimerStatus; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; import net.codingarea.challenges.plugin.utils.item.ItemBuilder.PotionBuilder; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import net.codingarea.challenges.plugin.utils.misc.InventoryUtils; import org.bukkit.Bukkit; import org.bukkit.Color; @@ -60,7 +60,7 @@ public void updateFirstPage() { Inventory inventory = inventories.get(0); inventory.setItem(START_SLOT, Challenges.getInstance().getChallengeTimer().isStarted() ? new ItemBuilder(Material.LIME_DYE).name(Message.forName("timer-is-running")).build() : - new ItemBuilder(MaterialWrapper.RED_DYE).name(Message.forName("timer-is-paused")).build()); + new ItemBuilder(MinecraftNameWrapper.RED_DYE).name(Message.forName("timer-is-paused")).build()); inventory.setItem(MODE_SLOT, Challenges.getInstance().getChallengeTimer().isCountingUp() ? new PotionBuilder(Material.TIPPED_ARROW).setColor(Color.LIME).name(Message.forName("timer-counting-up")).hideAttributes().build() : new PotionBuilder(Material.TIPPED_ARROW).setColor(Color.RED).name(Message.forName("timer-counting-down")).hideAttributes().build()); diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/implementation/custom/InfoMenuGenerator.java b/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/implementation/custom/InfoMenuGenerator.java index b8cc9a1ac..cee413afc 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/implementation/custom/InfoMenuGenerator.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/implementation/custom/InfoMenuGenerator.java @@ -19,6 +19,7 @@ import net.codingarea.challenges.plugin.spigot.listener.ChatInputListener; import net.codingarea.challenges.plugin.utils.bukkit.misc.BukkitStringUtils; import net.codingarea.challenges.plugin.utils.item.ItemBuilder; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import net.codingarea.challenges.plugin.utils.misc.InventoryUtils; import net.codingarea.challenges.plugin.utils.misc.InventoryUtils.InventorySetter; import org.bukkit.Bukkit; @@ -44,7 +45,7 @@ public class InfoMenuGenerator extends MenuGenerator implements IParentCustomGen static { savePlayerChallenges = Challenges.getInstance().getConfigDocument().getBoolean("save-player_challenges"); - ArrayList list = new ArrayList<>(Arrays.asList(Material.values())); + ArrayList list = new ArrayList<>(Arrays.asList(ExperimentalUtils.getMaterials())); list.removeIf(material1 -> !material1.isItem()); defaultMaterials = list.toArray(new Material[0]); } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/implementation/custom/MaterialMenuGenerator.java b/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/implementation/custom/MaterialMenuGenerator.java index aae75618e..ed35c3120 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/implementation/custom/MaterialMenuGenerator.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/management/menu/generator/implementation/custom/MaterialMenuGenerator.java @@ -3,6 +3,7 @@ import net.anweisen.utilities.bukkit.utils.misc.BukkitReflectionUtils; import net.codingarea.challenges.plugin.challenges.custom.settings.SettingType; import net.codingarea.challenges.plugin.management.menu.generator.ChooseItemGenerator; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import net.codingarea.challenges.plugin.utils.misc.MapUtils; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -26,7 +27,7 @@ public MaterialMenuGenerator(IParentCustomGenerator parent) { public static LinkedHashMap createMaterialsMap() { LinkedHashMap map = new LinkedHashMap<>(); - for (Material material : Material.values()) { + for (Material material : ExperimentalUtils.getMaterials()) { if (BukkitReflectionUtils.isAir(material)) continue; if (!material.isItem()) continue; map.put(material.name(), new ItemStack(material)); diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/management/server/ServerManager.java b/plugin/src/main/java/net/codingarea/challenges/plugin/management/server/ServerManager.java index 31e53ef50..fbcbf4249 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/management/server/ServerManager.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/management/server/ServerManager.java @@ -9,12 +9,12 @@ import net.codingarea.challenges.plugin.Challenges; import net.codingarea.challenges.plugin.challenges.type.IGoal; import net.codingarea.challenges.plugin.content.Prefix; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import net.codingarea.challenges.plugin.utils.misc.NameHelper; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.World.Environment; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -109,7 +109,7 @@ private void setSpectator() { SoundSample.BLAST.play(player); try { - player.getWorld().spawnEntity(player.getLocation(), EntityType.FIREWORK); + player.getWorld().spawnEntity(player.getLocation(), MinecraftNameWrapper.FIREWORK); } catch (IllegalArgumentException ex) { // We cant spawn fireworks like that in some versions of spigot } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/spigot/command/SearchCommand.java b/plugin/src/main/java/net/codingarea/challenges/plugin/spigot/command/SearchCommand.java index 422d75abb..d92ec1ede 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/spigot/command/SearchCommand.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/spigot/command/SearchCommand.java @@ -8,6 +8,7 @@ import net.codingarea.challenges.plugin.management.blocks.BlockDropManager.RegisteredDrops; import net.codingarea.challenges.plugin.utils.bukkit.command.Completer; import net.codingarea.challenges.plugin.utils.bukkit.command.SenderCommand; +import net.codingarea.challenges.plugin.utils.misc.ExperimentalUtils; import net.codingarea.challenges.plugin.utils.misc.Utils; import org.bukkit.Material; import org.bukkit.command.CommandSender; @@ -67,7 +68,7 @@ public void onCommand(@Nonnull CommandSender sender, @Nonnull String[] args) thr @Override public List onTabComplete(@Nonnull CommandSender sender, @Nonnull String[] args) { return args.length != 1 ? null : - Arrays.stream(Material.values()) + Arrays.stream(ExperimentalUtils.getMaterials()) .filter(ItemUtils::isObtainableInSurvival) .filter(Material::isItem) .map(material -> material.name().toLowerCase()) diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/spigot/listener/PlayerConnectionListener.java b/plugin/src/main/java/net/codingarea/challenges/plugin/spigot/listener/PlayerConnectionListener.java index 81834872e..89bccee4d 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/spigot/listener/PlayerConnectionListener.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/spigot/listener/PlayerConnectionListener.java @@ -1,5 +1,7 @@ package net.codingarea.challenges.plugin.spigot.listener; +import java.util.List; +import javax.annotation.Nonnull; import net.anweisen.utilities.common.config.Document; import net.codingarea.challenges.plugin.ChallengeAPI; import net.codingarea.challenges.plugin.Challenges; @@ -7,10 +9,10 @@ import net.codingarea.challenges.plugin.content.Prefix; import net.codingarea.challenges.plugin.content.loader.UpdateLoader; import net.codingarea.challenges.plugin.utils.misc.DatabaseHelper; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import net.codingarea.challenges.plugin.utils.misc.NameHelper; import net.codingarea.challenges.plugin.utils.misc.ParticleUtils; import org.bukkit.Bukkit; -import org.bukkit.Particle; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -18,9 +20,6 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; -import javax.annotation.Nonnull; -import java.util.List; - /** * @author anweisen | https://github.com/anweisen * @since 1.0 @@ -50,7 +49,8 @@ public void onJoin(@Nonnull PlayerJoinEvent event) { Player player = event.getPlayer(); player.getLocation().getChunk().load(true); - ParticleUtils.spawnUpGoingParticleCircle(Challenges.getInstance(), player.getLocation(), Particle.SPELL_MOB, 17, 1, 2); + ParticleUtils.spawnUpGoingParticleCircle(Challenges.getInstance(), player.getLocation(), + MinecraftNameWrapper.ENTITY_EFFECT, 17, 1, 2); Challenges.getInstance().getScoreboardManager().handleJoin(player); if (player.hasPermission("challenges.gui")) { diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/utils/item/DefaultItem.java b/plugin/src/main/java/net/codingarea/challenges/plugin/utils/item/DefaultItem.java index 3a0ad2837..e816a15ff 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/utils/item/DefaultItem.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/utils/item/DefaultItem.java @@ -1,8 +1,8 @@ package net.codingarea.challenges.plugin.utils.item; -import net.anweisen.utilities.bukkit.utils.item.MaterialWrapper; import net.codingarea.challenges.plugin.content.Message; import net.codingarea.challenges.plugin.utils.item.ItemBuilder.SkullBuilder; +import net.codingarea.challenges.plugin.utils.misc.MinecraftNameWrapper; import org.bukkit.Material; import javax.annotation.Nonnull; @@ -45,12 +45,12 @@ public static ItemBuilder enabled() { @Nonnull public static ItemBuilder disabled() { - return new ItemBuilder(MaterialWrapper.RED_DYE).setName(getTitle(Message.forName("disabled"))).hideAttributes(); + return new ItemBuilder(MinecraftNameWrapper.RED_DYE).setName(getTitle(Message.forName("disabled"))).hideAttributes(); } @Nonnull public static ItemBuilder customize() { - return new ItemBuilder(MaterialWrapper.SIGN).setName(getTitle(Message.forName("customize"))).hideAttributes(); + return new ItemBuilder(MinecraftNameWrapper.SIGN).setName(getTitle(Message.forName("customize"))).hideAttributes(); } @Nonnull diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/ColorConversions.java b/plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/ColorConversions.java index 57498ebf5..2078261ed 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/ColorConversions.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/ColorConversions.java @@ -1,6 +1,5 @@ package net.codingarea.challenges.plugin.utils.misc; -import net.anweisen.utilities.bukkit.utils.item.MaterialWrapper; import org.bukkit.ChatColor; import org.bukkit.DyeColor; import org.bukkit.Material; @@ -82,11 +81,11 @@ public static ChatColor convertDyeColorToChatColor(@Nonnull DyeColor color) { public static Material convertDyeColorToMaterial(@Nonnull DyeColor color) { switch (color) { case YELLOW: - return MaterialWrapper.YELLOW_DYE; + return MinecraftNameWrapper.YELLOW_DYE; case RED: - return MaterialWrapper.RED_DYE; + return MinecraftNameWrapper.RED_DYE; case GREEN: - return MaterialWrapper.GREEN_DYE; + return MinecraftNameWrapper.GREEN_DYE; case BLACK: return Material.INK_SAC; case GRAY: diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/ExperimentalUtils.java b/plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/ExperimentalUtils.java new file mode 100644 index 000000000..7ad1d358b --- /dev/null +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/ExperimentalUtils.java @@ -0,0 +1,59 @@ +package net.codingarea.challenges.plugin.utils.misc; + +import java.util.LinkedList; +import java.util.List; +import net.codingarea.challenges.plugin.Challenges; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.EntityType; + +public class ExperimentalUtils { + + private static Material[] materials; + private static EntityType[] entityTypes; + + public static Material[] getMaterials() { + if (materials == null) { + loadMaterials(); + } + return materials; + } + + private static void loadMaterials() { + List materials = new LinkedList<>(); + + for (Material material : Material.values()) { + try { + if (!material.isEnabledByFeature(Challenges.getInstance().getGameWorldStorage().getWorld(World.Environment.NORMAL))) { + continue; + } + } catch (Exception ignored) {} // only NoSuchMethodException + + materials.add(material); + } + ExperimentalUtils.materials = materials.toArray(new Material[0]); + } + + public static EntityType[] getEntityTypes() { + if (entityTypes == null) { + loadEntityTypes(); + } + return entityTypes; + } + + private static void loadEntityTypes() { + List entityTypes = new LinkedList<>(); + + for (EntityType type : EntityType.values()) { + try { + if (!type.isEnabledByFeature(Challenges.getInstance().getGameWorldStorage().getWorld(World.Environment.NORMAL))) { + continue; + } + } catch (Exception ignored) {} // only NoSuchMethodException + + entityTypes.add(type); + } + ExperimentalUtils.entityTypes = entityTypes.toArray(new EntityType[0]); + } + +} diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/InventoryUtils.java b/plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/InventoryUtils.java index 50f12e4fb..e055de09c 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/InventoryUtils.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/InventoryUtils.java @@ -35,7 +35,7 @@ public final class InventoryUtils { static { random = IRandom.create(); - items = new ArrayList<>(Arrays.asList(Material.values())); + items = new ArrayList<>(Arrays.asList(ExperimentalUtils.getMaterials())); items.removeIf(material -> !material.isItem()); } diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/MinecraftNameWrapper.java b/plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/MinecraftNameWrapper.java new file mode 100644 index 000000000..6d167b4a0 --- /dev/null +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/MinecraftNameWrapper.java @@ -0,0 +1,77 @@ +package net.codingarea.challenges.plugin.utils.misc; + +import java.lang.reflect.Field; +import java.util.Arrays; +import javax.annotation.Nonnull; +import net.anweisen.utilities.common.misc.ReflectionUtils; +import net.codingarea.challenges.plugin.utils.bukkit.nms.ReflectionUtil; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.potion.PotionEffectType; + +public class MinecraftNameWrapper { + + public static final Material GREEN_DYE = getItemByNames("CACTUS_GREEN", "GREEN_DYE"); + public static final Material RED_DYE = getItemByNames("ROSE_RED", "RED_DYE"); + public static final Material YELLOW_DYE = getItemByNames("DANDELION_YELLOW", "YELLOW_DYE"); + public static final Material SIGN = getItemByNames("SIGN", "OAK_SIGN"); + + public static final EntityType FIREWORK = getEntityByNames("FIREWORK", "FIREWORK_ROCKET"); + public static final EntityType SNOW_GOLEM = getEntityByNames("SNOWMAN", "SNOW_GOLEM"); + + public static final Particle INSTANT_EFFECT = getParticleByNames("SPELL_INSTANT", "INSTANT_EFFECT"); + public static final Particle WITCH_EFFECT = getParticleByNames("SPELL_WITCH", "WITCH"); + public static final Particle ENTITY_EFFECT = getParticleByNames("SPELL_MOB", "ENTITY_EFFECT"); + public static final Particle REDSTONE_DUST = getParticleByNames("REDSTONE", "DUST"); + + public static final PotionEffectType NAUSEA = getPotionByNames("CONFUSION", "NAUSEA"); + public static final PotionEffectType INSTANT_HEALTH = getPotionByNames("HEAL", "INSTANT_HEALTH"); + public static final PotionEffectType INSTANT_DAMAGE = getPotionByNames("HARM", "INSTANT_DAMAGE"); + public static final PotionEffectType SLOWNESS = getPotionByNames("SLOW", "SLOWNESS"); + + public static final Enchantment UNBREAKING = getEnchantByNames("DURABILITY", "UNBREAKING"); + + private MinecraftNameWrapper() { + } + + @Nonnull + private static Material getItemByNames(@Nonnull String... names) { + return ReflectionUtils.getFirstEnumByNames(Material.class, names); + } + + @Nonnull + private static EntityType getEntityByNames(@Nonnull String... names) { + return ReflectionUtils.getFirstEnumByNames(EntityType.class, names); + } + + @Nonnull + private static Particle getParticleByNames(@Nonnull String... names) { + return ReflectionUtils.getFirstEnumByNames(Particle.class, names); + } + + @Nonnull + private static PotionEffectType getPotionByNames(@Nonnull String... names) { + return getFirstAttributeByNames(PotionEffectType.class, names); + } + + @Nonnull + private static Enchantment getEnchantByNames(@Nonnull String... names) { + return getFirstAttributeByNames(Enchantment.class, names); + } + + @SuppressWarnings("unchecked") + @Nonnull + public static T getFirstAttributeByNames(@Nonnull Class clazz, @Nonnull String... names) { + for (String name : names) { + try { + Field field = ReflectionUtil.getField(clazz, name); + return (T) field.get(null); + } catch (NoSuchFieldException | IllegalAccessException ignored) { + } + } + throw new IllegalArgumentException("No attribute found in: " + clazz.getName() + " for " + Arrays.toString(names)); + } + +} diff --git a/plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/ParticleUtils.java b/plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/ParticleUtils.java index b438df035..b57acbd9a 100644 --- a/plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/ParticleUtils.java +++ b/plugin/src/main/java/net/codingarea/challenges/plugin/utils/misc/ParticleUtils.java @@ -61,7 +61,7 @@ public static void spawnUpGoingParticleCircle(@Nonnull JavaPlugin plugin, @Nonnu } public static void spawnParticleCircleAroundEntity(@Nonnull JavaPlugin plugin, @Nonnull Entity entity) { - spawnParticleCircleAroundBoundingBox(plugin, entity.getLocation(), Particle.SPELL_INSTANT, entity.getBoundingBox(), 0.25); + spawnParticleCircleAroundBoundingBox(plugin, entity.getLocation(), MinecraftNameWrapper.INSTANT_EFFECT, entity.getBoundingBox(), 0.25); } public static void spawnParticleCircleAroundBoundingBox(@Nonnull JavaPlugin plugin, @Nonnull Location location, @Nonnull Particle particle, @Nonnull BoundingBox box, double height) { diff --git a/pom.xml b/pom.xml index 5add26d33..20594aa0f 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ 1.3.13 - 1.20.4-R0.1-SNAPSHOT + 1.21-R0.1-SNAPSHOT