diff --git a/pom.xml b/pom.xml index 694c204..ca531a8 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.xemor Superheroes - 3.1.2 + 3.2.0 jar ${project.artifactId} diff --git a/src/main/java/me/xemor/superheroes/commands/Reroll.java b/src/main/java/me/xemor/superheroes/commands/Reroll.java index 2056787..73f2bf7 100644 --- a/src/main/java/me/xemor/superheroes/commands/Reroll.java +++ b/src/main/java/me/xemor/superheroes/commands/Reroll.java @@ -22,11 +22,11 @@ public class Reroll implements SubCommand, Listener { - HeroHandler heroHandler; - ConfigHandler configHandler; - boolean isEnabled; + private final HeroHandler heroHandler; + private final ConfigHandler configHandler; + private final boolean isEnabled; private final Component noPermission = MiniMessage.miniMessage().deserialize("You do not have permission to use this power!"); - CooldownHandler cooldownHandler = new CooldownHandler("", ChatMessageType.ACTION_BAR); + private final CooldownHandler cooldownHandler = new CooldownHandler("", ChatMessageType.ACTION_BAR); public Reroll(HeroHandler heroHandler, ConfigHandler configHandler) { this.heroHandler = heroHandler; diff --git a/src/main/java/me/xemor/superheroes/data/ConfigHandler.java b/src/main/java/me/xemor/superheroes/data/ConfigHandler.java index 132a2f5..670b743 100644 --- a/src/main/java/me/xemor/superheroes/data/ConfigHandler.java +++ b/src/main/java/me/xemor/superheroes/data/ConfigHandler.java @@ -139,6 +139,7 @@ public void reloadConfig(HeroHandler heroHandler) { Bukkit.getServer().getPluginManager().callEvent(superheroesReloadEvent); superheroes.reloadConfig(); config = superheroes.getConfig(); + heroHandler.loadConfigItems(); handleSuperpowersFolder(); heroHandler.handlePlayerData(); loadSuperheroes(heroHandler); @@ -147,7 +148,6 @@ public void reloadConfig(HeroHandler heroHandler) { heroHandler.setHeroesIntoMemory(new HashMap<>()); for (Player player : Bukkit.getOnlinePlayers()) { heroHandler.preLoginLoadSuperheroPlayer(player.getUniqueId()); - } } @@ -168,13 +168,17 @@ public ItemComparisonData getRerollItem() { } public boolean isRerollEnabled() { - return config.getConfigurationSection("reroll").getBoolean("isEnabled", true); + return config.getBoolean("reroll.isEnabled", true); } public boolean isPowerOnStartEnabled() { return config.getBoolean("powerOnStart.isEnabled", true); } + public List getDisabledWorlds() { + return config.getStringList("disabledWorlds"); + } + public boolean shouldShowHeroOnStart() { return config.getBoolean("powerOnStart.showHero", true); } @@ -191,6 +195,13 @@ public String getCurrentHeroMessage() { return language.getString("Chat.currentHero", ", you are currently "); } + public Superhero getDefaultHero() { + String name = config.getString("defaultHero.name", "Powerless"); + String colouredName = config.getString("defaultHero.colouredName", "Powerless"); + String description = config.getString("defaultHero.description", "You have no power"); + return new Superhero(name, colouredName, description); + } + public String getHeroCooldownMessage() { return language.getString("Chat.heroCommandCooldown", ", /hero is currently on cooldown. You need to wait / more seconds!"); } @@ -215,7 +226,9 @@ public long getHeroCommandCooldown() { return config.getLong("heroCommand.cooldown", 0); } - public double getRerollCooldown() { return config.getDouble("reroll.cooldown", 1.0);} + public double getRerollCooldown() { + return config.getDouble("reroll.cooldown", 1.0); + } public boolean areHeroPermissionsRequired() {return config.getConfigurationSection("reroll").getBoolean("eachHeroRequiresPermissions", false); } diff --git a/src/main/java/me/xemor/superheroes/data/HeroHandler.java b/src/main/java/me/xemor/superheroes/data/HeroHandler.java index 4171a77..4137771 100644 --- a/src/main/java/me/xemor/superheroes/data/HeroHandler.java +++ b/src/main/java/me/xemor/superheroes/data/HeroHandler.java @@ -9,7 +9,6 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.title.Title; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -31,19 +30,30 @@ public class HeroHandler { private HashMap nameToSuperhero = new HashMap<>(); private final Superheroes superheroes; private final ConfigHandler configHandler; - private final Superhero noPower = new Superhero("NOPOWER", "NOPOWER", "They have no power"); + private Superhero noPower; private HeroIOHandler heroIOHandler; + private List disabledWorlds; + private final ConcurrentHashMap> isProcessing = new ConcurrentHashMap<>(); public HeroHandler(Superheroes superheroes, ConfigHandler configHandler) { this.configHandler = configHandler; this.superheroes = superheroes; + loadConfigItems(); + } + + /* + Calls ConfigHandler methods to fetch default hero and disabledWorlds + */ + public void loadConfigItems() { + noPower = configHandler.getDefaultHero(); + disabledWorlds = configHandler.getDisabledWorlds(); } public void registerHeroes(HashMap nameToSuperhero) { this.nameToSuperhero = nameToSuperhero; - nameToSuperhero.put("nopower", noPower); + nameToSuperhero.put(noPower.getName().toLowerCase(), noPower); } public void setHeroesIntoMemory(HashMap playerHeroes) { @@ -62,6 +72,9 @@ public SuperheroPlayer getSuperheroPlayer(Player player) { @NotNull public Superhero getSuperhero(Player player) { + if (disabledWorlds.contains(player.getWorld().getName())) { + return noPower; + } SuperheroPlayer heroPlayer = uuidToData.get(player.getUniqueId()); if (heroPlayer == null) { return noPower; diff --git a/src/main/java/me/xemor/superheroes/skills/skilldata/PotionEffectSkillData.java b/src/main/java/me/xemor/superheroes/skills/skilldata/PotionEffectSkillData.java index f2baecd..50446ee 100644 --- a/src/main/java/me/xemor/superheroes/skills/skilldata/PotionEffectSkillData.java +++ b/src/main/java/me/xemor/superheroes/skills/skilldata/PotionEffectSkillData.java @@ -12,7 +12,6 @@ public class PotionEffectSkillData extends SkillData { public PotionEffectSkillData(int skill, ConfigurationSection configurationSection) { super(skill, configurationSection); potionData = new PotionEffectData(configurationSection, PotionEffectType.REGENERATION, 4, 0); - } public PotionEffect getPotionEffect() { diff --git a/src/main/java/me/xemor/superheroes/skills/skilldata/SummonSkillData.java b/src/main/java/me/xemor/superheroes/skills/skilldata/SummonSkillData.java index e36e54b..736c386 100644 --- a/src/main/java/me/xemor/superheroes/skills/skilldata/SummonSkillData.java +++ b/src/main/java/me/xemor/superheroes/skills/skilldata/SummonSkillData.java @@ -22,7 +22,7 @@ public class SummonSkillData extends PotionEffectSkillData implements Cooldown { public SummonSkillData(int skill, ConfigurationSection configurationSection) { super(skill, configurationSection); entityType = EntityType.valueOf(configurationSection.getString("entity", "LIGHTNING")); - range = configurationSection.getInt("range"); + range = configurationSection.getInt("range", 10); action = configurationSection.getStringList("action").stream().map(Action::valueOf).collect(Collectors.toCollection(HashSet::new)); if (action.isEmpty()) { action = new HashSet<>(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 689f302..3bf82b8 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,9 +1,7 @@ -#Do not set this as false unless all your configs are written in legacy colour codes / minedown and you want to convert to MiniMessage. -#If it is already MiniMessage, those configs will break. -textconvert: true #Do not set this as false unless you want the plugin to move your folder called Superheroes2 to one called Superheroes movedtosuperheroespluginname: false +#These are the settings which dictate where your players' heroes are stored database: type: YAML host: this needs filling with your host name if using mysql @@ -13,19 +11,32 @@ database: to mysql if using mysql password: this needs filling with the password being used to connect to mysql if using mysql + +#The reroll settings customise how /hero reroll and right-clicking with a reroll item work reroll: item: - types: + types: # the types of material which trigger a reroll, by default this is a diamond block. Other items like nether stars work great too. - DIAMOND_BLOCK - isEnabled: true - eachHeroRequiresPermissions: false - cooldown: 1 + isEnabled: true # whether rerolling via the item is enabled or not + eachHeroRequiresPermissions: false # whether you can only obtain heroes via rerolling and hero select that the user has permission for + cooldown: 1 # the cooldown between usages of the reroll item in seconds + powerOnStart: - isEnabled: true - showHero: true + isEnabled: true # whether they get a random hero, or no hero. + showHero: true # whether a popup telling the user which hero they are appears on join + heroCommand: cooldown: 0 # cooldown in seconds aliases: - '' +defaultHero: # note this section does not support Skills as of 2023/02/01 + name: "Powerless" # this is dangerous to change as the plugin would not be able to interpret players with this hero and would reset them to default. + colouredName: "Powerless" + description: "You have no power" + +# The worlds in which Superheroes is disabled (this is implemented as all users in that world being the default hero / no power hero) +# This likely has bugs / issues with heroes that give items, particularly when switching between these heroes. +disabledWorlds: [] +