From 18190be6740c8276cae1462f1cdc41450eb6abcb Mon Sep 17 00:00:00 2001 From: NeumimTo Date: Sun, 19 Apr 2020 14:22:41 +0200 Subject: [PATCH] validation changes, bugfixes --- .../players/classes/ClassDefinition.java | 8 +++---- .../neumimto/rpg/api/skills/CommandSkill.java | 21 +++++++++++++++++++ .../skills/scripting/ActiveScriptSkill.java | 16 ++++++++------ .../skills/scripting/ScriptSkillModel.java | 21 ------------------- .../rpg/api/skills/tree/SkillTree.java | 2 +- .../configuration/SkillTreeLoaderImpl.java | 2 ++ .../cz/neumimto/rpg/common/gui/GuiParser.java | 2 +- .../common/skills/AbstractSkillService.java | 7 ++++++- .../permissions/SpigotPermissionService.java | 7 +------ Implementations/Sponge/7/build.gradle | 2 +- .../neumimto/rpg/sponge/SpongeRpgPlugin.java | 3 ++- .../permission/SpongePermissionService.java | 2 -- .../Sponge/7/src/main/resources/Main.js | 8 +++---- .../java/cz/neumimto/rpg/api/RpgTests.java | 5 +++++ 14 files changed, 58 insertions(+), 48 deletions(-) diff --git a/API/src/main/java/cz/neumimto/rpg/api/entity/players/classes/ClassDefinition.java b/API/src/main/java/cz/neumimto/rpg/api/entity/players/classes/ClassDefinition.java index 67b2f9d84..b083b0f6a 100644 --- a/API/src/main/java/cz/neumimto/rpg/api/entity/players/classes/ClassDefinition.java +++ b/API/src/main/java/cz/neumimto/rpg/api/entity/players/classes/ClassDefinition.java @@ -18,10 +18,8 @@ package cz.neumimto.rpg.api.entity.players.classes; -import com.electronwill.nightconfig.core.conversion.Conversion; -import com.electronwill.nightconfig.core.conversion.Converter; -import com.electronwill.nightconfig.core.conversion.Path; -import com.electronwill.nightconfig.core.conversion.SpecValidator; +import com.electronwill.nightconfig.core.conversion.*; +import com.typesafe.config.Optional; import cz.neumimto.rpg.api.configuration.AttributeConfig; import cz.neumimto.rpg.api.configuration.adapters.*; import cz.neumimto.rpg.api.effects.*; @@ -114,9 +112,11 @@ public class ClassDefinition implements IEffectSourceProvider { protected SkillTree skillTree; @Path("SkillPointsPerLevel") + @PreserveNotNull protected int skillpointsPerLevel; @Path("AttributePointsPerLevel") + @PreserveNotNull protected int attributepointsPerLevel; @Path("Leveling") diff --git a/API/src/main/java/cz/neumimto/rpg/api/skills/CommandSkill.java b/API/src/main/java/cz/neumimto/rpg/api/skills/CommandSkill.java index cc204c098..d6f8f88bf 100644 --- a/API/src/main/java/cz/neumimto/rpg/api/skills/CommandSkill.java +++ b/API/src/main/java/cz/neumimto/rpg/api/skills/CommandSkill.java @@ -4,11 +4,13 @@ import com.typesafe.config.ConfigException; import cz.neumimto.rpg.api.Rpg; import cz.neumimto.rpg.api.entity.players.IActiveCharacter; +import cz.neumimto.rpg.api.permissions.PermissionService; import cz.neumimto.rpg.api.skills.mods.SkillContext; import cz.neumimto.rpg.api.skills.tree.SkillTree; import cz.neumimto.rpg.api.skills.types.ActiveSkill; import cz.neumimto.rpg.api.skills.utils.SkillLoadingErrors; +import javax.inject.Inject; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -16,6 +18,9 @@ public class CommandSkill extends ActiveSkill { + @Inject + private PermissionService permissionService; + @Override public void cast(IActiveCharacter character, PlayerSkillContext info, SkillContext skillContext) { CommandData skillData = (CommandData) info.getSkillData(); @@ -26,7 +31,17 @@ public void cast(IActiveCharacter character, PlayerSkillContext info, SkillConte if (skillData.isConsole()) { Rpg.get().executeCommandBatch(args, command); } else { + boolean permApplied = false; + + if (skillData.permission != null && permissionService.hasPermission(character, skillData.permission)) { + permissionService.addPermissions(character, Collections.singletonList(skillData.permission)); + permApplied = true; + } + Rpg.get().executeCommandAs(character.getUUID(), args, command); + if (permApplied) { + permissionService.removePermissions(character, Collections.singletonList(skillData.permission)); + } } skillContext.next(character, info, skillContext); @@ -46,10 +61,16 @@ public void loadSkillData(T skillData, SkillTree context, boolean executeAsConsole = c.getBoolean("ExecuteAsConsole"); data.console = executeAsConsole; } catch (ConfigException ignored) {} + + try { + String perm = c.getString("Permission"); + data.permission = perm; + } catch (ConfigException ignored) {} } public class CommandData extends SkillData { + public String permission; boolean console; private String command; diff --git a/API/src/main/java/cz/neumimto/rpg/api/skills/scripting/ActiveScriptSkill.java b/API/src/main/java/cz/neumimto/rpg/api/skills/scripting/ActiveScriptSkill.java index 0142fdc46..5e92cc165 100644 --- a/API/src/main/java/cz/neumimto/rpg/api/skills/scripting/ActiveScriptSkill.java +++ b/API/src/main/java/cz/neumimto/rpg/api/skills/scripting/ActiveScriptSkill.java @@ -10,6 +10,7 @@ import cz.neumimto.rpg.api.skills.types.ScriptSkill; import cz.neumimto.rpg.api.entity.players.IActiveCharacter; +import java.util.Collections; import java.util.List; import java.util.Optional; @@ -45,12 +46,15 @@ public void setModel(ScriptSkillModel model) { setDamageType(model.getDamageType()); setCatalogId(model.getId()); List configTypes = model.getSkillTypes(); - for (String configType : configTypes) { - Optional skillType = Rpg.get().getSkillService().getSkillType(configType); - if (skillType.isPresent()) { - addSkillType(skillType.get()); - } else { - Log.warn("Unknown skill type " + configType); + + if (configTypes != null) { + for (String configType : configTypes) { + Optional skillType = Rpg.get().getSkillService().getSkillType(configType); + if (skillType.isPresent()) { + addSkillType(skillType.get()); + } else { + Log.warn("Unknown skill type " + configType); + } } } } diff --git a/API/src/main/java/cz/neumimto/rpg/api/skills/scripting/ScriptSkillModel.java b/API/src/main/java/cz/neumimto/rpg/api/skills/scripting/ScriptSkillModel.java index 2bf138236..e74149698 100644 --- a/API/src/main/java/cz/neumimto/rpg/api/skills/scripting/ScriptSkillModel.java +++ b/API/src/main/java/cz/neumimto/rpg/api/skills/scripting/ScriptSkillModel.java @@ -14,9 +14,6 @@ public class ScriptSkillModel { @Path("Id") private String id; - @Path("Name") - private String name; - @Path("Parent") private String parent; @@ -26,12 +23,6 @@ public class ScriptSkillModel { @Path("Damage-Type") private String damageType; - @Path("Lore") - private List lore; - - @Path("Description") - private List description; - @Path("Settings") @Conversion(SettingsToMap.class) private Map settings; @@ -50,10 +41,6 @@ public void setId(String id) { this.id = id; } - public String getName() { - return name; - } - public String getParent() { return parent; } @@ -66,14 +53,6 @@ public String getDamageType() { return damageType; } - public List getLore() { - return lore; - } - - public List getDescription() { - return description; - } - public Map getSettings() { return settings; } diff --git a/API/src/main/java/cz/neumimto/rpg/api/skills/tree/SkillTree.java b/API/src/main/java/cz/neumimto/rpg/api/skills/tree/SkillTree.java index 1e85c37ac..2e19a6a5d 100644 --- a/API/src/main/java/cz/neumimto/rpg/api/skills/tree/SkillTree.java +++ b/API/src/main/java/cz/neumimto/rpg/api/skills/tree/SkillTree.java @@ -87,7 +87,7 @@ public void addSkill(SkillData value) { } public void addSkillTreeId(SkillData value) { - if (value.getModelId() != null) { + if (value.getSkillTreeId() > 0) { skillsById.put(value.getSkillTreeId(), value); } } diff --git a/Common/src/main/java/cz/neumimto/rpg/common/configuration/SkillTreeLoaderImpl.java b/Common/src/main/java/cz/neumimto/rpg/common/configuration/SkillTreeLoaderImpl.java index 1529022f5..519fd8bf9 100644 --- a/Common/src/main/java/cz/neumimto/rpg/common/configuration/SkillTreeLoaderImpl.java +++ b/Common/src/main/java/cz/neumimto/rpg/common/configuration/SkillTreeLoaderImpl.java @@ -24,6 +24,7 @@ import cz.neumimto.rpg.api.configuration.ItemString; import cz.neumimto.rpg.api.configuration.SkillItemCost; import cz.neumimto.rpg.api.configuration.SkillTreeDao; +import cz.neumimto.rpg.api.entity.players.IActiveCharacter; import cz.neumimto.rpg.api.gui.ISkillTreeInterfaceModel; import cz.neumimto.rpg.api.localization.LocalizationService; import cz.neumimto.rpg.api.logging.Log; @@ -253,6 +254,7 @@ protected void loadSkill(SkillTree skillTree, ConfigObject co) { skillNodeDescription = scriptedSkillNodeDescription; } catch (ConfigException ee) { + skillNodeDescription = character -> Collections.emptyList(); } } info.setDescription(skillNodeDescription); diff --git a/Common/src/main/java/cz/neumimto/rpg/common/gui/GuiParser.java b/Common/src/main/java/cz/neumimto/rpg/common/gui/GuiParser.java index e95bfaf49..4666b800a 100644 --- a/Common/src/main/java/cz/neumimto/rpg/common/gui/GuiParser.java +++ b/Common/src/main/java/cz/neumimto/rpg/common/gui/GuiParser.java @@ -70,7 +70,7 @@ public Map initInventories(ClassLoader classLoader, String confN .map(this::toItemStack) .collect(Collectors.toList()); return collect.toArray(initArray(collect.size())); - }; + }}; ConfigInventory c2 = createCachedMenu( sFactorz, guiName, gui, context2 ); diff --git a/Common/src/main/java/cz/neumimto/rpg/common/skills/AbstractSkillService.java b/Common/src/main/java/cz/neumimto/rpg/common/skills/AbstractSkillService.java index e05f07447..5cd335da6 100644 --- a/Common/src/main/java/cz/neumimto/rpg/common/skills/AbstractSkillService.java +++ b/Common/src/main/java/cz/neumimto/rpg/common/skills/AbstractSkillService.java @@ -152,6 +152,9 @@ todo it should be easiest to lock (maybe even joining) specific commands, save @Override public void registerAdditionalCatalog(ISkill extraCatalog) { + if (extraCatalog == null) { + warn("Cannot register skill null"); + } if (extraCatalog.getId() == null) { warn("Cannot register skill " + extraCatalog.getId() + ", " + extraCatalog.getClass().getSimpleName() + " getId() returned" + " null"); @@ -209,9 +212,11 @@ public ISkill skillDefinitionToSkill(ScriptSkillModel scriptSkillModel, ClassLoa return null; } + String name = scriptSkillModel.getId(); + name = name.replaceAll("[\\W]", ""); Class sk = new ByteBuddy() .subclass(type) - .name("cz.neumimto.skills.scripts." + scriptSkillModel.getName()) + .name("cz.neumimto.skills.scripts." + name) .annotateType(AnnotationDescription.Builder.ofType(ResourceLoader.Skill.class) .define("value", scriptSkillModel.getId()) .build()) diff --git a/Implementations/Spigot/14/src/main/java/cz/neumimto/rpg/spigot/permissions/SpigotPermissionService.java b/Implementations/Spigot/14/src/main/java/cz/neumimto/rpg/spigot/permissions/SpigotPermissionService.java index 9cbd4ede6..03a0a6121 100644 --- a/Implementations/Spigot/14/src/main/java/cz/neumimto/rpg/spigot/permissions/SpigotPermissionService.java +++ b/Implementations/Spigot/14/src/main/java/cz/neumimto/rpg/spigot/permissions/SpigotPermissionService.java @@ -18,13 +18,8 @@ public boolean hasPermission(ISpigotCharacter character, String value) { @Override public void removePermissions(ISpigotCharacter character, Collection perms) { Player player = character.getPlayer(); - Set efPerms = player.getEffectivePermissions(); for (String perm : perms) { - for (PermissionAttachmentInfo efPerm : efPerms) { - if (efPerm.getPermission().equalsIgnoreCase(perm)) { - player.removeAttachment(efPerm.getAttachment()); - } - } + player.addAttachment(SpigotRpgPlugin.getInstance(), perm, false); } } diff --git a/Implementations/Sponge/7/build.gradle b/Implementations/Sponge/7/build.gradle index 27b7b5399..69c7451e9 100644 --- a/Implementations/Sponge/7/build.gradle +++ b/Implementations/Sponge/7/build.gradle @@ -3,7 +3,7 @@ plugins { } group = 'cz.neumimto.rpg' -version = '2.1.0-SNAPSHOT-2' +version = '2.1.0-SNAPSHOT-4' repositories { maven { diff --git a/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/SpongeRpgPlugin.java b/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/SpongeRpgPlugin.java index a81ed6d5d..e383c6d36 100644 --- a/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/SpongeRpgPlugin.java +++ b/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/SpongeRpgPlugin.java @@ -73,7 +73,8 @@ * Created by NeumimTo on 29.4.2015. */ @Plugin(id = "nt-rpg", version = "2.1.0-SNAPSHOT-1", name = "NT-Rpg", description = "RPG features for sponge", dependencies = { - @Dependency(id = "placeholderapi", version = "4.5", optional = true) + @Dependency(id = "placeholderapi", version = "4.5", optional = true), + @Dependency(id = "Holograms", optional = true) }) @Resource public class SpongeRpgPlugin extends Rpg { diff --git a/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/permission/SpongePermissionService.java b/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/permission/SpongePermissionService.java index 875d276ad..61a1c04ef 100644 --- a/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/permission/SpongePermissionService.java +++ b/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/permission/SpongePermissionService.java @@ -1,7 +1,5 @@ package cz.neumimto.rpg.sponge.permission; -import cz.neumimto.rpg.api.entity.players.classes.PlayerClassData; -import cz.neumimto.rpg.api.entity.players.classes.PlayerClassPermission; import cz.neumimto.rpg.api.permissions.PermissionService; import cz.neumimto.rpg.sponge.entities.players.ISpongeCharacter; import org.spongepowered.api.service.permission.SubjectData; diff --git a/Implementations/Sponge/7/src/main/resources/Main.js b/Implementations/Sponge/7/src/main/resources/Main.js index 1e6c40dcd..24d307fb4 100644 --- a/Implementations/Sponge/7/src/main/resources/Main.js +++ b/Implementations/Sponge/7/src/main/resources/Main.js @@ -99,7 +99,7 @@ function registerAttributes() { for (obj in attributes) { var a = attributes.get(obj); if (a instanceof CharacterAttribute) { - GlobalScope.propertyService.registerAttribute(a); + Rpg.getPropertyService().registerAttribute(a); } } } @@ -111,7 +111,7 @@ function registerSkills() { for (obj in skills) { var s = skills.get(obj); s.init(); - GlobalScope.skillService.registerAdditionalCatalog(s); + Rpg.getSkilLService().registerAdditionalCatalog(s); } } @@ -121,7 +121,7 @@ function registerGlobalEffects() { for (obj in globalEffects) { var g = globalEffects.get(obj); if (g instanceof Java.type("cz.neumimto.rpg.api.effects.IGlobalEffect")) { - GlobalScope.effectService.registerGlobalEffect(g); + Rpg.getEffectService().registerGlobalEffect(g); } } } @@ -129,7 +129,7 @@ function registerGlobalEffects() { function generateListener() { if (!events.isEmpty()) { log("generateListener") - GlobalScope.jsLoader.generateDynamicListener(events); + Rpg.getScriptEngine().generateDynamicListener(events); } events.clear(); } \ No newline at end of file diff --git a/Peristence/Common-Tests/src/main/java/cz/neumimto/rpg/api/RpgTests.java b/Peristence/Common-Tests/src/main/java/cz/neumimto/rpg/api/RpgTests.java index e286983be..cb81cb20c 100644 --- a/Peristence/Common-Tests/src/main/java/cz/neumimto/rpg/api/RpgTests.java +++ b/Peristence/Common-Tests/src/main/java/cz/neumimto/rpg/api/RpgTests.java @@ -201,6 +201,11 @@ public EquipedSlot createEquipedSlot(String className, int slotId) { return new TestHelper.EquipedSlotImpl(slotId); } + @Override + public void invalidateGUICaches(IActiveCharacter cc) { + + } + }; }