mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-23 01:27:40 +01:00
[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:
parent
dbc653edb8
commit
57b5af7829
34
Essentials/src/com/earth2me/essentials/Console.java
Normal file
34
Essentials/src/com/earth2me/essentials/Console.java
Normal 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;
|
||||
}
|
||||
}
|
9
Essentials/src/com/earth2me/essentials/IReplyTo.java
Normal file
9
Essentials/src/com/earth2me/essentials/IReplyTo.java
Normal 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();
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user