diff --git a/API/src/main/java/cz/neumimto/rpg/api/entity/players/IActiveCharacter.java b/API/src/main/java/cz/neumimto/rpg/api/entity/players/IActiveCharacter.java index 098beb4b3..392e1a019 100644 --- a/API/src/main/java/cz/neumimto/rpg/api/entity/players/IActiveCharacter.java +++ b/API/src/main/java/cz/neumimto/rpg/api/entity/players/IActiveCharacter.java @@ -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); 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 d6f8f88bf..a5f5bc3bb 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 @@ -26,7 +26,7 @@ public void cast(IActiveCharacter character, PlayerSkillContext info, SkillConte CommandData skillData = (CommandData) info.getSkillData(); List command = Collections.singletonList(skillData.getCommand()); Map args = new HashMap<>(); - args.put("{{player}}", character.getPlayerAccountName()); + args.put("player", character.getPlayerAccountName()); if (skillData.isConsole()) { Rpg.get().executeCommandBatch(args, command); @@ -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 diff --git a/Common/src/main/java/cz/neumimto/rpg/common/commands/AdminCommandFacade.java b/Common/src/main/java/cz/neumimto/rpg/common/commands/AdminCommandFacade.java index ac86c21e3..733ebbce7 100644 --- a/Common/src/main/java/cz/neumimto/rpg/common/commands/AdminCommandFacade.java +++ b/Common/src/main/java/cz/neumimto/rpg/common/commands/AdminCommandFacade.java @@ -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); diff --git a/Common/src/main/java/cz/neumimto/rpg/common/entity/players/ActiveCharacter.java b/Common/src/main/java/cz/neumimto/rpg/common/entity/players/ActiveCharacter.java index 8f2143ad1..32cf92405 100644 --- a/Common/src/main/java/cz/neumimto/rpg/common/entity/players/ActiveCharacter.java +++ b/Common/src/main/java/cz/neumimto/rpg/common/entity/players/ActiveCharacter.java @@ -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; @@ -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; diff --git a/Common/src/main/java/cz/neumimto/rpg/common/entity/players/PreloadCharacter.java b/Common/src/main/java/cz/neumimto/rpg/common/entity/players/PreloadCharacter.java index 972c917f0..34c81a103 100644 --- a/Common/src/main/java/cz/neumimto/rpg/common/entity/players/PreloadCharacter.java +++ b/Common/src/main/java/cz/neumimto/rpg/common/entity/players/PreloadCharacter.java @@ -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; diff --git a/Implementations/Spigot/14/src/main/java/cz/neumimto/rpg/spigot/commands/SpigotAdminCommands.java b/Implementations/Spigot/14/src/main/java/cz/neumimto/rpg/spigot/commands/SpigotAdminCommands.java index 0cd9291bd..8033c4765 100644 --- a/Implementations/Spigot/14/src/main/java/cz/neumimto/rpg/spigot/commands/SpigotAdminCommands.java +++ b/Implementations/Spigot/14/src/main/java/cz/neumimto/rpg/spigot/commands/SpigotAdminCommands.java @@ -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; @@ -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; @@ -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") @@ -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; @@ -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); } @@ -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"); @@ -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 + "/" + @@ -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)); @@ -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 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 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> TO_TEXT = weaponClass -> { List list = new ArrayList<>();