Stuff for new the new Command Block, mostly.

Added /cartsit, mainly for command blocks.
Added -s (silent) switch to qop and qdeop, for command blocks.
Removed TFM_Messages class, since it was just clutter.
Added proprietary handler for CommandBlockChangeEvent, you'll need to implement this yourself in CraftBukkit or remove the event if you want to compile.
This commit is contained in:
Steven Lawson 2012-11-02 21:03:12 -04:00
parent fa934e1eca
commit b46bbd3eba
6 changed files with 123 additions and 31 deletions

View File

@ -0,0 +1,77 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player;
public class Command_cartsit extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
Player target_player = sender_p;
if (args.length == 1)
{
try
{
target_player = getPlayer(args[0]);
}
catch (CantFindPlayerException ex)
{
sender.sendMessage(ex.getMessage());
return true;
}
}
if (senderIsConsole)
{
if (target_player == null)
{
sender.sendMessage("When used from the console, you must define a target player: /cartsit <player>");
return true;
}
}
else if (target_player != sender_p && !TFM_Util.isUserSuperadmin(sender))
{
sender.sendMessage("Only superadmins can select another player as a /cartsit target.");
return true;
}
if (target_player.isInsideVehicle())
{
target_player.getVehicle().eject();
}
else
{
Minecart nearest_cart = null;
for (Minecart cart : target_player.getWorld().getEntitiesByClass(Minecart.class))
{
if (nearest_cart == null)
{
nearest_cart = cart;
}
else
{
if (cart.getLocation().distance(target_player.getLocation()) < nearest_cart.getLocation().distance(target_player.getLocation()))
{
nearest_cart = cart;
}
}
}
if (nearest_cart != null)
{
nearest_cart.setPassenger(target_player);
}
else
{
sender.sendMessage("There are no minecarts in the target world.");
}
}
return true;
}
}

View File

@ -11,7 +11,7 @@ public class Command_qdeop extends TFM_Command
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length != 1)
if (args.length < 1)
{
return false;
}
@ -22,6 +22,12 @@ public class Command_qdeop extends TFM_Command
return true;
}
boolean silent = false;
if (args.length == 2)
{
silent = args[1].equalsIgnoreCase("-s");
}
boolean matched_player = false;
String target_name = args[0].toLowerCase();
@ -32,7 +38,10 @@ public class Command_qdeop extends TFM_Command
{
matched_player = true;
TFM_Util.adminAction(sender.getName(), "De-opping " + p.getName(), false);
if (!silent)
{
TFM_Util.adminAction(sender.getName(), "De-opping " + p.getName(), false);
}
p.setOp(false);
p.sendMessage(TotalFreedomMod.YOU_ARE_NOT_OP);
}

View File

@ -11,7 +11,7 @@ public class Command_qop extends TFM_Command
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length != 1)
if (args.length < 1)
{
return false;
}
@ -22,6 +22,12 @@ public class Command_qop extends TFM_Command
return true;
}
boolean silent = false;
if (args.length == 2)
{
silent = args[1].equalsIgnoreCase("-s");
}
boolean matched_player = false;
String target_name = args[0].toLowerCase();
@ -32,7 +38,10 @@ public class Command_qop extends TFM_Command
{
matched_player = true;
TFM_Util.adminAction(sender.getName(), "Opping " + p.getName(), false);
if (!silent)
{
TFM_Util.adminAction(sender.getName(), "Opping " + p.getName(), false);
}
p.setOp(true);
p.sendMessage(TotalFreedomMod.YOU_ARE_OP);
}

View File

@ -224,4 +224,25 @@ public class TFM_BlockListener implements Listener
event.setCancelled(true);
}
}
//This event is not in the standard Bukkit / CraftBukkit server, only my custom version. Remove it if you want to compile this plugin yourself.
@EventHandler(priority = EventPriority.NORMAL)
public void onCommandBlockChangeEvent(CommandBlockChangeEvent event)
{
Player player = event.getPlayer();
if (!TFM_Util.isUserSuperadmin(player))
{
TFM_Util.playerMsg(player, "You do not have permission to set Command Block commands.");
event.setCancelled(true);
return;
}
if (!TotalFreedomMod.superAwesomeAdmins.contains(player.getName().toLowerCase()))
{
TFM_Util.playerMsg(player, "You do not have permission to set Command Block commands.");
event.setCancelled(true);
return;
}
}
}

View File

@ -1,27 +0,0 @@
package me.StevenLawson.TotalFreedomMod;
import org.bukkit.ChatColor;
// Work in progress
@Deprecated
public enum TFM_Messages
{
NO_PERMS(ChatColor.YELLOW + "You do not have permission to use this command."),
YOU_ARE_OP(ChatColor.YELLOW + "You are now op!"),
YOU_ARE_NOT_OP(ChatColor.YELLOW + "You are no longer op!"),
CAKE_LYRICS("But there's no sense crying over every mistake. You just keep on trying till you run out of cake."),
NOT_FROM_CONSOLE("This command may not be used from the console.");
private final String message;
TFM_Messages(String message)
{
this.message = message;
}
@Override
public String toString()
{
return message;
}
}

View File

@ -13,6 +13,9 @@ commands:
cake:
description: Superadmin command - For the people that are still alive.
usage: /<command>
cartsit:
description: Sit in nearest minecart. If target is in a minecart already, they will disembark.
usage: /<command> [partialname]
clearall:
description: Superadmin command - Removes all entities, nicks and disguises
usage: /<command>