mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-26 02:34:42 +02:00
Added '/hardcore' and '/vampirism' commands for toggling these modes on
or off, along with the necessary permissions nodes.
This commit is contained in:
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
@ -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"));
|
||||
}
|
||||
}
|
@ -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,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);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user