mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-26 17:05:01 +00:00
A few more changes
- Cleans up /potion a tiny bit - Rewrites part of /moblimiter - Resolves FS-346 by cleaning up /setlever - Modernizes /opall a bit - Changes more components to use Adventure
This commit is contained in:
parent
2698cbf46d
commit
9064f4b1f2
@ -2,10 +2,8 @@ package me.totalfreedom.totalfreedommod;
|
|||||||
|
|
||||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
|
@ -2,9 +2,8 @@ package me.totalfreedom.totalfreedommod;
|
|||||||
|
|
||||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||||
import me.totalfreedom.totalfreedommod.util.FSync;
|
import net.kyori.adventure.text.Component;
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -70,17 +69,16 @@ public class AntiSpam extends FreedomService
|
|||||||
int time = count * minutes;
|
int time = count * minutes;
|
||||||
playerdata.setMuted(true, time);
|
playerdata.setMuted(true, time);
|
||||||
|
|
||||||
FSync.bcastMsg(String.format("%s has automatically been muted for %d minutes for spamming chat.",
|
server.broadcast(Component.text(player.getName()).append(Component.text(" has been automatically muted for "))
|
||||||
player.getName(),
|
.append(Component.text(time)).append(Component.text(" minutes for spamming chat."))
|
||||||
time),
|
.color(NamedTextColor.RED));
|
||||||
ChatColor.RED);
|
|
||||||
|
|
||||||
playerdata.resetMsgCount();
|
playerdata.resetMsgCount();
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
else if (playerdata.incrementAndGetMsgCount() > MSG_PER_CYCLE / 2)
|
else if (playerdata.incrementAndGetMsgCount() > MSG_PER_CYCLE / 2)
|
||||||
{
|
{
|
||||||
FUtil.playerMsg(player, "Please refrain from spamming chat.", ChatColor.GRAY);
|
player.sendMessage(Component.text("Please refrain from spamming chat.", NamedTextColor.GRAY));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +94,7 @@ public class AntiSpam extends FreedomService
|
|||||||
|
|
||||||
if (fPlayer.allCommandsBlocked())
|
if (fPlayer.allCommandsBlocked())
|
||||||
{
|
{
|
||||||
FUtil.playerMsg(player, "Your commands have been blocked by an admin.", ChatColor.RED);
|
player.sendMessage(Component.text("Your commands have been blocked by an admin.", NamedTextColor.RED));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -108,7 +106,9 @@ public class AntiSpam extends FreedomService
|
|||||||
|
|
||||||
if (fPlayer.incrementAndGetMsgCount() > MSG_PER_CYCLE)
|
if (fPlayer.incrementAndGetMsgCount() > MSG_PER_CYCLE)
|
||||||
{
|
{
|
||||||
FUtil.bcastMsg(player.getName() + " was automatically kicked for spamming commands.", ChatColor.RED);
|
server.broadcast(Component.text(player.getName())
|
||||||
|
.append(Component.text(" was automatically kicked for spamming commands."))
|
||||||
|
.color(NamedTextColor.RED));
|
||||||
plugin.ae.autoEject(player, "Kicked for spamming commands.");
|
plugin.ae.autoEject(player, "Kicked for spamming commands.");
|
||||||
|
|
||||||
fPlayer.resetMsgCount();
|
fPlayer.resetMsgCount();
|
||||||
|
@ -4,6 +4,8 @@ import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
|||||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
import me.totalfreedom.totalfreedommod.util.FSync;
|
import me.totalfreedom.totalfreedommod.util.FSync;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -42,7 +44,7 @@ public class Muter extends FreedomService
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FSync.playerMsg(event.getPlayer(), ChatColor.RED + "You are muted.");
|
player.sendMessage(Component.text("You are muted.", NamedTextColor.RED));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +82,7 @@ public class Muter extends FreedomService
|
|||||||
|
|
||||||
if (ConfigEntry.MUTED_BLOCKED_COMMANDS.getStringList().contains(cmdName))
|
if (ConfigEntry.MUTED_BLOCKED_COMMANDS.getStringList().contains(cmdName))
|
||||||
{
|
{
|
||||||
player.sendMessage(ChatColor.RED + "That command is blocked while you are muted.");
|
player.sendMessage(Component.text("That command is blocked while you are muted.", NamedTextColor.RED));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,15 @@ package me.totalfreedom.totalfreedommod.command;
|
|||||||
import me.totalfreedom.totalfreedommod.GameRuleHandler;
|
import me.totalfreedom.totalfreedommod.GameRuleHandler;
|
||||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
|
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Control mob limiting parameters.", usage = "/<command> <on|off|setmax <count>|dragon|giant|ghast|slime>")
|
@CommandParameters(description = "Control mob limiting parameters.", usage = "/<command> <on | off | setmax <count> | dragon | giant | ghast | slime>")
|
||||||
public class Command_moblimiter extends FreedomCommand
|
public class Command_moblimiter extends FreedomCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
@ -20,45 +20,29 @@ public class Command_moblimiter extends FreedomCommand
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("on"))
|
switch (args[0].toLowerCase())
|
||||||
{
|
{
|
||||||
ConfigEntry.MOB_LIMITER_ENABLED.setBoolean(true);
|
case "on" -> ConfigEntry.MOB_LIMITER_ENABLED.setBoolean(true);
|
||||||
}
|
case "off" -> ConfigEntry.MOB_LIMITER_ENABLED.setBoolean(false);
|
||||||
else if (args[0].equalsIgnoreCase("off"))
|
case "dragon" -> ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean());
|
||||||
{
|
case "giant" -> ConfigEntry.MOB_LIMITER_DISABLE_GIANT.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean());
|
||||||
ConfigEntry.MOB_LIMITER_ENABLED.setBoolean(false);
|
case "slime" -> ConfigEntry.MOB_LIMITER_DISABLE_SLIME.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean());
|
||||||
}
|
case "ghast" -> ConfigEntry.MOB_LIMITER_DISABLE_GHAST.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean());
|
||||||
else if (args[0].equalsIgnoreCase("dragon"))
|
case "setmax" ->
|
||||||
{
|
|
||||||
ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean());
|
|
||||||
}
|
|
||||||
else if (args[0].equalsIgnoreCase("giant"))
|
|
||||||
{
|
|
||||||
ConfigEntry.MOB_LIMITER_DISABLE_GIANT.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean());
|
|
||||||
}
|
|
||||||
else if (args[0].equalsIgnoreCase("slime"))
|
|
||||||
{
|
|
||||||
ConfigEntry.MOB_LIMITER_DISABLE_SLIME.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean());
|
|
||||||
}
|
|
||||||
else if (args[0].equalsIgnoreCase("ghast"))
|
|
||||||
{
|
|
||||||
ConfigEntry.MOB_LIMITER_DISABLE_GHAST.setBoolean(!ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (args.length < 2)
|
|
||||||
{
|
{
|
||||||
return false;
|
if (args.length < 2)
|
||||||
}
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("setmax"))
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ConfigEntry.MOB_LIMITER_MAX.setInteger(Math.max(0, Math.min(2000, Integer.parseInt(args[1]))));
|
ConfigEntry.MOB_LIMITER_MAX.setInteger(Math.max(0, Math.min(2000, Integer.parseInt(args[1]))));
|
||||||
}
|
}
|
||||||
catch (NumberFormatException ignored)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
msg("Invalid number: " + args[1], ChatColor.RED);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,7 +62,6 @@ public class Command_moblimiter extends FreedomCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugin.gr.setGameRule(GameRuleHandler.GameRule.DO_MOB_SPAWNING, !ConfigEntry.MOB_LIMITER_ENABLED.getBoolean());
|
plugin.gr.setGameRule(GameRuleHandler.GameRule.DO_MOB_SPAWNING, !ConfigEntry.MOB_LIMITER_ENABLED.getBoolean());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,13 +10,12 @@ import org.bukkit.entity.Player;
|
|||||||
@CommandParameters(description = "OP everyone on the server.", usage = "/<command>")
|
@CommandParameters(description = "OP everyone on the server.", usage = "/<command>")
|
||||||
public class Command_opall extends FreedomCommand
|
public class Command_opall extends FreedomCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
FUtil.adminAction(sender.getName(), "Opping all players on the server", false);
|
FUtil.adminAction(sender.getName(), "Opping all players on the server", false);
|
||||||
|
|
||||||
for (Player player : server.getOnlinePlayers())
|
server.getOnlinePlayers().forEach(player ->
|
||||||
{
|
{
|
||||||
if (!player.isOp())
|
if (!player.isOp())
|
||||||
{
|
{
|
||||||
@ -28,7 +27,7 @@ public class Command_opall extends FreedomCommand
|
|||||||
{
|
{
|
||||||
player.recalculatePermissions();
|
player.recalculatePermissions();
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -21,8 +20,6 @@ import org.bukkit.potion.PotionEffectType;
|
|||||||
aliases = "effect")
|
aliases = "effect")
|
||||||
public class Command_potion extends FreedomCommand
|
public class Command_potion extends FreedomCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
@ -32,15 +29,8 @@ public class Command_potion extends FreedomCommand
|
|||||||
{
|
{
|
||||||
if (args[0].equalsIgnoreCase("list"))
|
if (args[0].equalsIgnoreCase("list"))
|
||||||
{
|
{
|
||||||
List<String> potionEffectTypeNames = new ArrayList<>();
|
msg("Potion effect types: " + FUtil.listToString(Arrays.stream(PotionEffectType.values())
|
||||||
for (PotionEffectType potion_effect_type : PotionEffectType.values())
|
.map(PotionEffectType::getName).toList()), ChatColor.AQUA);
|
||||||
{
|
|
||||||
if (potion_effect_type != null)
|
|
||||||
{
|
|
||||||
potionEffectTypeNames.add(potion_effect_type.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
msg("Potion effect types: " + StringUtils.join(potionEffectTypeNames, ", "), ChatColor.AQUA);
|
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("clearall"))
|
else if (args[0].equalsIgnoreCase("clearall"))
|
||||||
{
|
{
|
||||||
@ -50,14 +40,9 @@ public class Command_potion extends FreedomCommand
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
FUtil.adminAction(sender.getName(), "Cleared all potion effects from all players", true);
|
FUtil.adminAction(sender.getName(), "Clearing all potion effects from all players", true);
|
||||||
for (Player target : server.getOnlinePlayers())
|
server.getOnlinePlayers().forEach(target -> target.getActivePotionEffects().forEach(effect ->
|
||||||
{
|
target.removePotionEffect(effect.getType())));
|
||||||
for (PotionEffect potion_effect : target.getActivePotionEffects())
|
|
||||||
{
|
|
||||||
target.removePotionEffect(potion_effect.getType());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +71,7 @@ public class Command_potion extends FreedomCommand
|
|||||||
|
|
||||||
if (target == null)
|
if (target == null)
|
||||||
{
|
{
|
||||||
msg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
|
msg(PLAYER_NOT_FOUND, ChatColor.RED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +80,8 @@ public class Command_potion extends FreedomCommand
|
|||||||
target.removePotionEffect(potion_effect.getType());
|
target.removePotionEffect(potion_effect.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
msg("Cleared all active potion effects " + (!target.equals(playerSender) ? "from player " + target.getName() + "." : "from yourself."), ChatColor.AQUA);
|
msg("Cleared all active potion effects " + (!target.equals(playerSender) ? "from player "
|
||||||
|
+ target.getName() + "." : "from yourself."), ChatColor.AQUA);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -132,44 +118,41 @@ public class Command_potion extends FreedomCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PotionEffectType potion_effect_type = PotionEffectType.getByName(args[1]);
|
PotionEffectType effectType = PotionEffectType.getByName(args[1]);
|
||||||
if (potion_effect_type == null)
|
if (effectType == null)
|
||||||
{
|
{
|
||||||
msg("Invalid potion effect type.", ChatColor.AQUA);
|
msg("Invalid potion effect: " + args[1], ChatColor.AQUA);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int duration;
|
int duration;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
duration = Integer.parseInt(args[2]);
|
duration = Math.min(Integer.parseInt(args[2]), 100000);
|
||||||
duration = Math.min(duration, 100000);
|
|
||||||
}
|
}
|
||||||
catch (NumberFormatException ex)
|
catch (NumberFormatException ex)
|
||||||
{
|
{
|
||||||
msg("Invalid potion duration.", ChatColor.RED);
|
msg("Invalid duration: " + args[2], ChatColor.RED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int amplifier;
|
int amplifier;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
amplifier = Integer.parseInt(args[3]);
|
amplifier = Math.min(Integer.parseInt(args[3]), 100000);
|
||||||
amplifier = Math.min(amplifier, 100000);
|
|
||||||
}
|
}
|
||||||
catch (NumberFormatException ex)
|
catch (NumberFormatException ex)
|
||||||
{
|
{
|
||||||
msg("Invalid potion amplifier.", ChatColor.RED);
|
msg("Invalid potion amplifier: " + args[3], ChatColor.RED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
PotionEffect new_effect = potion_effect_type.createEffect(duration, amplifier);
|
PotionEffect new_effect = effectType.createEffect(duration, amplifier);
|
||||||
target.addPotionEffect(new_effect, true);
|
target.addPotionEffect(new_effect);
|
||||||
msg(
|
msg("Added potion effect: " + new_effect.getType().getName()
|
||||||
"Added potion effect: " + new_effect.getType().getName()
|
+ ", Duration: " + new_effect.getDuration()
|
||||||
+ ", Duration: " + new_effect.getDuration()
|
+ ", Amplifier: " + new_effect.getAmplifier()
|
||||||
+ ", Amplifier: " + new_effect.getAmplifier()
|
+ (!target.equals(playerSender) ? " to player " + target.getName() + "." : " to yourself."), ChatColor.AQUA);
|
||||||
+ (!target.equals(playerSender) ? " to player " + target.getName() + "." : " to yourself."), ChatColor.AQUA);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -206,7 +189,7 @@ public class Command_potion extends FreedomCommand
|
|||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("add"))
|
else if (args[0].equalsIgnoreCase("add"))
|
||||||
{
|
{
|
||||||
return getAllPotionTypes();
|
return Arrays.stream(PotionEffectType.values()).map(PotionEffectType::getName).toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 3 ->
|
case 3 ->
|
||||||
@ -237,17 +220,4 @@ public class Command_potion extends FreedomCommand
|
|||||||
|
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getAllPotionTypes()
|
|
||||||
{
|
|
||||||
List<String> types = new ArrayList<>();
|
|
||||||
for (PotionEffectType potionEffectType : PotionEffectType.values())
|
|
||||||
{
|
|
||||||
if (potionEffectType != null)
|
|
||||||
{
|
|
||||||
types.add(potionEffectType.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,7 +1,6 @@
|
|||||||
package me.totalfreedom.totalfreedommod.command;
|
package me.totalfreedom.totalfreedommod.command;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.Optional;
|
||||||
|
|
||||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -15,10 +14,9 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.NON_OP, source = SourceType.BOTH)
|
@CommandPermissions(level = Rank.NON_OP, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Set the on/off state of the lever at position x, y, z in world 'worldname'.", usage = "/<command> <x> <y> <z> <worldname> <on|off>")
|
@CommandParameters(description = "Set the on/off state of the lever at position x, y, z in world 'worldname'.", usage = "/<command> <x> <y> <z> <worldname> <on | off>")
|
||||||
public class Command_setlever extends FreedomCommand
|
public class Command_setlever extends FreedomCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
@ -33,50 +31,38 @@ public class Command_setlever extends FreedomCommand
|
|||||||
x = Double.parseDouble(args[0]);
|
x = Double.parseDouble(args[0]);
|
||||||
y = Double.parseDouble(args[1]);
|
y = Double.parseDouble(args[1]);
|
||||||
z = Double.parseDouble(args[2]);
|
z = Double.parseDouble(args[2]);
|
||||||
|
|
||||||
|
// Shows the "Invalid coordinates" message without having to do boilerplate bullshit
|
||||||
|
if (Math.abs(x) > 29999998 || Math.abs(y) > 29999998 || Math.abs(z) > 29999998)
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (NumberFormatException ex)
|
catch (IllegalArgumentException ex)
|
||||||
{
|
{
|
||||||
msg("Invalid coordinates.");
|
msg("Invalid coordinates.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x > 29999998 || x < -29999998 || y > 29999998 || y < -29999998 || z > 29999998 || z < -29999998)
|
Optional<World> optionalWorld = server.getWorlds().stream().filter(world ->
|
||||||
|
world.getName().equalsIgnoreCase(args[3])).findAny();
|
||||||
|
|
||||||
|
if (optionalWorld.isEmpty())
|
||||||
{
|
{
|
||||||
msg("Coordinates cannot be larger than 29999998 or smaller than -29999998 blocks.");
|
msg("Invalid world: " + args[3]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
World world = null;
|
final Location leverLocation = new Location(optionalWorld.get(), x, y, z);
|
||||||
final String needleWorldName = args[3].trim();
|
|
||||||
final List<World> worlds = server.getWorlds();
|
|
||||||
for (final World testWorld : worlds)
|
|
||||||
{
|
|
||||||
if (testWorld.getName().trim().equalsIgnoreCase(needleWorldName))
|
|
||||||
{
|
|
||||||
world = testWorld;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world == null)
|
|
||||||
{
|
|
||||||
msg("Invalid world name.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Location leverLocation = new Location(world, x, y, z);
|
|
||||||
|
|
||||||
final boolean leverOn = (args[4].trim().equalsIgnoreCase("on") || args[4].trim().equalsIgnoreCase("1"));
|
|
||||||
|
|
||||||
final Block targetBlock = leverLocation.getBlock();
|
final Block targetBlock = leverLocation.getBlock();
|
||||||
|
|
||||||
if (targetBlock.getType() == Material.LEVER)
|
if (targetBlock.getType() == Material.LEVER)
|
||||||
{
|
{
|
||||||
BlockState state = targetBlock.getState();
|
BlockState state = targetBlock.getState();
|
||||||
BlockData data = state.getBlockData();
|
BlockData data = state.getBlockData();
|
||||||
Switch caster = (Switch)data;
|
Switch caster = (Switch) data;
|
||||||
|
|
||||||
caster.setPowered(leverOn);
|
caster.setPowered(args[4].trim().equalsIgnoreCase("on") || args[4].trim().equalsIgnoreCase("1"));
|
||||||
state.setBlockData(data);
|
state.setBlockData(data);
|
||||||
state.update();
|
state.update();
|
||||||
|
|
||||||
@ -84,8 +70,7 @@ public class Command_setlever extends FreedomCommand
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
msg("Target block " + targetBlock + " is not a lever.");
|
msg("That block isn't a lever.");
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user