Class option for class permission

This commit is contained in:
Indyuce 2022-07-26 15:20:13 +02:00
parent 0121c5d106
commit 7d2d8a59b2
3 changed files with 49 additions and 52 deletions

View File

@ -2,51 +2,57 @@ package net.Indyuce.mmocore.api.player.profess;
public enum ClassOption { public enum ClassOption {
/** /**
* If the class should be applied to newcomers * If the class should be applied to newcomers
*/ */
DEFAULT, DEFAULT,
/** /**
* If the class should in the /class GUI * When set to true any player has to have the
*/ * mmocore.class.lower_case_name permission to use the class
DISPLAY(true), */
NEEDS_PERMISSION,
/** /**
* Health only regens when out of combat * If the class should in the /class GUI
*/ */
OFF_COMBAT_HEALTH_REGEN, DISPLAY(true),
/** /**
* Mana only regens when out of combat * Health only regens when out of combat
*/ */
OFF_COMBAT_MANA_REGEN, OFF_COMBAT_HEALTH_REGEN,
/** /**
* Stamina only regens when out of combat * Mana only regens when out of combat
*/ */
OFF_COMBAT_STAMINA_REGEN, OFF_COMBAT_MANA_REGEN,
/** /**
* Stellium only regens when out of combat * Stamina only regens when out of combat
*/ */
OFF_COMBAT_STELLIUM_REGEN; OFF_COMBAT_STAMINA_REGEN,
private final boolean def; /**
* Stellium only regens when out of combat
*/
OFF_COMBAT_STELLIUM_REGEN;
ClassOption() { private final boolean def;
this(false);
}
ClassOption(boolean def) { ClassOption() {
this.def = def; this(false);
} }
public boolean getDefault() { ClassOption(boolean def) {
return def; this.def = def;
} }
public String getPath() { public boolean getDefault() {
return name().toLowerCase().replace("_", "-"); return def;
} }
public String getPath() {
return name().toLowerCase().replace("_", "-");
}
} }

View File

@ -60,8 +60,6 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
private final Map<PlayerResource, ResourceRegeneration> resourceHandlers = new HashMap<>(); private final Map<PlayerResource, ResourceRegeneration> resourceHandlers = new HashMap<>();
private final boolean needsPermission;
@Deprecated @Deprecated
private final Map<String, EventTrigger> eventTriggers = new HashMap<>(); private final Map<String, EventTrigger> eventTriggers = new HashMap<>();
@ -168,8 +166,6 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
} }
} }
needsPermission =config.contains("needs-permission")?config.getBoolean("needs-permission"):false;
/* /*
* Must make sure all the resourceHandlers are registered * Must make sure all the resourceHandlers are registered
* when the placer class is initialized. * when the placer class is initialized.
@ -209,7 +205,6 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
expTable = null; expTable = null;
castParticle = new CastingParticle(Particle.SPELL_INSTANT); castParticle = new CastingParticle(Particle.SPELL_INSTANT);
actionBarFormat = ""; actionBarFormat = "";
needsPermission =false;
this.icon = new ItemStack(material); this.icon = new ItemStack(material);
setOption(ClassOption.DISPLAY, false); setOption(ClassOption.DISPLAY, false);
setOption(ClassOption.DEFAULT, false); setOption(ClassOption.DEFAULT, false);
@ -279,10 +274,6 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
return expTable != null; return expTable != null;
} }
public boolean needsPermission() {
return needsPermission;
}
public ItemStack getIcon() { public ItemStack getIcon() {
return icon.clone(); return icon.clone();
} }
@ -304,7 +295,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
} }
public boolean hasOption(ClassOption option) { public boolean hasOption(ClassOption option) {
return options.containsKey(option) ? options.get(option) : option.getDefault(); return options.getOrDefault(option, option.getDefault());
} }
@Override @Override

View File

@ -4,16 +4,16 @@ import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigMessage;
import net.Indyuce.mmocore.api.SoundEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.ClassOption;
import net.Indyuce.mmocore.api.player.profess.PlayerClass; import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.gui.api.EditableInventory; import net.Indyuce.mmocore.gui.api.EditableInventory;
import net.Indyuce.mmocore.gui.api.GeneratedInventory; import net.Indyuce.mmocore.gui.api.GeneratedInventory;
import net.Indyuce.mmocore.gui.api.item.InventoryItem; import net.Indyuce.mmocore.gui.api.item.InventoryItem;
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem; import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
import net.Indyuce.mmocore.manager.InventoryManager; import net.Indyuce.mmocore.manager.InventoryManager;
import net.Indyuce.mmocore.api.ConfigMessage;
import net.Indyuce.mmocore.api.SoundEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.ClassOption;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
@ -116,7 +116,7 @@ public class ClassSelect extends EditableInventory {
} }
PlayerClass profess = MMOCore.plugin.classManager.get(tag); PlayerClass profess = MMOCore.plugin.classManager.get(tag);
if(profess.needsPermission()&&!player.hasPermission("mmocore.class."+profess.getName().toLowerCase())) { if (profess.hasOption(ClassOption.NEEDS_PERMISSION) && !player.hasPermission("mmocore.class." + profess.getId().toLowerCase())) {
MMOCore.plugin.soundManager.getSound(SoundEvent.CANT_SELECT_CLASS).playTo(player); MMOCore.plugin.soundManager.getSound(SoundEvent.CANT_SELECT_CLASS).playTo(player);
new ConfigMessage("no-permission-for-class").send(player); new ConfigMessage("no-permission-for-class").send(player);
return; return;