Permissions for classes

This commit is contained in:
Ka0rX 2022-07-25 17:18:20 +02:00
parent dc2efdea99
commit 6df4b2e9f7
10 changed files with 50 additions and 2 deletions

View File

@ -60,6 +60,8 @@ 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<>();
@ -166,6 +168,8 @@ 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.
@ -205,7 +209,7 @@ 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);
@ -275,6 +279,10 @@ 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();
} }

View File

@ -82,6 +82,7 @@ public class ClassSelect extends EditableInventory {
lore.add(index + j, profess.getAttributeDescription().get(j)); lore.add(index + j, profess.getAttributeDescription().get(j));
} }
meta.setLore(lore); meta.setLore(lore);
item.setItemMeta(meta); item.setItemMeta(meta);
return NBTItem.get(item).addTag(new ItemTag("classId", profess.getId())).toItem(); return NBTItem.get(item).addTag(new ItemTag("classId", profess.getId())).toItem();
@ -115,6 +116,12 @@ 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())) {
MMOCore.plugin.soundManager.getSound(SoundEvent.CANT_SELECT_CLASS).playTo(player);
new ConfigMessage("no-permission-for-class").send(player);
return;
}
if (profess.equals(playerData.getProfess())) { if (profess.equals(playerData.getProfess())) {
MMOCore.plugin.soundManager.getSound(SoundEvent.CANT_SELECT_CLASS).playTo(player); MMOCore.plugin.soundManager.getSound(SoundEvent.CANT_SELECT_CLASS).playTo(player);
MMOCore.plugin.configManager.getSimpleMessage("already-on-class", "class", profess.getName()).send(player); MMOCore.plugin.configManager.getSimpleMessage("already-on-class", "class", profess.getName()).send(player);

View File

@ -99,6 +99,9 @@ skills:
level: 15 level: 15
max-level: 30 max-level: 30
#If true the player will need to have the mmocore.class.{class_name} permission
needs-permission: false
# Experience sources for main class experience. # Experience sources for main class experience.
main-exp-sources: main-exp-sources:
- 'killmob{type=ZOMBIE;amount=1-3}' - 'killmob{type=ZOMBIE;amount=1-3}'

View File

@ -19,6 +19,11 @@ options:
# Must match an existing exp curve filename from the 'expcurves' folder # Must match an existing exp curve filename from the 'expcurves' folder
exp-curve: levels exp-curve: levels
#If true the player will need to have the mmocore.class.{class_name} permission
needs-permission: false
# Experience sources for main class experience. # Experience sources for main class experience.
main-exp-sources: main-exp-sources:
- 'killmob{type=ZOMBIE;amount=1-3}' - 'killmob{type=ZOMBIE;amount=1-3}'

View File

@ -139,6 +139,11 @@ skills:
level: 15 level: 15
max-level: 30 max-level: 30
#If true the player will need to have the mmocore.class.{class_name} permission
needs-permission: false
# Experience sources for main class experience. # Experience sources for main class experience.
main-exp-sources: main-exp-sources:
- 'killmob{type=ZOMBIE;amount=1-3}' - 'killmob{type=ZOMBIE;amount=1-3}'

View File

@ -85,6 +85,11 @@ attributes:
base: .105 base: .105
per-level: 0 per-level: 0
#If true the player will need to have the mmocore.class.{class_name} permission
needs-permission: false
# Experience sources for main class experience. # Experience sources for main class experience.
main-exp-sources: main-exp-sources:
- 'killmob{type=ZOMBIE;amount=1-3}' - 'killmob{type=ZOMBIE;amount=1-3}'

View File

@ -75,6 +75,11 @@ attributes:
base: .095 base: .095
per-level: 0 per-level: 0
#If true the player will need to have the mmocore.class.{class_name} permission
needs-permission: false
# Experience sources for main class experience. # Experience sources for main class experience.
main-exp-sources: main-exp-sources:
- 'killmob{type=ZOMBIE;amount=1-3}' - 'killmob{type=ZOMBIE;amount=1-3}'

View File

@ -78,6 +78,11 @@ attributes:
base: .105 base: .105
per-level: 0 per-level: 0
#If true the player will need to have the mmocore.class.{class_name} permission
needs-permission: false
# Experience sources for main class experience. # Experience sources for main class experience.
main-exp-sources: main-exp-sources:
- 'killmob{type=ZOMBIE;amount=1-3}' - 'killmob{type=ZOMBIE;amount=1-3}'

View File

@ -115,6 +115,10 @@ attributes:
base: 4.2 base: 4.2
per-level: 0.05 per-level: 0.05
#If true the player will need to have the mmocore.class.{class_name} permission
needs-permission: false
# Experience sources for main class experience. # Experience sources for main class experience.
main-exp-sources: main-exp-sources:
- 'killmob{type=ZOMBIE;amount=1-3}' - 'killmob{type=ZOMBIE;amount=1-3}'

View File

@ -152,7 +152,8 @@ start-quest: '&eYou successfully started &6{quest}&e.'
cant-choose-new-class: cant-choose-new-class:
- '&cYou need one class point to perform this action.' - '&cYou need one class point to perform this action.'
no-permission-for-class:
- "&cYou don't have the permission to choose this class."
# Attributes # Attributes
no-attribute-points-spent: '&cYou have not spent any attribute points.' no-attribute-points-spent: '&cYou have not spent any attribute points.'
not-attribute-reallocation-point: '&cYou do not have 1 reallocation point.' not-attribute-reallocation-point: '&cYou do not have 1 reallocation point.'