From d4ab829812cd7c1d88977cb32237f4f496d175d9 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 21 Sep 2020 21:20:53 -0700 Subject: [PATCH 01/10] Mark blocks always in BlockPlaceEvent --- Changelog.txt | 1 + .../nossr50/listeners/BlockListener.java | 22 ++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 4ee9b23ce..d90ff305c 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,4 +1,5 @@ Version 2.1.146 + A dupe exploit has been patched Players no longer lose levels below the level threshold in hardcore mode Hardcore now only applies penalties to levels above threshold diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index e5eafb665..e2a19af43 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -205,16 +205,6 @@ public class BlockListener implements Listener { */ @EventHandler(priority = EventPriority.MONITOR) public void onBlockPlace(BlockPlaceEvent event) { - /* WORLD BLACKLIST CHECK */ - if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) - return; - - Player player = event.getPlayer(); - - if (!UserManager.hasPlayerDataKey(player)) { - return; - } - BlockState blockState = event.getBlock().getState(); /* Check if the blocks placed should be monitored so they do not give out XP in the future */ @@ -224,6 +214,18 @@ public class BlockListener implements Listener { mcMMO.getPlaceStore().setTrue(blockState); } + /* WORLD BLACKLIST CHECK */ + if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) { + return; + } + + Player player = event.getPlayer(); + + if (!UserManager.hasPlayerDataKey(player)) { + return; + } + + McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); if(mcMMOPlayer == null) From f496d795fb0a8b012f860881122f9d25b7a14d5a Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 21 Sep 2020 21:23:10 -0700 Subject: [PATCH 02/10] Always track blocks in BlockMultiPlaceEvent --- .../nossr50/listeners/BlockListener.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index e2a19af43..a32ea2c24 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -246,16 +246,6 @@ public class BlockListener implements Listener { */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockMultiPlace(BlockMultiPlaceEvent event) { - /* WORLD BLACKLIST CHECK */ - if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) - return; - - Player player = event.getPlayer(); - - if (!UserManager.hasPlayerDataKey(player)) { - return; - } - for (BlockState replacedBlockState : event.getReplacedBlockStates()) { BlockState blockState = replacedBlockState.getBlock().getState(); @@ -265,6 +255,17 @@ public class BlockListener implements Listener { mcMMO.getPlaceStore().setTrue(blockState); } } + + /* WORLD BLACKLIST CHECK */ + if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) { + return; + } + + Player player = event.getPlayer(); + + if (!UserManager.hasPlayerDataKey(player)) { + return; + } } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) From 959a74b139032f4be309e1adc53d857b8886f2e0 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 21 Sep 2020 21:27:17 -0700 Subject: [PATCH 03/10] Temporarily mark debarked wood as unnatural (will undo later) --- .../java/com/gmail/nossr50/listeners/BlockListener.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index a32ea2c24..5e1582fd1 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -210,7 +210,7 @@ public class BlockListener implements Listener { /* Check if the blocks placed should be monitored so they do not give out XP in the future */ if (BlockUtils.shouldBeWatched(blockState)) { // Don't count de-barking wood - if (!Tag.LOGS.isTagged(event.getBlockReplacedState().getType()) || !Tag.LOGS.isTagged(event.getBlockPlaced().getType())) +// if (!Tag.LOGS.isTagged(event.getBlockReplacedState().getType()) || !Tag.LOGS.isTagged(event.getBlockPlaced().getType())) mcMMO.getPlaceStore().setTrue(blockState); } @@ -225,7 +225,6 @@ public class BlockListener implements Listener { return; } - McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); if(mcMMOPlayer == null) @@ -327,8 +326,11 @@ public class BlockListener implements Listener { McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); //Check if profile is loaded - if(mcMMOPlayer == null) + if(mcMMOPlayer == null) { + /* Remove metadata from placed watched blocks */ + mcMMO.getPlaceStore().setFalse(blockState); return; + } ItemStack heldItem = player.getInventory().getItemInMainHand(); From 3fd5cd03eef66b0016d5d49284b692673f42be62 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 21 Sep 2020 21:29:21 -0700 Subject: [PATCH 04/10] Blocks that have double drops enabled are also worth marking --- src/main/java/com/gmail/nossr50/util/BlockUtils.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/util/BlockUtils.java b/src/main/java/com/gmail/nossr50/util/BlockUtils.java index 4750785fe..843c178a9 100644 --- a/src/main/java/com/gmail/nossr50/util/BlockUtils.java +++ b/src/main/java/com/gmail/nossr50/util/BlockUtils.java @@ -66,7 +66,11 @@ public final class BlockUtils { * @return true if the block awards XP, false otherwise */ public static boolean shouldBeWatched(BlockState blockState) { - return affectedByGigaDrillBreaker(blockState) || affectedByGreenTerra(blockState) || affectedBySuperBreaker(blockState) || isLog(blockState); + return affectedByGigaDrillBreaker(blockState) || affectedByGreenTerra(blockState) || affectedBySuperBreaker(blockState) || isLog(blockState) + || Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.MINING, blockState.getType()) + || Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.EXCAVATION, blockState.getType()) + || Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.WOODCUTTING, blockState.getType()) + || Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.SMELTING, blockState.getType()); } /** From 0b20fc2c16f20d1c54f319da25db050a87fbefbd Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 21 Sep 2020 21:36:24 -0700 Subject: [PATCH 05/10] Some tweaks to tracking blocks as unnatural --- Changelog.txt | 2 +- .../nossr50/listeners/BlockListener.java | 30 +++++++------------ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index d90ff305c..10e620817 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,5 +1,5 @@ Version 2.1.146 - A dupe exploit has been patched + Improvements were made to tracking player placed blocks in mcMMO Players no longer lose levels below the level threshold in hardcore mode Hardcore now only applies penalties to levels above threshold diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 5e1582fd1..94d038468 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -127,10 +127,8 @@ public class BlockListener implements Listener { Block movedBlock; for (Block b : event.getBlocks()) { - if (BlockUtils.shouldBeWatched(b.getState())) { - movedBlock = b.getRelative(direction); - mcMMO.getPlaceStore().setTrue(movedBlock); - } + movedBlock = b.getRelative(direction); + mcMMO.getPlaceStore().setTrue(movedBlock); } } @@ -190,7 +188,6 @@ public class BlockListener implements Listener { if(ExperienceConfig.getInstance().preventStoneLavaFarming()) { if(event.getNewState().getType() != Material.OBSIDIAN - && BlockUtils.shouldBeWatched(event.getNewState()) && ExperienceConfig.getInstance().doesBlockGiveSkillXP(PrimarySkillType.MINING, event.getNewState().getBlockData())) { mcMMO.getPlaceStore().setTrue(event.getNewState()); @@ -208,11 +205,8 @@ public class BlockListener implements Listener { BlockState blockState = event.getBlock().getState(); /* Check if the blocks placed should be monitored so they do not give out XP in the future */ - if (BlockUtils.shouldBeWatched(blockState)) { - // Don't count de-barking wood -// if (!Tag.LOGS.isTagged(event.getBlockReplacedState().getType()) || !Tag.LOGS.isTagged(event.getBlockPlaced().getType())) - mcMMO.getPlaceStore().setTrue(blockState); - } +// if (!Tag.LOGS.isTagged(event.getBlockReplacedState().getType()) || !Tag.LOGS.isTagged(event.getBlockPlaced().getType())) + mcMMO.getPlaceStore().setTrue(blockState); /* WORLD BLACKLIST CHECK */ if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) { @@ -250,9 +244,7 @@ public class BlockListener implements Listener { BlockState blockState = replacedBlockState.getBlock().getState(); /* Check if the blocks placed should be monitored so they do not give out XP in the future */ - if (BlockUtils.shouldBeWatched(blockState)) { - mcMMO.getPlaceStore().setTrue(blockState); - } + mcMMO.getPlaceStore().setTrue(blockState); } /* WORLD BLACKLIST CHECK */ @@ -276,9 +268,9 @@ public class BlockListener implements Listener { BlockState blockState = event.getBlock().getState(); - if (!BlockUtils.shouldBeWatched(blockState)) { - return; - } +// if (!BlockUtils.shouldBeWatched(blockState)) { +// return; +// } mcMMO.getPlaceStore().setFalse(blockState); } @@ -308,9 +300,9 @@ public class BlockListener implements Listener { BlockState blockState = event.getBlock().getState(); Location location = blockState.getLocation(); - if (!BlockUtils.shouldBeWatched(blockState)) { - return; - } +// if (!BlockUtils.shouldBeWatched(blockState)) { +// return; +// } /* ALCHEMY - Cancel any brew in progress for that BrewingStand */ if (blockState instanceof BrewingStand && Alchemy.brewingStandMap.containsKey(location)) { From 02fe8addb7d6b2ab8e8b30b87bc3debfb84e51b4 Mon Sep 17 00:00:00 2001 From: Riley Park Date: Thu, 24 Sep 2020 07:08:24 -0700 Subject: [PATCH 06/10] adventure --- pom.xml | 20 +- .../commands/skills/AcrobaticsCommand.java | 6 +- .../commands/skills/AlchemyCommand.java | 6 +- .../commands/skills/ArcheryCommand.java | 6 +- .../nossr50/commands/skills/AxesCommand.java | 6 +- .../commands/skills/ExcavationCommand.java | 6 +- .../commands/skills/FishingCommand.java | 6 +- .../commands/skills/HerbalismCommand.java | 6 +- .../commands/skills/MiningCommand.java | 6 +- .../commands/skills/RepairCommand.java | 6 +- .../commands/skills/SalvageCommand.java | 6 +- .../nossr50/commands/skills/SkillCommand.java | 5 +- .../commands/skills/SmeltingCommand.java | 6 +- .../commands/skills/SwordsCommand.java | 6 +- .../commands/skills/TamingCommand.java | 6 +- .../commands/skills/UnarmedCommand.java | 6 +- .../commands/skills/WoodcuttingCommand.java | 6 +- .../skills/subskills/acrobatics/Roll.java | 3 +- .../skills/subskills/interfaces/SubSkill.java | 3 +- .../skills/McMMOPlayerNotificationEvent.java | 18 +- src/main/java/com/gmail/nossr50/mcMMO.java | 10 + .../gmail/nossr50/util/McMMOMessageType.java | 21 ++ .../nossr50/util/TextComponentFactory.java | 355 +++++++++--------- .../util/player/NotificationManager.java | 32 +- .../gmail/nossr50/util/skills/PerksUtils.java | 2 +- 25 files changed, 300 insertions(+), 259 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/util/McMMOMessageType.java diff --git a/pom.xml b/pom.xml index bd4447210..d1228adbe 100755 --- a/pom.xml +++ b/pom.xml @@ -160,16 +160,16 @@ - - - - - - - - - - + + net.kyori + adventure-api + 4.0.0-SNAPSHOT + + + net.kyori + adventure-platform-bukkit + 4.0.0-SNAPSHOT + org.apache.maven.scm maven-scm-provider-gitexe diff --git a/src/main/java/com/gmail/nossr50/commands/skills/AcrobaticsCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/AcrobaticsCommand.java index 91e86ef0f..1733329ff 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/AcrobaticsCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/AcrobaticsCommand.java @@ -9,7 +9,7 @@ import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.random.RandomChanceSkill; import com.gmail.nossr50.util.random.RandomChanceUtil; import com.gmail.nossr50.util.skills.SkillActivationType; -import net.md_5.bungee.api.chat.TextComponent; +import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -89,8 +89,8 @@ public class AcrobaticsCommand extends SkillCommand { } @Override - protected List getTextComponents(Player player) { - List textComponents = new ArrayList<>(); + protected List getTextComponents(Player player) { + List textComponents = new ArrayList<>(); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.ACROBATICS); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/AlchemyCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/AlchemyCommand.java index b8df20ad4..cdb87e461 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/AlchemyCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/AlchemyCommand.java @@ -8,7 +8,7 @@ import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.RankUtils; -import net.md_5.bungee.api.chat.TextComponent; +import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -93,8 +93,8 @@ public class AlchemyCommand extends SkillCommand { } @Override - protected List getTextComponents(Player player) { - List textComponents = new ArrayList<>(); + protected List getTextComponents(Player player) { + List textComponents = new ArrayList<>(); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.ALCHEMY); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/ArcheryCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/ArcheryCommand.java index 4deeb9262..bbf0f875b 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/ArcheryCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/ArcheryCommand.java @@ -7,7 +7,7 @@ import com.gmail.nossr50.skills.archery.Archery; import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.SkillActivationType; -import net.md_5.bungee.api.chat.TextComponent; +import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -84,8 +84,8 @@ public class ArcheryCommand extends SkillCommand { } @Override - protected List getTextComponents(Player player) { - List textComponents = new ArrayList<>(); + protected List getTextComponents(Player player) { + List textComponents = new ArrayList<>(); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.ARCHERY); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/AxesCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/AxesCommand.java index 8454b4af3..52aa62d8e 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/AxesCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/AxesCommand.java @@ -10,7 +10,7 @@ import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.SkillActivationType; -import net.md_5.bungee.api.chat.TextComponent; +import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -105,8 +105,8 @@ public class AxesCommand extends SkillCommand { } @Override - protected List getTextComponents(Player player) { - List textComponents = new ArrayList<>(); + protected List getTextComponents(Player player) { + List textComponents = new ArrayList<>(); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.AXES); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/ExcavationCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/ExcavationCommand.java index 2f3d53a0f..170e80054 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/ExcavationCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/ExcavationCommand.java @@ -8,7 +8,7 @@ import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.RankUtils; -import net.md_5.bungee.api.chat.TextComponent; +import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -66,8 +66,8 @@ public class ExcavationCommand extends SkillCommand { } @Override - protected List getTextComponents(Player player) { - List textComponents = new ArrayList<>(); + protected List getTextComponents(Player player) { + List textComponents = new ArrayList<>(); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.EXCAVATION); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/FishingCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/FishingCommand.java index 2788b98d4..33f2c4cd5 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/FishingCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/FishingCommand.java @@ -13,7 +13,7 @@ import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.random.RandomChanceUtil; import com.gmail.nossr50.util.skills.RankUtils; -import net.md_5.bungee.api.chat.TextComponent; +import net.kyori.adventure.text.Component; import org.bukkit.Location; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -167,8 +167,8 @@ public class FishingCommand extends SkillCommand { } @Override - protected List getTextComponents(Player player) { - List textComponents = new ArrayList<>(); + protected List getTextComponents(Player player) { + List textComponents = new ArrayList<>(); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.FISHING); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/HerbalismCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/HerbalismCommand.java index 9884ecba8..8f82ce3ff 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/HerbalismCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/HerbalismCommand.java @@ -7,7 +7,7 @@ import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.SkillActivationType; -import net.md_5.bungee.api.chat.TextComponent; +import net.kyori.adventure.text.Component; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -141,8 +141,8 @@ public class HerbalismCommand extends SkillCommand { } @Override - protected List getTextComponents(Player player) { - List textComponents = new ArrayList<>(); + protected List getTextComponents(Player player) { + List textComponents = new ArrayList<>(); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.HERBALISM); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/MiningCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/MiningCommand.java index 27102d7b4..950953908 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/MiningCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/MiningCommand.java @@ -9,7 +9,7 @@ import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.SkillActivationType; -import net.md_5.bungee.api.chat.TextComponent; +import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -111,8 +111,8 @@ public class MiningCommand extends SkillCommand { } @Override - protected List getTextComponents(Player player) { - List textComponents = new ArrayList<>(); + protected List getTextComponents(Player player) { + List textComponents = new ArrayList<>(); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.MINING); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/RepairCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/RepairCommand.java index a88a45bb6..7444a9fb6 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/RepairCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/RepairCommand.java @@ -14,7 +14,7 @@ import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.SkillActivationType; -import net.md_5.bungee.api.chat.TextComponent; +import net.kyori.adventure.text.Component; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -121,8 +121,8 @@ public class RepairCommand extends SkillCommand { } @Override - protected List getTextComponents(Player player) { - List textComponents = new ArrayList<>(); + protected List getTextComponents(Player player) { + List textComponents = new ArrayList<>(); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.REPAIR); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/SalvageCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/SalvageCommand.java index 9dc5263fe..ebbd629e3 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/SalvageCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/SalvageCommand.java @@ -8,7 +8,7 @@ import com.gmail.nossr50.skills.salvage.SalvageManager; import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.RankUtils; -import net.md_5.bungee.api.chat.TextComponent; +import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -64,8 +64,8 @@ public class SalvageCommand extends SkillCommand { } @Override - protected List getTextComponents(Player player) { - List textComponents = new ArrayList<>(); + protected List getTextComponents(Player player) { + List textComponents = new ArrayList<>(); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.SALVAGE); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/SkillCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/SkillCommand.java index 91c683a43..bece332e5 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/SkillCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/SkillCommand.java @@ -19,6 +19,7 @@ import com.gmail.nossr50.util.skills.PerksUtils; import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.SkillActivationType; import com.google.common.collect.ImmutableList; +import net.kyori.adventure.text.Component; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.command.Command; @@ -85,7 +86,7 @@ public abstract class SkillCommand implements TabExecutor { sendSkillCommandHeader(player, mcMMOPlayer, (int) skillValue); //Make JSON text components - List subskillTextComponents = getTextComponents(player); + List subskillTextComponents = getTextComponents(player); //Subskills Header player.sendMessage(LocaleLoader.getString("Skills.Overhaul.Header", LocaleLoader.getString("Effects.SubSkills.Overhaul"))); @@ -283,7 +284,7 @@ public abstract class SkillCommand implements TabExecutor { protected abstract List statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky); - protected abstract List getTextComponents(Player player); + protected abstract List getTextComponents(Player player); /** * Checks if a player can use a skill diff --git a/src/main/java/com/gmail/nossr50/commands/skills/SmeltingCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/SmeltingCommand.java index a3a5f5805..27ce7fc13 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/SmeltingCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/SmeltingCommand.java @@ -8,7 +8,7 @@ import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.SkillActivationType; -import net.md_5.bungee.api.chat.TextComponent; +import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -88,8 +88,8 @@ public class SmeltingCommand extends SkillCommand { } @Override - protected List getTextComponents(Player player) { - List textComponents = new ArrayList<>(); + protected List getTextComponents(Player player) { + List textComponents = new ArrayList<>(); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.SMELTING); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/SwordsCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/SwordsCommand.java index 0933d6c79..325b5bb10 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/SwordsCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/SwordsCommand.java @@ -10,7 +10,7 @@ import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.SkillActivationType; -import net.md_5.bungee.api.chat.TextComponent; +import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -110,8 +110,8 @@ public class SwordsCommand extends SkillCommand { } @Override - protected List getTextComponents(Player player) { - List textComponents = new ArrayList<>(); + protected List getTextComponents(Player player) { + List textComponents = new ArrayList<>(); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.SWORDS); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/TamingCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/TamingCommand.java index e54ce1505..8970f5c08 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/TamingCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/TamingCommand.java @@ -7,7 +7,7 @@ import com.gmail.nossr50.skills.taming.Taming; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.skills.SkillActivationType; -import net.md_5.bungee.api.chat.TextComponent; +import net.kyori.adventure.text.Component; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -92,8 +92,8 @@ public class TamingCommand extends SkillCommand { } @Override - protected List getTextComponents(Player player) { - List textComponents = new ArrayList<>(); + protected List getTextComponents(Player player) { + List textComponents = new ArrayList<>(); TextComponentFactory.getSubSkillTextComponents(player, textComponents, this.skill); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/UnarmedCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/UnarmedCommand.java index 8db4ebdf6..e8e85418e 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/UnarmedCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/UnarmedCommand.java @@ -9,7 +9,7 @@ import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.SkillActivationType; -import net.md_5.bungee.api.chat.TextComponent; +import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -123,8 +123,8 @@ public class UnarmedCommand extends SkillCommand { } @Override - protected List getTextComponents(Player player) { - List textComponents = new ArrayList<>(); + protected List getTextComponents(Player player) { + List textComponents = new ArrayList<>(); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.UNARMED); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/WoodcuttingCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/WoodcuttingCommand.java index e96c7b07e..b26b385b1 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/WoodcuttingCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/WoodcuttingCommand.java @@ -7,7 +7,7 @@ import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.SkillActivationType; -import net.md_5.bungee.api.chat.TextComponent; +import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -83,8 +83,8 @@ public class WoodcuttingCommand extends SkillCommand { } @Override - protected List getTextComponents(Player player) { - List textComponents = new ArrayList<>(); + protected List getTextComponents(Player player) { + List textComponents = new ArrayList<>(); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.WOODCUTTING); diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java index 62f58a582..fc6886a27 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java @@ -22,6 +22,7 @@ import com.gmail.nossr50.util.skills.SkillActivationType; import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.sounds.SoundManager; import com.gmail.nossr50.util.sounds.SoundType; +import net.kyori.adventure.text.TextComponent; import net.md_5.bungee.api.chat.ComponentBuilder; import org.bukkit.Location; import org.bukkit.Material; @@ -116,7 +117,7 @@ public class Roll extends AcrobaticsSubSkill { * @param player target player */ @Override - public void addStats(ComponentBuilder componentBuilder, Player player) { + public void addStats(TextComponent.Builder componentBuilder, Player player) { String rollChance, rollChanceLucky, gracefulRollChance, gracefulRollChanceLucky; /* Values related to the player */ diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/interfaces/SubSkill.java b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/interfaces/SubSkill.java index 1bd26403d..701a528aa 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/interfaces/SubSkill.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/interfaces/SubSkill.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.datatypes.skills.subskills.interfaces; import com.gmail.nossr50.datatypes.skills.interfaces.Skill; +import net.kyori.adventure.text.TextComponent; import net.md_5.bungee.api.chat.ComponentBuilder; import org.bukkit.entity.Player; @@ -61,7 +62,7 @@ public interface SubSkill extends Skill { * @param componentBuilder target component builder * @param player owner of this skill */ - void addStats(ComponentBuilder componentBuilder, Player player); + void addStats(TextComponent.Builder componentBuilder, Player player); /** * Whether or not this subskill is enabled diff --git a/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerNotificationEvent.java b/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerNotificationEvent.java index 08de8fc99..45424ae40 100644 --- a/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerNotificationEvent.java +++ b/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerNotificationEvent.java @@ -1,8 +1,8 @@ package com.gmail.nossr50.events.skills; import com.gmail.nossr50.datatypes.interactions.NotificationType; -import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.TextComponent; +import com.gmail.nossr50.util.McMMOMessageType; +import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; @@ -22,12 +22,12 @@ public class McMMOPlayerNotificationEvent extends Event implements Cancellable { private boolean isMessageAlsoBeingSentToChat; private static final HandlerList handlers = new HandlerList(); - protected ChatMessageType chatMessageType; + protected McMMOMessageType chatMessageType; - protected TextComponent notificationTextComponent; + protected Component notificationTextComponent; protected final NotificationType notificationType; - public McMMOPlayerNotificationEvent(Player who, NotificationType notificationType, TextComponent notificationTextComponent, ChatMessageType chatMessageType, boolean isMessageAlsoBeingSentToChat) { + public McMMOPlayerNotificationEvent(Player who, NotificationType notificationType, Component notificationTextComponent, McMMOMessageType chatMessageType, boolean isMessageAlsoBeingSentToChat) { super(false); this.notificationType = notificationType; this.notificationTextComponent = notificationTextComponent; @@ -48,19 +48,19 @@ public class McMMOPlayerNotificationEvent extends Event implements Cancellable { isMessageAlsoBeingSentToChat = messageAlsoBeingSentToChat; } - public TextComponent getNotificationTextComponent() { + public Component getNotificationTextComponent() { return notificationTextComponent; } - public void setNotificationTextComponent(TextComponent notificationTextComponent) { + public void setNotificationTextComponent(Component notificationTextComponent) { this.notificationTextComponent = notificationTextComponent; } - public ChatMessageType getChatMessageType() { + public McMMOMessageType getChatMessageType() { return chatMessageType; } - public void setChatMessageType(ChatMessageType chatMessageType) { + public void setChatMessageType(McMMOMessageType chatMessageType) { this.chatMessageType = chatMessageType; } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 697e91439..998c6d638 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -50,6 +50,7 @@ import com.gmail.nossr50.util.skills.SmeltingTracker; import com.gmail.nossr50.util.upgrade.UpgradeManager; import com.gmail.nossr50.worldguard.WorldGuardManager; import com.google.common.base.Charsets; +import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.shatteredlands.shatt.backup.ZipLibrary; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; @@ -81,6 +82,9 @@ public class mcMMO extends JavaPlugin { private static PlayerLevelUtils playerLevelUtils; private static SmeltingTracker smeltingTracker; + /* Adventure */ + private static BukkitAudiences audiences; + /* Blacklist */ private static WorldBlacklist worldBlacklist; @@ -270,6 +274,8 @@ public class mcMMO extends JavaPlugin { //Init smelting tracker smeltingTracker = new SmeltingTracker(); + + audiences = BukkitAudiences.create(this); } public static PlayerLevelUtils getPlayerLevelUtils() { @@ -678,4 +684,8 @@ public class mcMMO extends JavaPlugin { public static SmeltingTracker getSmeltingTracker() { return smeltingTracker; } + + public static BukkitAudiences getAudiences() { + return audiences; + } } diff --git a/src/main/java/com/gmail/nossr50/util/McMMOMessageType.java b/src/main/java/com/gmail/nossr50/util/McMMOMessageType.java new file mode 100644 index 000000000..741c94767 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/util/McMMOMessageType.java @@ -0,0 +1,21 @@ +package com.gmail.nossr50.util; + +import java.util.function.BiConsumer; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.audience.MessageType; +import net.kyori.adventure.text.Component; + +public enum McMMOMessageType { + ACTION_BAR(Audience::sendActionBar), + SYSTEM((audience, message) -> audience.sendMessage(message, MessageType.SYSTEM)); + + private final BiConsumer sender; + + McMMOMessageType(final BiConsumer sender) { + this.sender = sender; + } + + public void send(final Audience audience, final Component message) { + this.sender.accept(audience, message); + } +} diff --git a/src/main/java/com/gmail/nossr50/util/TextComponentFactory.java b/src/main/java/com/gmail/nossr50/util/TextComponentFactory.java index f96e305a2..48d016da5 100644 --- a/src/main/java/com/gmail/nossr50/util/TextComponentFactory.java +++ b/src/main/java/com/gmail/nossr50/util/TextComponentFactory.java @@ -9,10 +9,20 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill; import com.gmail.nossr50.listeners.InteractionManager; import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.skills.RankUtils; -import net.md_5.bungee.api.ChatColor; +import java.util.concurrent.atomic.AtomicReference; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.audience.MessageType; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentBuilder; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.event.HoverEvent; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextColor; +import net.kyori.adventure.text.format.TextDecoration; import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.*; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -33,24 +43,23 @@ public class TextComponentFactory { public static TextComponent getNotificationMultipleValues(String localeKey, String... values) { String preColoredString = LocaleLoader.getString(localeKey, (Object[]) values); - TextComponent msg = new TextComponent(preColoredString); - return new TextComponent(msg); + return TextComponent.of(preColoredString); } - public static TextComponent getNotificationTextComponentFromLocale(String localeKey) + public static Component getNotificationTextComponentFromLocale(String localeKey) { return getNotificationTextComponent(LocaleLoader.getString(localeKey)); } - public static TextComponent getNotificationLevelUpTextComponent(PrimarySkillType skill, int levelsGained, int currentLevel) + public static Component getNotificationLevelUpTextComponent(PrimarySkillType skill, int levelsGained, int currentLevel) { - return new TextComponent(LocaleLoader.getString("Overhaul.Levelup", LocaleLoader.getString("Overhaul.Name."+StringUtils.getCapitalized(skill.toString())), levelsGained, currentLevel)); + return TextComponent.of(LocaleLoader.getString("Overhaul.Levelup", LocaleLoader.getString("Overhaul.Name."+StringUtils.getCapitalized(skill.toString())), levelsGained, currentLevel)); } private static TextComponent getNotificationTextComponent(String text) { //textComponent.setColor(getNotificationColor(notificationType)); - return new TextComponent(text); + return TextComponent.of(text); } public static void sendPlayerSubSkillWikiLink(Player player, String subskillformatted) @@ -58,225 +67,225 @@ public class TextComponentFactory { if(!Config.getInstance().getUrlLinksEnabled()) return; - Player.Spigot spigotPlayer = player.spigot(); - - TextComponent wikiLinkComponent = new TextComponent(LocaleLoader.getString("Overhaul.mcMMO.MmoInfo.Wiki")); - wikiLinkComponent.setUnderlined(true); + TextComponent.Builder wikiLinkComponent = TextComponent.builder(LocaleLoader.getString("Overhaul.mcMMO.MmoInfo.Wiki")); + wikiLinkComponent.decoration(TextDecoration.UNDERLINED, true); String wikiUrl = "https://mcmmo.org/wiki/"+subskillformatted; - wikiLinkComponent.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, wikiUrl)); + wikiLinkComponent.clickEvent(ClickEvent.openUrl(wikiUrl)); - ComponentBuilder componentBuilder = new ComponentBuilder(subskillformatted).append("\n").append(wikiUrl).color(ChatColor.GRAY).italic(true); + TextComponent.Builder componentBuilder = TextComponent.builder(subskillformatted).append("\n").append(wikiUrl).color(NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, true); - wikiLinkComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, componentBuilder.create())); + wikiLinkComponent.hoverEvent(HoverEvent.showText(componentBuilder.build())); - spigotPlayer.sendMessage(ChatMessageType.SYSTEM, wikiLinkComponent); + mcMMO.getAudiences().audience(player).sendMessage(wikiLinkComponent, MessageType.SYSTEM); } public static void sendPlayerUrlHeader(Player player) { - Player.Spigot spigotPlayer = player.spigot(); - - TextComponent prefix = new TextComponent(LocaleLoader.getString("Overhaul.mcMMO.Url.Wrap.Prefix") + " "); + TextComponent prefix = TextComponent.of(LocaleLoader.getString("Overhaul.mcMMO.Url.Wrap.Prefix") + " "); /*prefix.setColor(ChatColor.DARK_AQUA);*/ - TextComponent suffix = new TextComponent(" "+LocaleLoader.getString("Overhaul.mcMMO.Url.Wrap.Suffix")); + TextComponent suffix = TextComponent.of(" "+LocaleLoader.getString("Overhaul.mcMMO.Url.Wrap.Suffix")); /*suffix.setColor(ChatColor.DARK_AQUA);*/ - TextComponent emptySpace = new TextComponent(" "); + TextComponent emptySpace = TextComponent.space(); - BaseComponent[] baseComponents = {new TextComponent(prefix), - getWebLinkTextComponent(McMMOWebLinks.WEBSITE), - emptySpace, - getWebLinkTextComponent(McMMOWebLinks.DISCORD), - emptySpace, - getWebLinkTextComponent(McMMOWebLinks.PATREON), - emptySpace, - getWebLinkTextComponent(McMMOWebLinks.WIKI), - emptySpace, - getWebLinkTextComponent(McMMOWebLinks.SPIGOT), - emptySpace, - getWebLinkTextComponent(McMMOWebLinks.HELP_TRANSLATE), - new TextComponent(suffix)}; - - spigotPlayer.sendMessage(baseComponents); + mcMMO.getAudiences().audience(player).sendMessage(TextComponent.ofChildren( + prefix, + getWebLinkTextComponent(McMMOWebLinks.WEBSITE), + emptySpace, + getWebLinkTextComponent(McMMOWebLinks.DISCORD), + emptySpace, + getWebLinkTextComponent(McMMOWebLinks.PATREON), + emptySpace, + getWebLinkTextComponent(McMMOWebLinks.WIKI), + emptySpace, + getWebLinkTextComponent(McMMOWebLinks.SPIGOT), + emptySpace, + getWebLinkTextComponent(McMMOWebLinks.HELP_TRANSLATE), + suffix + ), MessageType.SYSTEM); } - public static void sendPlayerSubSkillList(Player player, List textComponents) + public static void sendPlayerSubSkillList(Player player, List textComponents) { - TextComponent emptySpace = new TextComponent(" "); + TextComponent emptySpace = TextComponent.space(); - ArrayList bulkMessage = new ArrayList<>(); + AtomicReference messageToSend = new AtomicReference<>(); int newLineCount = 0; //Hacky solution to wordwrap problems - for (TextComponent textComponent : textComponents) { + final Audience audience = mcMMO.getAudiences().audience(player); + for (Component textComponent : textComponents) { //Don't send more than 3 subskills per line to avoid MOST wordwrap problems if(newLineCount > 2) { - TextComponent[] bulkArray = new TextComponent[bulkMessage.size()]; - bulkArray = bulkMessage.toArray(bulkArray); + Component toSend = messageToSend.get(); + if (toSend != null) { + audience.sendMessage(toSend.append(emptySpace)); + } - player.spigot().sendMessage(bulkArray); - bulkMessage = new ArrayList<>(); + messageToSend.set(null); newLineCount = 0; } //Style the skills into @links - final String originalTxt = textComponent.getText(); + final String originalTxt = textComponent instanceof TextComponent ? ((TextComponent) textComponent).content() : ""; - TextComponent stylizedText = new TextComponent(LocaleLoader.getString("JSON.Hover.AtSymbolSkills")); + TextComponent.Builder stylizedText = TextComponent.builder(LocaleLoader.getString("JSON.Hover.AtSymbolSkills")); addChild(stylizedText, originalTxt); - if(textComponent.getHoverEvent() != null) - stylizedText.setHoverEvent(textComponent.getHoverEvent()); + if(textComponent.hoverEvent() != null) + stylizedText.hoverEvent(textComponent.hoverEvent()); - if(textComponent.getClickEvent() != null) - stylizedText.setClickEvent(textComponent.getClickEvent()); + if(textComponent.clickEvent() != null) + stylizedText.clickEvent(textComponent.clickEvent()); - bulkMessage.add(stylizedText); - bulkMessage.add(emptySpace); + messageToSend.set(stylizedText.build().append(emptySpace)); newLineCount++; } - /* - * Convert our list into an array - */ - TextComponent[] bulkArray = new TextComponent[bulkMessage.size()]; - bulkArray = bulkMessage.toArray(bulkArray); - - player.spigot().sendMessage(bulkArray); + Component toSend = messageToSend.get(); + if (toSend != null) { + audience.sendMessage(toSend.append(emptySpace)); + } } - private static TextComponent getWebLinkTextComponent(McMMOWebLinks webLinks) + private static Component getWebLinkTextComponent(McMMOWebLinks webLinks) { - TextComponent webTextComponent; + TextComponent.Builder webTextComponent; switch(webLinks) { case WEBSITE: - webTextComponent = new TextComponent(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); + webTextComponent = TextComponent.builder(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); addChild(webTextComponent, "Web"); - webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlWebsite)); + webTextComponent.clickEvent(getUrlClickEvent(McMMOUrl.urlWebsite)); break; case SPIGOT: - webTextComponent = new TextComponent(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); + webTextComponent = TextComponent.builder(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); addChild(webTextComponent, "Spigot"); - webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlSpigot)); + webTextComponent.clickEvent(getUrlClickEvent(McMMOUrl.urlSpigot)); break; case DISCORD: - webTextComponent = new TextComponent(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); + webTextComponent = TextComponent.builder(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); addChild(webTextComponent, "Discord"); - webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlDiscord)); + webTextComponent.clickEvent(getUrlClickEvent(McMMOUrl.urlDiscord)); break; case PATREON: - webTextComponent = new TextComponent(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); + webTextComponent = TextComponent.builder(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); addChild(webTextComponent, "Patreon"); - webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlPatreon)); + webTextComponent.clickEvent(getUrlClickEvent(McMMOUrl.urlPatreon)); break; case WIKI: - webTextComponent = new TextComponent(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); + webTextComponent = TextComponent.builder(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); addChild(webTextComponent, "Wiki"); - webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlWiki)); + webTextComponent.clickEvent(getUrlClickEvent(McMMOUrl.urlWiki)); break; case HELP_TRANSLATE: - webTextComponent = new TextComponent(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); + webTextComponent = TextComponent.builder(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); addChild(webTextComponent, "Lang"); - webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlTranslate)); + webTextComponent.clickEvent(getUrlClickEvent(McMMOUrl.urlTranslate)); break; default: - webTextComponent = new TextComponent("NOT DEFINED"); + webTextComponent = TextComponent.builder("NOT DEFINED"); } addNewHoverComponentToTextComponent(webTextComponent, getUrlHoverEvent(webLinks)); - webTextComponent.setInsertion(webLinks.getUrl()); + webTextComponent.insertion(webLinks.getUrl()); - return webTextComponent; + return webTextComponent.build(); } - private static void addChild(TextComponent webTextComponent, String childName) { - TextComponent childComponent = new TextComponent(childName); - childComponent.setColor(ChatColor.BLUE); - webTextComponent.addExtra(childComponent); + private static void addChild(Component webTextComponent, String childName) { + TextComponent childComponent = TextComponent.of(childName); + childComponent.color(NamedTextColor.BLUE); + webTextComponent.append(childComponent); } - private static BaseComponent[] getUrlHoverEvent(McMMOWebLinks webLinks) + private static void addChild(ComponentBuilder webTextComponent, String childName) { + TextComponent childComponent = TextComponent.of(childName); + childComponent.color(NamedTextColor.BLUE); + webTextComponent.append(childComponent); + } + + private static Component getUrlHoverEvent(McMMOWebLinks webLinks) { - ComponentBuilder componentBuilder = new ComponentBuilder(webLinks.getNiceTitle()); + TextComponent.Builder componentBuilder = TextComponent.builder(webLinks.getNiceTitle()); switch(webLinks) { case WEBSITE: addUrlHeaderHover(webLinks, componentBuilder); - componentBuilder.append("\n\n").italic(false); - componentBuilder.append(webLinks.getLocaleDescription()).color(ChatColor.GREEN); - componentBuilder.append("\nDev Blogs, and information related to mcMMO can be found here").color(ChatColor.GRAY); + componentBuilder.append("\n\n"); + componentBuilder.append(TextComponent.of(webLinks.getLocaleDescription(), NamedTextColor.GREEN)); + componentBuilder.append(TextComponent.of("\nDev Blogs, and information related to mcMMO can be found here", NamedTextColor.GRAY)); break; case SPIGOT: addUrlHeaderHover(webLinks, componentBuilder); - componentBuilder.append("\n\n").italic(false); - componentBuilder.append(webLinks.getLocaleDescription()).color(ChatColor.GREEN); - componentBuilder.append("\nI post regularly in the discussion thread here!").color(ChatColor.GRAY); + componentBuilder.append("\n\n"); + componentBuilder.append(TextComponent.of(webLinks.getLocaleDescription(), NamedTextColor.GREEN)); + componentBuilder.append(TextComponent.of("\nI post regularly in the discussion thread here!", NamedTextColor.GRAY)); break; case PATREON: addUrlHeaderHover(webLinks, componentBuilder); - componentBuilder.append("\n\n").italic(false); - componentBuilder.append(webLinks.getLocaleDescription()).color(ChatColor.GREEN); + componentBuilder.append("\n\n"); + componentBuilder.append(TextComponent.of(webLinks.getLocaleDescription(), NamedTextColor.GREEN)); componentBuilder.append("\n"); - componentBuilder.append("Show support by buying me a coffee :)").italic(false).color(ChatColor.GRAY); + componentBuilder.append(TextComponent.of("Show support by buying me a coffee :)", NamedTextColor.GRAY)); break; case WIKI: addUrlHeaderHover(webLinks, componentBuilder); - componentBuilder.append("\n\n").italic(false); - componentBuilder.append(webLinks.getLocaleDescription()).color(ChatColor.GREEN); + componentBuilder.append("\n\n"); + componentBuilder.append(TextComponent.of(webLinks.getLocaleDescription(), NamedTextColor.GREEN)); componentBuilder.append("\n"); - componentBuilder.append("I'm looking for more wiki staff, contact me on our discord!").italic(false).color(ChatColor.DARK_GRAY); + componentBuilder.append(TextComponent.of("I'm looking for more wiki staff, contact me on our discord!", NamedTextColor.DARK_GRAY)); break; case DISCORD: addUrlHeaderHover(webLinks, componentBuilder); - componentBuilder.append("\n\n").italic(false); - componentBuilder.append(webLinks.getLocaleDescription()).color(ChatColor.GREEN); + componentBuilder.append("\n\n"); + componentBuilder.append(TextComponent.of(webLinks.getLocaleDescription(), NamedTextColor.GREEN)); break; case HELP_TRANSLATE: addUrlHeaderHover(webLinks, componentBuilder); - componentBuilder.append("\n\n").italic(false); - componentBuilder.append(webLinks.getLocaleDescription()).color(ChatColor.GREEN); + componentBuilder.append("\n\n"); + componentBuilder.append(TextComponent.of(webLinks.getLocaleDescription(), NamedTextColor.GREEN)); componentBuilder.append("\n"); - componentBuilder.append("You can use this website to help translate mcMMO into your language!" + - "\nIf you want to know more contact me in discord.").italic(false).color(ChatColor.DARK_GRAY); + componentBuilder.append(TextComponent.of("You can use this website to help translate mcMMO into your language!" + + "\nIf you want to know more contact me in discord.", NamedTextColor.DARK_GRAY)); } - return componentBuilder.create(); + return componentBuilder.build(); } - private static void addUrlHeaderHover(McMMOWebLinks webLinks, ComponentBuilder componentBuilder) { + private static void addUrlHeaderHover(McMMOWebLinks webLinks, TextComponent.Builder componentBuilder) { componentBuilder.append("\n"); - componentBuilder.append(webLinks.getUrl()).color(ChatColor.GRAY).italic(true); + componentBuilder.append(TextComponent.of(webLinks.getUrl(), NamedTextColor.GRAY, TextDecoration.ITALIC)); } private static ClickEvent getUrlClickEvent(String url) { - return new ClickEvent(ClickEvent.Action.OPEN_URL, url); + return ClickEvent.openUrl(url); } - private static TextComponent getSubSkillTextComponent(Player player, SubSkillType subSkillType) + private static Component getSubSkillTextComponent(Player player, SubSkillType subSkillType) { //Get skill name String skillName = subSkillType.getLocaleName(); boolean skillUnlocked = RankUtils.hasUnlockedSubskill(player, subSkillType); - TextComponent textComponent = initNewSkillTextComponent(player, skillName, subSkillType, skillUnlocked); + TextComponent.Builder textComponent = initNewSkillTextComponent(player, skillName, subSkillType, skillUnlocked); //Hover Event addNewHoverComponentToTextComponent(textComponent, getSubSkillHoverComponent(player, subSkillType)); //Insertion - textComponent.setInsertion(skillName); + textComponent.insertion(skillName); - return textComponent; + return textComponent.build(); } - private static void addNewHoverComponentToTextComponent(TextComponent textComponent, BaseComponent[] baseComponent) { - textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, baseComponent)); + private static void addNewHoverComponentToTextComponent(TextComponent.Builder textComponent, Component baseComponent) { + textComponent.hoverEvent(HoverEvent.showText(baseComponent)); } private static TextComponent getSubSkillTextComponent(Player player, AbstractSubSkill abstractSubSkill) @@ -289,42 +298,42 @@ public class TextComponentFactory { boolean skillUnlocked = RankUtils.hasUnlockedSubskill(player, subSkillType); - TextComponent textComponent = initNewSkillTextComponent(player, skillName, subSkillType, skillUnlocked); + TextComponent.Builder textComponent = initNewSkillTextComponent(player, skillName, subSkillType, skillUnlocked); //Hover Event addNewHoverComponentToTextComponent(textComponent, getSubSkillHoverComponent(player, abstractSubSkill)); //Insertion - textComponent.setInsertion(skillName); + textComponent.insertion(skillName); - return textComponent; + return textComponent.build(); } - private static TextComponent initNewSkillTextComponent(Player player, String skillName, SubSkillType subSkillType, boolean skillUnlocked) { - TextComponent textComponent; + private static TextComponent.Builder initNewSkillTextComponent(Player player, String skillName, SubSkillType subSkillType, boolean skillUnlocked) { + TextComponent.Builder textComponent; if (skillUnlocked) { if (RankUtils.getHighestRank(subSkillType) == RankUtils.getRank(player, subSkillType) && subSkillType.getNumRanks() > 1) - textComponent = new TextComponent(LocaleLoader.getString("JSON.Hover.MaxRankSkillName", skillName)); + textComponent = TextComponent.builder(LocaleLoader.getString("JSON.Hover.MaxRankSkillName", skillName)); else - textComponent = new TextComponent(LocaleLoader.getString("JSON.Hover.SkillName", skillName)); + textComponent = TextComponent.builder(LocaleLoader.getString("JSON.Hover.SkillName", skillName)); - textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/mmoinfo " + subSkillType.getNiceNameNoSpaces(subSkillType))); + textComponent.clickEvent(ClickEvent.runCommand("/mmoinfo " + subSkillType.getNiceNameNoSpaces(subSkillType))); } else { - textComponent = new TextComponent(LocaleLoader.getString("JSON.Hover.Mystery", + textComponent = TextComponent.builder(LocaleLoader.getString("JSON.Hover.Mystery", String.valueOf(RankUtils.getUnlockLevel(subSkillType)))); - textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/mmoinfo ???")); + textComponent.clickEvent(ClickEvent.runCommand("/mmoinfo ???")); } return textComponent; } - private static BaseComponent[] getSubSkillHoverComponent(Player player, AbstractSubSkill abstractSubSkill) + private static Component getSubSkillHoverComponent(Player player, AbstractSubSkill abstractSubSkill) { return getSubSkillHoverEventJSON(abstractSubSkill, player); } - private static BaseComponent[] getSubSkillHoverComponent(Player player, SubSkillType subSkillType) + private static Component getSubSkillHoverComponent(Player player, SubSkillType subSkillType) { return getSubSkillHoverEventJSON(subSkillType, player); } @@ -335,27 +344,27 @@ public class TextComponentFactory { * @param player the player who owns this subskill * @return the hover basecomponent object for this subskill */ - private static BaseComponent[] getSubSkillHoverEventJSON(AbstractSubSkill abstractSubSkill, Player player) + private static Component getSubSkillHoverEventJSON(AbstractSubSkill abstractSubSkill, Player player) { String skillName = abstractSubSkill.getNiceName(); /* * Hover Event BaseComponent color table */ - ChatColor ccSubSkillHeader = ChatColor.GOLD; - ChatColor ccRank = ChatColor.BLUE; - ChatColor ccCurRank = ChatColor.GREEN; - ChatColor ccPossessive = ChatColor.WHITE; + TextColor ccSubSkillHeader = NamedTextColor.GOLD; + TextColor ccRank = NamedTextColor.BLUE; + TextColor ccCurRank = NamedTextColor.GREEN; + TextColor ccPossessive = NamedTextColor.WHITE; //ChatColor ccDescriptionHeader = ChatColor.DARK_PURPLE; //ChatColor ccDescription = ChatColor.WHITE; - ChatColor ccLocked = ChatColor.DARK_GRAY; - ChatColor ccLevelRequirement = ChatColor.BLUE; - ChatColor ccLevelRequired = ChatColor.RED; + TextColor ccLocked = NamedTextColor.DARK_GRAY; + TextColor ccLevelRequirement = NamedTextColor.BLUE; + TextColor ccLevelRequired = NamedTextColor.RED; SubSkillType subSkillType = abstractSubSkill.getSubSkillType(); //SubSkillType Name - ComponentBuilder componentBuilder = setupSkillComponentNameStyle(player, skillName, subSkillType, RankUtils.hasUnlockedSubskill(player, abstractSubSkill)); + TextComponent.Builder componentBuilder = setupSkillComponentNameStyle(player, skillName, subSkillType, RankUtils.hasUnlockedSubskill(player, abstractSubSkill)); if(!RankUtils.hasUnlockedSubskill(player, abstractSubSkill)) { @@ -379,18 +388,18 @@ public class TextComponentFactory { componentBuilder.append("\n").append(abstractSubSkill.getDescription()).append("\n"); //Empty line - componentBuilder.append("\n").bold(false); + componentBuilder.append("\n").decoration(TextDecoration.BOLD, false); componentBuilder.append("\n"); //Finally, add details to the tooltip abstractSubSkill.addStats(componentBuilder, player); } - return componentBuilder.create(); + return componentBuilder.build(); } - private static ComponentBuilder setupSkillComponentNameStyle(Player player, String skillName, SubSkillType subSkillType, boolean skillUnlocked) { - ComponentBuilder componentBuilder; + private static TextComponent.Builder setupSkillComponentNameStyle(Player player, String skillName, SubSkillType subSkillType, boolean skillUnlocked) { + TextComponent.Builder componentBuilder; if (skillUnlocked) { if (RankUtils.getHighestRank(subSkillType) == RankUtils.getRank(player, subSkillType) && subSkillType.getNumRanks() > 1) componentBuilder = getNewComponentBuilder(LocaleLoader.getString("JSON.Hover.MaxRankSkillName", skillName)); @@ -402,66 +411,64 @@ public class TextComponentFactory { return componentBuilder; } - private static ComponentBuilder getNewComponentBuilder(String skillName) { - ComponentBuilder componentBuilder = new ComponentBuilder(skillName); + private static TextComponent.Builder getNewComponentBuilder(String skillName) { + TextComponent.Builder componentBuilder = TextComponent.builder(skillName); componentBuilder.append("\n"); return componentBuilder; } - private static void addRanked(ChatColor ccRank, ChatColor ccCurRank, ChatColor ccPossessive, ChatColor ccNumRanks, ComponentBuilder componentBuilder, int numRanks, int rank, int nextRank) { + private static void addRanked(TextColor ccRank, TextColor ccCurRank, TextColor ccPossessive, TextColor ccNumRanks, TextComponent.Builder componentBuilder, int numRanks, int rank, int nextRank) { if (numRanks > 0) { //Rank: x - componentBuilder.append(LocaleLoader.getString("JSON.Hover.Rank", String.valueOf(rank))).append("\n") - .bold(false).italic(false).strikethrough(false).underlined(false); + componentBuilder.append(LocaleLoader.getString("JSON.Hover.Rank", String.valueOf(rank))).append("\n"); //Next Rank: x if(nextRank > rank) - componentBuilder.append(LocaleLoader.getString("JSON.Hover.NextRank", String.valueOf(nextRank))).append("\n") - .bold(false).italic(false).strikethrough(false).underlined(false); + componentBuilder.append(LocaleLoader.getString("JSON.Hover.NextRank", String.valueOf(nextRank))).append("\n"); /*componentBuilder.append(" " + LocaleLoader.getString("JSON.RankPossesive") + " ").color(ccPossessive); componentBuilder.append(String.valueOf(numRanks)).color(ccNumRanks);*/ } } - private static void addLocked(SubSkillType subSkillType, ChatColor ccLocked, ChatColor ccLevelRequirement, ChatColor ccLevelRequired, ComponentBuilder componentBuilder) { + private static void addLocked(SubSkillType subSkillType, TextColor ccLocked, TextColor ccLevelRequirement, TextColor ccLevelRequired, TextComponent.Builder componentBuilder) { addLocked(ccLocked, ccLevelRequirement, componentBuilder); - componentBuilder.append(String.valueOf(RankConfig.getInstance().getSubSkillUnlockLevel(subSkillType, 1))).color(ccLevelRequired); + componentBuilder.append(TextComponent.of(String.valueOf(RankConfig.getInstance().getSubSkillUnlockLevel(subSkillType, 1)), ccLevelRequired)); //componentBuilder.append("\n"); } - private static void addLocked(AbstractSubSkill abstractSubSkill, ChatColor ccLocked, ChatColor ccLevelRequirement, ChatColor ccLevelRequired, ComponentBuilder componentBuilder) { + private static void addLocked(AbstractSubSkill abstractSubSkill, TextColor ccLocked, TextColor ccLevelRequirement, TextColor ccLevelRequired, TextComponent.Builder componentBuilder) { addLocked(ccLocked, ccLevelRequirement, componentBuilder); - componentBuilder.append(String.valueOf(RankConfig.getInstance().getSubSkillUnlockLevel(abstractSubSkill, 1))).color(ccLevelRequired); + componentBuilder.append(TextComponent.of(String.valueOf(RankConfig.getInstance().getSubSkillUnlockLevel(abstractSubSkill, 1)), ccLevelRequired)); //componentBuilder.append("\n"); } - private static void addLocked(ChatColor ccLocked, ChatColor ccLevelRequirement, ComponentBuilder componentBuilder) { - componentBuilder.append(LocaleLoader.getString("JSON.Locked")).color(ccLocked).bold(true); - componentBuilder.append("\n").append("\n").bold(false); - componentBuilder.append(LocaleLoader.getString("JSON.LevelRequirement") + ": ").color(ccLevelRequirement); + private static void addLocked(TextColor ccLocked, TextColor ccLevelRequirement, TextComponent.Builder componentBuilder) { + componentBuilder.append(TextComponent.of(LocaleLoader.getString("JSON.Locked"), ccLocked, TextDecoration.BOLD)); + componentBuilder.append("\n").append("\n"); + componentBuilder.append(TextComponent.of(LocaleLoader.getString("JSON.LevelRequirement") + ": ", ccLevelRequirement)); } @Deprecated - private static BaseComponent[] getSubSkillHoverEventJSON(SubSkillType subSkillType, Player player) + private static Component getSubSkillHoverEventJSON(SubSkillType subSkillType, Player player) { String skillName = subSkillType.getLocaleName(); /* * Hover Event BaseComponent color table */ - ChatColor ccSubSkillHeader = ChatColor.GOLD; - ChatColor ccRank = ChatColor.BLUE; - ChatColor ccCurRank = ChatColor.GREEN; - ChatColor ccPossessive = ChatColor.WHITE; - ChatColor ccDescriptionHeader = ChatColor.DARK_PURPLE; - ChatColor ccDescription = ChatColor.DARK_GRAY; - ChatColor ccLocked = ChatColor.DARK_GRAY; - ChatColor ccLevelRequirement = ChatColor.BLUE; - ChatColor ccLevelRequired = ChatColor.RED; + TextColor ccSubSkillHeader = NamedTextColor.GOLD; + TextColor ccRank = NamedTextColor.BLUE; + TextColor ccCurRank = NamedTextColor.GREEN; + TextColor ccPossessive = NamedTextColor.WHITE; + TextColor ccDescriptionHeader = NamedTextColor.DARK_PURPLE; + TextColor ccDescription = NamedTextColor.DARK_GRAY; + TextColor ccLocked = NamedTextColor.DARK_GRAY; + TextColor ccLevelRequirement = NamedTextColor.BLUE; + TextColor ccLevelRequired = NamedTextColor.RED; //SubSkillType Name - ComponentBuilder componentBuilder = setupSkillComponentNameStyle(player, skillName, subSkillType, RankUtils.hasUnlockedSubskill(player, subSkillType)); + TextComponent.Builder componentBuilder = setupSkillComponentNameStyle(player, skillName, subSkillType, RankUtils.hasUnlockedSubskill(player, subSkillType)); if(!RankUtils.hasUnlockedSubskill(player, subSkillType)) { @@ -485,7 +492,7 @@ public class TextComponentFactory { } - componentBuilder.append("\n").bold(false); + componentBuilder.append("\n"); componentBuilder.append(LocaleLoader.getString("JSON.DescriptionHeader")); componentBuilder.color(ccDescriptionHeader); componentBuilder.append("\n"); @@ -493,28 +500,25 @@ public class TextComponentFactory { componentBuilder.color(ccDescription); } - return componentBuilder.create(); + return componentBuilder.build(); } - private static void addSubSkillTypeToHoverEventJSON(AbstractSubSkill abstractSubSkill, ComponentBuilder componentBuilder) + private static void addSubSkillTypeToHoverEventJSON(AbstractSubSkill abstractSubSkill, TextComponent.Builder componentBuilder) { if(abstractSubSkill.isSuperAbility()) { - componentBuilder.append(LocaleLoader.getString("JSON.Type.SuperAbility")).color(ChatColor.LIGHT_PURPLE); - componentBuilder.bold(true); + componentBuilder.append(TextComponent.of(LocaleLoader.getString("JSON.Type.SuperAbility"), NamedTextColor.LIGHT_PURPLE, TextDecoration.BOLD)); } else if(abstractSubSkill.isActiveUse()) { - componentBuilder.append(LocaleLoader.getString("JSON.Type.Active")).color(ChatColor.DARK_RED); - componentBuilder.bold(true); + componentBuilder.append(TextComponent.of(LocaleLoader.getString("JSON.Type.Active"), NamedTextColor.DARK_RED, TextDecoration.BOLD)); } else { - componentBuilder.append(LocaleLoader.getString("JSON.Type.Passive")).color(ChatColor.GREEN); - componentBuilder.bold(true); + componentBuilder.append(TextComponent.of(LocaleLoader.getString("JSON.Type.Passive"), NamedTextColor.GREEN, TextDecoration.BOLD)); } componentBuilder.append("\n"); } - public static void getSubSkillTextComponents(Player player, List textComponents, PrimarySkillType parentSkill) { + public static void getSubSkillTextComponents(Player player, List textComponents, PrimarySkillType parentSkill) { for(SubSkillType subSkillType : SubSkillType.values()) { if(subSkillType.getParentSkill() == parentSkill) @@ -540,11 +544,10 @@ public class TextComponentFactory { public static TextComponent getSubSkillUnlockedNotificationComponents(Player player, SubSkillType subSkillType) { - TextComponent unlockMessage = new TextComponent(""); - unlockMessage.setText(LocaleLoader.getString("JSON.SkillUnlockMessage", subSkillType.getLocaleName(), RankUtils.getRank(player, subSkillType))); - unlockMessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, getSubSkillHoverComponent(player, subSkillType))); - unlockMessage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/"+subSkillType.getParentSkill().toString().toLowerCase(Locale.ENGLISH))); - return unlockMessage; + TextComponent.Builder unlockMessage = TextComponent.builder(LocaleLoader.getString("JSON.SkillUnlockMessage", subSkillType.getLocaleName(), RankUtils.getRank(player, subSkillType))); + unlockMessage.hoverEvent(HoverEvent.showText(getSubSkillHoverComponent(player, subSkillType))); + unlockMessage.clickEvent(ClickEvent.runCommand("/"+subSkillType.getParentSkill().toString().toLowerCase(Locale.ENGLISH))); + return unlockMessage.build(); } } diff --git a/src/main/java/com/gmail/nossr50/util/player/NotificationManager.java b/src/main/java/com/gmail/nossr50/util/player/NotificationManager.java index 2bd02aa6a..b5a4ce499 100644 --- a/src/main/java/com/gmail/nossr50/util/player/NotificationManager.java +++ b/src/main/java/com/gmail/nossr50/util/player/NotificationManager.java @@ -10,12 +10,14 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.events.skills.McMMOPlayerNotificationEvent; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.util.McMMOMessageType; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.sounds.SoundManager; import com.gmail.nossr50.util.sounds.SoundType; -import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.TextComponent; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.audience.MessageType; +import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Server; @@ -36,9 +38,9 @@ public class NotificationManager { if(UserManager.getPlayer(player) == null || !UserManager.getPlayer(player).useChatNotifications()) return; - ChatMessageType destination = AdvancedConfig.getInstance().doesNotificationUseActionBar(notificationType) ? ChatMessageType.ACTION_BAR : ChatMessageType.SYSTEM; + McMMOMessageType destination = AdvancedConfig.getInstance().doesNotificationUseActionBar(notificationType) ? McMMOMessageType.ACTION_BAR : McMMOMessageType.SYSTEM; - TextComponent message = TextComponentFactory.getNotificationTextComponentFromLocale(key); + Component message = TextComponentFactory.getNotificationTextComponentFromLocale(key); McMMOPlayerNotificationEvent customEvent = checkNotificationEvent(player, notificationType, destination, message); sendNotification(player, customEvent); @@ -91,9 +93,9 @@ public class NotificationManager { if(UserManager.getPlayer(player) == null || !UserManager.getPlayer(player).useChatNotifications()) return; - ChatMessageType destination = AdvancedConfig.getInstance().doesNotificationUseActionBar(notificationType) ? ChatMessageType.ACTION_BAR : ChatMessageType.SYSTEM; + McMMOMessageType destination = AdvancedConfig.getInstance().doesNotificationUseActionBar(notificationType) ? McMMOMessageType.ACTION_BAR : McMMOMessageType.SYSTEM; - TextComponent message = TextComponentFactory.getNotificationMultipleValues(key, values); + Component message = TextComponentFactory.getNotificationMultipleValues(key, values); McMMOPlayerNotificationEvent customEvent = checkNotificationEvent(player, notificationType, destination, message); sendNotification(player, customEvent); @@ -103,22 +105,24 @@ public class NotificationManager { if (customEvent.isCancelled()) return; + final Audience audience = mcMMO.getAudiences().audience(player); + //If the message is being sent to the action bar we need to check if the copy if a copy is sent to the chat system - if(customEvent.getChatMessageType() == ChatMessageType.ACTION_BAR) + if(customEvent.getChatMessageType() == McMMOMessageType.ACTION_BAR) { - player.spigot().sendMessage(customEvent.getChatMessageType(), customEvent.getNotificationTextComponent()); + audience.sendActionBar(customEvent.getNotificationTextComponent()); if(customEvent.isMessageAlsoBeingSentToChat()) { //Send copy to chat system - player.spigot().sendMessage(ChatMessageType.SYSTEM, customEvent.getNotificationTextComponent()); + audience.sendMessage(customEvent.getNotificationTextComponent(), MessageType.SYSTEM); } } else { - player.spigot().sendMessage(customEvent.getChatMessageType(), customEvent.getNotificationTextComponent()); + audience.sendMessage(customEvent.getNotificationTextComponent(), MessageType.SYSTEM); } } - private static McMMOPlayerNotificationEvent checkNotificationEvent(Player player, NotificationType notificationType, ChatMessageType destination, TextComponent message) { + private static McMMOPlayerNotificationEvent checkNotificationEvent(Player player, NotificationType notificationType, McMMOMessageType destination, Component message) { //Init event McMMOPlayerNotificationEvent customEvent = new McMMOPlayerNotificationEvent(player, notificationType, message, destination, AdvancedConfig.getInstance().doesNotificationSendCopyToChat(notificationType)); @@ -139,9 +143,9 @@ public class NotificationManager { if(!mcMMOPlayer.useChatNotifications()) return; - ChatMessageType destination = AdvancedConfig.getInstance().doesNotificationUseActionBar(NotificationType.LEVEL_UP_MESSAGE) ? ChatMessageType.ACTION_BAR : ChatMessageType.SYSTEM; + McMMOMessageType destination = AdvancedConfig.getInstance().doesNotificationUseActionBar(NotificationType.LEVEL_UP_MESSAGE) ? McMMOMessageType.ACTION_BAR : McMMOMessageType.SYSTEM; - TextComponent levelUpTextComponent = TextComponentFactory.getNotificationLevelUpTextComponent(skillName, levelsGained, newLevel); + Component levelUpTextComponent = TextComponentFactory.getNotificationLevelUpTextComponent(skillName, levelsGained, newLevel); McMMOPlayerNotificationEvent customEvent = checkNotificationEvent(mcMMOPlayer.getPlayer(), NotificationType.LEVEL_UP_MESSAGE, destination, levelUpTextComponent); sendNotification(mcMMOPlayer.getPlayer(), customEvent); @@ -161,7 +165,7 @@ public class NotificationManager { return; //CHAT MESSAGE - mcMMOPlayer.getPlayer().spigot().sendMessage(TextComponentFactory.getSubSkillUnlockedNotificationComponents(mcMMOPlayer.getPlayer(), subSkillType)); + mcMMO.getAudiences().audience(mcMMOPlayer.getPlayer()).sendMessage(TextComponentFactory.getSubSkillUnlockedNotificationComponents(mcMMOPlayer.getPlayer(), subSkillType)); //Unlock Sound Effect SoundManager.sendCategorizedSound(mcMMOPlayer.getPlayer(), mcMMOPlayer.getPlayer().getLocation(), SoundType.SKILL_UNLOCKED, SoundCategory.MASTER); diff --git a/src/main/java/com/gmail/nossr50/util/skills/PerksUtils.java b/src/main/java/com/gmail/nossr50/util/skills/PerksUtils.java index 70063bdea..165008068 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/PerksUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/PerksUtils.java @@ -4,7 +4,7 @@ import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.player.UserManager; -import net.md_5.bungee.api.ChatColor; +import org.bukkit.ChatColor; import org.bukkit.entity.Player; public final class PerksUtils { From 6f999405403f33b0ec000da968c23842bcd43b3d Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 25 Sep 2020 10:40:26 -0700 Subject: [PATCH 07/10] Add missing includes --- Changelog.txt | 1 + pom.xml | 35 +++++++++++++++++++ .../nossr50/util/TextComponentFactory.java | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Changelog.txt b/Changelog.txt index 10e620817..93b49d8af 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,4 +1,5 @@ Version 2.1.146 + JSON Text components are now done through 'adventure' library by Kyori, this should help reduce player disconnects from messages due to an unfixed Spigot bug. Improvements were made to tracking player placed blocks in mcMMO Players no longer lose levels below the level threshold in hardcore mode Hardcore now only applies penalties to levels above threshold diff --git a/pom.xml b/pom.xml index d1228adbe..fc89690db 100755 --- a/pom.xml +++ b/pom.xml @@ -100,6 +100,16 @@ org.apache.tomcat:tomcat-juli org.bstats:bstats-bukkit net.kyori:adventure-api + net.kyori:adventure-text-serializer-gson + net.kyori:adventure-platform-bukkit + net.kyori:adventure-platform-api + net.kyori:adventure-platform-common + net.kyori:adventure-platform-viaversion + net.kyori:adventure-nbt + net.kyori:examination-api + net.kyori:examination-string + net.kyori:adventure-text-serializer-legacy + net.kyori:adventure-text-serializer-bungeecord @@ -115,6 +125,10 @@ org.apache.tomcat com.gmail.nossr50.database.tomcat + + net.kyori.adventure + com.gmail.nossr50.kyori.adventure + org.bstats com.gmail.nossr50.metrics.bstat @@ -160,16 +174,37 @@ + + + net.kyori + adventure-text-serializer-gson + 4.0.0-SNAPSHOT + net.kyori adventure-api 4.0.0-SNAPSHOT + + net.kyori + adventure-nbt + 4.0.0-SNAPSHOT + net.kyori adventure-platform-bukkit 4.0.0-SNAPSHOT + + net.kyori + adventure-platform-api + 4.0.0-SNAPSHOT + + + net.kyori + adventure-platform-common + 4.0.0-SNAPSHOT + org.apache.maven.scm maven-scm-provider-gitexe diff --git a/src/main/java/com/gmail/nossr50/util/TextComponentFactory.java b/src/main/java/com/gmail/nossr50/util/TextComponentFactory.java index 48d016da5..d9f24b675 100644 --- a/src/main/java/com/gmail/nossr50/util/TextComponentFactory.java +++ b/src/main/java/com/gmail/nossr50/util/TextComponentFactory.java @@ -483,7 +483,7 @@ public class TextComponentFactory { int curRank = RankUtils.getRank(player, subSkillType); int nextRank = 0; - if(curRank < subSkillType.getNumRanks() && subSkillType.getNumRanks() > 0) + if(curRank < subSkillType.getNumRanks()) { nextRank = RankUtils.getRankUnlockLevel(subSkillType, curRank+1); } From adbcf11c1585c0e39fe9ac7fac9b574a210a15cc Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 25 Sep 2020 11:01:47 -0700 Subject: [PATCH 08/10] 2.1.146 --- Changelog.txt | 31 ++++++++++++++++++++++++++++++- pom.xml | 2 +- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 93b49d8af..43b552678 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,9 +1,38 @@ Version 2.1.146 - JSON Text components are now done through 'adventure' library by Kyori, this should help reduce player disconnects from messages due to an unfixed Spigot bug. + A bug where players would disconnect from mcMMO messages has been fixed (thanks kashike / read notes) + It should be noted this was NOT an mcMMO bug, but a bug within Spigot since Spigot 1.16 + A dupe exploit has been fixed Improvements were made to tracking player placed blocks in mcMMO Players no longer lose levels below the level threshold in hardcore mode Hardcore now only applies penalties to levels above threshold + NOTES: + Shout out to Kashike + If you guys are looking to hire someone of exceptional quality for a Java project, Kashike is a skilled developer who I respect and he makes a living off free lance right now. Try contacting him if you do! + Kashike is a developer on the mcMMO team, however after I recruited him had a lot of life stuff come at him and hasn't had a chance to contribute until now! + + JSON is used by Minecraft for a lot of stuff, in this case the JSON mcMMO made use of was related to displaying text in chat or displaying text on the clients screen in other places such as the action bar, there's been a bad bug in Spigot since 1.16 that would disconnect players some of the time when sending JSON components. + mcMMO makes heavy use of these components, so since spigot has yet to fix the bug I decided we needed a work around for the time being. + The library named 'adventure' is developed by the Kyori organization, which is Kashike's baby. + Kashike is a very talented and skilled developer and he did the work on this patch to solve this issue. + + This is a link to an bug report I did on this bug on Spigot's issue tracker, it is my understanding they have yet to find a way to reliably reproduce this bug. + If you have any information please post about it in this thread. + + https://hub.spigotmc.org/jira/browse/SPIGOT-6056 + Although mcMMO solved this issue by switching to Kyori's Adventure library for sending JSON Components, most Spigot plugins have not implemented a work around like this and will continue to make players disconnect until it is solved within Spigot. + + Hardcore changes + If you set a level threshold of 100 and player with 150 levels dies, they should never lose more than 50 levels as the first 100 are considered part of the threshold. + Prior to this change in this exact same scenario a player could be penalized and be put below the threshold. + + Shout out to HexedHero for reporting the dupe exploit and providing a demonstration of how to replicate it + + Tridents & Crossbows update + It is still being worked on but it won't make a September release. + October is the new target release but I am terrible with estimates so take it with a grain of salt! + + Version 2.1.145 Reverted 'Changed one of the PlayerInteractEvent listeners to ignore cancelled events' from 2.1.144 diff --git a/pom.xml b/pom.xml index fc89690db..f8fef7074 100755 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.gmail.nossr50.mcMMO mcMMO - 2.1.146-SNAPSHOT + 2.1.146 mcMMO https://github.com/mcMMO-Dev/mcMMO From 8451f84083a036682fb51132d18fc4f43c6847d5 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 25 Sep 2020 11:36:42 -0700 Subject: [PATCH 09/10] dev mode --- Changelog.txt | 4 +- pom.xml | 2 +- .../nossr50/listeners/CommandListener.java | 40 +++++++++++++++++++ src/main/java/com/gmail/nossr50/mcMMO.java | 1 + .../gmail/nossr50/util/skills/SkillUtils.java | 4 -- 5 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/listeners/CommandListener.java diff --git a/Changelog.txt b/Changelog.txt index 43b552678..7f67c15e8 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,6 @@ +Version 2.1.147 + + Version 2.1.146 A bug where players would disconnect from mcMMO messages has been fixed (thanks kashike / read notes) It should be noted this was NOT an mcMMO bug, but a bug within Spigot since Spigot 1.16 @@ -8,7 +11,6 @@ Version 2.1.146 NOTES: Shout out to Kashike - If you guys are looking to hire someone of exceptional quality for a Java project, Kashike is a skilled developer who I respect and he makes a living off free lance right now. Try contacting him if you do! Kashike is a developer on the mcMMO team, however after I recruited him had a lot of life stuff come at him and hasn't had a chance to contribute until now! JSON is used by Minecraft for a lot of stuff, in this case the JSON mcMMO made use of was related to displaying text in chat or displaying text on the clients screen in other places such as the action bar, there's been a bad bug in Spigot since 1.16 that would disconnect players some of the time when sending JSON components. diff --git a/pom.xml b/pom.xml index f8fef7074..a3d6c5776 100755 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.gmail.nossr50.mcMMO mcMMO - 2.1.146 + 2.1.147-SNAPSHOT mcMMO https://github.com/mcMMO-Dev/mcMMO diff --git a/src/main/java/com/gmail/nossr50/listeners/CommandListener.java b/src/main/java/com/gmail/nossr50/listeners/CommandListener.java new file mode 100644 index 000000000..484faa5bb --- /dev/null +++ b/src/main/java/com/gmail/nossr50/listeners/CommandListener.java @@ -0,0 +1,40 @@ +//package com.gmail.nossr50.listeners; +// +//import com.gmail.nossr50.datatypes.player.McMMOPlayer; +//import com.gmail.nossr50.datatypes.skills.SuperAbilityType; +//import com.gmail.nossr50.mcMMO; +//import com.gmail.nossr50.util.player.UserManager; +//import com.gmail.nossr50.util.skills.SkillUtils; +//import org.bukkit.Bukkit; +//import org.bukkit.entity.Player; +//import org.bukkit.event.EventHandler; +//import org.bukkit.event.EventPriority; +//import org.bukkit.event.Listener; +//import org.bukkit.event.player.PlayerCommandPreprocessEvent; +// +//public class CommandListener implements Listener { +// +// private final mcMMO pluginRef; +// +// public CommandListener(mcMMO plugin) { +// this.pluginRef = plugin; +// } +// +// @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) +// public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { +// Player player = event.getPlayer(); +// +// SkillUtils.removeAbilityBoostsFromInventory(player); +// +// McMMOPlayer mmoPlayer = UserManager.getPlayer(player); +// +// if(mmoPlayer == null) +// return; +// +// Bukkit.getServer().getScheduler().runTaskLater(pluginRef, () -> { +// if(mmoPlayer.getAbilityMode(SuperAbilityType.GIGA_DRILL_BREAKER) || mmoPlayer.getAbilityMode(SuperAbilityType.SUPER_BREAKER)) { +// SkillUtils.handleAbilitySpeedIncrease(player); +// } +// }, 5); +// } +//} diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 998c6d638..64c1509ef 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -555,6 +555,7 @@ public class mcMMO extends JavaPlugin { pluginManager.registerEvents(new InventoryListener(this), this); pluginManager.registerEvents(new SelfListener(this), this); pluginManager.registerEvents(new WorldListener(this), this); +// pluginManager.registerEvents(new CommandListener(this), this); } /** diff --git a/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java b/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java index d9ccf532f..76c73d391 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java @@ -198,10 +198,6 @@ public class SkillUtils { } public static void removeAbilityBoostsFromInventory(@NotNull Player player) { - if (!HiddenConfig.getInstance().useEnchantmentBuffs()) { - return; - } - for (ItemStack itemStack : player.getInventory().getContents()) { removeAbilityBuff(itemStack); } From 4005c218101b2cb3967aac5eeb0c5910f333371b Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 28 Sep 2020 17:36:33 -0700 Subject: [PATCH 10/10] 2.1.147 --- Changelog.txt | 2 +- pom.xml | 2 +- .../com/gmail/nossr50/util/EventUtils.java | 18 ++++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 7f67c15e8..2b1ac3612 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,5 +1,5 @@ Version 2.1.147 - + Fixed a bug where players below the level threshold on a hardcore mode enabled server would gain levels on death in certain circumstances Version 2.1.146 A bug where players would disconnect from mcMMO messages has been fixed (thanks kashike / read notes) diff --git a/pom.xml b/pom.xml index a3d6c5776..b0125040b 100755 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.gmail.nossr50.mcMMO mcMMO - 2.1.147-SNAPSHOT + 2.1.147 mcMMO https://github.com/mcMMO-Dev/mcMMO diff --git a/src/main/java/com/gmail/nossr50/util/EventUtils.java b/src/main/java/com/gmail/nossr50/util/EventUtils.java index 3065bc5cb..b75dcd197 100644 --- a/src/main/java/com/gmail/nossr50/util/EventUtils.java +++ b/src/main/java/com/gmail/nossr50/util/EventUtils.java @@ -331,16 +331,18 @@ public class EventUtils { for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) { String skillName = primarySkillType.toString(); int playerSkillLevel = playerProfile.getSkillLevel(primarySkillType); + int threshold = Config.getInstance().getHardcoreDeathStatPenaltyLevelThreshold(); + if(playerSkillLevel > threshold) { + playerProfile.modifySkill(primarySkillType, Math.max(threshold, playerSkillLevel - levelChanged.get(skillName))); + playerProfile.removeXp(primarySkillType, experienceChanged.get(skillName)); - playerProfile.modifySkill(primarySkillType, Math.max(Config.getInstance().getHardcoreDeathStatPenaltyLevelThreshold(), playerSkillLevel - levelChanged.get(skillName))); - playerProfile.removeXp(primarySkillType, experienceChanged.get(skillName)); + if (playerProfile.getSkillXpLevel(primarySkillType) < 0) { + playerProfile.setSkillXpLevel(primarySkillType, 0); + } - if (playerProfile.getSkillXpLevel(primarySkillType) < 0) { - playerProfile.setSkillXpLevel(primarySkillType, 0); - } - - if (playerProfile.getSkillLevel(primarySkillType) < 0) { - playerProfile.modifySkill(primarySkillType, 0); + if (playerProfile.getSkillLevel(primarySkillType) < 0) { + playerProfile.modifySkill(primarySkillType, 0); + } } } }