From a6e7febf7762195aaa5e219ad0f0cd5a0070ccf9 Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Wed, 21 Aug 2013 16:46:38 +0200 Subject: [PATCH] Hardcore mode can now be toggled for each skill individually --- Changelog.txt | 1 + .../commands/hardcore/HardcoreCommand.java | 51 +++++++++---- .../hardcore/HardcoreModeCommand.java | 48 ++++++++++--- .../commands/hardcore/VampirismCommand.java | 39 +++++++--- .../java/com/gmail/nossr50/config/Config.java | 20 +++--- .../nossr50/datatypes/skills/SkillType.java | 8 +++ .../nossr50/listeners/PlayerListener.java | 4 +- .../gmail/nossr50/util/HardcoreManager.java | 72 +++++++++++++++++++ .../java/com/gmail/nossr50/util/Motd.java | 4 +- src/main/resources/config.yml | 32 +++++++-- .../resources/locale/locale_en_US.properties | 8 +-- 11 files changed, 235 insertions(+), 52 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index fd612b98c..022ffa832 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -26,6 +26,7 @@ Version 1.4.07-dev = Fixed a bug where the Dodge DamageModifier wasn't being read from advanced.yml ! Changed the way Repair hands out XP, also added config options to control Repair XP ! Changed Swords "Counter Attack" ability from passive to active. Blocking is required to activate. + ! Hardcore mode can now be toggled for each skill individually ! Admin and Party chat prefixes are now customizable ! Changed the color of party leader names in Party chat ! Moved all experience formula related settings from config.yml to experienceFormula.yml (This includes skill modifiers and curve modifiers) diff --git a/src/main/java/com/gmail/nossr50/commands/hardcore/HardcoreCommand.java b/src/main/java/com/gmail/nossr50/commands/hardcore/HardcoreCommand.java index ce4f53f2e..9e779b5c1 100644 --- a/src/main/java/com/gmail/nossr50/commands/hardcore/HardcoreCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/hardcore/HardcoreCommand.java @@ -2,22 +2,12 @@ package com.gmail.nossr50.commands.hardcore; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.util.HardcoreManager; import com.gmail.nossr50.util.Permissions; public class HardcoreCommand extends HardcoreModeCommand { - @Override - protected void disable() { - Config.getInstance().setHardcoreEnabled(false); - mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Disabled")); - } - - @Override - protected void enable() { - Config.getInstance().setHardcoreEnabled(true); - mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Enabled")); - } - @Override protected boolean checkTogglePermissions() { return Permissions.hardcoreToggle(sender); @@ -29,8 +19,41 @@ public class HardcoreCommand extends HardcoreModeCommand { } @Override - protected boolean checkEnabled() { - return Config.getInstance().getHardcoreEnabled(); + protected boolean checkEnabled(String skill) { + if (skill.equalsIgnoreCase("ALL")) { + return !HardcoreManager.getHardcoreStatLossDisabled(); + } + else { + return SkillType.getSkill(skill).getHardcoreStatLossEnabled(); + } + } + + @Override + protected void enable(String skill) { + if (skill.equalsIgnoreCase("ALL")) { + for (SkillType skillType : SkillType.nonChildSkills()) { + Config.getInstance().setHardcoreStatLossEnabled(skillType, true); + } + } + else { + Config.getInstance().setHardcoreStatLossEnabled(SkillType.getSkill(skill), true); + } + + mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Enabled", skill)); + } + + @Override + protected void disable(String skill) { + if (skill.equalsIgnoreCase("ALL")) { + for (SkillType skillType : SkillType.nonChildSkills()) { + Config.getInstance().setHardcoreStatLossEnabled(skillType, false); + } + } + else { + Config.getInstance().setHardcoreStatLossEnabled(SkillType.getSkill(skill), false); + } + + mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Disabled", skill)); } @Override diff --git a/src/main/java/com/gmail/nossr50/commands/hardcore/HardcoreModeCommand.java b/src/main/java/com/gmail/nossr50/commands/hardcore/HardcoreModeCommand.java index f564ca6c8..3c4518cd0 100644 --- a/src/main/java/com/gmail/nossr50/commands/hardcore/HardcoreModeCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/hardcore/HardcoreModeCommand.java @@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; import org.bukkit.util.StringUtil; +import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.commands.CommandUtils; @@ -19,6 +20,7 @@ public abstract class HardcoreModeCommand implements TabExecutor { protected CommandSender sender; protected double newPercent; protected DecimalFormat percent; + protected String skill; public HardcoreModeCommand() { percent = new DecimalFormat("##0.00%"); @@ -35,11 +37,11 @@ public abstract class HardcoreModeCommand implements TabExecutor { return true; } - if (checkEnabled()) { - disable(); + if (checkEnabled("ALL")) { + disable("ALL"); } else { - enable(); + enable("ALL"); } return true; @@ -51,7 +53,7 @@ public abstract class HardcoreModeCommand implements TabExecutor { return true; } - enable(); + enable("ALL"); return true; } @@ -61,7 +63,7 @@ public abstract class HardcoreModeCommand implements TabExecutor { return true; } - disable(); + disable("ALL"); return true; } @@ -77,6 +79,36 @@ public abstract class HardcoreModeCommand implements TabExecutor { modify(); return true; + + case 2: + if (!args[0].equalsIgnoreCase("ALL") && CommandUtils.isChildSkill(sender, SkillType.getSkill(args[0]))) { + return true; + } + + skill = args[0]; + + if (CommandUtils.shouldEnableToggle(args[1])) { + if (!Permissions.hardcoreToggle(sender)) { + sender.sendMessage(command.getPermissionMessage()); + return true; + } + + enable(skill); + return true; + } + + if (CommandUtils.shouldDisableToggle(args[1])) { + if (!Permissions.hardcoreToggle(sender)) { + sender.sendMessage(command.getPermissionMessage()); + return true; + } + + disable(skill); + return true; + } + + return true; + default: return false; } @@ -98,9 +130,9 @@ public abstract class HardcoreModeCommand implements TabExecutor { protected abstract boolean checkTogglePermissions(); protected abstract boolean checkModifyPermissions(); - protected abstract boolean checkEnabled(); - protected abstract void enable(); - protected abstract void disable(); + protected abstract boolean checkEnabled(String skill); + protected abstract void enable(String skill); + protected abstract void disable(String skill); protected abstract void modify(); private boolean isInvalidPercentage(CommandSender sender, String value) { diff --git a/src/main/java/com/gmail/nossr50/commands/hardcore/VampirismCommand.java b/src/main/java/com/gmail/nossr50/commands/hardcore/VampirismCommand.java index ad52f07a9..29f0cda1a 100644 --- a/src/main/java/com/gmail/nossr50/commands/hardcore/VampirismCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/hardcore/VampirismCommand.java @@ -2,7 +2,9 @@ package com.gmail.nossr50.commands.hardcore; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.util.HardcoreManager; import com.gmail.nossr50.util.Permissions; public class VampirismCommand extends HardcoreModeCommand { @@ -17,20 +19,41 @@ public class VampirismCommand extends HardcoreModeCommand { } @Override - protected boolean checkEnabled() { - return Config.getInstance().getHardcoreVampirismEnabled(); + protected boolean checkEnabled(String skill) { + if (skill.equalsIgnoreCase("ALL")) { + return !HardcoreManager.getHardcoreVampirismDisabled(); + } + else { + return SkillType.getSkill(skill).getHardcoreVampirismEnabled(); + } } @Override - protected void enable() { - Config.getInstance().setHardcoreVampirismEnabled(true); - mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Vampirism.Enabled")); + protected void enable(String skill) { + if (skill.equalsIgnoreCase("ALL")) { + for (SkillType skillType : SkillType.nonChildSkills()) { + Config.getInstance().setHardcoreVampirismEnabled(skillType, true); + } + } + else { + Config.getInstance().setHardcoreVampirismEnabled(SkillType.getSkill(skill), true); + } + + mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Vampirism.Enabled", skill)); } @Override - protected void disable() { - Config.getInstance().setHardcoreVampirismEnabled(false); - mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Vampirism.Disabled")); + protected void disable(String skill) { + if (skill.equalsIgnoreCase("ALL")) { + for (SkillType skillType : SkillType.nonChildSkills()) { + Config.getInstance().setHardcoreVampirismEnabled(skillType, false); + } + } + else { + Config.getInstance().setHardcoreVampirismEnabled(SkillType.getSkill(skill), false); + } + + mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Vampirism.Disabled", skill)); } @Override diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index 0b2e2dc29..e525d642c 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -77,11 +77,11 @@ public class Config extends AutoUpdateConfigLoader { /* Hardcore Mode */ if (getHardcoreDeathStatPenaltyPercentage() < 1 || getHardcoreDeathStatPenaltyPercentage() > 100) { - reason.add("Hardcore.Death_Stat_Loss_Penalty_Percentage only accepts values from 1 to 100!"); + reason.add("Hardcore.Death_Stat_Loss.Penalty_Percentage only accepts values from 1 to 100!"); } if (getHardcoreVampirismStatLeechPercentage() < 1 || getHardcoreVampirismStatLeechPercentage() > 100) { - reason.add("Hardcore.Death_Stat_Loss_Penalty_Percentage only accepts values from 1 to 100!"); + reason.add("Hardcore.Vampirism.Leech_Percentage only accepts values from 1 to 100!"); } /* Items */ @@ -286,17 +286,17 @@ public class Config extends AutoUpdateConfigLoader { } /* Hardcore Mode */ - public boolean getHardcoreEnabled() { return config.getBoolean("Hardcore.Enabled", false); } - public void setHardcoreEnabled(boolean enabled) { config.set("Hardcore.Enabled", enabled); } + public boolean getHardcoreStatLossEnabled(SkillType skillType) { return config.getBoolean("Hardcore.Death_Stat_Loss.Enabled." + StringUtils.getCapitalized(skillType.toString()), false); } + public void setHardcoreStatLossEnabled(SkillType skillType, boolean enabled) { config.set("Hardcore.Death_Stat_Loss.Enabled." + StringUtils.getCapitalized(skillType.toString()), enabled); } - public double getHardcoreDeathStatPenaltyPercentage() { return config.getDouble("Hardcore.Death_Stat_Loss_Penalty_Percentage", 75.0); } - public void setHardcoreDeathStatPenaltyPercentage(double value) { config.set("Hardcore.Death_Stat_Loss_Penalty_Percentage", value); } + public double getHardcoreDeathStatPenaltyPercentage() { return config.getDouble("Hardcore.Death_Stat_Loss.Penalty_Percentage", 75.0); } + public void setHardcoreDeathStatPenaltyPercentage(double value) { config.set("Hardcore.Death_Stat_Loss.Penalty_Percentage", value); } - public double getHardcoreVampirismStatLeechPercentage() { return config.getDouble("Hardcore.Vampirism_Stat_Leech_Percentage", 5.0); } - public void setHardcoreVampirismStatLeechPercentage(double value) { config.set("Hardcore.Vampirism_Stat_Leech_Percentage", value); } + public boolean getHardcoreVampirismEnabled(SkillType skillType) { return config.getBoolean("Hardcore.Vampirism.Enabled." + StringUtils.getCapitalized(skillType.toString()), false); } + public void setHardcoreVampirismEnabled(SkillType skillType, boolean enabled) { config.set("Hardcore.Vampirism.Enabled." + StringUtils.getCapitalized(skillType.toString()), enabled); } - public boolean getHardcoreVampirismEnabled() { return config.getBoolean("Hardcore.Vampirism", false); } - public void setHardcoreVampirismEnabled(boolean enabled) { config.set("Hardcore.Vampirism", enabled); } + public double getHardcoreVampirismStatLeechPercentage() { return config.getDouble("Hardcore.Vampirism.Leech_Percentage", 5.0); } + public void setHardcoreVampirismStatLeechPercentage(double value) { config.set("Hardcore.Vampirism.Leech_Percentage", value); } /* SMP Mods */ public boolean getToolModsEnabled() { return config.getBoolean("Mods.Tool_Mods_Enabled", false); } diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/SkillType.java b/src/main/java/com/gmail/nossr50/datatypes/skills/SkillType.java index 12e8bb74a..5525293a2 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/SkillType.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/SkillType.java @@ -104,6 +104,14 @@ public enum SkillType { return Config.getInstance().getDoubleDropsDisabled(this); } + public boolean getHardcoreStatLossEnabled() { + return Config.getInstance().getHardcoreStatLossEnabled(this); + } + + public boolean getHardcoreVampirismEnabled() { + return Config.getInstance().getHardcoreVampirismEnabled(this); + } + public ToolType getTool() { return tool; } diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index f0f99cd6a..161fe99aa 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -123,7 +123,7 @@ public class PlayerListener implements Listener { */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerDeathMonitor(PlayerDeathEvent event) { - if (!Config.getInstance().getHardcoreEnabled()) { + if (!HardcoreManager.getHardcoreStatLossEnabled()) { return; } @@ -135,7 +135,7 @@ public class PlayerListener implements Listener { Player killer = killedPlayer.getKiller(); - if (killer != null && Config.getInstance().getHardcoreVampirismEnabled()) { + if (killer != null && HardcoreManager.getHardcoreVampirismEnabled()) { HardcoreManager.invokeVampirism(killer, killedPlayer); } diff --git a/src/main/java/com/gmail/nossr50/util/HardcoreManager.java b/src/main/java/com/gmail/nossr50/util/HardcoreManager.java index 6fc3b3fa9..4d4479ef1 100644 --- a/src/main/java/com/gmail/nossr50/util/HardcoreManager.java +++ b/src/main/java/com/gmail/nossr50/util/HardcoreManager.java @@ -88,4 +88,76 @@ public final class HardcoreManager { victim.sendMessage(LocaleLoader.getString("Vampirism.Victim.Failure", killer.getName())); } } + + /** + * Check if Hardcore Stat Loss is enabled for one or more skill types + * + * @return true if Stat Loss is enabled for one or more skill types + */ + public static boolean getHardcoreStatLossEnabled() { + boolean enabled = false; + + for (SkillType skillType : SkillType.nonChildSkills()) { + if (skillType.getHardcoreStatLossEnabled()) { + enabled = true; + break; + } + } + + return enabled; + } + + /** + * Check if Hardcore Stat Loss is disabled for one or more skill types + * + * @return true if Stat Loss is disabled for one or more skill types + */ + public static boolean getHardcoreStatLossDisabled() { + boolean disabled = false; + + for (SkillType skillType : SkillType.nonChildSkills()) { + if (!skillType.getHardcoreStatLossEnabled()) { + disabled = true; + break; + } + } + + return disabled; + } + + /** + * Check if Hardcore Vampirism is enabled for one or more skill types + * + * @return true if Vampirism is enabled for one or more skill types + */ + public static boolean getHardcoreVampirismEnabled() { + boolean enabled = false; + + for (SkillType skillType : SkillType.nonChildSkills()) { + if (skillType.getHardcoreVampirismEnabled()) { + enabled = true; + break; + } + } + + return enabled; + } + + /** + * Check if Hardcore Vampirism is disabled for one or more skill types + * + * @return true if Vampirism is disabled for one or more skill types + */ + public static boolean getHardcoreVampirismDisabled() { + boolean disabled = false; + + for (SkillType skillType : SkillType.nonChildSkills()) { + if (!skillType.getHardcoreVampirismEnabled()) { + disabled = true; + break; + } + } + + return disabled; + } } diff --git a/src/main/java/com/gmail/nossr50/util/Motd.java b/src/main/java/com/gmail/nossr50/util/Motd.java index c09205c39..dfdb831a0 100644 --- a/src/main/java/com/gmail/nossr50/util/Motd.java +++ b/src/main/java/com/gmail/nossr50/util/Motd.java @@ -43,8 +43,8 @@ public final class Motd { * @param player Target player */ public static void displayHardcoreSettings(Player player) { - if (Config.getInstance().getHardcoreEnabled()) { - if (Config.getInstance().getHardcoreVampirismEnabled()) { + if (HardcoreManager.getHardcoreStatLossEnabled()) { + if (HardcoreManager.getHardcoreVampirismEnabled()) { player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.VampireOn")); player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", Config.getInstance().getHardcoreDeathStatPenaltyPercentage())); player.sendMessage(LocaleLoader.getString("MOTD.Vampire.Stats", Config.getInstance().getHardcoreVampirismStatLeechPercentage())); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 03af9d530..5eeacac87 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -90,10 +90,34 @@ MySQL: # Settings for Hardcore mode ### Hardcore: - Enabled: false - Death_Stat_Loss_Penalty_Percentage: 75 - Vampirism: false - Vampirism_Stat_Leech_Percentage: 5 + Death_Stat_Loss: + Penalty_Percentage: 75 + Enabled: + Acrobatics: false + Archery: false + Axes: false + Fishing: false + Herbalism: false + Mining: false + Repair: false + Swords: false + Taming: false + Unarmed: false + Woodcutting: false + Vampirism: + Leech_Percentage: 5 + Enabled: + Acrobatics: false + Archery: false + Axes: false + Fishing: false + Herbalism: false + Mining: false + Repair: false + Swords: false + Taming: false + Unarmed: false + Woodcutting: false # # Settings for SMP Mods diff --git a/src/main/resources/locale/locale_en_US.properties b/src/main/resources/locale/locale_en_US.properties index 49a80c756..93bc925a8 100644 --- a/src/main/resources/locale/locale_en_US.properties +++ b/src/main/resources/locale/locale_en_US.properties @@ -693,11 +693,11 @@ Vampirism.Killer.Failure=[[GOLD]][mcMMO] [[YELLOW]]{0}[[GRAY]] was too unskilled Vampirism.Killer.Success=[[GOLD]][mcMMO] [[DARK_AQUA]]You have stolen [[BLUE]]{0}[[DARK_AQUA]] levels from [[YELLOW]]{1}. Vampirism.Victim.Failure=[[GOLD]][mcMMO] [[YELLOW]]{0}[[GRAY]] was unable to steal knowledge from you! Vampirism.Victim.Success=[[GOLD]][mcMMO] [[YELLOW]]{0}[[DARK_RED]] has stolen [[BLUE]]{1}[[DARK_RED]] levels from you! -Hardcore.Disabled=[[GOLD]][mcMMO] Hardcore mode disabled. -Hardcore.Enabled=[[GOLD]][mcMMO] Hardcore mode enabled. +Hardcore.Disabled=[[GOLD]][mcMMO] Hardcore mode disabled. {0} +Hardcore.Enabled=[[GOLD]][mcMMO] Hardcore mode enabled. {0} Hardcore.PercentageChanged=[[GOLD]][mcMMO] The stat loss percentage was changed to {0}. -Vampirism.Disabled=[[GOLD]][mcMMO] Vampirism mode disabled. -Vampirism.Enabled=[[GOLD]][mcMMO] Vampirism mode enabled. +Vampirism.Disabled=[[GOLD]][mcMMO] Vampirism mode disabled. {0} +Vampirism.Enabled=[[GOLD]][mcMMO] Vampirism mode enabled. {0} Vampirism.PercentageChanged=[[GOLD]][mcMMO] The stat leech percentage was changed to {0}. #SPOUT