Merge branch 'master' of github.com:mcMMO-Dev/mcMMO into tridentsxbows

This commit is contained in:
nossr50 2020-09-30 11:33:00 -07:00
commit 790ac99aa4
31 changed files with 458 additions and 308 deletions

View File

@ -84,10 +84,43 @@ Version 2.2.000
Parties got unnecessarily complex in my absence, I have removed many party features in order to simplify parties and bring them closer to my vision. I have also added new features which should improve parties where it matters. Parties got unnecessarily complex in my absence, I have removed many party features in order to simplify parties and bring them closer to my vision. I have also added new features which should improve parties where it matters.
About the removed party features, all the features I removed I consider poor quality features and I don't think they belong in mcMMO. Feel free to yell at me in discord if you disagree. About the removed party features, all the features I removed I consider poor quality features and I don't think they belong in mcMMO. Feel free to yell at me in discord if you disagree.
I don't know what genius decided to make parties public by default, when I found out that parties had been changed to such a system I could barely contain my disgust. Parties are back to being private, you get invited by a party leader or party officer. That is the only way to join a party. I don't know what genius decided to make parties public by default, when I found out that parties had been changed to such a system I could barely contain my disgust. Parties are back to being private, you get invited by a party leader or party officer. That is the only way to join a party.
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 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
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 Players no longer lose levels below the level threshold in hardcore mode
Hardcore now only applies penalties to levels above threshold Hardcore now only applies penalties to levels above threshold
NOTES:
Shout out to Kashike
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 Version 2.1.145
Reverted 'Changed one of the PlayerInteractEvent listeners to ignore cancelled events' from 2.1.144 Reverted 'Changed one of the PlayerInteractEvent listeners to ignore cancelled events' from 2.1.144

55
pom.xml
View File

@ -100,6 +100,16 @@
<include>org.apache.tomcat:tomcat-juli</include> <include>org.apache.tomcat:tomcat-juli</include>
<include>org.bstats:bstats-bukkit</include> <include>org.bstats:bstats-bukkit</include>
<include>net.kyori:adventure-api</include> <include>net.kyori:adventure-api</include>
<include>net.kyori:adventure-text-serializer-gson</include>
<include>net.kyori:adventure-platform-bukkit</include>
<include>net.kyori:adventure-platform-api</include>
<include>net.kyori:adventure-platform-common</include>
<include>net.kyori:adventure-platform-viaversion</include>
<include>net.kyori:adventure-nbt</include>
<include>net.kyori:examination-api</include>
<include>net.kyori:examination-string</include>
<include>net.kyori:adventure-text-serializer-legacy</include>
<include>net.kyori:adventure-text-serializer-bungeecord</include>
</includes> </includes>
</artifactSet> </artifactSet>
<relocations> <relocations>
@ -115,6 +125,10 @@
<pattern>org.apache.tomcat</pattern> <pattern>org.apache.tomcat</pattern>
<shadedPattern>com.gmail.nossr50.database.tomcat</shadedPattern> <shadedPattern>com.gmail.nossr50.database.tomcat</shadedPattern>
</relocation> </relocation>
<relocation>
<pattern>net.kyori.adventure</pattern>
<shadedPattern>com.gmail.nossr50.kyori.adventure</shadedPattern>
</relocation>
<relocation> <relocation>
<pattern>org.bstats</pattern> <pattern>org.bstats</pattern>
<shadedPattern>com.gmail.nossr50.metrics.bstat</shadedPattern> <shadedPattern>com.gmail.nossr50.metrics.bstat</shadedPattern>
@ -160,16 +174,37 @@
<!-- ... --> <!-- ... -->
</repositories> </repositories>
<dependencies> <dependencies>
<!-- <dependency>--> <!-- adventure-api, adventure-text-serializer-gson, adventure-platform-bukkit-->
<!-- <groupId>net.kyori</groupId>--> <dependency>
<!-- <artifactId>adventure-platform-bukkit</artifactId>--> <groupId>net.kyori</groupId>
<!-- <version>4.0.0-SNAPSHOT</version>--> <artifactId>adventure-text-serializer-gson</artifactId>
<!-- </dependency>--> <version>4.0.0-SNAPSHOT</version>
<!-- <dependency>--> </dependency>
<!-- <groupId>net.kyori</groupId>--> <dependency>
<!-- <artifactId>adventure-api</artifactId>--> <groupId>net.kyori</groupId>
<!-- <version>4.0.0-SNAPSHOT</version>--> <artifactId>adventure-api</artifactId>
<!-- </dependency>--> <version>4.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-nbt</artifactId>
<version>4.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-api</artifactId>
<version>4.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-common</artifactId>
<version>4.0.0-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.maven.scm</groupId> <groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-gitexe</artifactId> <artifactId>maven-scm-provider-gitexe</artifactId>

View File

@ -9,7 +9,7 @@ import com.gmail.nossr50.util.TextComponentFactory;
import com.gmail.nossr50.util.random.RandomChanceSkill; import com.gmail.nossr50.util.random.RandomChanceSkill;
import com.gmail.nossr50.util.random.RandomChanceUtil; import com.gmail.nossr50.util.random.RandomChanceUtil;
import com.gmail.nossr50.util.skills.SkillActivationType; 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 org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
@ -89,8 +89,8 @@ public class AcrobaticsCommand extends SkillCommand {
} }
@Override @Override
protected List<TextComponent> getTextComponents(Player player) { protected List<Component> getTextComponents(Player player) {
List<TextComponent> textComponents = new ArrayList<>(); List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.ACROBATICS); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.ACROBATICS);

View File

@ -7,7 +7,7 @@ import com.gmail.nossr50.skills.alchemy.AlchemyManager;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.TextComponentFactory;
import com.gmail.nossr50.util.skills.RankUtils; 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 org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
@ -92,8 +92,8 @@ public class AlchemyCommand extends SkillCommand {
} }
@Override @Override
protected List<TextComponent> getTextComponents(Player player) { protected List<Component> getTextComponents(Player player) {
List<TextComponent> textComponents = new ArrayList<>(); List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.ALCHEMY); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.ALCHEMY);

View File

@ -7,7 +7,7 @@ import com.gmail.nossr50.skills.archery.Archery;
import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.TextComponentFactory;
import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.SkillActivationType; 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 org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
@ -84,8 +84,8 @@ public class ArcheryCommand extends SkillCommand {
} }
@Override @Override
protected List<TextComponent> getTextComponents(Player player) { protected List<Component> getTextComponents(Player player) {
List<TextComponent> textComponents = new ArrayList<>(); List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.ARCHERY); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.ARCHERY);

View File

@ -9,7 +9,7 @@ import com.gmail.nossr50.util.TextComponentFactory;
import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillActivationType; 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 org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
@ -104,8 +104,8 @@ public class AxesCommand extends SkillCommand {
} }
@Override @Override
protected List<TextComponent> getTextComponents(Player player) { protected List<Component> getTextComponents(Player player) {
List<TextComponent> textComponents = new ArrayList<>(); List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.AXES); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.AXES);

View File

@ -7,7 +7,7 @@ import com.gmail.nossr50.skills.excavation.ExcavationManager;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.TextComponentFactory;
import com.gmail.nossr50.util.skills.RankUtils; 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 org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
@ -65,8 +65,8 @@ public class ExcavationCommand extends SkillCommand {
} }
@Override @Override
protected List<TextComponent> getTextComponents(Player player) { protected List<Component> getTextComponents(Player player) {
List<TextComponent> textComponents = new ArrayList<>(); List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.EXCAVATION); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.EXCAVATION);

View File

@ -12,7 +12,7 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.TextComponentFactory;
import com.gmail.nossr50.util.random.RandomChanceUtil; import com.gmail.nossr50.util.random.RandomChanceUtil;
import com.gmail.nossr50.util.skills.RankUtils; 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.Location;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -166,8 +166,8 @@ public class FishingCommand extends SkillCommand {
} }
@Override @Override
protected List<TextComponent> getTextComponents(Player player) { protected List<Component> getTextComponents(Player player) {
List<TextComponent> textComponents = new ArrayList<>(); List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.FISHING); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.FISHING);

View File

@ -7,7 +7,7 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.TextComponentFactory;
import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillActivationType; 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.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -141,8 +141,8 @@ public class HerbalismCommand extends SkillCommand {
} }
@Override @Override
protected List<TextComponent> getTextComponents(Player player) { protected List<Component> getTextComponents(Player player) {
List<TextComponent> textComponents = new ArrayList<>(); List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.HERBALISM); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.HERBALISM);

View File

@ -8,7 +8,7 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.TextComponentFactory;
import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillActivationType; 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 org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
@ -110,8 +110,8 @@ public class MiningCommand extends SkillCommand {
} }
@Override @Override
protected List<TextComponent> getTextComponents(Player player) { protected List<Component> getTextComponents(Player player) {
List<TextComponent> textComponents = new ArrayList<>(); List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.MINING); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.MINING);

View File

@ -13,7 +13,7 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.TextComponentFactory;
import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillActivationType; 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.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -120,8 +120,8 @@ public class RepairCommand extends SkillCommand {
} }
@Override @Override
protected List<TextComponent> getTextComponents(Player player) { protected List<Component> getTextComponents(Player player) {
List<TextComponent> textComponents = new ArrayList<>(); List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.REPAIR); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.REPAIR);

View File

@ -7,7 +7,7 @@ import com.gmail.nossr50.skills.salvage.Salvage;
import com.gmail.nossr50.skills.salvage.SalvageManager; import com.gmail.nossr50.skills.salvage.SalvageManager;
import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.TextComponentFactory;
import com.gmail.nossr50.util.skills.RankUtils; 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 org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
@ -63,8 +63,8 @@ public class SalvageCommand extends SkillCommand {
} }
@Override @Override
protected List<TextComponent> getTextComponents(Player player) { protected List<Component> getTextComponents(Player player) {
List<TextComponent> textComponents = new ArrayList<>(); List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.SALVAGE); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.SALVAGE);

View File

@ -18,6 +18,7 @@ import com.gmail.nossr50.util.skills.PerksUtils;
import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillActivationType; import com.gmail.nossr50.util.skills.SkillActivationType;
import com.google.common.collect.ImmutableList; 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.ChatColor;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -84,7 +85,7 @@ public abstract class SkillCommand implements TabExecutor {
sendSkillCommandHeader(player, mmoPlayer, (int) skillValue); sendSkillCommandHeader(player, mmoPlayer, (int) skillValue);
//Make JSON text components //Make JSON text components
List<TextComponent> subskillTextComponents = getTextComponents(player); List<Component> subskillTextComponents = getTextComponents(player);
//Subskills Header //Subskills Header
player.sendMessage(LocaleLoader.getString("Skills.Overhaul.Header", LocaleLoader.getString("Effects.SubSkills.Overhaul"))); player.sendMessage(LocaleLoader.getString("Skills.Overhaul.Header", LocaleLoader.getString("Effects.SubSkills.Overhaul")));
@ -282,7 +283,7 @@ public abstract class SkillCommand implements TabExecutor {
protected abstract List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky); protected abstract List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky);
protected abstract List<TextComponent> getTextComponents(Player player); protected abstract List<Component> getTextComponents(Player player);
/** /**
* Checks if a player can use a skill * Checks if a player can use a skill

View File

@ -7,7 +7,7 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.TextComponentFactory;
import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillActivationType; 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 org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
@ -87,8 +87,8 @@ public class SmeltingCommand extends SkillCommand {
} }
@Override @Override
protected List<TextComponent> getTextComponents(Player player) { protected List<Component> getTextComponents(Player player) {
List<TextComponent> textComponents = new ArrayList<>(); List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.SMELTING); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.SMELTING);

View File

@ -9,7 +9,7 @@ import com.gmail.nossr50.util.TextComponentFactory;
import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillActivationType; 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 org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
@ -109,8 +109,8 @@ public class SwordsCommand extends SkillCommand {
} }
@Override @Override
protected List<TextComponent> getTextComponents(Player player) { protected List<Component> getTextComponents(Player player) {
List<TextComponent> textComponents = new ArrayList<>(); List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.SWORDS); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.SWORDS);

View File

@ -7,7 +7,7 @@ import com.gmail.nossr50.skills.taming.Taming;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.TextComponentFactory;
import com.gmail.nossr50.util.skills.SkillActivationType; 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.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -92,8 +92,8 @@ public class TamingCommand extends SkillCommand {
} }
@Override @Override
protected List<TextComponent> getTextComponents(Player player) { protected List<Component> getTextComponents(Player player) {
List<TextComponent> textComponents = new ArrayList<>(); List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, this.skill); TextComponentFactory.getSubSkillTextComponents(player, textComponents, this.skill);

View File

@ -9,7 +9,7 @@ import com.gmail.nossr50.util.TextComponentFactory;
import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillActivationType; 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 org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
@ -123,8 +123,8 @@ public class UnarmedCommand extends SkillCommand {
} }
@Override @Override
protected List<TextComponent> getTextComponents(Player player) { protected List<Component> getTextComponents(Player player) {
List<TextComponent> textComponents = new ArrayList<>(); List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.UNARMED); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.UNARMED);

View File

@ -7,7 +7,7 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.TextComponentFactory;
import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillActivationType; 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 org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
@ -83,8 +83,8 @@ public class WoodcuttingCommand extends SkillCommand {
} }
@Override @Override
protected List<TextComponent> getTextComponents(Player player) { protected List<Component> getTextComponents(Player player) {
List<TextComponent> textComponents = new ArrayList<>(); List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.WOODCUTTING); TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.WOODCUTTING);

View File

@ -20,6 +20,7 @@ import com.gmail.nossr50.util.skills.SkillActivationType;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
import com.gmail.nossr50.util.sounds.SoundManager; import com.gmail.nossr50.util.sounds.SoundManager;
import com.gmail.nossr50.util.sounds.SoundType; import com.gmail.nossr50.util.sounds.SoundType;
import net.kyori.adventure.text.TextComponent;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -114,7 +115,7 @@ public class Roll extends AcrobaticsSubSkill {
* @param player target player * @param player target player
*/ */
@Override @Override
public void addStats(ComponentBuilder componentBuilder, Player player) { public void addStats(TextComponent.Builder componentBuilder, Player player) {
String rollChance, rollChanceLucky, gracefulRollChance, gracefulRollChanceLucky; String rollChance, rollChanceLucky, gracefulRollChance, gracefulRollChanceLucky;
/* Values related to the player */ /* Values related to the player */

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.datatypes.skills.subskills.interfaces; package com.gmail.nossr50.datatypes.skills.subskills.interfaces;
import com.gmail.nossr50.datatypes.skills.interfaces.Skill; import com.gmail.nossr50.datatypes.skills.interfaces.Skill;
import net.kyori.adventure.text.TextComponent;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -61,7 +62,7 @@ public interface SubSkill extends Skill {
* @param componentBuilder target component builder * @param componentBuilder target component builder
* @param player owner of this skill * @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 * Whether or not this subskill is enabled

View File

@ -1,8 +1,8 @@
package com.gmail.nossr50.events.skills; package com.gmail.nossr50.events.skills;
import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.interactions.NotificationType;
import net.md_5.bungee.api.ChatMessageType; import com.gmail.nossr50.util.McMMOMessageType;
import net.md_5.bungee.api.chat.TextComponent; import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
@ -22,12 +22,12 @@ public class McMMOPlayerNotificationEvent extends Event implements Cancellable {
private boolean isMessageAlsoBeingSentToChat; private boolean isMessageAlsoBeingSentToChat;
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
protected ChatMessageType chatMessageType; protected McMMOMessageType chatMessageType;
protected TextComponent notificationTextComponent; protected Component notificationTextComponent;
protected final NotificationType notificationType; 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); super(false);
this.notificationType = notificationType; this.notificationType = notificationType;
this.notificationTextComponent = notificationTextComponent; this.notificationTextComponent = notificationTextComponent;
@ -48,19 +48,19 @@ public class McMMOPlayerNotificationEvent extends Event implements Cancellable {
isMessageAlsoBeingSentToChat = messageAlsoBeingSentToChat; isMessageAlsoBeingSentToChat = messageAlsoBeingSentToChat;
} }
public TextComponent getNotificationTextComponent() { public Component getNotificationTextComponent() {
return notificationTextComponent; return notificationTextComponent;
} }
public void setNotificationTextComponent(TextComponent notificationTextComponent) { public void setNotificationTextComponent(Component notificationTextComponent) {
this.notificationTextComponent = notificationTextComponent; this.notificationTextComponent = notificationTextComponent;
} }
public ChatMessageType getChatMessageType() { public McMMOMessageType getChatMessageType() {
return chatMessageType; return chatMessageType;
} }
public void setChatMessageType(ChatMessageType chatMessageType) { public void setChatMessageType(McMMOMessageType chatMessageType) {
this.chatMessageType = chatMessageType; this.chatMessageType = chatMessageType;
} }

View File

@ -126,12 +126,10 @@ public class BlockListener implements Listener {
Block movedBlock; Block movedBlock;
for (Block b : event.getBlocks()) { for (Block b : event.getBlocks()) {
if (BlockUtils.shouldBeWatched(b.getState())) {
movedBlock = b.getRelative(direction); movedBlock = b.getRelative(direction);
mcMMO.getPlaceStore().setTrue(movedBlock); mcMMO.getPlaceStore().setTrue(movedBlock);
} }
} }
}
/** /**
* Monitor BlockPistonRetract events. * Monitor BlockPistonRetract events.
@ -189,7 +187,6 @@ public class BlockListener implements Listener {
if(ExperienceConfig.getInstance().preventStoneLavaFarming()) if(ExperienceConfig.getInstance().preventStoneLavaFarming())
{ {
if(event.getNewState().getType() != Material.OBSIDIAN if(event.getNewState().getType() != Material.OBSIDIAN
&& BlockUtils.shouldBeWatched(event.getNewState())
&& ExperienceConfig.getInstance().doesBlockGiveSkillXP(PrimarySkillType.MINING, event.getNewState().getBlockData())) && ExperienceConfig.getInstance().doesBlockGiveSkillXP(PrimarySkillType.MINING, event.getNewState().getBlockData()))
{ {
mcMMO.getPlaceStore().setTrue(event.getNewState()); mcMMO.getPlaceStore().setTrue(event.getNewState());
@ -204,9 +201,16 @@ public class BlockListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
BlockState blockState = event.getBlock().getState();
/* Check if the blocks placed should be monitored so they do not give out XP in the future */
// if (!Tag.LOGS.isTagged(event.getBlockReplacedState().getType()) || !Tag.LOGS.isTagged(event.getBlockPlaced().getType()))
mcMMO.getPlaceStore().setTrue(blockState);
/* WORLD BLACKLIST CHECK */ /* WORLD BLACKLIST CHECK */
if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) {
return; return;
}
Player player = event.getPlayer(); Player player = event.getPlayer();
@ -214,15 +218,6 @@ public class BlockListener implements Listener {
return; return;
} }
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);
}
McMMOPlayer mmoPlayer = mcMMO.getUserManager().getPlayer(player); McMMOPlayer mmoPlayer = mcMMO.getUserManager().getPlayer(player);
if(mmoPlayer == null) if(mmoPlayer == null)
@ -243,24 +238,23 @@ public class BlockListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockMultiPlace(BlockMultiPlaceEvent event) { public void onBlockMultiPlace(BlockMultiPlaceEvent event) {
/* WORLD BLACKLIST CHECK */
if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld()))
return;
Player player = event.getPlayer();
if (!mcMMO.getUserManager().hasPlayerDataKey(player)) {
return;
}
for (BlockState replacedBlockState : event.getReplacedBlockStates()) for (BlockState replacedBlockState : event.getReplacedBlockStates())
{ {
BlockState blockState = replacedBlockState.getBlock().getState(); BlockState blockState = replacedBlockState.getBlock().getState();
/* Check if the blocks placed should be monitored so they do not give out XP in the future */ /* 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 */
if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) {
return;
}
Player player = event.getPlayer();
if (!mcMMO.getUserManager().hasPlayerDataKey(player)) {
return;
} }
} }
@ -273,9 +267,9 @@ public class BlockListener implements Listener {
BlockState blockState = event.getBlock().getState(); BlockState blockState = event.getBlock().getState();
if (!BlockUtils.shouldBeWatched(blockState)) { // if (!BlockUtils.shouldBeWatched(blockState)) {
return; // return;
} // }
mcMMO.getPlaceStore().setFalse(blockState); mcMMO.getPlaceStore().setFalse(blockState);
} }
@ -305,9 +299,9 @@ public class BlockListener implements Listener {
BlockState blockState = event.getBlock().getState(); BlockState blockState = event.getBlock().getState();
Location location = blockState.getLocation(); Location location = blockState.getLocation();
if (!BlockUtils.shouldBeWatched(blockState)) { // if (!BlockUtils.shouldBeWatched(blockState)) {
return; // return;
} // }
/* ALCHEMY - Cancel any brew in progress for that BrewingStand */ /* ALCHEMY - Cancel any brew in progress for that BrewingStand */
if (blockState instanceof BrewingStand && Alchemy.brewingStandMap.containsKey(location)) { if (blockState instanceof BrewingStand && Alchemy.brewingStandMap.containsKey(location)) {
@ -323,8 +317,11 @@ public class BlockListener implements Listener {
McMMOPlayer mmoPlayer = mcMMO.getUserManager().getPlayer(player); McMMOPlayer mmoPlayer = mcMMO.getUserManager().getPlayer(player);
//Check if profile is loaded //Check if profile is loaded
if(mmoPlayer == null) if(mmoPlayer == null) {
/* Remove metadata from placed watched blocks */
mcMMO.getPlaceStore().setFalse(blockState);
return; return;
}
ItemStack heldItem = player.getInventory().getItemInMainHand(); ItemStack heldItem = player.getInventory().getItemInMainHand();

View File

@ -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);
// }
//}

View File

@ -46,6 +46,7 @@ import com.gmail.nossr50.util.skills.SmeltingTracker;
import com.gmail.nossr50.util.upgrade.UpgradeManager; import com.gmail.nossr50.util.upgrade.UpgradeManager;
import com.gmail.nossr50.worldguard.WorldGuardManager; import com.gmail.nossr50.worldguard.WorldGuardManager;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.shatteredlands.shatt.backup.ZipLibrary; import net.shatteredlands.shatt.backup.ZipLibrary;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -80,6 +81,9 @@ public class mcMMO extends JavaPlugin {
private static UserManager userManager; private static UserManager userManager;
private static PartyManager partyManager; private static PartyManager partyManager;
/* Adventure */
private static BukkitAudiences audiences;
/* Blacklist */ /* Blacklist */
private static WorldBlacklist worldBlacklist; private static WorldBlacklist worldBlacklist;
@ -272,6 +276,7 @@ public class mcMMO extends JavaPlugin {
//Init Player Data Manager //Init Player Data Manager
userManager = new UserManager(); userManager = new UserManager();
audiences = BukkitAudiences.create(this);
} }
public static PlayerLevelUtils getPlayerLevelUtils() { public static PlayerLevelUtils getPlayerLevelUtils() {
@ -534,6 +539,7 @@ public class mcMMO extends JavaPlugin {
pluginManager.registerEvents(new InventoryListener(this), this); pluginManager.registerEvents(new InventoryListener(this), this);
pluginManager.registerEvents(new SelfListener(this), this); pluginManager.registerEvents(new SelfListener(this), this);
pluginManager.registerEvents(new WorldListener(this), this); pluginManager.registerEvents(new WorldListener(this), this);
// pluginManager.registerEvents(new CommandListener(this), this);
} }
/** /**
@ -653,4 +659,8 @@ public class mcMMO extends JavaPlugin {
public static PartyManager getPartyManager() { public static PartyManager getPartyManager() {
return partyManager; return partyManager;
} }
public static BukkitAudiences getAudiences() {
return audiences;
}
} }

View File

@ -67,7 +67,11 @@ public final class BlockUtils {
* @return true if the block awards XP, false otherwise * @return true if the block awards XP, false otherwise
*/ */
public static boolean shouldBeWatched(BlockState blockState) { 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());
} }
/** /**

View File

@ -330,8 +330,9 @@ public class EventUtils {
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) { for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
String skillName = primarySkillType.toString(); String skillName = primarySkillType.toString();
int playerSkillLevel = playerProfile.getSkillLevel(primarySkillType); int playerSkillLevel = playerProfile.getSkillLevel(primarySkillType);
int threshold = Config.getInstance().getHardcoreDeathStatPenaltyLevelThreshold();
playerProfile.modifySkill(primarySkillType, Math.max(Config.getInstance().getHardcoreDeathStatPenaltyLevelThreshold(), playerSkillLevel - levelChanged.get(skillName))); if(playerSkillLevel > threshold) {
playerProfile.modifySkill(primarySkillType, Math.max(threshold, playerSkillLevel - levelChanged.get(skillName)));
playerProfile.removeXp(primarySkillType, experienceChanged.get(skillName)); playerProfile.removeXp(primarySkillType, experienceChanged.get(skillName));
if (playerProfile.getSkillXpLevel(primarySkillType) < 0) { if (playerProfile.getSkillXpLevel(primarySkillType) < 0) {
@ -343,6 +344,7 @@ public class EventUtils {
} }
} }
} }
}
return !isCancelled; return !isCancelled;
} }

View File

@ -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<Audience, Component> sender;
McMMOMessageType(final BiConsumer<Audience, Component> sender) {
this.sender = sender;
}
public void send(final Audience audience, final Component message) {
this.sender.accept(audience, message);
}
}

View File

@ -9,10 +9,20 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill; import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
import com.gmail.nossr50.listeners.InteractionManager; import com.gmail.nossr50.listeners.InteractionManager;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.skills.RankUtils; 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.ChatMessageType;
import net.md_5.bungee.api.chat.*;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
@ -33,24 +43,23 @@ public class TextComponentFactory {
public static TextComponent getNotificationMultipleValues(String localeKey, String... values) public static TextComponent getNotificationMultipleValues(String localeKey, String... values)
{ {
String preColoredString = LocaleLoader.getString(localeKey, (Object[]) values); String preColoredString = LocaleLoader.getString(localeKey, (Object[]) values);
TextComponent msg = new TextComponent(preColoredString); return TextComponent.of(preColoredString);
return new TextComponent(msg);
} }
public static TextComponent getNotificationTextComponentFromLocale(String localeKey) public static Component getNotificationTextComponentFromLocale(String localeKey)
{ {
return getNotificationTextComponent(LocaleLoader.getString(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) private static TextComponent getNotificationTextComponent(String text)
{ {
//textComponent.setColor(getNotificationColor(notificationType)); //textComponent.setColor(getNotificationColor(notificationType));
return new TextComponent(text); return TextComponent.of(text);
} }
public static void sendPlayerSubSkillWikiLink(Player player, String subskillformatted) public static void sendPlayerSubSkillWikiLink(Player player, String subskillformatted)
@ -58,33 +67,30 @@ public class TextComponentFactory {
if(!Config.getInstance().getUrlLinksEnabled()) if(!Config.getInstance().getUrlLinksEnabled())
return; return;
Player.Spigot spigotPlayer = player.spigot(); TextComponent.Builder wikiLinkComponent = TextComponent.builder(LocaleLoader.getString("Overhaul.mcMMO.MmoInfo.Wiki"));
wikiLinkComponent.decoration(TextDecoration.UNDERLINED, true);
TextComponent wikiLinkComponent = new TextComponent(LocaleLoader.getString("Overhaul.mcMMO.MmoInfo.Wiki"));
wikiLinkComponent.setUnderlined(true);
String wikiUrl = "https://mcmmo.org/wiki/"+subskillformatted; 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) { public static void sendPlayerUrlHeader(Player player) {
Player.Spigot spigotPlayer = player.spigot(); TextComponent prefix = TextComponent.of(LocaleLoader.getString("Overhaul.mcMMO.Url.Wrap.Prefix") + " ");
TextComponent prefix = new TextComponent(LocaleLoader.getString("Overhaul.mcMMO.Url.Wrap.Prefix") + " ");
/*prefix.setColor(ChatColor.DARK_AQUA);*/ /*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);*/ /*suffix.setColor(ChatColor.DARK_AQUA);*/
TextComponent emptySpace = new TextComponent(" "); TextComponent emptySpace = TextComponent.space();
BaseComponent[] baseComponents = {new TextComponent(prefix), mcMMO.getAudiences().audience(player).sendMessage(TextComponent.ofChildren(
prefix,
getWebLinkTextComponent(McMMOWebLinks.WEBSITE), getWebLinkTextComponent(McMMOWebLinks.WEBSITE),
emptySpace, emptySpace,
getWebLinkTextComponent(McMMOWebLinks.DISCORD), getWebLinkTextComponent(McMMOWebLinks.DISCORD),
@ -96,187 +102,190 @@ public class TextComponentFactory {
getWebLinkTextComponent(McMMOWebLinks.SPIGOT), getWebLinkTextComponent(McMMOWebLinks.SPIGOT),
emptySpace, emptySpace,
getWebLinkTextComponent(McMMOWebLinks.HELP_TRANSLATE), getWebLinkTextComponent(McMMOWebLinks.HELP_TRANSLATE),
new TextComponent(suffix)}; suffix
), MessageType.SYSTEM);
spigotPlayer.sendMessage(baseComponents);
} }
public static void sendPlayerSubSkillList(Player player, List<TextComponent> textComponents) public static void sendPlayerSubSkillList(Player player, List<Component> textComponents)
{ {
TextComponent emptySpace = new TextComponent(" "); TextComponent emptySpace = TextComponent.space();
ArrayList<BaseComponent> bulkMessage = new ArrayList<>(); AtomicReference<Component> messageToSend = new AtomicReference<>();
int newLineCount = 0; //Hacky solution to wordwrap problems 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 //Don't send more than 3 subskills per line to avoid MOST wordwrap problems
if(newLineCount > 2) if(newLineCount > 2)
{ {
TextComponent[] bulkArray = new TextComponent[bulkMessage.size()]; Component toSend = messageToSend.get();
bulkArray = bulkMessage.toArray(bulkArray); if (toSend != null) {
audience.sendMessage(toSend.append(emptySpace));
}
player.spigot().sendMessage(bulkArray); messageToSend.set(null);
bulkMessage = new ArrayList<>();
newLineCount = 0; newLineCount = 0;
} }
//Style the skills into @links //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); addChild(stylizedText, originalTxt);
if(textComponent.getHoverEvent() != null) if(textComponent.hoverEvent() != null)
stylizedText.setHoverEvent(textComponent.getHoverEvent()); stylizedText.hoverEvent(textComponent.hoverEvent());
if(textComponent.getClickEvent() != null) if(textComponent.clickEvent() != null)
stylizedText.setClickEvent(textComponent.getClickEvent()); stylizedText.clickEvent(textComponent.clickEvent());
bulkMessage.add(stylizedText); messageToSend.set(stylizedText.build().append(emptySpace));
bulkMessage.add(emptySpace);
newLineCount++; newLineCount++;
} }
/* Component toSend = messageToSend.get();
* Convert our list into an array if (toSend != null) {
*/ audience.sendMessage(toSend.append(emptySpace));
TextComponent[] bulkArray = new TextComponent[bulkMessage.size()]; }
bulkArray = bulkMessage.toArray(bulkArray);
player.spigot().sendMessage(bulkArray);
} }
private static TextComponent getWebLinkTextComponent(McMMOWebLinks webLinks) private static Component getWebLinkTextComponent(McMMOWebLinks webLinks)
{ {
TextComponent webTextComponent; TextComponent.Builder webTextComponent;
switch(webLinks) switch(webLinks)
{ {
case WEBSITE: case WEBSITE:
webTextComponent = new TextComponent(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); webTextComponent = TextComponent.builder(LocaleLoader.getString("JSON.Hover.AtSymbolURL"));
addChild(webTextComponent, "Web"); addChild(webTextComponent, "Web");
webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlWebsite)); webTextComponent.clickEvent(getUrlClickEvent(McMMOUrl.urlWebsite));
break; break;
case SPIGOT: case SPIGOT:
webTextComponent = new TextComponent(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); webTextComponent = TextComponent.builder(LocaleLoader.getString("JSON.Hover.AtSymbolURL"));
addChild(webTextComponent, "Spigot"); addChild(webTextComponent, "Spigot");
webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlSpigot)); webTextComponent.clickEvent(getUrlClickEvent(McMMOUrl.urlSpigot));
break; break;
case DISCORD: case DISCORD:
webTextComponent = new TextComponent(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); webTextComponent = TextComponent.builder(LocaleLoader.getString("JSON.Hover.AtSymbolURL"));
addChild(webTextComponent, "Discord"); addChild(webTextComponent, "Discord");
webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlDiscord)); webTextComponent.clickEvent(getUrlClickEvent(McMMOUrl.urlDiscord));
break; break;
case PATREON: case PATREON:
webTextComponent = new TextComponent(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); webTextComponent = TextComponent.builder(LocaleLoader.getString("JSON.Hover.AtSymbolURL"));
addChild(webTextComponent, "Patreon"); addChild(webTextComponent, "Patreon");
webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlPatreon)); webTextComponent.clickEvent(getUrlClickEvent(McMMOUrl.urlPatreon));
break; break;
case WIKI: case WIKI:
webTextComponent = new TextComponent(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); webTextComponent = TextComponent.builder(LocaleLoader.getString("JSON.Hover.AtSymbolURL"));
addChild(webTextComponent, "Wiki"); addChild(webTextComponent, "Wiki");
webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlWiki)); webTextComponent.clickEvent(getUrlClickEvent(McMMOUrl.urlWiki));
break; break;
case HELP_TRANSLATE: case HELP_TRANSLATE:
webTextComponent = new TextComponent(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); webTextComponent = TextComponent.builder(LocaleLoader.getString("JSON.Hover.AtSymbolURL"));
addChild(webTextComponent, "Lang"); addChild(webTextComponent, "Lang");
webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlTranslate)); webTextComponent.clickEvent(getUrlClickEvent(McMMOUrl.urlTranslate));
break; break;
default: default:
webTextComponent = new TextComponent("NOT DEFINED"); webTextComponent = TextComponent.builder("NOT DEFINED");
} }
addNewHoverComponentToTextComponent(webTextComponent, getUrlHoverEvent(webLinks)); 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) { private static void addChild(Component webTextComponent, String childName) {
TextComponent childComponent = new TextComponent(childName); TextComponent childComponent = TextComponent.of(childName);
childComponent.setColor(ChatColor.BLUE); childComponent.color(NamedTextColor.BLUE);
webTextComponent.addExtra(childComponent); 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) switch(webLinks)
{ {
case WEBSITE: case WEBSITE:
addUrlHeaderHover(webLinks, componentBuilder); addUrlHeaderHover(webLinks, componentBuilder);
componentBuilder.append("\n\n").italic(false); componentBuilder.append("\n\n");
componentBuilder.append(webLinks.getLocaleDescription()).color(ChatColor.GREEN); componentBuilder.append(TextComponent.of(webLinks.getLocaleDescription(), NamedTextColor.GREEN));
componentBuilder.append("\nDev Blogs, and information related to mcMMO can be found here").color(ChatColor.GRAY); componentBuilder.append(TextComponent.of("\nDev Blogs, and information related to mcMMO can be found here", NamedTextColor.GRAY));
break; break;
case SPIGOT: case SPIGOT:
addUrlHeaderHover(webLinks, componentBuilder); addUrlHeaderHover(webLinks, componentBuilder);
componentBuilder.append("\n\n").italic(false); componentBuilder.append("\n\n");
componentBuilder.append(webLinks.getLocaleDescription()).color(ChatColor.GREEN); componentBuilder.append(TextComponent.of(webLinks.getLocaleDescription(), NamedTextColor.GREEN));
componentBuilder.append("\nI post regularly in the discussion thread here!").color(ChatColor.GRAY); componentBuilder.append(TextComponent.of("\nI post regularly in the discussion thread here!", NamedTextColor.GRAY));
break; break;
case PATREON: case PATREON:
addUrlHeaderHover(webLinks, componentBuilder); addUrlHeaderHover(webLinks, componentBuilder);
componentBuilder.append("\n\n").italic(false); componentBuilder.append("\n\n");
componentBuilder.append(webLinks.getLocaleDescription()).color(ChatColor.GREEN); componentBuilder.append(TextComponent.of(webLinks.getLocaleDescription(), NamedTextColor.GREEN));
componentBuilder.append("\n"); 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; break;
case WIKI: case WIKI:
addUrlHeaderHover(webLinks, componentBuilder); addUrlHeaderHover(webLinks, componentBuilder);
componentBuilder.append("\n\n").italic(false); componentBuilder.append("\n\n");
componentBuilder.append(webLinks.getLocaleDescription()).color(ChatColor.GREEN); componentBuilder.append(TextComponent.of(webLinks.getLocaleDescription(), NamedTextColor.GREEN));
componentBuilder.append("\n"); 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; break;
case DISCORD: case DISCORD:
addUrlHeaderHover(webLinks, componentBuilder); addUrlHeaderHover(webLinks, componentBuilder);
componentBuilder.append("\n\n").italic(false); componentBuilder.append("\n\n");
componentBuilder.append(webLinks.getLocaleDescription()).color(ChatColor.GREEN); componentBuilder.append(TextComponent.of(webLinks.getLocaleDescription(), NamedTextColor.GREEN));
break; break;
case HELP_TRANSLATE: case HELP_TRANSLATE:
addUrlHeaderHover(webLinks, componentBuilder); addUrlHeaderHover(webLinks, componentBuilder);
componentBuilder.append("\n\n").italic(false); componentBuilder.append("\n\n");
componentBuilder.append(webLinks.getLocaleDescription()).color(ChatColor.GREEN); componentBuilder.append(TextComponent.of(webLinks.getLocaleDescription(), NamedTextColor.GREEN));
componentBuilder.append("\n"); componentBuilder.append("\n");
componentBuilder.append("You can use this website to help translate mcMMO into your language!" + 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.").italic(false).color(ChatColor.DARK_GRAY); "\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("\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) 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 //Get skill name
String skillName = subSkillType.getLocaleName(); String skillName = subSkillType.getLocaleName();
boolean skillUnlocked = RankUtils.hasUnlockedSubskill(player, subSkillType); boolean skillUnlocked = RankUtils.hasUnlockedSubskill(player, subSkillType);
TextComponent textComponent = initNewSkillTextComponent(player, skillName, subSkillType, skillUnlocked); TextComponent.Builder textComponent = initNewSkillTextComponent(player, skillName, subSkillType, skillUnlocked);
//Hover Event //Hover Event
addNewHoverComponentToTextComponent(textComponent, getSubSkillHoverComponent(player, subSkillType)); addNewHoverComponentToTextComponent(textComponent, getSubSkillHoverComponent(player, subSkillType));
//Insertion //Insertion
textComponent.setInsertion(skillName); textComponent.insertion(skillName);
return textComponent; return textComponent.build();
} }
private static void addNewHoverComponentToTextComponent(TextComponent textComponent, BaseComponent[] baseComponent) { private static void addNewHoverComponentToTextComponent(TextComponent.Builder textComponent, Component baseComponent) {
textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, baseComponent)); textComponent.hoverEvent(HoverEvent.showText(baseComponent));
} }
private static TextComponent getSubSkillTextComponent(Player player, AbstractSubSkill abstractSubSkill) private static TextComponent getSubSkillTextComponent(Player player, AbstractSubSkill abstractSubSkill)
@ -289,42 +298,42 @@ public class TextComponentFactory {
boolean skillUnlocked = RankUtils.hasUnlockedSubskill(player, subSkillType); boolean skillUnlocked = RankUtils.hasUnlockedSubskill(player, subSkillType);
TextComponent textComponent = initNewSkillTextComponent(player, skillName, subSkillType, skillUnlocked); TextComponent.Builder textComponent = initNewSkillTextComponent(player, skillName, subSkillType, skillUnlocked);
//Hover Event //Hover Event
addNewHoverComponentToTextComponent(textComponent, getSubSkillHoverComponent(player, abstractSubSkill)); addNewHoverComponentToTextComponent(textComponent, getSubSkillHoverComponent(player, abstractSubSkill));
//Insertion //Insertion
textComponent.setInsertion(skillName); textComponent.insertion(skillName);
return textComponent; return textComponent.build();
} }
private static TextComponent initNewSkillTextComponent(Player player, String skillName, SubSkillType subSkillType, boolean skillUnlocked) { private static TextComponent.Builder initNewSkillTextComponent(Player player, String skillName, SubSkillType subSkillType, boolean skillUnlocked) {
TextComponent textComponent; TextComponent.Builder textComponent;
if (skillUnlocked) { if (skillUnlocked) {
if (RankUtils.getHighestRank(subSkillType) == RankUtils.getRank(player, subSkillType) && subSkillType.getNumRanks() > 1) 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 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 { } else {
textComponent = new TextComponent(LocaleLoader.getString("JSON.Hover.Mystery", textComponent = TextComponent.builder(LocaleLoader.getString("JSON.Hover.Mystery",
String.valueOf(RankUtils.getUnlockLevel(subSkillType)))); String.valueOf(RankUtils.getUnlockLevel(subSkillType))));
textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/mmoinfo ???")); textComponent.clickEvent(ClickEvent.runCommand("/mmoinfo ???"));
} }
return textComponent; return textComponent;
} }
private static BaseComponent[] getSubSkillHoverComponent(Player player, AbstractSubSkill abstractSubSkill) private static Component getSubSkillHoverComponent(Player player, AbstractSubSkill abstractSubSkill)
{ {
return getSubSkillHoverEventJSON(abstractSubSkill, player); return getSubSkillHoverEventJSON(abstractSubSkill, player);
} }
private static BaseComponent[] getSubSkillHoverComponent(Player player, SubSkillType subSkillType) private static Component getSubSkillHoverComponent(Player player, SubSkillType subSkillType)
{ {
return getSubSkillHoverEventJSON(subSkillType, player); return getSubSkillHoverEventJSON(subSkillType, player);
} }
@ -335,27 +344,27 @@ public class TextComponentFactory {
* @param player the player who owns this subskill * @param player the player who owns this subskill
* @return the hover basecomponent object for 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(); String skillName = abstractSubSkill.getNiceName();
/* /*
* Hover Event BaseComponent color table * Hover Event BaseComponent color table
*/ */
ChatColor ccSubSkillHeader = ChatColor.GOLD; TextColor ccSubSkillHeader = NamedTextColor.GOLD;
ChatColor ccRank = ChatColor.BLUE; TextColor ccRank = NamedTextColor.BLUE;
ChatColor ccCurRank = ChatColor.GREEN; TextColor ccCurRank = NamedTextColor.GREEN;
ChatColor ccPossessive = ChatColor.WHITE; TextColor ccPossessive = NamedTextColor.WHITE;
//ChatColor ccDescriptionHeader = ChatColor.DARK_PURPLE; //ChatColor ccDescriptionHeader = ChatColor.DARK_PURPLE;
//ChatColor ccDescription = ChatColor.WHITE; //ChatColor ccDescription = ChatColor.WHITE;
ChatColor ccLocked = ChatColor.DARK_GRAY; TextColor ccLocked = NamedTextColor.DARK_GRAY;
ChatColor ccLevelRequirement = ChatColor.BLUE; TextColor ccLevelRequirement = NamedTextColor.BLUE;
ChatColor ccLevelRequired = ChatColor.RED; TextColor ccLevelRequired = NamedTextColor.RED;
SubSkillType subSkillType = abstractSubSkill.getSubSkillType(); SubSkillType subSkillType = abstractSubSkill.getSubSkillType();
//SubSkillType Name //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)) if(!RankUtils.hasUnlockedSubskill(player, abstractSubSkill))
{ {
@ -379,18 +388,18 @@ public class TextComponentFactory {
componentBuilder.append("\n").append(abstractSubSkill.getDescription()).append("\n"); componentBuilder.append("\n").append(abstractSubSkill.getDescription()).append("\n");
//Empty line //Empty line
componentBuilder.append("\n").bold(false); componentBuilder.append("\n").decoration(TextDecoration.BOLD, false);
componentBuilder.append("\n"); componentBuilder.append("\n");
//Finally, add details to the tooltip //Finally, add details to the tooltip
abstractSubSkill.addStats(componentBuilder, player); abstractSubSkill.addStats(componentBuilder, player);
} }
return componentBuilder.create(); return componentBuilder.build();
} }
private static ComponentBuilder setupSkillComponentNameStyle(Player player, String skillName, SubSkillType subSkillType, boolean skillUnlocked) { private static TextComponent.Builder setupSkillComponentNameStyle(Player player, String skillName, SubSkillType subSkillType, boolean skillUnlocked) {
ComponentBuilder componentBuilder; TextComponent.Builder componentBuilder;
if (skillUnlocked) { if (skillUnlocked) {
if (RankUtils.getHighestRank(subSkillType) == RankUtils.getRank(player, subSkillType) && subSkillType.getNumRanks() > 1) if (RankUtils.getHighestRank(subSkillType) == RankUtils.getRank(player, subSkillType) && subSkillType.getNumRanks() > 1)
componentBuilder = getNewComponentBuilder(LocaleLoader.getString("JSON.Hover.MaxRankSkillName", skillName)); componentBuilder = getNewComponentBuilder(LocaleLoader.getString("JSON.Hover.MaxRankSkillName", skillName));
@ -402,66 +411,64 @@ public class TextComponentFactory {
return componentBuilder; return componentBuilder;
} }
private static ComponentBuilder getNewComponentBuilder(String skillName) { private static TextComponent.Builder getNewComponentBuilder(String skillName) {
ComponentBuilder componentBuilder = new ComponentBuilder(skillName); TextComponent.Builder componentBuilder = TextComponent.builder(skillName);
componentBuilder.append("\n"); componentBuilder.append("\n");
return componentBuilder; 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) { if (numRanks > 0) {
//Rank: x //Rank: x
componentBuilder.append(LocaleLoader.getString("JSON.Hover.Rank", String.valueOf(rank))).append("\n") componentBuilder.append(LocaleLoader.getString("JSON.Hover.Rank", String.valueOf(rank))).append("\n");
.bold(false).italic(false).strikethrough(false).underlined(false);
//Next Rank: x //Next Rank: x
if(nextRank > rank) if(nextRank > rank)
componentBuilder.append(LocaleLoader.getString("JSON.Hover.NextRank", String.valueOf(nextRank))).append("\n") 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.RankPossesive") + " ").color(ccPossessive); /*componentBuilder.append(" " + LocaleLoader.getString("JSON.RankPossesive") + " ").color(ccPossessive);
componentBuilder.append(String.valueOf(numRanks)).color(ccNumRanks);*/ 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); 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"); //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); 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"); //componentBuilder.append("\n");
} }
private static void addLocked(ChatColor ccLocked, ChatColor ccLevelRequirement, ComponentBuilder componentBuilder) { private static void addLocked(TextColor ccLocked, TextColor ccLevelRequirement, TextComponent.Builder componentBuilder) {
componentBuilder.append(LocaleLoader.getString("JSON.Locked")).color(ccLocked).bold(true); componentBuilder.append(TextComponent.of(LocaleLoader.getString("JSON.Locked"), ccLocked, TextDecoration.BOLD));
componentBuilder.append("\n").append("\n").bold(false); componentBuilder.append("\n").append("\n");
componentBuilder.append(LocaleLoader.getString("JSON.LevelRequirement") + ": ").color(ccLevelRequirement); componentBuilder.append(TextComponent.of(LocaleLoader.getString("JSON.LevelRequirement") + ": ", ccLevelRequirement));
} }
@Deprecated @Deprecated
private static BaseComponent[] getSubSkillHoverEventJSON(SubSkillType subSkillType, Player player) private static Component getSubSkillHoverEventJSON(SubSkillType subSkillType, Player player)
{ {
String skillName = subSkillType.getLocaleName(); String skillName = subSkillType.getLocaleName();
/* /*
* Hover Event BaseComponent color table * Hover Event BaseComponent color table
*/ */
ChatColor ccSubSkillHeader = ChatColor.GOLD; TextColor ccSubSkillHeader = NamedTextColor.GOLD;
ChatColor ccRank = ChatColor.BLUE; TextColor ccRank = NamedTextColor.BLUE;
ChatColor ccCurRank = ChatColor.GREEN; TextColor ccCurRank = NamedTextColor.GREEN;
ChatColor ccPossessive = ChatColor.WHITE; TextColor ccPossessive = NamedTextColor.WHITE;
ChatColor ccDescriptionHeader = ChatColor.DARK_PURPLE; TextColor ccDescriptionHeader = NamedTextColor.DARK_PURPLE;
ChatColor ccDescription = ChatColor.DARK_GRAY; TextColor ccDescription = NamedTextColor.DARK_GRAY;
ChatColor ccLocked = ChatColor.DARK_GRAY; TextColor ccLocked = NamedTextColor.DARK_GRAY;
ChatColor ccLevelRequirement = ChatColor.BLUE; TextColor ccLevelRequirement = NamedTextColor.BLUE;
ChatColor ccLevelRequired = ChatColor.RED; TextColor ccLevelRequired = NamedTextColor.RED;
//SubSkillType Name //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)) if(!RankUtils.hasUnlockedSubskill(player, subSkillType))
{ {
@ -476,7 +483,7 @@ public class TextComponentFactory {
int curRank = RankUtils.getRank(player, subSkillType); int curRank = RankUtils.getRank(player, subSkillType);
int nextRank = 0; int nextRank = 0;
if(curRank < subSkillType.getNumRanks() && subSkillType.getNumRanks() > 0) if(curRank < subSkillType.getNumRanks())
{ {
nextRank = RankUtils.getRankUnlockLevel(subSkillType, curRank+1); nextRank = RankUtils.getRankUnlockLevel(subSkillType, curRank+1);
} }
@ -485,7 +492,7 @@ public class TextComponentFactory {
} }
componentBuilder.append("\n").bold(false); componentBuilder.append("\n");
componentBuilder.append(LocaleLoader.getString("JSON.DescriptionHeader")); componentBuilder.append(LocaleLoader.getString("JSON.DescriptionHeader"));
componentBuilder.color(ccDescriptionHeader); componentBuilder.color(ccDescriptionHeader);
componentBuilder.append("\n"); componentBuilder.append("\n");
@ -493,28 +500,25 @@ public class TextComponentFactory {
componentBuilder.color(ccDescription); 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()) if(abstractSubSkill.isSuperAbility())
{ {
componentBuilder.append(LocaleLoader.getString("JSON.Type.SuperAbility")).color(ChatColor.LIGHT_PURPLE); componentBuilder.append(TextComponent.of(LocaleLoader.getString("JSON.Type.SuperAbility"), NamedTextColor.LIGHT_PURPLE, TextDecoration.BOLD));
componentBuilder.bold(true);
} else if(abstractSubSkill.isActiveUse()) } else if(abstractSubSkill.isActiveUse())
{ {
componentBuilder.append(LocaleLoader.getString("JSON.Type.Active")).color(ChatColor.DARK_RED); componentBuilder.append(TextComponent.of(LocaleLoader.getString("JSON.Type.Active"), NamedTextColor.DARK_RED, TextDecoration.BOLD));
componentBuilder.bold(true);
} else { } else {
componentBuilder.append(LocaleLoader.getString("JSON.Type.Passive")).color(ChatColor.GREEN); componentBuilder.append(TextComponent.of(LocaleLoader.getString("JSON.Type.Passive"), NamedTextColor.GREEN, TextDecoration.BOLD));
componentBuilder.bold(true);
} }
componentBuilder.append("\n"); componentBuilder.append("\n");
} }
public static void getSubSkillTextComponents(Player player, List<TextComponent> textComponents, PrimarySkillType parentSkill) { public static void getSubSkillTextComponents(Player player, List<Component> textComponents, PrimarySkillType parentSkill) {
for(SubSkillType subSkillType : SubSkillType.values()) for(SubSkillType subSkillType : SubSkillType.values())
{ {
if(subSkillType.getParentSkill() == parentSkill) if(subSkillType.getParentSkill() == parentSkill)
@ -540,11 +544,10 @@ public class TextComponentFactory {
public static TextComponent getSubSkillUnlockedNotificationComponents(Player player, SubSkillType subSkillType) public static TextComponent getSubSkillUnlockedNotificationComponents(Player player, SubSkillType subSkillType)
{ {
TextComponent unlockMessage = new TextComponent(""); TextComponent.Builder unlockMessage = TextComponent.builder(LocaleLoader.getString("JSON.SkillUnlockMessage", subSkillType.getLocaleName(), RankUtils.getRank(player, subSkillType)));
unlockMessage.setText(LocaleLoader.getString("JSON.SkillUnlockMessage", subSkillType.getLocaleName(), RankUtils.getRank(player, subSkillType))); unlockMessage.hoverEvent(HoverEvent.showText(getSubSkillHoverComponent(player, subSkillType)));
unlockMessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, getSubSkillHoverComponent(player, subSkillType))); unlockMessage.clickEvent(ClickEvent.runCommand("/"+subSkillType.getParentSkill().toString().toLowerCase(Locale.ENGLISH)));
unlockMessage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/"+subSkillType.getParentSkill().toString().toLowerCase(Locale.ENGLISH))); return unlockMessage.build();
return unlockMessage;
} }
} }

View File

@ -10,12 +10,14 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.events.skills.McMMOPlayerNotificationEvent; import com.gmail.nossr50.events.skills.McMMOPlayerNotificationEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.McMMOMessageType;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.TextComponentFactory;
import com.gmail.nossr50.util.sounds.SoundManager; import com.gmail.nossr50.util.sounds.SoundManager;
import com.gmail.nossr50.util.sounds.SoundType; import com.gmail.nossr50.util.sounds.SoundType;
import net.md_5.bungee.api.ChatMessageType; import net.kyori.adventure.audience.Audience;
import net.md_5.bungee.api.chat.TextComponent; import net.kyori.adventure.audience.MessageType;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Server; import org.bukkit.Server;
@ -36,9 +38,9 @@ public class NotificationManager {
if(mcMMO.getUserManager().getPlayer(player) == null || !mcMMO.getUserManager().getPlayer(player).hasSkillChatNotifications()) if(mcMMO.getUserManager().getPlayer(player) == null || !mcMMO.getUserManager().getPlayer(player).hasSkillChatNotifications())
return; 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); McMMOPlayerNotificationEvent customEvent = checkNotificationEvent(player, notificationType, destination, message);
sendNotification(player, customEvent); sendNotification(player, customEvent);
@ -91,9 +93,9 @@ public class NotificationManager {
if(mcMMO.getUserManager().getPlayer(player) == null || !mcMMO.getUserManager().getPlayer(player).hasSkillChatNotifications()) if(mcMMO.getUserManager().getPlayer(player) == null || !mcMMO.getUserManager().getPlayer(player).hasSkillChatNotifications())
return; 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); McMMOPlayerNotificationEvent customEvent = checkNotificationEvent(player, notificationType, destination, message);
sendNotification(player, customEvent); sendNotification(player, customEvent);
@ -103,22 +105,24 @@ public class NotificationManager {
if (customEvent.isCancelled()) if (customEvent.isCancelled())
return; 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 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()) if(customEvent.isMessageAlsoBeingSentToChat())
{ {
//Send copy to chat system //Send copy to chat system
player.spigot().sendMessage(ChatMessageType.SYSTEM, customEvent.getNotificationTextComponent()); audience.sendMessage(customEvent.getNotificationTextComponent(), MessageType.SYSTEM);
} }
} else { } 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 //Init event
McMMOPlayerNotificationEvent customEvent = new McMMOPlayerNotificationEvent(player, McMMOPlayerNotificationEvent customEvent = new McMMOPlayerNotificationEvent(player,
notificationType, message, destination, AdvancedConfig.getInstance().doesNotificationSendCopyToChat(notificationType)); notificationType, message, destination, AdvancedConfig.getInstance().doesNotificationSendCopyToChat(notificationType));
@ -139,9 +143,9 @@ public class NotificationManager {
if(!mmoPlayer.hasSkillChatNotifications()) if(!mmoPlayer.hasSkillChatNotifications())
return; 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(mmoPlayer.getPlayer(), NotificationType.LEVEL_UP_MESSAGE, destination, levelUpTextComponent); McMMOPlayerNotificationEvent customEvent = checkNotificationEvent(mmoPlayer.getPlayer(), NotificationType.LEVEL_UP_MESSAGE, destination, levelUpTextComponent);
sendNotification(mmoPlayer.getPlayer(), customEvent); sendNotification(mmoPlayer.getPlayer(), customEvent);
@ -161,7 +165,8 @@ public class NotificationManager {
return; return;
//CHAT MESSAGE //CHAT MESSAGE
mmoPlayer.getPlayer().spigot().sendMessage(TextComponentFactory.getSubSkillUnlockedNotificationComponents(mmoPlayer.getPlayer(), subSkillType));
mcMMO.getAudiences().audience(mcMMOPlayer.getPlayer()).sendMessage(TextComponentFactory.getSubSkillUnlockedNotificationComponents(mmoPlayer.getPlayer(), subSkillType));
//Unlock Sound Effect //Unlock Sound Effect
SoundManager.sendCategorizedSound(mmoPlayer.getPlayer(), mmoPlayer.getPlayer().getLocation(), SoundType.SKILL_UNLOCKED, SoundCategory.MASTER); SoundManager.sendCategorizedSound(mmoPlayer.getPlayer(), mmoPlayer.getPlayer().getLocation(), SoundType.SKILL_UNLOCKED, SoundCategory.MASTER);

View File

@ -2,8 +2,9 @@ package com.gmail.nossr50.util.skills;
import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import net.md_5.bungee.api.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public final class PerksUtils { public final class PerksUtils {

View File

@ -209,10 +209,6 @@ public class SkillUtils {
} }
public static void removeAbilityBoostsFromInventory(@NotNull Player player) { public static void removeAbilityBoostsFromInventory(@NotNull Player player) {
if (!HiddenConfig.getInstance().useEnchantmentBuffs()) {
return;
}
for (ItemStack itemStack : player.getInventory().getContents()) { for (ItemStack itemStack : player.getInventory().getContents()) {
removeAbilityBuff(itemStack); removeAbilityBuff(itemStack);
} }