[trunk] /msg /r Reply to the console. Add /r console command.

git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1129 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
snowleo 2011-04-05 15:57:54 +00:00
parent dbc653edb8
commit 57b5af7829
5 changed files with 89 additions and 54 deletions

View File

@ -0,0 +1,34 @@
package com.earth2me.essentials;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.CraftServer;
public class Console implements IReplyTo {
private static Console instance = new Console();
private CommandSender replyTo;
public final static String NAME = "Console";
private Console() {
}
public static CommandSender getCommandSender(Server server) throws Exception {
if (! (server instanceof CraftServer)) {
throw new Exception("Invalid server!");
}
return ((CraftServer)server).getServer().console;
}
public void setReplyTo(CommandSender user) {
replyTo = user;
}
public CommandSender getReplyTo() {
return replyTo;
}
public static Console getConsoleReplyTo() {
return instance;
}
}

View File

@ -0,0 +1,9 @@
package com.earth2me.essentials;
import org.bukkit.command.CommandSender;
public interface IReplyTo {
public void setReplyTo(CommandSender user);
public CommandSender getReplyTo();
}

View File

@ -6,6 +6,7 @@ import java.io.*;
import org.bukkit.*;
import com.earth2me.essentials.commands.IEssentialsCommand;
import net.minecraft.server.EntityHuman;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack;
@ -14,7 +15,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.reader.UnicodeReader;
public class User extends PlayerExtension implements Comparable<User>
public class User extends PlayerExtension implements Comparable<User>, IReplyTo
{
private static final Logger logger = Logger.getLogger("Minecraft");
private final Yaml yaml = new Yaml(new SafeConstructor());
@ -29,7 +30,7 @@ public class User extends PlayerExtension implements Comparable<User>
//private TimerTask teleTimer = null;
private int teleTimer = -1;
public Location lastLocation = null;
private User replyTo = null;
private CommandSender replyTo = null;
private boolean isNew = false;
public String currentJail;
public CraftItemStack[] savedInventory;
@ -631,12 +632,12 @@ public class User extends PlayerExtension implements Comparable<User>
justPortaled = value;
}
public void setReplyTo(User user)
public void setReplyTo(CommandSender user)
{
replyTo = user;
}
public User getReplyTo()
public CommandSender getReplyTo()
{
return replyTo;
}

View File

@ -5,6 +5,8 @@ import org.bukkit.Server;
import com.earth2me.essentials.Essentials;
import org.bukkit.entity.Player;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Console;
import com.earth2me.essentials.IReplyTo;
import org.bukkit.command.CommandSender;
public class Commandmsg extends EssentialsCommand
@ -20,40 +22,6 @@ public class Commandmsg extends EssentialsCommand
return new String[] { getName(), "m", "tell", "whisper" };
}
@Override
public void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception
{
if (args.length < 2 || args[0].trim().length() == 0 || args[1].trim().length() == 0)
{
user.sendMessage("§cUsage: /" + commandLabel + " [player] [message]");
return;
}
StringBuilder message = new StringBuilder();
for (int i = 1; i < args.length; i++)
{
message.append(args[i]);
message.append(' ');
}
List<Player> matches = server.matchPlayer(args[0]);
if (matches.isEmpty())
{
user.sendMessage("§cThere are no players matching that name.");
return;
}
user.charge(this);
for (Player p : matches)
{
user.sendMessage("[Me -> " + p.getDisplayName() + "§f] " + message);
p.sendMessage("[" + user.getDisplayName() + " -> Me§f] " + message);
user.setReplyTo(User.get(p));
User.get(p).setReplyTo(user);
}
}
@Override
public void run(Server server, Essentials parent, CommandSender sender, String commandLabel, String[] args) throws Exception
{
@ -63,23 +31,35 @@ public class Commandmsg extends EssentialsCommand
return;
}
StringBuilder message = new StringBuilder();
for (int i = 1; i < args.length; i++)
String message = getFinalArg(args, 1);
IReplyTo replyTo = sender instanceof User?(User)sender:Console.getConsoleReplyTo();
String senderName = sender instanceof User?((User)sender).getDisplayName():Console.NAME;
if (args[0].equalsIgnoreCase(Console.NAME))
{
message.append(args[i]);
message.append(' ');
sender.sendMessage("[Me -> " + senderName + "§f] " + message);
CommandSender cs = Console.getCommandSender(server);
cs.sendMessage("[" + senderName + " -> Me§f] " + message);
replyTo.setReplyTo(cs);
Console.getConsoleReplyTo().setReplyTo(sender);
}
List<Player> matches = server.matchPlayer(args[0]);
if (matches.isEmpty())
{
sender.sendMessage("§cThere are no players matching that name.");
return;
}
charge(sender);
for (Player p : matches)
{
sender.sendMessage("[§2Me -> " + p.getDisplayName() + "§f] " + message);
p.sendMessage("[§2{Console} -> Me§f] " + message);
sender.sendMessage("[Me -> " + p.getDisplayName() + "§f] " + message);
p.sendMessage("[" + senderName + " -> Me§f] " + message);
replyTo.setReplyTo(User.get(p));
User.get(p).setReplyTo(sender);
}
}
}

View File

@ -1,7 +1,11 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.*;
import com.earth2me.essentials.Console;
import com.earth2me.essentials.IReplyTo;
import org.bukkit.*;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Commandr extends EssentialsCommand
@ -10,28 +14,35 @@ public class Commandr extends EssentialsCommand
{
super("r");
}
@Override
public void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception
public void run(Server server, Essentials parent, CommandSender sender, String commandLabel, String[] args) throws Exception
{
if (args.length < 1)
{
user.sendMessage("§cUsage: /" + commandLabel + " [message]");
sender.sendMessage("§cUsage: /" + commandLabel + " [message]");
return;
}
String message = getFinalArg(args, 0);
User target = user.getReplyTo();
IReplyTo replyTo = sender instanceof User?(User)sender:Console.getConsoleReplyTo();
String senderName = sender instanceof User?((User)sender).getDisplayName():Console.NAME;
CommandSender target = replyTo.getReplyTo();
String targetName = target instanceof User?((User)target).getDisplayName():Console.NAME;
if (target == null)
{
user.sendMessage("§cYou have nobody to whom you can reply.");
sender.sendMessage("§cYou have nobody to whom you can reply.");
}
user.charge(this);
user.sendMessage("[Me -> " + target.getDisplayName() + "] " + message);
target.sendMessage("[" + user.getDisplayName() + " -> Me] " + message);
user.setReplyTo(target);
target.setReplyTo(user);
charge(sender);
sender.sendMessage("[Me -> " + targetName + "] " + message);
target.sendMessage("[" + senderName + " -> Me] " + message);
replyTo.setReplyTo(target);
if (target instanceof Player) {
User.get((Player)target).setReplyTo(sender);
} else {
Console.getConsoleReplyTo().setReplyTo(sender);
}
}
}