Skip to content

Commit

Permalink
Added custom nopower heroes (and changed the default to be more user …
Browse files Browse the repository at this point in the history
…friendly)

Added support for a disabledWorlds field
  • Loading branch information
Xemorr committed Feb 1, 2023
1 parent fadcae7 commit 50f578d
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.xemor</groupId>
<artifactId>Superheroes</artifactId>
<version>3.1.2</version>
<version>3.2.0</version>
<packaging>jar</packaging>

<name>${project.artifactId}</name>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/me/xemor/superheroes/commands/Reroll.java
Original file line number Diff line number Diff line change
Expand Up @@ -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("<dark_red>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;
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/me/xemor/superheroes/data/ConfigHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -147,7 +148,6 @@ public void reloadConfig(HeroHandler heroHandler) {
heroHandler.setHeroesIntoMemory(new HashMap<>());
for (Player player : Bukkit.getOnlinePlayers()) {
heroHandler.preLoginLoadSuperheroPlayer(player.getUniqueId());

}
}

Expand All @@ -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<String> getDisabledWorlds() {
return config.getStringList("disabledWorlds");
}

public boolean shouldShowHeroOnStart() {
return config.getBoolean("powerOnStart.showHero", true);
}
Expand All @@ -191,6 +195,13 @@ public String getCurrentHeroMessage() {
return language.getString("Chat.currentHero", "<bold><player>, you are currently <hero>");
}

public Superhero getDefaultHero() {
String name = config.getString("defaultHero.name", "Powerless");
String colouredName = config.getString("defaultHero.colouredName", "<yellow><b>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", "<bold><player>, /hero is currently on cooldown. You need to wait <currentcooldown>/<cooldown> more seconds!");
}
Expand All @@ -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); }

Expand Down
19 changes: 16 additions & 3 deletions src/main/java/me/xemor/superheroes/data/HeroHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,19 +30,30 @@ public class HeroHandler {
private HashMap<String, Superhero> nameToSuperhero = new HashMap<>();
private final Superheroes superheroes;
private final ConfigHandler configHandler;
private final Superhero noPower = new Superhero("NOPOWER", "<yellow><b>NOPOWER", "They have no power");
private Superhero noPower;
private HeroIOHandler heroIOHandler;

private List<String> disabledWorlds;

private final ConcurrentHashMap<UUID, CompletableFuture<SuperheroPlayer>> 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<String, Superhero> nameToSuperhero) {
this.nameToSuperhero = nameToSuperhero;
nameToSuperhero.put("nopower", noPower);
nameToSuperhero.put(noPower.getName().toLowerCase(), noPower);
}

public void setHeroesIntoMemory(HashMap<UUID, SuperheroPlayer> playerHeroes) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<>();
Expand Down
29 changes: 20 additions & 9 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: "<yellow><b>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: []


0 comments on commit 50f578d

Please sign in to comment.