mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-20 14:25:00 +00:00
c4fce3f0f9
* Command_adminworld.java * Command_adventure.java * Command_banip.java * Command_blockedit.java * Command_blockpvp.java * Command_cage.java * Command_cartsit.java * Command_clearchat.java * Command_clearinventory.java * Command_commandlist.java * Command_creative.java * Command_deop.java * Command_deopall.java * Command_dispfill.java * Command_doom.java * Command_gcmd.java * Command_hubworld.java * Command_inspect.java * Command_list.java * Command_lockup.java * Command_manageshop.java * Command_manuallyverify.java * Command_masterbuilderworld.java * Command_mbconfig.java * Command_moblimiter.java * Command_mp44.java * Command_mute.java * Command_nickfilter.java * Command_op.java * Command_opall.java * Command_opme.java * Command_potion.java (Also corrected the inconsistent "player not found" message's color) * Command_rank.java * Command_ride.java * Command_saconfig.java * Command_scare.java * Command_setplayerlimit.java * Command_settotalvotes.java * Command_smite.java * Command_spectator.java * Command_survival.java * Command_unblockcmd.java * Command_uncage.java * Command_unmute.java * Command_verifynoadmin.java Here are some commands I added functionality to: * Command_dispfill.java: Added some code that hooks into the CoreProtect API to log the items being removed from and added into the dispensers. * Command_setlever.java: Added some code that hooks into the CoreProtect API to log the levers being interacted with. Here's a command I fixed a critical bug in: * Command_setlever.java
243 lines
8.8 KiB
Java
243 lines
8.8 KiB
Java
package me.totalfreedom.totalfreedommod.command;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.potion.PotionEffect;
|
|
import org.bukkit.potion.PotionEffectType;
|
|
|
|
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
|
|
@CommandParameters(
|
|
description = "Manipulate your potion effects. Duration is measured in server ticks (~20 ticks per second).",
|
|
usage = "/<command> <list | clearall | clear [target name] | add <type> <duration> <amplifier> [target name]>",
|
|
aliases = "effect")
|
|
public class Command_potion extends FreedomCommand
|
|
{
|
|
|
|
@SuppressWarnings("deprecation")
|
|
@Override
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
{
|
|
switch (args.length)
|
|
{
|
|
case 1:
|
|
if (args[0].equalsIgnoreCase("list"))
|
|
{
|
|
List<String> potionEffectTypeNames = new ArrayList<>();
|
|
for (PotionEffectType potion_effect_type : PotionEffectType.values())
|
|
{
|
|
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"))
|
|
{
|
|
if (!(plugin.al.isAdmin(sender) || senderIsConsole))
|
|
{
|
|
noPerms();
|
|
return true;
|
|
}
|
|
|
|
FUtil.adminAction(sender.getName(), "Cleared all potion effects from all players", true);
|
|
for (Player target : server.getOnlinePlayers())
|
|
{
|
|
for (PotionEffect potion_effect : target.getActivePotionEffects())
|
|
{
|
|
target.removePotionEffect(potion_effect.getType());
|
|
}
|
|
}
|
|
}
|
|
|
|
case 2:
|
|
if (args[0].equalsIgnoreCase("clear"))
|
|
{
|
|
Player target = playerSender;
|
|
if (args.length == 2)
|
|
{
|
|
if (!plugin.al.isAdmin(sender) && !target.equals(getPlayer(sender.getName())))
|
|
{
|
|
msg(ChatColor.RED + "Only admins can clear potion effects from other players.");
|
|
return true;
|
|
}
|
|
target = getPlayer(args[1], true);
|
|
}
|
|
else
|
|
{
|
|
if (senderIsConsole)
|
|
{
|
|
msg("You must specify a target player when using this command from the console.");
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if (target == null)
|
|
{
|
|
msg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
|
|
return true;
|
|
}
|
|
|
|
for (PotionEffect potion_effect : target.getActivePotionEffects())
|
|
{
|
|
target.removePotionEffect(potion_effect.getType());
|
|
}
|
|
|
|
msg("Cleared all active potion effects " + (!target.equals(playerSender) ? "from player " + target.getName() + "." : "from yourself."), ChatColor.AQUA);
|
|
}
|
|
break;
|
|
|
|
case 4:
|
|
case 5:
|
|
if (args[0].equalsIgnoreCase("add"))
|
|
{
|
|
Player target = playerSender;
|
|
|
|
if (args.length == 5)
|
|
{
|
|
if (!plugin.al.isAdmin(sender) && !getPlayer(args[4]).equals(getPlayer(sender.getName())))
|
|
{
|
|
msg("Only admins can apply potion effects to other players.", ChatColor.RED);
|
|
return true;
|
|
}
|
|
|
|
target = getPlayer(args[4]);
|
|
|
|
if (target == null || plugin.al.isVanished(target.getName()) && !plugin.al.isAdmin(sender))
|
|
{
|
|
msg(PLAYER_NOT_FOUND);
|
|
return true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (senderIsConsole)
|
|
{
|
|
msg("You must specify a target player when using this command from the console.");
|
|
return true;
|
|
}
|
|
}
|
|
|
|
PotionEffectType potion_effect_type = PotionEffectType.getByName(args[1]);
|
|
if (potion_effect_type == null)
|
|
{
|
|
msg("Invalid potion effect type.", ChatColor.AQUA);
|
|
return true;
|
|
}
|
|
|
|
int duration;
|
|
try
|
|
{
|
|
duration = Integer.parseInt(args[2]);
|
|
duration = Math.min(duration, 100000);
|
|
}
|
|
catch (NumberFormatException ex)
|
|
{
|
|
msg("Invalid potion duration.", ChatColor.RED);
|
|
return true;
|
|
}
|
|
|
|
int amplifier;
|
|
try
|
|
{
|
|
amplifier = Integer.parseInt(args[3]);
|
|
amplifier = Math.min(amplifier, 100000);
|
|
}
|
|
catch (NumberFormatException ex)
|
|
{
|
|
msg("Invalid potion amplifier.", ChatColor.RED);
|
|
return true;
|
|
}
|
|
|
|
PotionEffect new_effect = potion_effect_type.createEffect(duration, amplifier);
|
|
target.addPotionEffect(new_effect, true);
|
|
msg(
|
|
"Added potion effect: " + new_effect.getType().getName()
|
|
+ ", Duration: " + new_effect.getDuration()
|
|
+ ", Amplifier: " + new_effect.getAmplifier()
|
|
+ (!target.equals(playerSender) ? " to player " + target.getName() + "." : " to yourself."), ChatColor.AQUA);
|
|
}
|
|
break;
|
|
default:
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
|
{
|
|
switch (args.length)
|
|
{
|
|
case 1:
|
|
List<String> arguments = new ArrayList<>(Arrays.asList("list", "clear", "add"));
|
|
if (plugin.al.isAdmin(sender))
|
|
{
|
|
arguments.add("clearall");
|
|
}
|
|
return arguments;
|
|
|
|
case 2:
|
|
if (args[0].equals("clear"))
|
|
{
|
|
if (plugin.al.isAdmin(sender))
|
|
{
|
|
return FUtil.getPlayerList();
|
|
}
|
|
}
|
|
else if (args[0].equals("add"))
|
|
{
|
|
return getAllPotionTypes();
|
|
}
|
|
break;
|
|
|
|
case 3:
|
|
if (args[0].equals("add"))
|
|
{
|
|
return Collections.singletonList("<duration>");
|
|
}
|
|
break;
|
|
|
|
case 4:
|
|
if (args[0].equals("add"))
|
|
{
|
|
return Collections.singletonList("<amplifier>");
|
|
}
|
|
break;
|
|
|
|
case 5:
|
|
if (plugin.al.isAdmin(sender))
|
|
{
|
|
if (args[0].equals("add"))
|
|
{
|
|
return FUtil.getPlayerList();
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
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;
|
|
}
|
|
} |