فهرست منبع

Added '/hardcore' and '/vampirism' commands for toggling these modes on
or off, along with the necessary permissions nodes.

GJ 12 سال پیش
والد
کامیت
0319e2cbff

+ 1 - 0
Changelog.txt

@@ -30,6 +30,7 @@ Version 1.4.00-dev
  + Added Shears, Buckets, Fishing Rods, Flint & Steel, Carrot Sticks, and Bows to the list of items that can be Salvaged
  + Added the "wait" music disc to the default fishing treasures
  + Added "Chinese (Taiwan)" localization files (zh_TW)
+ + Added '/hardcore' and '/vampirism' commands for toggling these modes on or off.
  = Fixed /ptp telporting the target to the player, rather than the other way around.
  = Fixed Impact reducing durability of non-armor equipped blocks
  = Fixed multiple commands not working properly on offline players

+ 22 - 0
src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java

@@ -10,10 +10,12 @@ import com.gmail.nossr50.chat.commands.AdminChatCommand;
 import com.gmail.nossr50.chat.commands.PartyChatCommand;
 import com.gmail.nossr50.commands.admin.AddlevelsCommand;
 import com.gmail.nossr50.commands.admin.AddxpCommand;
+import com.gmail.nossr50.commands.admin.HardcoreCommand;
 import com.gmail.nossr50.commands.admin.McgodCommand;
 import com.gmail.nossr50.commands.admin.McrefreshCommand;
 import com.gmail.nossr50.commands.admin.MmoeditCommand;
 import com.gmail.nossr50.commands.admin.SkillresetCommand;
+import com.gmail.nossr50.commands.admin.VampirismCommand;
 import com.gmail.nossr50.commands.admin.XprateCommand;
 import com.gmail.nossr50.commands.player.InspectCommand;
 import com.gmail.nossr50.commands.player.McabilityCommand;
@@ -335,4 +337,24 @@ public final class CommandRegistrationHelper {
         command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.1", "ptp", "<toggle|accept|acceptall>"));
         command.setExecutor(new PtpCommand());
     }
+
+    public static void registerHardcoreCommand() {
+        PluginCommand command = mcMMO.p.getCommand("hardcore");
+        command.setDescription(LocaleLoader.getString("Commands.Description.hardcore"));
+        command.setPermission("mcmmo.commands.hardcore;mcmmo.commands.hardcore.toggle;mcmmo.commands.hardcore.modify");
+        command.setPermissionMessage(permissionsMessage);
+        command.setUsage(LocaleLoader.getString("Commands.Usage.1", "hardcore", "[on|off]"));
+        command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.1", "hardcore", "<" + LocaleLoader.getString("Commands.Usage.Rate") + ">"));
+        command.setExecutor(new HardcoreCommand());
+    }
+
+    public static void registerVampirismCommand() {
+        PluginCommand command = mcMMO.p.getCommand("vampirism");
+        command.setDescription(LocaleLoader.getString("Commands.Description.vampirism"));
+        command.setPermission("mcmmo.commands.vampirism;mcmmo.commands.vampirism.toggle;mcmmo.commands.vampirism.modify");
+        command.setPermissionMessage(permissionsMessage);
+        command.setUsage(LocaleLoader.getString("Commands.Usage.1", "vampirism", "[on|off]"));
+        command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.1", "vampirism", "<" + LocaleLoader.getString("Commands.Usage.Rate") + ">"));
+        command.setExecutor(new VampirismCommand());
+    }
 }

+ 85 - 0
src/main/java/com/gmail/nossr50/commands/admin/HardcoreCommand.java

@@ -0,0 +1,85 @@
+package com.gmail.nossr50.commands.admin;
+
+import java.text.DecimalFormat;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+
+import com.gmail.nossr50.mcMMO;
+import com.gmail.nossr50.config.Config;
+import com.gmail.nossr50.locale.LocaleLoader;
+import com.gmail.nossr50.util.Misc;
+
+public class HardcoreCommand implements CommandExecutor{
+
+    @Override
+    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+        switch (args.length) {
+        case 0:
+            if (!sender.hasPermission("mcmmo.commands.hardcore.toggle")) {
+                sender.sendMessage(command.getPermissionMessage());
+                return true;
+            }
+
+            if (Config.getInstance().getHardcoreEnabled()) {
+                disableHardcore();
+            }
+            else {
+                enableHardcore();
+            }
+
+            return true;
+
+        case 1:
+            if (args[0].equalsIgnoreCase("on") || args[0].equalsIgnoreCase("true") || args[0].equalsIgnoreCase("enabled")) {
+                if (!sender.hasPermission("mcmmo.commands.hardcore.toggle")) {
+                    sender.sendMessage(command.getPermissionMessage());
+                    return true;
+                }
+
+                enableHardcore();
+                return true;
+            }
+
+            if (args[0].equalsIgnoreCase("off") || args[0].equalsIgnoreCase("false") || args[0].equalsIgnoreCase("disabled")) {
+                if (!sender.hasPermission("mcmmo.commands.hardcore.toggle")) {
+                    sender.sendMessage(command.getPermissionMessage());
+                    return true;
+                }
+
+                disableHardcore();
+                return true;
+            }
+
+            if (!Misc.isDouble(args[0])) {
+                return false;
+            }
+
+            if (!sender.hasPermission("mcmmo.commands.hardcore.modify")) {
+                sender.sendMessage(command.getPermissionMessage());
+                return true;
+            }
+
+            DecimalFormat percent = new DecimalFormat("##0.00%");
+            double newPercent = Misc.getDouble(args[0]);
+
+            Config.getInstance().setHardcoreDeathStatPenaltyPercentage(newPercent);
+            sender.sendMessage(LocaleLoader.getString("Hardcore.PercentageChanged", percent.format(newPercent / 100D)));
+            return true;
+
+        default:
+            return false;
+        }
+    }
+
+    private void disableHardcore() {
+        Config.getInstance().setHardcoreEnabled(false);
+        mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Disabled"));
+    }
+
+    private void enableHardcore() {
+        Config.getInstance().setHardcoreEnabled(true);
+        mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Hardcore.Enabled"));
+    }
+}

+ 90 - 0
src/main/java/com/gmail/nossr50/commands/admin/VampirismCommand.java

@@ -0,0 +1,90 @@
+package com.gmail.nossr50.commands.admin;
+
+import java.text.DecimalFormat;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+
+import com.gmail.nossr50.mcMMO;
+import com.gmail.nossr50.config.Config;
+import com.gmail.nossr50.locale.LocaleLoader;
+import com.gmail.nossr50.util.Misc;
+
+public class VampirismCommand implements CommandExecutor {
+
+    @Override
+    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+        if (!Config.getInstance().getHardcoreEnabled()) {
+            sender.sendMessage(LocaleLoader.getString("Hardcore.Disabled"));
+            return true;
+        }
+
+        switch (args.length) {
+        case 0:
+            if (!sender.hasPermission("mcmmo.commands.vampirism.toggle")) {
+                sender.sendMessage(command.getPermissionMessage());
+                return true;
+            }
+
+            if (Config.getInstance().getHardcoreVampirismEnabled()) {
+                disableVampirism();
+            }
+            else {
+                enableVampirism();
+            }
+
+            return true;
+
+        case 1:
+            if (args[0].equalsIgnoreCase("on") || args[0].equalsIgnoreCase("true") || args[0].equalsIgnoreCase("enabled")) {
+                if (!sender.hasPermission("mcmmo.commands.vampirism.toggle")) {
+                    sender.sendMessage(command.getPermissionMessage());
+                    return true;
+                }
+
+                enableVampirism();
+                return true;
+            }
+
+            if (args[0].equalsIgnoreCase("off") || args[0].equalsIgnoreCase("false") || args[0].equalsIgnoreCase("disabled")) {
+                if (!sender.hasPermission("mcmmo.commands.vampirism.toggle")) {
+                    sender.sendMessage(command.getPermissionMessage());
+                    return true;
+                }
+
+                disableVampirism();
+                return true;
+            }
+
+            if (!Misc.isDouble(args[0])) {
+                return false;
+            }
+
+            if (!sender.hasPermission("mcmmo.commands.vampirism.modify")) {
+                sender.sendMessage(command.getPermissionMessage());
+                return true;
+            }
+
+            DecimalFormat percent = new DecimalFormat("##0.00%");
+            double newPercent = Misc.getDouble(args[0]);
+
+            Config.getInstance().setHardcoreVampirismStatLeechPercentage(newPercent);
+            sender.sendMessage(LocaleLoader.getString("Vampirism.PercentageChanged", percent.format(newPercent / 100D)));
+            return true;
+
+        default:
+            return false;
+        }
+    }
+
+    private void disableVampirism() {
+        Config.getInstance().setHardcoreVampirismEnabled(false);
+        mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Vampirism.Disabled"));
+    }
+
+    private void enableVampirism() {
+        Config.getInstance().setHardcoreVampirismEnabled(true);
+        mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Vampirism.Enabled"));
+    }
+}

+ 9 - 2
src/main/java/com/gmail/nossr50/config/Config.java

@@ -70,9 +70,16 @@ public class Config extends ConfigLoader {
 
     /* Hardcore Mode */
     public boolean getHardcoreEnabled() { return config.getBoolean("Hardcore.Enabled", false); }
-    public double getHardcoreDeathStatPenaltyPercentage() { return config.getDouble("Hardcore.Death_Stat_Loss_Penalty_Percentage", 75); }
-    public double getHardcoreVampirismStatLeechPercentage() { return config.getDouble("Hardcore.Vampirism_Stat_Leech_Percentage", 5); }
+    public void setHardcoreEnabled(boolean enabled) { config.set("Hardcore.Enabled", 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 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() { return config.getBoolean("Hardcore.Vampirism", false); }
+    public void setHardcoreVampirismEnabled(boolean enabled) { config.set("Hardcore.Vampirism", enabled); }
 
     /* SMP Mods */
     public boolean getToolModsEnabled() { return config.getBoolean("Mods.Tool_Mods_Enabled", false); }

+ 6 - 1
src/main/java/com/gmail/nossr50/listeners/HardcoreListener.java

@@ -6,6 +6,7 @@ import org.bukkit.event.EventPriority;
 import org.bukkit.event.Listener;
 import org.bukkit.event.entity.PlayerDeathEvent;
 
+import com.gmail.nossr50.config.Config;
 import com.gmail.nossr50.util.Hardcore;
 import com.gmail.nossr50.util.Misc;
 import com.gmail.nossr50.util.Permissions;
@@ -18,6 +19,10 @@ public class HardcoreListener implements Listener {
      */
     @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
     public void onPlayerDeath(PlayerDeathEvent event) {
+        if (!Config.getInstance().getHardcoreEnabled()) {
+            return;
+        }
+
         Player player = event.getEntity();
 
         if (Misc.isNPCPlayer(player)) {
@@ -27,7 +32,7 @@ public class HardcoreListener implements Listener {
         if (!Permissions.hardcoremodeBypass(player)) {
             Player killer = player.getKiller();
 
-            if (killer != null && Hardcore.vampirismEnabled) {
+            if (killer != null && Config.getInstance().getHardcoreVampirismEnabled()) {
                 Hardcore.invokeVampirism(killer, player);
             }
 

+ 3 - 4
src/main/java/com/gmail/nossr50/mcMMO.java

@@ -260,10 +260,7 @@ public class mcMMO extends JavaPlugin {
         pluginManager.registerEvents(entityListener, this);
         pluginManager.registerEvents(inventoryListener, this);
         pluginManager.registerEvents(worldListener, this);
-
-        if (Config.getInstance().getHardcoreEnabled()) {
-            pluginManager.registerEvents(hardcoreListener, this);
-        }
+        pluginManager.registerEvents(hardcoreListener, this);
     }
 
     /**
@@ -297,6 +294,8 @@ public class mcMMO extends JavaPlugin {
         CommandRegistrationHelper.registerXprateCommand();
         CommandRegistrationHelper.registerMmoupdateCommand();
         CommandRegistrationHelper.registerSkillresetCommand();
+        CommandRegistrationHelper.registerHardcoreCommand();
+        CommandRegistrationHelper.registerVampirismCommand();
 
         // Spout commands
         CommandRegistrationHelper.registerXplockCommand();

+ 4 - 5
src/main/java/com/gmail/nossr50/util/Hardcore.java

@@ -8,14 +8,11 @@ import com.gmail.nossr50.locale.LocaleLoader;
 import com.gmail.nossr50.skills.utilities.SkillType;
 
 public final class Hardcore {
-    public static double statLossPercentage = Config.getInstance().getHardcoreDeathStatPenaltyPercentage();
-    public static double vampirismStatLeechPercentage = Config.getInstance().getHardcoreVampirismStatLeechPercentage();
-    public static boolean statLossEnabled = Config.getInstance().getHardcoreEnabled();
-    public static boolean vampirismEnabled = Config.getInstance().getHardcoreVampirismEnabled();
-
     private Hardcore() {}
 
     public static void invokeStatPenalty(Player player) {
+        double statLossPercentage = Config.getInstance().getHardcoreDeathStatPenaltyPercentage();
+
         if (statLossPercentage <= 0 || statLossPercentage > 100) {
             return;
         }
@@ -44,6 +41,8 @@ public final class Hardcore {
     }
 
     public static void invokeVampirism(Player killer, Player victim) {
+        double vampirismStatLeechPercentage = Config.getInstance().getHardcoreVampirismStatLeechPercentage();
+
         if (vampirismStatLeechPercentage <= 0 || vampirismStatLeechPercentage > 100) {
             return;
         }

+ 31 - 0
src/main/java/com/gmail/nossr50/util/Misc.java

@@ -166,6 +166,21 @@ public final class Misc {
 
         return 0;
     }
+
+    /**
+     * Gets the long represented by this string.
+     *
+     * @param string The string to parse
+     * @return the long represented by this string
+     */
+    public static double getDouble(String string) {
+        if (isDouble(string)) {
+            return Double.parseDouble(string);
+        }
+
+        return 0;
+    }
+
     /**
      * Checks to see if an entity is currently invincible.
      *
@@ -300,6 +315,22 @@ public final class Misc {
         }
     }
 
+    /**
+     * Determine if a string represents a Double
+     *
+     * @param string String to check
+     * @return true if the string is a Double, false otherwise
+     */
+    public static boolean isDouble(String string) {
+        try {
+            Double.parseDouble(string);
+            return true;
+        }
+        catch (NumberFormatException nFE) {
+            return false;
+        }
+    }
+
     /**
      * Drop items at a given location.
      *

+ 6 - 5
src/main/java/com/gmail/nossr50/util/Motd.java

@@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
 import org.bukkit.plugin.PluginDescriptionFile;
 
 import com.gmail.nossr50.mcMMO;
+import com.gmail.nossr50.config.Config;
 import com.gmail.nossr50.locale.LocaleLoader;
 import com.gmail.nossr50.skills.utilities.SkillType;
 
@@ -37,15 +38,15 @@ public final class Motd {
      * @param player Target player
      */
     public static void displayHardcoreSettings(Player player) {
-        if (Hardcore.statLossEnabled) {
-            if (Hardcore.vampirismEnabled) {
+        if (Config.getInstance().getHardcoreEnabled()) {
+            if (Config.getInstance().getHardcoreVampirismEnabled()) {
                 player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.VampireOn"));
-                player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", Hardcore.statLossPercentage));
-                player.sendMessage(LocaleLoader.getString("MOTD.Vampire.Stats", Hardcore.vampirismStatLeechPercentage));
+                player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", Config.getInstance().getHardcoreDeathStatPenaltyPercentage()));
+                player.sendMessage(LocaleLoader.getString("MOTD.Vampire.Stats", Config.getInstance().getHardcoreVampirismStatLeechPercentage()));
             }
             else {
                 player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.VampireOff"));
-                player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", Hardcore.statLossPercentage  ));
+                player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", Config.getInstance().getHardcoreDeathStatPenaltyPercentage()));
             }
         }
     }

+ 9 - 1
src/main/resources/locale/locale_en_US.properties

@@ -650,6 +650,12 @@ 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.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.PercentageChanged=[[GOLD]][mcMMO] The stat leech percentage was changed to {0}.
 
 #SPOUT
 Spout.Donate=[[YELLOW]][mcMMO] Donate!
@@ -695,6 +701,7 @@ Smelting.SkillName=SMELTING
 Commands.Description.addlevels=Add mcMMO levels to a user
 Commands.Description.adminchat=Toggle mcMMO admin chat on/off or send admin chat messages
 Commands.Description.addxp=Add mcMMO XP to a user
+Commands.Description.hardcore=Modify the mcMMO hardcore percentage or toggle hardcore mode on/off
 Commands.Description.inspect=View detailed mcMMO info on another player
 Commands.Description.mcability=Toggle mcMMO abilities being readied on right-click on/off
 Commands.Description.mcgod=Toggle mcMMO god-mode on/off
@@ -713,5 +720,6 @@ Commands.Description.partychat=Toggle mcMMO party chat on/off or send party chat
 Commands.Description.ptp=Teleport to an mcMMO party member
 Commands.Description.Skill=Display detailed mcMMO skill info for {0}
 Commands.Description.skillreset=Reset mcMMO levels for a user
+Commands.Description.vampirism=Modify the mcMMO vampirism percentage or toggle vampirism mode on/off
 Commands.Description.xplock=Lock your mcMMO XP bar to a specific mcMMO skill
-Commands.Description.xprate=Modify the mcMMO XP rate or start an mcMMO XP event
+Commands.Description.xprate=Modify the mcMMO XP rate or start an mcMMO XP event

+ 43 - 1
src/main/resources/plugin.yml

@@ -94,7 +94,13 @@ commands:
         aliases: [ac, a]
         description: Toggle Admin chat or send admin chat messages
     mcpurge:
-        description: Purge users with 0 powerlevel and/or who haven't connected in several months from the server DB.
+        description: Purge users with 0 powerlevel and/or who haven't connected in several months from the server DB.	
+    hardcore:
+        aliases: [mchardcore]	
+        description: Modify the mcMMO hardcore percentage or toggle hardcore mode on/off
+    vampirism:
+        aliases: [mcvampirism]	
+        description: Modify the mcMMO vampirism percentage or toggle vampirism mode on/off		
 permissions:
     mcmmo.*:
         default: false
@@ -587,6 +593,7 @@ 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.offline: true
             mcmmo.commands.mcability.others: true
@@ -599,6 +606,7 @@ permissions:
             mcmmo.commands.mmoedit.others: true
             mcmmo.commands.ptp.world.all: true
             mcmmo.commands.skillreset.all: true
+            mcmmo.commands.vampirism.all: true			
             mcmmo.commands.xprate.all: true
     mcmmo.commands.ability:
         default: false
@@ -623,6 +631,23 @@ 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.*:
@@ -945,6 +970,23 @@ 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.xplock.*: