Hardcore mode can now be toggled for each skill individually

This commit is contained in:
TfT_02 2013-08-21 16:46:38 +02:00
parent ede0757d83
commit a6e7febf77
11 changed files with 235 additions and 52 deletions

View File

@ -26,6 +26,7 @@ Version 1.4.07-dev
= Fixed a bug where the Dodge DamageModifier wasn't being read from advanced.yml = 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 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. ! 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 ! Admin and Party chat prefixes are now customizable
! Changed the color of party leader names in Party chat ! 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) ! Moved all experience formula related settings from config.yml to experienceFormula.yml (This includes skill modifiers and curve modifiers)

View File

@ -2,22 +2,12 @@ package com.gmail.nossr50.commands.hardcore;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.HardcoreManager;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class HardcoreCommand extends HardcoreModeCommand { 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 @Override
protected boolean checkTogglePermissions() { protected boolean checkTogglePermissions() {
return Permissions.hardcoreToggle(sender); return Permissions.hardcoreToggle(sender);
@ -29,8 +19,41 @@ public class HardcoreCommand extends HardcoreModeCommand {
} }
@Override @Override
protected boolean checkEnabled() { protected boolean checkEnabled(String skill) {
return Config.getInstance().getHardcoreEnabled(); 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 @Override

View File

@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
import org.bukkit.util.StringUtil; import org.bukkit.util.StringUtil;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
@ -19,6 +20,7 @@ public abstract class HardcoreModeCommand implements TabExecutor {
protected CommandSender sender; protected CommandSender sender;
protected double newPercent; protected double newPercent;
protected DecimalFormat percent; protected DecimalFormat percent;
protected String skill;
public HardcoreModeCommand() { public HardcoreModeCommand() {
percent = new DecimalFormat("##0.00%"); percent = new DecimalFormat("##0.00%");
@ -35,11 +37,11 @@ public abstract class HardcoreModeCommand implements TabExecutor {
return true; return true;
} }
if (checkEnabled()) { if (checkEnabled("ALL")) {
disable(); disable("ALL");
} }
else { else {
enable(); enable("ALL");
} }
return true; return true;
@ -51,7 +53,7 @@ public abstract class HardcoreModeCommand implements TabExecutor {
return true; return true;
} }
enable(); enable("ALL");
return true; return true;
} }
@ -61,7 +63,7 @@ public abstract class HardcoreModeCommand implements TabExecutor {
return true; return true;
} }
disable(); disable("ALL");
return true; return true;
} }
@ -77,6 +79,36 @@ public abstract class HardcoreModeCommand implements TabExecutor {
modify(); modify();
return true; 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: default:
return false; return false;
} }
@ -98,9 +130,9 @@ public abstract class HardcoreModeCommand implements TabExecutor {
protected abstract boolean checkTogglePermissions(); protected abstract boolean checkTogglePermissions();
protected abstract boolean checkModifyPermissions(); protected abstract boolean checkModifyPermissions();
protected abstract boolean checkEnabled(); protected abstract boolean checkEnabled(String skill);
protected abstract void enable(); protected abstract void enable(String skill);
protected abstract void disable(); protected abstract void disable(String skill);
protected abstract void modify(); protected abstract void modify();
private boolean isInvalidPercentage(CommandSender sender, String value) { private boolean isInvalidPercentage(CommandSender sender, String value) {

View File

@ -2,7 +2,9 @@ package com.gmail.nossr50.commands.hardcore;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.HardcoreManager;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class VampirismCommand extends HardcoreModeCommand { public class VampirismCommand extends HardcoreModeCommand {
@ -17,20 +19,41 @@ public class VampirismCommand extends HardcoreModeCommand {
} }
@Override @Override
protected boolean checkEnabled() { protected boolean checkEnabled(String skill) {
return Config.getInstance().getHardcoreVampirismEnabled(); if (skill.equalsIgnoreCase("ALL")) {
return !HardcoreManager.getHardcoreVampirismDisabled();
}
else {
return SkillType.getSkill(skill).getHardcoreVampirismEnabled();
}
} }
@Override @Override
protected void enable() { protected void enable(String skill) {
Config.getInstance().setHardcoreVampirismEnabled(true); if (skill.equalsIgnoreCase("ALL")) {
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Vampirism.Enabled")); 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 @Override
protected void disable() { protected void disable(String skill) {
Config.getInstance().setHardcoreVampirismEnabled(false); if (skill.equalsIgnoreCase("ALL")) {
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Vampirism.Disabled")); 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 @Override

View File

@ -77,11 +77,11 @@ public class Config extends AutoUpdateConfigLoader {
/* Hardcore Mode */ /* Hardcore Mode */
if (getHardcoreDeathStatPenaltyPercentage() < 1 || getHardcoreDeathStatPenaltyPercentage() > 100) { 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) { 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 */ /* Items */
@ -286,17 +286,17 @@ public class Config extends AutoUpdateConfigLoader {
} }
/* Hardcore Mode */ /* Hardcore Mode */
public boolean getHardcoreEnabled() { return config.getBoolean("Hardcore.Enabled", false); } public boolean getHardcoreStatLossEnabled(SkillType skillType) { return config.getBoolean("Hardcore.Death_Stat_Loss.Enabled." + StringUtils.getCapitalized(skillType.toString()), false); }
public void setHardcoreEnabled(boolean enabled) { config.set("Hardcore.Enabled", enabled); } 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 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 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 boolean getHardcoreVampirismEnabled(SkillType skillType) { return config.getBoolean("Hardcore.Vampirism.Enabled." + StringUtils.getCapitalized(skillType.toString()), false); }
public void setHardcoreVampirismStatLeechPercentage(double value) { config.set("Hardcore.Vampirism_Stat_Leech_Percentage", value); } 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 double getHardcoreVampirismStatLeechPercentage() { return config.getDouble("Hardcore.Vampirism.Leech_Percentage", 5.0); }
public void setHardcoreVampirismEnabled(boolean enabled) { config.set("Hardcore.Vampirism", enabled); } public void setHardcoreVampirismStatLeechPercentage(double value) { config.set("Hardcore.Vampirism.Leech_Percentage", value); }
/* SMP Mods */ /* SMP Mods */
public boolean getToolModsEnabled() { return config.getBoolean("Mods.Tool_Mods_Enabled", false); } public boolean getToolModsEnabled() { return config.getBoolean("Mods.Tool_Mods_Enabled", false); }

View File

@ -104,6 +104,14 @@ public enum SkillType {
return Config.getInstance().getDoubleDropsDisabled(this); return Config.getInstance().getDoubleDropsDisabled(this);
} }
public boolean getHardcoreStatLossEnabled() {
return Config.getInstance().getHardcoreStatLossEnabled(this);
}
public boolean getHardcoreVampirismEnabled() {
return Config.getInstance().getHardcoreVampirismEnabled(this);
}
public ToolType getTool() { public ToolType getTool() {
return tool; return tool;
} }

View File

@ -123,7 +123,7 @@ public class PlayerListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerDeathMonitor(PlayerDeathEvent event) { public void onPlayerDeathMonitor(PlayerDeathEvent event) {
if (!Config.getInstance().getHardcoreEnabled()) { if (!HardcoreManager.getHardcoreStatLossEnabled()) {
return; return;
} }
@ -135,7 +135,7 @@ public class PlayerListener implements Listener {
Player killer = killedPlayer.getKiller(); Player killer = killedPlayer.getKiller();
if (killer != null && Config.getInstance().getHardcoreVampirismEnabled()) { if (killer != null && HardcoreManager.getHardcoreVampirismEnabled()) {
HardcoreManager.invokeVampirism(killer, killedPlayer); HardcoreManager.invokeVampirism(killer, killedPlayer);
} }

View File

@ -88,4 +88,76 @@ public final class HardcoreManager {
victim.sendMessage(LocaleLoader.getString("Vampirism.Victim.Failure", killer.getName())); 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;
}
} }

View File

@ -43,8 +43,8 @@ public final class Motd {
* @param player Target player * @param player Target player
*/ */
public static void displayHardcoreSettings(Player player) { public static void displayHardcoreSettings(Player player) {
if (Config.getInstance().getHardcoreEnabled()) { if (HardcoreManager.getHardcoreStatLossEnabled()) {
if (Config.getInstance().getHardcoreVampirismEnabled()) { if (HardcoreManager.getHardcoreVampirismEnabled()) {
player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.VampireOn")); player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.VampireOn"));
player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", Config.getInstance().getHardcoreDeathStatPenaltyPercentage())); player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", Config.getInstance().getHardcoreDeathStatPenaltyPercentage()));
player.sendMessage(LocaleLoader.getString("MOTD.Vampire.Stats", Config.getInstance().getHardcoreVampirismStatLeechPercentage())); player.sendMessage(LocaleLoader.getString("MOTD.Vampire.Stats", Config.getInstance().getHardcoreVampirismStatLeechPercentage()));

View File

@ -90,10 +90,34 @@ MySQL:
# Settings for Hardcore mode # Settings for Hardcore mode
### ###
Hardcore: Hardcore:
Enabled: false Death_Stat_Loss:
Death_Stat_Loss_Penalty_Percentage: 75 Penalty_Percentage: 75
Vampirism: false Enabled:
Vampirism_Stat_Leech_Percentage: 5 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 # Settings for SMP Mods

View File

@ -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.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.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! 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.Disabled=[[GOLD]][mcMMO] Hardcore mode disabled. {0}
Hardcore.Enabled=[[GOLD]][mcMMO] Hardcore mode enabled. Hardcore.Enabled=[[GOLD]][mcMMO] Hardcore mode enabled. {0}
Hardcore.PercentageChanged=[[GOLD]][mcMMO] The stat loss percentage was changed to {0}. Hardcore.PercentageChanged=[[GOLD]][mcMMO] The stat loss percentage was changed to {0}.
Vampirism.Disabled=[[GOLD]][mcMMO] Vampirism mode disabled. Vampirism.Disabled=[[GOLD]][mcMMO] Vampirism mode disabled. {0}
Vampirism.Enabled=[[GOLD]][mcMMO] Vampirism mode enabled. Vampirism.Enabled=[[GOLD]][mcMMO] Vampirism mode enabled. {0}
Vampirism.PercentageChanged=[[GOLD]][mcMMO] The stat leech percentage was changed to {0}. Vampirism.PercentageChanged=[[GOLD]][mcMMO] The stat leech percentage was changed to {0}.
#SPOUT #SPOUT