Skip to content

Commit

Permalink
add back permission skills
Browse files Browse the repository at this point in the history
  • Loading branch information
NeumimTo committed Jun 26, 2021
1 parent ed7cdd5 commit 663c45e
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 10 deletions.
4 changes: 1 addition & 3 deletions .run/RunServer.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/server-spigot" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
<option name="ALTERNATIVE_JRE_PATH" value="1.8" />
<method v="2">
<option name="RunConfigurationTask" enabled="true" run_configuration_name="NT-RPG [build]" run_configuration_type="GradleRunConfiguration" />
</method>
<method v="2" />
</configuration>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,26 @@

package cz.neumimto.rpg.api.skills.types;

import com.typesafe.config.Config;
import cz.neumimto.rpg.api.entity.players.IActiveCharacter;
import cz.neumimto.rpg.api.permissions.PermissionService;
import cz.neumimto.rpg.api.skills.PlayerSkillContext;
import cz.neumimto.rpg.api.skills.SkillData;
import cz.neumimto.rpg.api.skills.SkillExecutionType;
import cz.neumimto.rpg.api.skills.SkillResult;
import cz.neumimto.rpg.api.skills.tree.SkillTree;
import cz.neumimto.rpg.api.skills.utils.SkillLoadingErrors;

import javax.inject.Inject;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class PermissionSkill extends AbstractSkill<IActiveCharacter> {

@Inject
private PermissionService permissionService;

@Override
public SkillResult onPreUse(IActiveCharacter character, PlayerSkillContext esi) {
return SkillResult.CANCELLED;
Expand All @@ -36,16 +49,48 @@ public SkillExecutionType getSkillExecutionType() {
@Override
public void skillLearn(IActiveCharacter IActiveCharacter, PlayerSkillContext context) {
super.skillLearn(IActiveCharacter, context);
PermissionData permissionData = (PermissionData) context.getSkillData();
if (permissionData.permissions != null) {
permissionService.addPermissions(IActiveCharacter, permissionData.permissions);
}
}

@Override
public void skillUpgrade(IActiveCharacter IActiveCharacter, int level, PlayerSkillContext context) {
super.skillUpgrade(IActiveCharacter, level, context);
public void skillRefund(IActiveCharacter IActiveCharacter, PlayerSkillContext context) {
super.skillRefund(IActiveCharacter, context);
PermissionData permissionData = (PermissionData) context.getSkillData();
if (permissionData.permissions != null) {
permissionService.removePermissions(IActiveCharacter, permissionData.permissions);
}
}

@Override
public void skillRefund(IActiveCharacter IActiveCharacter, PlayerSkillContext context) {
super.skillRefund(IActiveCharacter, context);
public <T extends SkillData> void loadSkillData(T skillData, SkillTree context, SkillLoadingErrors errors, Config c) {
PermissionData permissionData = (PermissionData) skillData;
List<String> permissions = c.getStringList("Permissions");
if (permissions != null) {
permissionData.permissions = new HashSet<>(permissions);
}
}

@Override
public SkillData constructSkillData() {
return new PermissionData(getId());
}

public class PermissionData extends SkillData {
private Set<String> permissions;

public PermissionData(String skill) {
super(skill);
}

public Set<String> getPermissions() {
return permissions;
}

public void setPermissions(Set<String> permissions) {
this.permissions = permissions;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import cz.neumimto.rpg.api.Rpg;
import cz.neumimto.rpg.api.classes.ClassService;
import cz.neumimto.rpg.api.configuration.SkillTreeDao;
import cz.neumimto.rpg.api.effects.model.mappers.SingleValueModelMapper;
import cz.neumimto.rpg.api.gui.ISkillTreeInterfaceModel;
import cz.neumimto.rpg.api.localization.LocalizationService;
import cz.neumimto.rpg.api.logging.Log;
Expand All @@ -40,7 +39,6 @@
import cz.neumimto.rpg.common.skills.SkillConfigLoader;
import cz.neumimto.rpg.common.skills.SkillConfigLoaders;
import cz.neumimto.rpg.common.skills.SkillExecutor;
import org.apache.commons.lang3.math.NumberUtils;

import javax.inject.Inject;
import javax.inject.Singleton;
Expand All @@ -49,7 +47,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
import java.util.*;

import static cz.neumimto.rpg.api.logging.Log.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cz.neumimto.rpg.api.skills.*;
import cz.neumimto.rpg.api.skills.tree.SkillTreeSpecialization;
import cz.neumimto.rpg.api.skills.types.CharacterAttributeSkill;
import cz.neumimto.rpg.api.skills.types.PermissionSkill;
import cz.neumimto.rpg.common.skills.types.ItemAccessSkill;

import java.util.HashMap;
Expand All @@ -19,6 +20,7 @@ public class SkillConfigLoaders {
static SkillConfigLoader WRAPPER = new SkillConfigLoader("wrapper", WrappedSkill.class);
static SkillConfigLoader REPEATING = new SkillConfigLoader("repeating", RepeatingSkill.class);
static SkillConfigLoader UPGRADE = new SkillConfigLoader("upgrade", SkillUpgrade.class);
static SkillConfigLoader PERMISSION = new SkillConfigLoader("permission", PermissionSkill.class);

private static Map<String, SkillConfigLoader> internalCache = new HashMap<>();

Expand All @@ -32,6 +34,7 @@ public class SkillConfigLoaders {
register(WRAPPER);
register(REPEATING);
register(UPGRADE);
register(PERMISSION);
}

public static Optional<SkillConfigLoader> getById(String id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,16 @@ Skills: [
manacost: 10
}
}
{
SkillId: "myexample:giveperm01"
Name: PermExample
MinPlayerLevel: 100
MaxSkillLevel: 1
SkillTreeId: 16
Icon: "minecraft:web"
ModelId: 999
Permissions: [
"some.permission.xxx.yyy"
]
}
]

0 comments on commit 663c45e

Please sign in to comment.