Skip to content

Commit

Permalink
fix command skill
Browse files Browse the repository at this point in the history
  • Loading branch information
NeumimTo committed Apr 19, 2020
1 parent 18190be commit cb7303b
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,6 @@ default boolean hasEffectType(EffectType effectType) {

float getCharacterPropertyWithoutLevel(int index);

double getMaxMana();

void setMaxMana(float mana);

void setMaxHealth(float maxHealth);

void setHealth(float maxHealth);

IReservable getMana();

void setMana(IReservable mana);
Expand Down
14 changes: 8 additions & 6 deletions API/src/main/java/cz/neumimto/rpg/api/skills/CommandSkill.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void cast(IActiveCharacter character, PlayerSkillContext info, SkillConte
CommandData skillData = (CommandData) info.getSkillData();
List<String> command = Collections.singletonList(skillData.getCommand());
Map<String, String> args = new HashMap<>();
args.put("{{player}}", character.getPlayerAccountName());
args.put("player", character.getPlayerAccountName());

if (skillData.isConsole()) {
Rpg.get().executeCommandBatch(args, command);
Expand All @@ -37,14 +37,16 @@ public void cast(IActiveCharacter character, PlayerSkillContext info, SkillConte
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));
try {
Rpg.get().executeCommandAs(character.getUUID(), args, command);
} finally {
if (permApplied) {
permissionService.removePermissions(character, Collections.singletonList(skillData.permission));
}
}
}

skillContext.next(character, info, skillContext);
skillContext.next(character, info, SkillResult.OK);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ public void commandExecuteSkill(IActiveCharacter character, ISkill skill, int le

PlayerSkillContext playerSkillContext = new PlayerSkillContext(null, skill, character);
playerSkillContext.setLevel(level);
SkillData skillData = new SkillData(skill.getId());
SkillData skillData = skill.constructSkillData();

skillData.setSkillSettings(defaultSkillSettings);
playerSkillContext.setSkillData(skillData);
playerSkillContext.setSkill(skill);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,21 +259,6 @@ public float getCharacterPropertyWithoutLevel(int index) {
return primaryProperties[index];
}

@Override
public double getMaxMana() {
return getMana().getMaxValue();
}

@Override
public void setMaxMana(float mana) {
getMana().setMaxValue(mana);
}

@Override
public void setMaxHealth(float maxHealth) {
getHealth().setMaxValue(maxHealth);
}

@Override
public IReservable getMana() {
return mana;
Expand All @@ -288,12 +273,7 @@ public void setMana(IReservable mana) {
public IReservable getHealth() {
return health;
}

@Override
public void setHealth(float maxHealth) {
getHealth().setValue(maxHealth);
}


@Override
public void setHealth(IReservable health) {
this.health = health;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,26 +191,6 @@ public void setProperty(int index, float value) {

}

@Override
public double getMaxMana() {
return 0;
}

@Override
public void setMaxMana(float mana) {

}

@Override
public void setMaxHealth(float maxHealth) {

}

@Override
public void setHealth(float mana) {

}

@Override
public IReservable getMana() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import co.aikar.commands.annotation.Optional;
import co.aikar.commands.annotation.*;
import co.aikar.commands.bukkit.contexts.OnlinePlayer;
import com.google.inject.Injector;
import cz.neumimto.rpg.api.Rpg;
import cz.neumimto.rpg.api.damage.DamageService;
import cz.neumimto.rpg.api.effects.EffectService;
import cz.neumimto.rpg.api.effects.IGlobalEffect;
import cz.neumimto.rpg.api.entity.EntityService;
import cz.neumimto.rpg.api.entity.PropertyService;
Expand All @@ -18,14 +20,17 @@
import cz.neumimto.rpg.api.items.ItemClass;
import cz.neumimto.rpg.api.items.RpgItemType;
import cz.neumimto.rpg.api.logging.Log;
import cz.neumimto.rpg.api.persistance.model.CharacterBase;
import cz.neumimto.rpg.api.scripting.IScriptEngine;
import cz.neumimto.rpg.api.skills.ISkill;
import cz.neumimto.rpg.api.utils.ActionResult;
import cz.neumimto.rpg.common.commands.AdminCommandFacade;
import cz.neumimto.rpg.common.commands.CommandProcessingException;
import cz.neumimto.rpg.common.commands.InfoCommands;
import cz.neumimto.rpg.common.commands.OnlineOtherPlayer;
import cz.neumimto.rpg.spigot.entities.players.ISpigotCharacter;
import cz.neumimto.rpg.common.persistance.dao.ClassDefinitionDao;
import cz.neumimto.rpg.spigot.inventory.SpigotItemService;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
Expand All @@ -39,6 +44,8 @@
import java.util.*;
import java.util.function.Function;

import static cz.neumimto.rpg.api.logging.Log.info;

@Singleton
@CommandAlias("nadmin|na")
@CommandPermission("ntrpg.admin")
Expand Down Expand Up @@ -68,6 +75,12 @@ public class SpigotAdminCommands extends BaseCommand {
@Inject
private CharacterService characterService;

@Inject
private Injector injector;

@Inject
private EffectService effectService;

@Subcommand("class add")
public void addCharacterClass(CommandSender commandSender, OnlineOtherPlayer player, ClassDefinition classDefinition) {
IActiveCharacter character = player.character;
Expand All @@ -93,7 +106,7 @@ public void addSkillPointsCommand(CommandSender commandSender, OnlineOtherPlayer
if (classByName == null) {
throw new CommandException("Player " + character.getPlayerAccountName() + " character " + character.getName() + " do not have class " + characterClass.getName());
}
characterService.characterAddSkillPoints(character,characterClass, amount);
characterService.characterAddSkillPoints(character, characterClass, amount);

}

Expand Down Expand Up @@ -155,7 +168,7 @@ public void addClassToCharacterCommand(CommandSender executor, OnlineOtherPlayer
}

@Subcommand("add-unique-skillpoint")
public void addUniqueSkillpoint(CommandSender executor, OnlineOtherPlayer target, String classType, String sourceKey) {
public void addUniqueSkillpoint(CommandSender executor, OnlineOtherPlayer target, String classType, String sourceKey) {
IActiveCharacter character = target.character;
if (character.isStub()) {
throw new IllegalStateException("Stub character");
Expand All @@ -168,13 +181,13 @@ public void inspectPropertyCommand(CommandSender executor, OnlinePlayer target,
try {
int idByName = propertyService.getIdByName(property);
IActiveCharacter character = characterService.getCharacter(target.player.getUniqueId());
executor.sendMessage(ChatColor.GOLD +"==================");
executor.sendMessage(ChatColor.GREEN + property);
executor.sendMessage(ChatColor.GOLD + "==================");
executor.sendMessage(ChatColor.GREEN + property);

executor.sendMessage(ChatColor.GOLD + "Value" + ChatColor.WHITE + "/" +
ChatColor.AQUA + "Effective Value" + ChatColor.WHITE + "/" +
ChatColor.GRAY + "Cap" +
ChatColor.DARK_GRAY+ " .##");
ChatColor.DARK_GRAY + " .##");

NumberFormat formatter = new DecimalFormat("#0.00");
executor.sendMessage(ChatColor.GOLD + formatter.format(character.getProperty(idByName)) + ChatColor.WHITE + "/" +
Expand Down Expand Up @@ -230,7 +243,7 @@ public void inspectItemDamageCommand(CommandSender executor, OnlinePlayer oplaye


IActiveCharacter character = characterService.getCharacter(player.getUniqueId());
executor.sendMessage(ChatColor.RED + "Damage: "+ damageService.getCharacterItemDamage(character, fromItemStack));
executor.sendMessage(ChatColor.RED + "Damage: " + damageService.getCharacterItemDamage(character, fromItemStack));
executor.sendMessage(ChatColor.RED + "Details: ");
executor.sendMessage(ChatColor.GRAY + " - From Item: " + character.getBaseWeaponDamage(fromItemStack));

Expand Down Expand Up @@ -266,6 +279,111 @@ public void inspectItemDamageCommand(CommandSender executor, OnlinePlayer oplaye
}
}

@Subcommand("reload")
public void reload(@Optional @Default("a") String arg) {
boolean reloadAll = arg.equalsIgnoreCase("a");
boolean reloadJs = reloadAll || arg.equalsIgnoreCase("js");
boolean reloadLocalizations = reloadAll || arg.equalsIgnoreCase("l");
boolean reloadItems = reloadAll || arg.equalsIgnoreCase("i");
boolean reloadSkills = reloadAll || arg.equalsIgnoreCase("s");
boolean reloadClasses = reloadAll || reloadItems || reloadSkills || arg.equalsIgnoreCase("c");

info("[RELOAD] Saving current state of players");
Set<CharacterBase> characterBases = new HashSet<>();
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
IActiveCharacter character = characterService.getCharacter(player.getUniqueId());
if (character.isStub()) {
continue;
}
characterBases.add(character.getCharacterBase());
}
for (CharacterBase characterBase : characterBases) {
Log.info("[RELOAD] saving character " + characterBase.getLastKnownPlayerName());
characterService.save(characterBase);
}

for (Player player : Bukkit.getServer().getOnlinePlayers()) {
IActiveCharacter character = characterService.getCharacter(player.getUniqueId());
if (character.isStub()) {
continue;
}
IActiveCharacter preloadCharacter = characterService.buildDummyChar(player.getUniqueId());
characterService.registerDummyChar(preloadCharacter);
}

if (reloadAll) {
info("[RELOAD] Reading Settings.conf file: ");
Rpg.get().reloadMainPluginConfig();
}

if (reloadLocalizations) {
info("[RELOAD] Reading localization files: ");
Locale locale = Locale.forLanguageTag(Rpg.get().getPluginConfig().LOCALE);
try {
Rpg.get().getResourceLoader().reloadLocalizations(locale);
} catch (Exception e) {
Log.error("Could not read localizations in locale " + locale.toString() + " - " + e.getMessage());
}
}

if (reloadAll) {
info("[RELOAD] Reading Entity conf files: ");
Rpg.get().getEntityService().reload();
}

if (reloadJs) {
info("[RELOAD] Scripts ");
IScriptEngine jsLoader = injector.getInstance(IScriptEngine.class);
jsLoader.initEngine();
jsLoader.reloadSkills();
}

if (reloadItems) {
info("[RELOAD] ItemGroups ");
Rpg.get().getItemService().reload();
Rpg.get().getInventoryService().reload();
}

if (reloadSkills) {
info("[RELOAD] Properties, Attributes, Skills");
Rpg.get().getSkillService().init();
Rpg.get().getPropertyService().reload();
}

if (reloadClasses) {
info("[RELOAD] Experiences");
Rpg.get().getExperienceService().reload();

ClassDefinitionDao build = injector.getInstance(ClassDefinitionDao.class);
try {
info("[RELOAD] Checking class files: ");
Rpg.get().getClassService().load();
info("[RELOAD] Class files ok");
} catch (Exception e) {
e.printStackTrace();
}
}

Log.info("[RELOAD] Purging effect caches");
effectService.purgeEffectCache();
effectService.stopEffectScheduler();

System.gc();

effectService.startEffectScheduler();

for (Player player : Bukkit.getServer().getOnlinePlayers()) {
List<CharacterBase> playersCharacters = characterService.getPlayersCharacters(player.getUniqueId());
if (playersCharacters.isEmpty()) {
continue;
}
CharacterBase max = playersCharacters.stream().max(Comparator.comparing(CharacterBase::getUpdated)).get();
IActiveCharacter activeCharacter = characterService.createActiveCharacter(player.getUniqueId(), max);
characterService.setActiveCharacter(player.getUniqueId(), activeCharacter);
characterService.assignPlayerToCharacter(player.getUniqueId());
}
}

private Function<ItemClass, List<String>> TO_TEXT = weaponClass -> {
List<String> list = new ArrayList<>();

Expand Down

0 comments on commit cb7303b

Please sign in to comment.