hardcore and vampirism commands were a mistake

This commit is contained in:
nossr50 2019-02-18 15:17:35 -08:00
parent 9f9b456b0a
commit 4bb513c2d1
11 changed files with 84 additions and 328 deletions

View File

@ -1,64 +0,0 @@
package com.gmail.nossr50.commands.hardcore;
import com.gmail.nossr50.config.MainConfig;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Permissions;
import org.bukkit.command.CommandSender;
public class HardcoreCommand extends HardcoreModeCommand {
@Override
protected boolean checkTogglePermissions(CommandSender sender) {
return Permissions.hardcoreToggle(sender);
}
@Override
protected boolean checkModifyPermissions(CommandSender sender) {
return Permissions.hardcoreModify(sender);
}
@Override
protected boolean checkEnabled(PrimarySkillType skill) {
if (skill == null) {
for (PrimarySkillType primarySkillType : PrimarySkillType.values()) {
if (!primarySkillType.getHardcoreStatLossEnabled()) {
return false;
}
}
return true;
}
return skill.getHardcoreStatLossEnabled();
}
@Override
protected void enable(PrimarySkillType skill) {
toggle(true, skill);
}
@Override
protected void disable(PrimarySkillType skill) {
toggle(false, skill);
}
@Override
protected void modify(CommandSender sender, double newPercentage) {
MainConfig.getInstance().setHardcoreDeathStatPenaltyPercentage(newPercentage);
sender.sendMessage(LocaleLoader.getString("Hardcore.DeathStatLoss.PercentageChanged", percent.format(newPercentage / 100.0D)));
}
private void toggle(boolean enable, PrimarySkillType skill) {
if (skill == null) {
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
primarySkillType.setHardcoreStatLossEnabled(enable);
}
}
else {
skill.setHardcoreStatLossEnabled(enable);
}
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Mode." + (enable ? "Enabled" : "Disabled"), LocaleLoader.getString("Hardcore.DeathStatLoss.Name"), (skill == null ? "all skills" : skill.getName())));
}
}

View File

@ -1,130 +0,0 @@
package com.gmail.nossr50.commands.hardcore;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.google.common.collect.ImmutableList;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.util.StringUtil;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
public abstract class HardcoreModeCommand implements TabExecutor {
protected final DecimalFormat percent = new DecimalFormat("##0.00%");
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 0:
if (!checkTogglePermissions(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (checkEnabled(null)) {
disable(null);
}
else {
enable(null);
}
return true;
case 1:
if (CommandUtils.shouldEnableToggle(args[0])) {
if (!Permissions.hardcoreToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
enable(null);
return true;
}
if (CommandUtils.shouldDisableToggle(args[0])) {
if (!Permissions.hardcoreToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
disable(null);
return true;
}
if (CommandUtils.isInvalidDouble(sender, args[0])) {
return true;
}
if (!Permissions.hardcoreModify(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
modify(sender, Double.parseDouble(args[0]));
return true;
case 2:
if (CommandUtils.isInvalidSkill(sender, args[0])) {
return true;
}
PrimarySkillType skill = PrimarySkillType.getSkill(args[0]);
if (!CommandUtils.isChildSkill(sender, skill)) {
return true;
}
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;
}
enable(skill);
return true;
}
return true;
default:
return false;
}
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
switch (args.length) {
case 1:
if (StringUtils.isDouble(args[0])) {
return ImmutableList.of();
}
return StringUtil.copyPartialMatches(args[0], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList<String>(CommandUtils.TRUE_FALSE_OPTIONS.size()));
default:
return ImmutableList.of();
}
}
protected abstract boolean checkTogglePermissions(CommandSender sender);
protected abstract boolean checkModifyPermissions(CommandSender sender);
protected abstract boolean checkEnabled(PrimarySkillType skill);
protected abstract void enable(PrimarySkillType skill);
protected abstract void disable(PrimarySkillType skill);
protected abstract void modify(CommandSender sender, double newPercentage);
}

View File

@ -1,64 +0,0 @@
package com.gmail.nossr50.commands.hardcore;
import com.gmail.nossr50.config.MainConfig;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Permissions;
import org.bukkit.command.CommandSender;
public class VampirismCommand extends HardcoreModeCommand {
@Override
protected boolean checkTogglePermissions(CommandSender sender) {
return Permissions.vampirismToggle(sender);
}
@Override
protected boolean checkModifyPermissions(CommandSender sender) {
return Permissions.vampirismModify(sender);
}
@Override
protected boolean checkEnabled(PrimarySkillType skill) {
if (skill == null) {
for (PrimarySkillType primarySkillType : PrimarySkillType.values()) {
if (!primarySkillType.getHardcoreVampirismEnabled()) {
return false;
}
}
return true;
}
return skill.getHardcoreVampirismEnabled();
}
@Override
protected void enable(PrimarySkillType skill) {
toggle(true, skill);
}
@Override
protected void disable(PrimarySkillType skill) {
toggle(false, skill);
}
@Override
protected void modify(CommandSender sender, double newPercentage) {
MainConfig.getInstance().setHardcoreVampirismStatLeechPercentage(newPercentage);
sender.sendMessage(LocaleLoader.getString("Hardcore.Vampirism.PercentageChanged", percent.format(newPercentage / 100.0D)));
}
private void toggle(boolean enable, PrimarySkillType skill) {
if (skill == null) {
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
primarySkillType.setHardcoreVampirismEnabled(enable);
}
}
else {
skill.setHardcoreVampirismEnabled(enable);
}
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Mode." + (enable ? "Enabled" : "Disabled"), LocaleLoader.getString("Hardcore.Vampirism.Name"), (skill == null ? "all skills" : skill)));
}
}

View File

@ -61,6 +61,8 @@ public abstract class Config implements VersionedConfig, Unload {
DIRECTORY_DATA_FOLDER = pathToParentFolder; //Data Folder for our plugin
FILE_RELATIVE_PATH = relativePath; //Relative path to config from a parent folder
registerUnload();
//Attempt IO Operations
try {
//Makes sure we have valid Files corresponding to this config
@ -77,8 +79,15 @@ public abstract class Config implements VersionedConfig, Unload {
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Registers with the config managers unloader
* The unloader runs when the plugin gets disabled which cleans up registries to make reloading safe
*/
private void registerUnload()
{
mcMMO.getConfigManager().registerUnloadable(this);
}
/**

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.config;
import com.gmail.nossr50.config.collectionconfigs.CollectionClassType;
import com.gmail.nossr50.config.collectionconfigs.MultiConfigContainer;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.config.party.ItemWeightConfig;
import com.gmail.nossr50.config.skills.alchemy.PotionConfig;
import com.gmail.nossr50.config.treasure.TreasureConfig;
import com.gmail.nossr50.skills.repair.repairables.Repairable;
@ -62,6 +63,7 @@ public final class ConfigManager {
private CoreSkillsConfig coreSkillsConfig;
private SoundConfig soundConfig;
private RankConfig rankConfig;
private ItemWeightConfig itemWeightConfig;
@ -102,6 +104,9 @@ public final class ConfigManager {
rankConfig = new RankConfig();
unloadables.add(rankConfig);
itemWeightConfig = new ItemWeightConfig();
unloadables.add(itemWeightConfig);
/*if (MainConfig.getInstance().getToolModsEnabled()) {
new ToolConfigManager();
}
@ -186,6 +191,16 @@ public final class ConfigManager {
unloadables.clear();
}
/**
* Registers an unloadable
* Unloadables call unload() on plugin disable to cleanup registries
*/
public void registerUnloadable(Unload unload)
{
if(!unloadables.contains(unload))
unloadables.add(unload);
}
/*
* GETTER BOILER PLATE
*/

View File

@ -6,6 +6,7 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.StringUtils;
public class CoreSkillsConfig extends Config {
public static final String ENABLED = "Enabled";
//private static CoreSkillsConfig instance;
public CoreSkillsConfig() {
@ -52,7 +53,7 @@ public class CoreSkillsConfig extends Config {
* @return true if subskill is enabled
*/
public boolean isSkillEnabled(AbstractSubSkill abstractSubSkill) {
return getBooleanValue(StringUtils.getCapitalized(abstractSubSkill.getPrimarySkill().toString()) + "." + abstractSubSkill.getConfigKeyName() + ".Enabled", true);
return getBooleanValue(StringUtils.getCapitalized(abstractSubSkill.getPrimarySkill().toString()), abstractSubSkill.getConfigKeyName(), ENABLED);
}
/**
@ -62,6 +63,6 @@ public class CoreSkillsConfig extends Config {
* @return true if enabled
*/
public boolean isPrimarySkillEnabled(PrimarySkillType primarySkillType) {
return getBooleanValue(StringUtils.getCapitalized(primarySkillType.toString()) + ".Enabled", true);
return getBooleanValue(StringUtils.getCapitalized(primarySkillType.toString()), ENABLED);
}
}

View File

@ -51,7 +51,7 @@ public class MainConfig extends ConfigValidated {
public static final String PLAYER_COOLDOWN = "Player_" + COOLDOWN;
public static final String LEVEL_UP = "LevelUp_";
public static final String SOUND = "Sound";
public static final String LEVEL_UP_SOUNDS = LEVEL_UP + SOUNDS;
public static final String LEVEL_UP_SOUNDS = "LevelUp_Sounds";
public static final String REFRESH_CHUNKS = "Refresh_Chunks";
public static final String MOB_HEALTHBAR = "Mob_Healthbar";
public static final String DISPLAY_TYPE = "Display_Type";
@ -688,11 +688,11 @@ public class MainConfig extends ConfigValidated {
}
public String getMySQLDatabaseName() {
return getStringIncludingInts(MY_SQL, DATABASE, NAME);
return getStringValue(MY_SQL, DATABASE, NAME);
}
public String getMySQLUserName() {
return getStringIncludingInts(MY_SQL, DATABASE, USER_NAME);
return getStringValue(MY_SQL, DATABASE, USER_NAME);
}
public int getMySQLServerPort() {
@ -704,7 +704,7 @@ public class MainConfig extends ConfigValidated {
}
public String getMySQLUserPassword() {
return getStringIncludingInts(MY_SQL, DATABASE, USER_PASSWORD);
return getStringValue(MY_SQL, DATABASE, USER_PASSWORD);
}
public int getMySQLMaxConnections(SQLDatabaseManager.PoolIdentifier identifier) {
@ -719,7 +719,8 @@ public class MainConfig extends ConfigValidated {
return getBooleanValue(MY_SQL, SERVER, SSL);
}
ssadprivate String getStringIncludingInts(String[] key) {
//TODO: Legit cannot tell what the point of this method was
/*ssadprivate String getStringIncludingInts(String[] key) {
String str = getStringValue(key);
if (str == null) {
@ -730,24 +731,24 @@ public class MainConfig extends ConfigValidated {
str = "No value set for '" + key + "'";
}
return str;
}
}*/
/* Hardcore Mode */
public boolean getHardcoreStatLossEnabled(PrimarySkillType primarySkillType) {
return getBooleanValue(HARDCORE, DEATH_STAT_LOSS, ENABLED, StringUtils.getCapitalized(primarySkillType.toString()));
}
public void setHardcoreStatLossEnabled(PrimarySkillType primarySkillType, boolean enabled) {
/*public void setHardcoreStatLossEnabled(PrimarySkillType primarySkillType, boolean enabled) {
config.set(HARDCORE, DEATH_STAT_LOSS, ENABLED, StringUtils.getCapitalized(primarySkillType.toString()), enabled);
}
}*/
public double getHardcoreDeathStatPenaltyPercentage() {
return getDoubleValue(HARDCORE, DEATH_STAT_LOSS, PENALTY_PERCENTAGE);
}
public void setHardcoreDeathStatPenaltyPercentage(double value) {
/*public void setHardcoreDeathStatPenaltyPercentage(double value) {
config.set(HARDCORE, DEATH_STAT_LOSS, PENALTY_PERCENTAGE, value);
}
}*/
public int getHardcoreDeathStatPenaltyLevelThreshold() {
return getIntValue(HARDCORE, DEATH_STAT_LOSS, LEVEL_THRESHOLD);
@ -757,17 +758,17 @@ public class MainConfig extends ConfigValidated {
return getBooleanValue(HARDCORE, VAMPIRISM, ENABLED, StringUtils.getCapitalized(primarySkillType.toString()));
}
public void setHardcoreVampirismEnabled(PrimarySkillType primarySkillType, boolean enabled) {
/*public void setHardcoreVampirismEnabled(PrimarySkillType primarySkillType, boolean enabled) {
config.set(HARDCORE, VAMPIRISM, ENABLED, StringUtils.getCapitalized(primarySkillType.toString()), enabled);
}
}*/
public double getHardcoreVampirismStatLeechPercentage() {
return getDoubleValue(HARDCORE, VAMPIRISM, LEECH_PERCENTAGE);
}
public void setHardcoreVampirismStatLeechPercentage(double value) {
/*public void setHardcoreVampirismStatLeechPercentage(double value) {
config.set(HARDCORE, VAMPIRISM, LEECH_PERCENTAGE, value);
}
}*/
public int getHardcoreVampirismLevelThreshold() {
return getIntValue(HARDCORE, VAMPIRISM, LEVEL_THRESHOLD);

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.config.party;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.MainConfig;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.StringUtils;
import org.bukkit.Material;
@ -8,29 +9,59 @@ import org.bukkit.Material;
import java.util.HashSet;
public class ItemWeightConfig extends Config {
public static final String ITEM_WEIGHTS = "Item_Weights";
public static final String DEFAULT = "Default";
public static final String PARTY_SHAREABLES = "Party_Shareables";
public static final String MISC_ITEMS = "Misc_Items";
private static ItemWeightConfig instance;
private ItemWeightConfig() {
public ItemWeightConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "itemweights.yml");
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "itemweights.yml");
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "itemweights.yml", true);
}
/**
* This grabs an instance of this config class from the Config Manager
* This method is deprecated and will be removed in the future
* @see mcMMO#getConfigManager()
* @return the instance of this config
* @deprecated Please use mcMMO.getConfigManager() to grab a specific config instead
*/
@Deprecated
public static ItemWeightConfig getInstance() {
return mcMMO.getConfigManager().getIte();
}
/**
* The version of this config
*
* @return
*/
@Override
public double getConfigVersion() {
return 1;
}
/*public static ItemWeightConfig getInstance() {
if (instance == null) {
instance = new ItemWeightConfig();
}
return instance;
}
}*/
public int getItemWeight(Material material) {
return getIntValue("Item_Weights." + StringUtils.getPrettyItemString(material).replace(" ", "_"), getIntValue("Item_Weights.Default"));
String[] keyPath = {ITEM_WEIGHTS, StringUtils.getPrettyItemString(material).replace(" ", "_")};
if(hasNode(keyPath))
return getIntValue(keyPath);
else
return getIntValue(ITEM_WEIGHTS, DEFAULT);
}
public HashSet<Material> getMiscItems() {
HashSet<Material> miscItems = new HashSet<Material>();
for (String item : getStringValueList("Party_Shareables.Misc_Items")) {
for (String item : getStringValueList(PARTY_SHAREABLES, MISC_ITEMS)) {
Material material = Material.getMaterial(item.toUpperCase());
if (material != null) {

View File

@ -158,17 +158,17 @@ public enum PrimarySkillType {
return MainConfig.getInstance().getHardcoreStatLossEnabled(this);
}
public void setHardcoreStatLossEnabled(boolean enable) {
/*public void setHardcoreStatLossEnabled(boolean enable) {
MainConfig.getInstance().setHardcoreStatLossEnabled(this, enable);
}
}*/
public boolean getHardcoreVampirismEnabled() {
return MainConfig.getInstance().getHardcoreVampirismEnabled(this);
}
public void setHardcoreVampirismEnabled(boolean enable) {
/*public void setHardcoreVampirismEnabled(boolean enable) {
MainConfig.getInstance().setHardcoreVampirismEnabled(this, enable);
}
}*/
public ToolType getTool() {
return tool;

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.party;
import com.gmail.nossr50.config.MainConfig;
import com.gmail.nossr50.config.party.ItemWeightConfig;
import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.experience.XPGainSource;
import com.gmail.nossr50.datatypes.party.ItemShareType;

View File

@ -145,14 +145,6 @@ commands:
mcpurge:
description: Purge users with 0 powerlevel and/or who haven't connected in several months from the server DB.
permission: mcmmo.commands.mcpurge
hardcore:
aliases: [mchardcore]
description: Modify the mcMMO hardcore percentage or toggle hardcore mode on/off
permission: mcmmo.commands.hardcore
vampirism:
aliases: [mcvampirism]
description: Modify the mcMMO vampirism percentage or toggle vampirism mode on/off
permission: mcmmo.commands.vampirism
mcnotify:
aliases: [notify]
description: Toggle mcMMO abilities chat display notifications on/off
@ -787,7 +779,6 @@ permissions:
mcmmo.commands.addxp: true
mcmmo.commands.addxp.others: true
mcmmo.commands.defaults: true
mcmmo.commands.hardcore.all: true
mcmmo.commands.inspect.far: true
mcmmo.commands.inspect.hidden: true
mcmmo.commands.inspect.offline: true
@ -808,7 +799,6 @@ permissions:
mcmmo.commands.mmoshowdb: true
mcmmo.commands.ptp.world.all: true
mcmmo.commands.skillreset.all: true
mcmmo.commands.vampirism.all: true
mcmmo.commands.xprate.all: true
mcmmo.commands.acrobatics:
description: Allows access to the acrobatics command
@ -830,23 +820,6 @@ permissions:
description: Allows access to the excavation command
mcmmo.commands.fishing:
description: Allows access to the fishing command
mcmmo.commands.hardcore.*:
default: false
description: Implies access to all mcmmo.commands.hardcore permissions
children:
mcmmo.commands.hardcore.all: true
mcmmo.commands.hardcore.all:
description: Implies access to all mcmmo.commands.hardcore permissions
children:
mcmmo.commands.hardcore: true
mcmmo.commands.hardcore.modify: true
mcmmo.commands.hardcore.toggle: true
mcmmo.commands.hardcore:
description: Allows access to the hardcore command
mcmmo.commands.hardcore.modify:
description: Allows access to the hardcore command to modify the hardcore rate
mcmmo.commands.hardcore.toggle:
description: Allows access to the hardcore command to toggle hardcore on/off
mcmmo.commands.herbalism:
description: Allows access to the herbalism command
mcmmo.commands.inspect.*:
@ -1243,23 +1216,6 @@ permissions:
description: Allows access to the taming command
mcmmo.commands.unarmed:
description: Allows access to the unarmed command
mcmmo.commands.vampirism.*:
default: false
description: Implies access to all mcmmo.commands.vampirism permissions
children:
mcmmo.commands.vampirism.all: true
mcmmo.commands.vampirism.all:
description: Implies access to all mcmmo.commands.vampirism permissions
children:
mcmmo.commands.vampirism: true
mcmmo.commands.vampirism.modify: true
mcmmo.commands.vampirism.toggle: true
mcmmo.commands.vampirism:
description: Allows access to the vampirism command
mcmmo.commands.vampirism.modify:
description: Allows access to the vampirism command to modify the vampirism rate
mcmmo.commands.vampirism.toggle:
description: Allows access to the vampirism command to toggle vampirism on/off
mcmmo.commands.woodcutting:
description: Allows access to the woodcutting command
mcmmo.commands.xprate.*: