new commands, fix /tempban, etc

This commit is contained in:
Ivan 2019-11-29 11:41:18 -05:00
parent 43b4fc89ef
commit acd7de715e
4 changed files with 137 additions and 8 deletions

View File

@ -0,0 +1,56 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.Collections;
import java.util.List;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.ChatColor;
import org.bukkit.Particle;
import org.bukkit.Sound;
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Surprise someone.", usage = "/<command> <player>")
public class Command_scare extends FreedomCommand
{
/* This command will not work on Paper because there was a patch to remove it. This will work on Spigot and Bukkit. */
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length == 0)
{
return false;
}
final Player player = getPlayer(args[0]);
if (player == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
msg("Scared " + player.getName());
player.spawnParticle(Particle.MOB_APPEARANCE, player.getLocation(), 4);
for (int i = 0; i < 10; ++i) {
player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_SCREAM, 1, 0);
}
return true;
}
@Override
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
{
if (args.length == 1 && plugin.al.isAdmin(sender))
{
return FUtil.getPlayerList();
}
return Collections.emptyList();
}
}

View File

@ -0,0 +1,63 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.Iterator;
import java.util.Map;
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;
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Change your tab color", usage = "/<command> <color>")
public class Command_tabcolor extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!FUtil.isExecutive(sender.getName()))
{
return noPerms();
}
if (args.length != 1)
{
return false;
}
if ("list".equalsIgnoreCase(args[0]))
{
msg("Colors: " + StringUtils.join(FUtil.CHAT_COLOR_NAMES.keySet(), ", "));
return true;
}
final String needle = args[0].trim().toLowerCase();
ChatColor color = null;
final Iterator<Map.Entry<String, ChatColor>> it = FUtil.CHAT_COLOR_NAMES.entrySet().iterator();
while (it.hasNext())
{
final Map.Entry<String, ChatColor> entry = it.next();
if (entry.getKey().contains(needle))
{
color = entry.getValue();
break;
}
}
if (color == null)
{
msg("Invalid color: " + needle + " - Use \"/tabcolor list\" to list colors.");
return true;
}
playerSender.setPlayerListName(StringUtils.substring(color + sender.getName(), 0, 16));
msg("ok dad");
return true;
}
}

View File

@ -37,17 +37,25 @@ public class Command_tempban extends FreedomCommand
final List<String> ips = new ArrayList<>(); final List<String> ips = new ArrayList<>();
final Player player = getPlayer(args[0]); final Player player = getPlayer(args[0]);
final PlayerData entry = plugin.pl.getData(args[0]);
if (player == null) if (player == null)
{ {
msg(FreedomCommand.PLAYER_NOT_FOUND); final PlayerData entry = plugin.pl.getData(args[0]);
if (entry == null)
{
msg("Can't find that user. If target is not logged in, make sure that you spelled the name exactly.");
return true; return true;
} }
username = entry.getUsername(); username = entry.getUsername();
ips.addAll(entry.getIps()); ips.addAll(entry.getIps());
}
else
{
final PlayerData entry = plugin.pl.getData(player);
username = player.getName();
ips.addAll(entry.getIps());
}
final StringBuilder message = new StringBuilder("Temporarily banned " + player.getName()); final StringBuilder message = new StringBuilder("Temporarily banned " + player.getName());
Date expires = FUtil.parseDateOffset("30m"); Date expires = FUtil.parseDateOffset("30m");

View File

@ -42,6 +42,8 @@ public class FUtil
public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z"; public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
public static final Map<String, ChatColor> CHAT_COLOR_NAMES = new HashMap<>(); public static final Map<String, ChatColor> CHAT_COLOR_NAMES = new HashMap<>();
public static final List<ChatColor> CHAT_COLOR_POOL = Arrays.asList( public static final List<ChatColor> CHAT_COLOR_POOL = Arrays.asList(
ChatColor.WHITE,
ChatColor.BLACK,
ChatColor.DARK_RED, ChatColor.DARK_RED,
ChatColor.RED, ChatColor.RED,
ChatColor.GOLD, ChatColor.GOLD,