mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 14:46:46 +01:00
Cleanup & remove code duplication.
This commit is contained in:
parent
956bf2d763
commit
23983422e0
@ -4,7 +4,6 @@ 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.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 {
|
||||||
@ -21,39 +20,26 @@ public class HardcoreCommand extends HardcoreModeCommand {
|
|||||||
@Override
|
@Override
|
||||||
protected boolean checkEnabled(String skill) {
|
protected boolean checkEnabled(String skill) {
|
||||||
if (skill.equalsIgnoreCase("ALL")) {
|
if (skill.equalsIgnoreCase("ALL")) {
|
||||||
return !HardcoreManager.getHardcoreStatLossDisabled();
|
for (SkillType skillType : SkillType.values()) {
|
||||||
}
|
if (!skillType.getHardcoreStatLossEnabled()) {
|
||||||
else {
|
return false;
|
||||||
return SkillType.getSkill(skill).getHardcoreStatLossEnabled();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return SkillType.getSkill(skill).getHardcoreStatLossEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void enable(String skill) {
|
protected void enable(String skill) {
|
||||||
if (skill.equalsIgnoreCase("ALL")) {
|
toggle(true);
|
||||||
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.Mode.Enabled", LocaleLoader.getString("Hardcore.DeathStatLoss.Name"), skill));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void disable(String skill) {
|
protected void disable(String skill) {
|
||||||
if (skill.equalsIgnoreCase("ALL")) {
|
toggle(false);
|
||||||
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.Mode.Disabled", LocaleLoader.getString("Hardcore.DeathStatLoss.Name"), skill));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -61,4 +47,17 @@ public class HardcoreCommand extends HardcoreModeCommand {
|
|||||||
Config.getInstance().setHardcoreDeathStatPenaltyPercentage(newPercent);
|
Config.getInstance().setHardcoreDeathStatPenaltyPercentage(newPercent);
|
||||||
sender.sendMessage(LocaleLoader.getString("Hardcore.DeathStatLoss.PercentageChanged", percent.format(newPercent / 100D)));
|
sender.sendMessage(LocaleLoader.getString("Hardcore.DeathStatLoss.PercentageChanged", percent.format(newPercent / 100D)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void toggle(boolean enable) {
|
||||||
|
if (skill.equalsIgnoreCase("ALL")) {
|
||||||
|
for (SkillType skillType : SkillType.nonChildSkills()) {
|
||||||
|
Config.getInstance().setHardcoreStatLossEnabled(skillType, enable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Config.getInstance().setHardcoreStatLossEnabled(SkillType.getSkill(skill), enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Mode." + (enable ? "Enabled" : "Disabled"), LocaleLoader.getString("Hardcore.DeathStatLoss.Name"), skill));
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,7 +4,6 @@ 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.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 {
|
||||||
@ -21,39 +20,26 @@ public class VampirismCommand extends HardcoreModeCommand {
|
|||||||
@Override
|
@Override
|
||||||
protected boolean checkEnabled(String skill) {
|
protected boolean checkEnabled(String skill) {
|
||||||
if (skill.equalsIgnoreCase("ALL")) {
|
if (skill.equalsIgnoreCase("ALL")) {
|
||||||
return !HardcoreManager.getHardcoreVampirismDisabled();
|
for (SkillType skillType : SkillType.values()) {
|
||||||
}
|
if (!skillType.getHardcoreVampirismEnabled()) {
|
||||||
else {
|
return false;
|
||||||
return SkillType.getSkill(skill).getHardcoreVampirismEnabled();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return SkillType.getSkill(skill).getHardcoreVampirismEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void enable(String skill) {
|
protected void enable(String skill) {
|
||||||
if (skill.equalsIgnoreCase("ALL")) {
|
toggle(true);
|
||||||
for (SkillType skillType : SkillType.nonChildSkills()) {
|
|
||||||
Config.getInstance().setHardcoreVampirismEnabled(skillType, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Config.getInstance().setHardcoreVampirismEnabled(SkillType.getSkill(skill), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Mode.Enabled", LocaleLoader.getString("Hardcore.Vampirism.Name"), skill));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void disable(String skill) {
|
protected void disable(String skill) {
|
||||||
if (skill.equalsIgnoreCase("ALL")) {
|
toggle(false);
|
||||||
for (SkillType skillType : SkillType.nonChildSkills()) {
|
|
||||||
Config.getInstance().setHardcoreVampirismEnabled(skillType, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Config.getInstance().setHardcoreVampirismEnabled(SkillType.getSkill(skill), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Mode.Disabled", LocaleLoader.getString("Hardcore.Vampirism.Name"), skill));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -61,4 +47,17 @@ public class VampirismCommand extends HardcoreModeCommand {
|
|||||||
Config.getInstance().setHardcoreVampirismStatLeechPercentage(newPercent);
|
Config.getInstance().setHardcoreVampirismStatLeechPercentage(newPercent);
|
||||||
sender.sendMessage(LocaleLoader.getString("Hardcore.Vampirism.PercentageChanged", percent.format(newPercent / 100D)));
|
sender.sendMessage(LocaleLoader.getString("Hardcore.Vampirism.PercentageChanged", percent.format(newPercent / 100D)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void toggle(boolean enabled) {
|
||||||
|
if (skill.equalsIgnoreCase("ALL")) {
|
||||||
|
for (SkillType skillType : SkillType.nonChildSkills()) {
|
||||||
|
Config.getInstance().setHardcoreVampirismEnabled(skillType, enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Config.getInstance().setHardcoreVampirismEnabled(SkillType.getSkill(skill), enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Mode." + (enabled ? "Enabled" : "Disabled"), LocaleLoader.getString("Hardcore.Vampirism.Name"), skill));
|
||||||
|
}
|
||||||
}
|
}
|
@ -107,24 +107,6 @@ public final class HardcoreManager {
|
|||||||
return enabled;
|
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
|
* Check if Hardcore Vampirism is enabled for one or more skill types
|
||||||
*
|
*
|
||||||
@ -142,22 +124,4 @@ public final class HardcoreManager {
|
|||||||
|
|
||||||
return enabled;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -43,25 +43,30 @@ 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 (!HardcoreManager.getHardcoreStatLossEnabled() && !HardcoreManager.getHardcoreVampirismEnabled()) {
|
boolean deathStatLossEnabled = HardcoreManager.getHardcoreStatLossEnabled();
|
||||||
|
boolean vampirismEnabled = HardcoreManager.getHardcoreVampirismEnabled();
|
||||||
|
|
||||||
|
if (!deathStatLossEnabled && !vampirismEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String enabledModes;
|
String statLossInfo = "";
|
||||||
|
String vampirismInfo = "";
|
||||||
|
String seperator = "";
|
||||||
|
|
||||||
|
if (deathStatLossEnabled) {
|
||||||
|
statLossInfo = LocaleLoader.getString("Hardcore.DeathStatLoss.Name");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vampirismEnabled) {
|
||||||
|
vampirismInfo = LocaleLoader.getString("Hardcore.Vampirism.Name");
|
||||||
|
}
|
||||||
|
|
||||||
boolean deathStatLossEnabled = HardcoreManager.getHardcoreStatLossEnabled();
|
|
||||||
boolean vampirismEnabled = HardcoreManager.getHardcoreVampirismEnabled();
|
|
||||||
if (deathStatLossEnabled && vampirismEnabled) {
|
if (deathStatLossEnabled && vampirismEnabled) {
|
||||||
enabledModes = LocaleLoader.getString("Hardcore.DeathStatLoss.Name") + " & " + LocaleLoader.getString("Hardcore.Vampirism.Name");
|
seperator = " & ";
|
||||||
}
|
|
||||||
else if (deathStatLossEnabled) {
|
|
||||||
enabledModes = LocaleLoader.getString("Hardcore.DeathStatLoss.Name");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
enabledModes = LocaleLoader.getString("Hardcore.Vampirism.Name");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Enabled", enabledModes));
|
player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Enabled", statLossInfo + seperator + vampirismInfo));
|
||||||
|
|
||||||
if (deathStatLossEnabled) {
|
if (deathStatLossEnabled) {
|
||||||
player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.DeathStatLoss.Stats", Config.getInstance().getHardcoreDeathStatPenaltyPercentage()));
|
player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.DeathStatLoss.Stats", Config.getInstance().getHardcoreDeathStatPenaltyPercentage()));
|
||||||
|
Loading…
Reference in New Issue
Block a user