2013-04-10 02:49:06 +02:00
|
|
|
package com.ne0nx3r0.betteralias.alias;
|
|
|
|
|
|
|
|
import com.ne0nx3r0.betteralias.BetterAlias;
|
2016-08-10 04:45:28 +02:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.GameMode;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.OutputStream;
|
2016-08-10 04:45:28 +02:00
|
|
|
import java.util.*;
|
2013-04-10 02:49:06 +02:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
// Helper methods
|
2016-08-10 04:45:28 +02:00
|
|
|
public class AliasManager {
|
2013-04-10 02:49:06 +02:00
|
|
|
private static BetterAlias plugin;
|
|
|
|
private HashMap<String, Alias> aliases;
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
public AliasManager(BetterAlias plugin) {
|
2013-04-10 02:49:06 +02:00
|
|
|
AliasManager.plugin = plugin;
|
2016-08-10 04:45:28 +02:00
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
this.loadAliases();
|
|
|
|
}
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
public final boolean loadAliases() {
|
|
|
|
this.aliases = new HashMap<String, Alias>();
|
|
|
|
|
|
|
|
File configFile = new File(plugin.getDataFolder(), "aliases.yml");
|
|
|
|
|
|
|
|
if (!configFile.exists()) {
|
2013-04-10 02:49:06 +02:00
|
|
|
configFile.getParentFile().mkdirs();
|
|
|
|
copy(plugin.getResource("aliases.yml"), configFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
FileConfiguration yml = YamlConfiguration.loadConfiguration(configFile);
|
|
|
|
|
|
|
|
Set<String> aliasList = yml.getKeys(false);
|
2016-08-10 04:45:28 +02:00
|
|
|
|
|
|
|
if (aliasList.isEmpty()) {
|
2013-04-10 02:49:06 +02:00
|
|
|
plugin.getLogger().log(Level.WARNING, "No aliases found in aliases.yml");
|
2016-08-10 04:45:28 +02:00
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
for (String sAlias : aliasList) {
|
2013-07-29 22:29:08 +02:00
|
|
|
Alias alias = new Alias(
|
2016-08-10 04:45:28 +02:00
|
|
|
sAlias,
|
|
|
|
yml.getBoolean(sAlias + ".caseSensitive", false),
|
|
|
|
yml.getString(sAlias + ".permission", null));
|
2013-04-10 02:49:06 +02:00
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
for (String sArg : yml.getConfigurationSection(sAlias).getKeys(false)) {
|
2013-04-10 02:49:06 +02:00
|
|
|
List<AliasCommand> commandsList = new ArrayList<AliasCommand>();
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
if (!sArg.equalsIgnoreCase("permission") && !sArg.equalsIgnoreCase("caseSensitive")) {
|
|
|
|
int iArg;
|
2013-04-10 02:49:06 +02:00
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
if (sArg.equals("*")) {
|
|
|
|
iArg = -1;
|
|
|
|
} else {
|
|
|
|
iArg = Integer.parseInt(sArg);
|
|
|
|
}
|
2013-04-10 02:49:06 +02:00
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
List<String> sArgLines = new ArrayList<String>();
|
2015-02-08 15:08:01 +01:00
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
if (yml.isList(sAlias + "." + sArg)) {
|
|
|
|
sArgLines = yml.getStringList(sAlias + "." + sArg);
|
|
|
|
} else {
|
|
|
|
sArgLines.add(yml.getString(sAlias + "." + sArg));
|
|
|
|
}
|
2013-04-10 02:49:06 +02:00
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
for (String sArgLine : sArgLines) {
|
|
|
|
AliasCommandTypes type = AliasCommandTypes.PLAYER;
|
|
|
|
|
|
|
|
int waitTime = 0;
|
|
|
|
|
|
|
|
if (sArgLine.contains(" ")) {
|
|
|
|
String sType = sArgLine.substring(0, sArgLine.indexOf(" "));
|
|
|
|
|
|
|
|
if (sType.equalsIgnoreCase("console")) {
|
|
|
|
type = AliasCommandTypes.CONSOLE;
|
|
|
|
|
|
|
|
sArgLine = sArgLine.substring(sArgLine.indexOf(" ") + 1);
|
|
|
|
} else if (sType.equalsIgnoreCase("player_as_op")) {
|
|
|
|
type = AliasCommandTypes.PLAYER_AS_OP;
|
|
|
|
|
|
|
|
sArgLine = sArgLine.substring(sArgLine.indexOf(" ") + 1);
|
|
|
|
} else if (sType.equalsIgnoreCase("reply")) {
|
|
|
|
type = AliasCommandTypes.REPLY_MESSAGE;
|
|
|
|
|
|
|
|
sArgLine = sArgLine.substring(sArgLine.indexOf(" ") + 1);
|
|
|
|
} else if (sType.equalsIgnoreCase("wait")) {
|
|
|
|
String[] sArgLineParams = sArgLine.split(" ");
|
|
|
|
|
|
|
|
try {
|
|
|
|
waitTime = Integer.parseInt(sArgLineParams[1]);
|
|
|
|
} catch (Exception e) {
|
|
|
|
plugin.getLogger().log(Level.WARNING, "Invalid wait time for command {0} in alias {1}, skipping line",
|
|
|
|
new Object[]{sArgLine, sAlias});
|
|
|
|
|
|
|
|
continue;
|
2013-04-10 02:49:06 +02:00
|
|
|
}
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
if (sArgLineParams[2].equalsIgnoreCase("reply")) {
|
|
|
|
type = AliasCommandTypes.WAIT_THEN_REPLY;
|
2013-04-10 02:49:06 +02:00
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
sArgLine = sArgLine.replace(sArgLineParams[0] + " " + sArgLineParams[1] + " " + sArgLineParams[2] + " ", "");
|
|
|
|
} else if (sArgLineParams[2].equalsIgnoreCase("console")) {
|
|
|
|
type = AliasCommandTypes.WAIT_THEN_CONSOLE;
|
|
|
|
|
|
|
|
sArgLine = sArgLine.replace(sArgLineParams[0] + " " + sArgLineParams[1] + " " + sArgLineParams[2] + " ", "");
|
|
|
|
} else {
|
|
|
|
type = AliasCommandTypes.WAIT;
|
|
|
|
|
|
|
|
sArgLine = sArgLine.replace(sArgLineParams[0] + " " + sArgLineParams[1] + " ", "");
|
|
|
|
}
|
|
|
|
}
|
2013-04-10 02:49:06 +02:00
|
|
|
}
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
sArgLine = this.replaceColorCodes(sArgLine);
|
|
|
|
|
|
|
|
commandsList.add(new AliasCommand(sArgLine, type, waitTime));
|
2013-04-10 02:49:06 +02:00
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
|
|
|
|
alias.setCommandsFor(iArg, commandsList);
|
|
|
|
}
|
2013-04-10 02:49:06 +02:00
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
this.aliases.put(sAlias, alias);
|
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
public boolean sendAliasCommands(Alias alias, CommandSender cs, String commandString) {
|
2013-04-10 02:49:06 +02:00
|
|
|
Player player = null;
|
2016-08-10 04:45:28 +02:00
|
|
|
|
|
|
|
if (cs instanceof Player) {
|
2013-04-10 02:49:06 +02:00
|
|
|
player = (Player) cs;
|
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
List<String> args = new ArrayList<String>();
|
2016-08-10 04:45:28 +02:00
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
Pattern regex = Pattern.compile("[^\\s\"']+|\"([^\"]*)\"|'([^']*)'");
|
|
|
|
|
|
|
|
Matcher regexMatcher = regex.matcher(commandString);
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
while (regexMatcher.find()) {
|
|
|
|
if (regexMatcher.group(1) != null) {
|
2013-04-10 02:49:06 +02:00
|
|
|
// Add double-quoted string without the quotes
|
|
|
|
args.add(regexMatcher.group(1));
|
2016-08-10 04:45:28 +02:00
|
|
|
} else if (regexMatcher.group(2) != null) {
|
2013-04-10 02:49:06 +02:00
|
|
|
// Add single-quoted string without the quotes
|
|
|
|
args.add(regexMatcher.group(2));
|
2016-08-10 04:45:28 +02:00
|
|
|
} else {
|
2013-04-10 02:49:06 +02:00
|
|
|
// Add unquoted word
|
|
|
|
args.add(regexMatcher.group());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
if (alias.hasCommandFor(args.size())) {
|
|
|
|
for (AliasCommand ac : alias.getCommands(args.size())) {
|
2013-04-10 02:49:06 +02:00
|
|
|
String sAliasCommand = ac.command;
|
|
|
|
|
|
|
|
Matcher m = Pattern.compile("!([0-9a-zA-Z~*]+)").matcher(sAliasCommand);
|
|
|
|
|
|
|
|
StringBuffer sb = new StringBuffer(sAliasCommand.length());
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
while (m.find()) {
|
2013-04-10 02:49:06 +02:00
|
|
|
String text = m.group(0).substring(1);
|
2016-08-10 04:45:28 +02:00
|
|
|
|
|
|
|
if (text.equalsIgnoreCase("name")) {
|
|
|
|
if (player != null) {
|
2013-04-10 02:49:06 +02:00
|
|
|
text = player.getName();
|
2016-08-10 04:45:28 +02:00
|
|
|
} else {
|
|
|
|
cs.sendMessage("[BetterAlias] " + ChatColor.RED + "A parameter of this alias requires a player.");
|
|
|
|
|
|
|
|
cs.sendMessage("[BetterAlias] Line: " + ac.command);
|
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
} else if (text.equalsIgnoreCase("handItemName")) {
|
|
|
|
if (player != null) {
|
2013-04-10 02:49:06 +02:00
|
|
|
text = player.getItemInHand().getType().name();
|
2016-08-10 04:45:28 +02:00
|
|
|
} else {
|
|
|
|
cs.sendMessage("[BetterAlias] " + ChatColor.RED + "A parameter of this alias requires a player.");
|
|
|
|
|
|
|
|
cs.sendMessage("[BetterAlias] Line: " + ac.command);
|
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
} else if (text.equalsIgnoreCase("handItemID")) {
|
|
|
|
if (player != null) {
|
2013-04-10 02:49:06 +02:00
|
|
|
text = new Integer(player.getItemInHand().getTypeId()).toString();
|
2016-08-10 04:45:28 +02:00
|
|
|
} else {
|
|
|
|
cs.sendMessage("[BetterAlias] " + ChatColor.RED + "A parameter of this alias requires a player.");
|
|
|
|
|
|
|
|
cs.sendMessage("[BetterAlias] Line: " + ac.command);
|
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
} else if (text.equalsIgnoreCase("oppositeGameMode")) {
|
|
|
|
if (player != null) {
|
|
|
|
text = player.getGameMode().equals(GameMode.SURVIVAL) ? "creative" : "survival";
|
|
|
|
} else {
|
|
|
|
cs.sendMessage("[BetterAlias] " + ChatColor.RED + "A parameter of this alias requires a player.");
|
|
|
|
|
|
|
|
cs.sendMessage("[BetterAlias] Line: " + ac.command);
|
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
} else if (text.equalsIgnoreCase("*")) {
|
|
|
|
//ltrim emulation
|
|
|
|
while(commandString.length() > 0 && commandString.substring(0,1).equals(" ")){
|
|
|
|
commandString = commandString.substring(1);
|
|
|
|
}
|
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
text = commandString;
|
2016-08-10 04:45:28 +02:00
|
|
|
} else if (text.length() >= 2 && text.substring(1, 2).equalsIgnoreCase("p")) {
|
2013-04-10 02:49:06 +02:00
|
|
|
int iParam = -1;
|
2016-08-10 04:45:28 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
iParam = Integer.parseInt(text.substring(0, 1));
|
|
|
|
} catch (Exception ex) {
|
2013-04-10 02:49:06 +02:00
|
|
|
}
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
if (iParam > -1 && args.size() >= iParam) {
|
|
|
|
String sPlayerName = args.get(iParam - 1).toLowerCase();
|
2013-04-10 02:49:06 +02:00
|
|
|
|
|
|
|
text = "BetterAliasPlayerNotFound";
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
for (Player p : plugin.getServer().getOnlinePlayers()) {
|
|
|
|
if (p.getName().toLowerCase().contains(sPlayerName)) {
|
2013-04-10 02:49:06 +02:00
|
|
|
text = p.getName();
|
2016-08-10 04:45:28 +02:00
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
} else {
|
2013-04-10 02:49:06 +02:00
|
|
|
int iParam = -1;
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
try {
|
2013-04-10 02:49:06 +02:00
|
|
|
iParam = Integer.parseInt(text);
|
2016-08-10 04:45:28 +02:00
|
|
|
} catch (Exception ex) {
|
2013-04-10 02:49:06 +02:00
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
|
|
|
|
if (iParam > -1 && args.size() >= iParam) {
|
|
|
|
text = args.get(iParam - 1);
|
|
|
|
} else {
|
2013-04-10 02:49:06 +02:00
|
|
|
text = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m.appendReplacement(sb, Matcher.quoteReplacement(text));
|
|
|
|
}
|
|
|
|
|
|
|
|
m.appendTail(sb);
|
2016-08-10 04:45:28 +02:00
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
String sNewCommand = sb.toString();
|
2016-08-10 04:45:28 +02:00
|
|
|
|
|
|
|
if (ac.type.equals(AliasCommandTypes.REPLY_MESSAGE)) {
|
2013-04-10 02:49:06 +02:00
|
|
|
cs.sendMessage(sNewCommand);
|
2016-08-10 04:45:28 +02:00
|
|
|
} else if (ac.type.equals(AliasCommandTypes.WAIT_THEN_REPLY)) {
|
2013-04-10 02:49:06 +02:00
|
|
|
final CommandSender csWait = cs;
|
|
|
|
final String message = sNewCommand;
|
2016-08-10 04:45:28 +02:00
|
|
|
|
|
|
|
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
|
|
|
|
public void run() {
|
2013-04-10 02:49:06 +02:00
|
|
|
csWait.sendMessage(message);
|
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
}, ac.waitTime);
|
2016-08-10 04:45:28 +02:00
|
|
|
} else if (ac.type.equals(AliasCommandTypes.WAIT_THEN_CONSOLE)) {
|
|
|
|
if (player != null) {
|
2013-04-10 02:49:06 +02:00
|
|
|
plugin.getServer().getScheduler().runTaskLater(plugin, new waitConsoleCommand(sNewCommand.substring(1),
|
2016-08-10 04:45:28 +02:00
|
|
|
"[BetterAlias] " + ChatColor.AQUA + "Running console command for " + player.getName() + ": " + sNewCommand), ac.waitTime);
|
|
|
|
} else {
|
|
|
|
plugin.getServer().getScheduler().runTaskLater(plugin, new waitConsoleCommand(sNewCommand.substring(1),
|
|
|
|
"[BetterAlias] " + ChatColor.AQUA + "Running: " + sNewCommand), ac.waitTime);
|
2013-04-10 02:49:06 +02:00
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
} else if (ac.type.equals(AliasCommandTypes.WAIT)) {
|
|
|
|
if (player != null) {
|
|
|
|
plugin.getServer().getScheduler().runTaskLater(plugin, new waitPlayerCommand(sNewCommand, player.getName()), ac.waitTime);
|
|
|
|
} else {
|
2013-04-10 02:49:06 +02:00
|
|
|
plugin.getServer().getScheduler().runTaskLater(plugin, new waitConsoleCommand(sNewCommand.substring(1),
|
2016-08-10 04:45:28 +02:00
|
|
|
"[BetterAlias] " + ChatColor.AQUA + "Running: " + sNewCommand), ac.waitTime);
|
2013-04-10 02:49:06 +02:00
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
} else if (ac.type.equals(AliasCommandTypes.PLAYER_AS_OP) && player != null) {
|
2015-02-08 15:08:01 +01:00
|
|
|
AliasManager.plugin.getLogger().log(
|
2016-08-10 04:45:28 +02:00
|
|
|
Level.INFO,
|
|
|
|
"[BetterAlias] {0}Running player_as_op command for {1}: {2}",
|
|
|
|
new Object[]{ChatColor.AQUA, player.getName(), sNewCommand}
|
2015-02-08 15:08:01 +01:00
|
|
|
);
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
if (player.isOp() == false) {
|
|
|
|
try {
|
2015-02-08 15:08:01 +01:00
|
|
|
player.setOp(true);
|
|
|
|
AliasManager.plugin.getServer().dispatchCommand(player, sNewCommand.substring(1));
|
2016-08-10 04:45:28 +02:00
|
|
|
} catch (Exception e) {
|
2015-02-08 15:08:01 +01:00
|
|
|
e.printStackTrace();
|
2016-08-10 04:45:28 +02:00
|
|
|
} finally {
|
2015-02-08 15:08:01 +01:00
|
|
|
player.setOp(false);
|
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
} else {
|
2015-02-08 15:08:01 +01:00
|
|
|
AliasManager.plugin.getServer().dispatchCommand(player, sNewCommand.substring(1));
|
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
} else if (ac.type.equals(AliasCommandTypes.CONSOLE)
|
|
|
|
|| player == null) {
|
|
|
|
if (player != null) {
|
|
|
|
plugin.getLogger().log(Level.INFO,
|
2013-04-10 02:49:06 +02:00
|
|
|
"[BetterAlias] {0}Running console command for {1}: {2}",
|
|
|
|
new Object[]{ChatColor.AQUA, player.getName(), sNewCommand});
|
2016-08-10 04:45:28 +02:00
|
|
|
} else {
|
|
|
|
cs.sendMessage("[BetterAlias] " + ChatColor.AQUA + "Running: " + sNewCommand);
|
2013-04-10 02:49:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), sNewCommand.substring(1));
|
2016-08-10 04:45:28 +02:00
|
|
|
} else {
|
2013-04-10 02:49:06 +02:00
|
|
|
player.chat(sNewCommand);
|
|
|
|
}
|
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
public Collection<Alias> getAliasMatches(String sCommand) {
|
|
|
|
String sCommandLower = sCommand.toLowerCase()+" ";
|
|
|
|
|
|
|
|
ArrayList<Alias> aliasMatches = new ArrayList<Alias>();
|
|
|
|
|
|
|
|
for (Alias alias : this.aliases.values()) {
|
|
|
|
if (alias.caseSensitive) {
|
|
|
|
if (sCommand.startsWith(alias.command+" ")) {
|
|
|
|
aliasMatches.add(alias);
|
2013-07-29 22:29:08 +02:00
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
}
|
|
|
|
else if (sCommandLower.startsWith(alias.command+" ")) {
|
|
|
|
aliasMatches.add(alias);
|
2013-07-28 23:57:48 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
|
|
|
|
return aliasMatches;
|
2013-07-28 23:57:48 +02:00
|
|
|
}
|
|
|
|
|
2015-02-08 15:08:01 +01:00
|
|
|
// Delayed tasks
|
2016-08-10 04:45:28 +02:00
|
|
|
private static class waitConsoleCommand implements Runnable {
|
2013-04-10 02:49:06 +02:00
|
|
|
private final String message;
|
|
|
|
private final String command;
|
2016-08-10 04:45:28 +02:00
|
|
|
|
|
|
|
public waitConsoleCommand(String command, String message) {
|
2013-04-10 02:49:06 +02:00
|
|
|
this.message = message;
|
|
|
|
this.command = command;
|
|
|
|
}
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
public void run() {
|
2013-04-10 02:49:06 +02:00
|
|
|
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
private static class waitPlayerCommand implements Runnable {
|
2013-04-10 02:49:06 +02:00
|
|
|
private final String playerName;
|
|
|
|
private final String command;
|
2016-08-10 04:45:28 +02:00
|
|
|
|
|
|
|
public waitPlayerCommand(String command, String playerName) {
|
2013-04-10 02:49:06 +02:00
|
|
|
this.playerName = playerName;
|
|
|
|
this.command = command;
|
|
|
|
}
|
|
|
|
|
2016-08-10 04:45:28 +02:00
|
|
|
public void run() {
|
2013-04-10 02:49:06 +02:00
|
|
|
Player p = plugin.getServer().getPlayer(playerName);
|
2016-08-10 04:45:28 +02:00
|
|
|
|
|
|
|
if (p != null) {
|
2013-04-10 02:49:06 +02:00
|
|
|
p.chat(command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
|
|
|
|
public void copy(InputStream in, File file) {
|
|
|
|
try {
|
2013-04-10 02:49:06 +02:00
|
|
|
OutputStream out = new FileOutputStream(file);
|
|
|
|
byte[] buf = new byte[1024];
|
|
|
|
int len;
|
2016-08-10 04:45:28 +02:00
|
|
|
while ((len = in.read(buf)) > 0) {
|
|
|
|
out.write(buf, 0, len);
|
2013-04-10 02:49:06 +02:00
|
|
|
}
|
|
|
|
out.close();
|
|
|
|
in.close();
|
2016-08-10 04:45:28 +02:00
|
|
|
} catch (Exception e) {
|
2013-04-10 02:49:06 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
|
|
|
|
private String replaceColorCodes(String str) {
|
|
|
|
for (ChatColor cc : ChatColor.values()) {
|
|
|
|
str = str.replace("&" + cc.name(), cc.toString());
|
2013-04-10 02:49:06 +02:00
|
|
|
}
|
2016-08-10 04:45:28 +02:00
|
|
|
|
2013-04-10 02:49:06 +02:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
}
|