mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-07-26 23:45:23 +00: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
5 changed files with 89 additions and 54 deletions
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 org.bukkit.*;
|
||||||
import com.earth2me.essentials.commands.IEssentialsCommand;
|
import com.earth2me.essentials.commands.IEssentialsCommand;
|
||||||
import net.minecraft.server.EntityHuman;
|
import net.minecraft.server.EntityHuman;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
@ -14,7 +15,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||||
import org.yaml.snakeyaml.reader.UnicodeReader;
|
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 static final Logger logger = Logger.getLogger("Minecraft");
|
||||||
private final Yaml yaml = new Yaml(new SafeConstructor());
|
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 TimerTask teleTimer = null;
|
||||||
private int teleTimer = -1;
|
private int teleTimer = -1;
|
||||||
public Location lastLocation = null;
|
public Location lastLocation = null;
|
||||||
private User replyTo = null;
|
private CommandSender replyTo = null;
|
||||||
private boolean isNew = false;
|
private boolean isNew = false;
|
||||||
public String currentJail;
|
public String currentJail;
|
||||||
public CraftItemStack[] savedInventory;
|
public CraftItemStack[] savedInventory;
|
||||||
|
@ -631,12 +632,12 @@ public class User extends PlayerExtension implements Comparable<User>
|
||||||
justPortaled = value;
|
justPortaled = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReplyTo(User user)
|
public void setReplyTo(CommandSender user)
|
||||||
{
|
{
|
||||||
replyTo = user;
|
replyTo = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getReplyTo()
|
public CommandSender getReplyTo()
|
||||||
{
|
{
|
||||||
return replyTo;
|
return replyTo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import org.bukkit.Server;
|
||||||
import com.earth2me.essentials.Essentials;
|
import com.earth2me.essentials.Essentials;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
|
import com.earth2me.essentials.Console;
|
||||||
|
import com.earth2me.essentials.IReplyTo;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public class Commandmsg extends EssentialsCommand
|
public class Commandmsg extends EssentialsCommand
|
||||||
|
@ -20,40 +22,6 @@ public class Commandmsg extends EssentialsCommand
|
||||||
return new String[] { getName(), "m", "tell", "whisper" };
|
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
|
@Override
|
||||||
public void run(Server server, Essentials parent, CommandSender sender, String commandLabel, String[] args) throws Exception
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder message = new StringBuilder();
|
String message = getFinalArg(args, 1);
|
||||||
for (int i = 1; i < args.length; i++)
|
|
||||||
|
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]);
|
sender.sendMessage("[Me -> " + senderName + "§f] " + message);
|
||||||
message.append(' ');
|
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]);
|
List<Player> matches = server.matchPlayer(args[0]);
|
||||||
|
|
||||||
if (matches.isEmpty())
|
if (matches.isEmpty())
|
||||||
{
|
{
|
||||||
sender.sendMessage("§cThere are no players matching that name.");
|
sender.sendMessage("§cThere are no players matching that name.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
charge(sender);
|
||||||
for (Player p : matches)
|
for (Player p : matches)
|
||||||
{
|
{
|
||||||
sender.sendMessage("[§2Me -> " + p.getDisplayName() + "§f] " + message);
|
sender.sendMessage("[Me -> " + p.getDisplayName() + "§f] " + message);
|
||||||
p.sendMessage("[§2{Console} -> Me§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;
|
package com.earth2me.essentials.commands;
|
||||||
|
|
||||||
import com.earth2me.essentials.*;
|
import com.earth2me.essentials.*;
|
||||||
|
import com.earth2me.essentials.Console;
|
||||||
|
import com.earth2me.essentials.IReplyTo;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
public class Commandr extends EssentialsCommand
|
public class Commandr extends EssentialsCommand
|
||||||
|
@ -12,26 +16,33 @@ public class Commandr extends EssentialsCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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)
|
if (args.length < 1)
|
||||||
{
|
{
|
||||||
user.sendMessage("§cUsage: /" + commandLabel + " [message]");
|
sender.sendMessage("§cUsage: /" + commandLabel + " [message]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String message = getFinalArg(args, 0);
|
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)
|
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);
|
charge(sender);
|
||||||
user.sendMessage("[Me -> " + target.getDisplayName() + "] " + message);
|
sender.sendMessage("[Me -> " + targetName + "] " + message);
|
||||||
target.sendMessage("[" + user.getDisplayName() + " -> Me] " + message);
|
target.sendMessage("[" + senderName + " -> Me] " + message);
|
||||||
user.setReplyTo(target);
|
replyTo.setReplyTo(target);
|
||||||
target.setReplyTo(user);
|
if (target instanceof Player) {
|
||||||
|
User.get((Player)target).setReplyTo(sender);
|
||||||
|
} else {
|
||||||
|
Console.getConsoleReplyTo().setReplyTo(sender);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue