2016-06-18 17:16:32 +02:00
|
|
|
package me.libraryaddict.disguise.commands;
|
|
|
|
|
2017-06-19 11:23:02 +02:00
|
|
|
import me.libraryaddict.disguise.DisguiseConfig;
|
|
|
|
import me.libraryaddict.disguise.LibsDisguises;
|
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
|
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
|
|
|
import me.libraryaddict.disguise.utilities.TranslateType;
|
2016-06-18 17:16:32 +02:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2017-01-20 19:58:51 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2016-06-18 17:16:32 +02:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2016-11-28 15:01:06 +01:00
|
|
|
import org.bukkit.command.TabCompleter;
|
2017-01-20 19:58:51 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2016-06-18 17:16:32 +02:00
|
|
|
|
2017-06-19 11:23:02 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
2016-06-18 17:16:32 +02:00
|
|
|
|
2016-11-28 22:47:48 +01:00
|
|
|
public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabCompleter {
|
2016-06-18 17:16:32 +02:00
|
|
|
@Override
|
2016-11-28 15:01:06 +01:00
|
|
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
|
|
if (sender.getName().equals("CONSOLE")) {
|
2017-06-19 11:23:02 +02:00
|
|
|
sender.sendMessage(
|
|
|
|
TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the console!"));
|
2016-06-18 17:16:32 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-11-28 15:01:06 +01:00
|
|
|
|
|
|
|
if (sender.hasPermission("libsdisguises.disguise.disguiseclone")) {
|
2016-06-18 17:16:32 +02:00
|
|
|
boolean doEquipment = true;
|
|
|
|
boolean doSneak = false;
|
|
|
|
boolean doSprint = false;
|
2017-01-20 19:58:51 +01:00
|
|
|
Player player = null;
|
2016-11-28 15:01:06 +01:00
|
|
|
|
2017-01-20 19:58:51 +01:00
|
|
|
if (args.length > 0) {
|
|
|
|
player = Bukkit.getPlayerExact(args[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = player == null ? 0 : 1; i < args.length; i++) {
|
|
|
|
String option = args[i];
|
2017-06-19 11:23:02 +02:00
|
|
|
if (StringUtils.startsWithIgnoreCase(option, "ignoreEquip") || StringUtils.startsWithIgnoreCase(option,
|
|
|
|
"ignoreEnquip")) {
|
2016-06-18 17:16:32 +02:00
|
|
|
doEquipment = false;
|
2017-06-19 11:23:02 +02:00
|
|
|
} else if (option.equalsIgnoreCase("doSneakSprint")) {
|
2016-06-18 17:16:32 +02:00
|
|
|
doSneak = true;
|
|
|
|
doSprint = true;
|
2017-06-19 11:23:02 +02:00
|
|
|
} else if (option.equalsIgnoreCase("doSneak")) {
|
2016-06-18 17:16:32 +02:00
|
|
|
doSneak = true;
|
2017-06-19 11:23:02 +02:00
|
|
|
} else if (option.equalsIgnoreCase("doSprint")) {
|
2016-06-18 17:16:32 +02:00
|
|
|
doSprint = true;
|
2017-06-19 11:23:02 +02:00
|
|
|
} else {
|
|
|
|
sender.sendMessage(String.format(TranslateType.MESSAGE.get(
|
|
|
|
ChatColor.DARK_RED + "Unknown " + "option '%s" + "' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' 'DoSneak' 'DoSprint'"),
|
|
|
|
option));
|
2016-06-18 17:16:32 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-11-28 15:01:06 +01:00
|
|
|
|
2017-06-19 11:23:02 +02:00
|
|
|
Boolean[] options = new Boolean[]{doEquipment, doSneak, doSprint};
|
2016-11-28 15:01:06 +01:00
|
|
|
|
2017-01-20 19:58:51 +01:00
|
|
|
if (player != null) {
|
|
|
|
DisguiseUtilities.createClonedDisguise((Player) sender, player, options);
|
2017-06-19 11:23:02 +02:00
|
|
|
} else {
|
2017-01-20 19:58:51 +01:00
|
|
|
LibsDisguises.getInstance().getListener().setDisguiseClone(sender.getName(), options);
|
|
|
|
|
2017-06-19 11:23:02 +02:00
|
|
|
sender.sendMessage(String.format(TranslateType.MESSAGE.get(
|
|
|
|
ChatColor.RED + "Right click a entity in the next %s" + " seconds to grab the disguise reference!"),
|
|
|
|
DisguiseConfig.getDisguiseCloneExpire()));
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
2017-06-19 11:23:02 +02:00
|
|
|
} else {
|
|
|
|
sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command."));
|
2016-06-18 17:16:32 +02:00
|
|
|
}
|
2016-11-28 15:01:06 +01:00
|
|
|
|
2016-06-18 17:16:32 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-28 15:01:06 +01:00
|
|
|
@Override
|
|
|
|
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
|
2017-06-19 11:23:02 +02:00
|
|
|
ArrayList<String> tabs = new ArrayList<>();
|
2016-11-28 15:01:06 +01:00
|
|
|
|
2017-01-20 19:58:51 +01:00
|
|
|
String[] args = getArgs(origArgs);
|
|
|
|
|
|
|
|
if (args.length == 0) {
|
|
|
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
|
|
tabs.add(player.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 15:01:06 +01:00
|
|
|
tabs.add("ignoreEquip");
|
|
|
|
tabs.add("doSneakSprint");
|
|
|
|
tabs.add("doSneak");
|
|
|
|
tabs.add("doSprint");
|
|
|
|
|
|
|
|
return filterTabs(tabs, origArgs);
|
|
|
|
}
|
|
|
|
|
2016-06-18 17:16:32 +02:00
|
|
|
/**
|
|
|
|
* Send the player the information
|
|
|
|
*/
|
|
|
|
@Override
|
2017-06-19 11:23:02 +02:00
|
|
|
protected void sendCommandUsage(CommandSender sender,
|
|
|
|
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) {
|
|
|
|
sender.sendMessage(TranslateType.MESSAGE.get(
|
|
|
|
ChatColor.DARK_GREEN + "Right click a entity to get a disguise reference you can pass to other " + "disguise commands!"));
|
|
|
|
sender.sendMessage(TranslateType.MESSAGE.get(
|
|
|
|
ChatColor.DARK_GREEN + "Security note: Any references you create will be available to all players " + "able to use disguise references."));
|
|
|
|
sender.sendMessage(TranslateType.MESSAGE.get(
|
|
|
|
ChatColor.DARK_GREEN + "/disguiseclone IgnoreEquipment" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")"));
|
2016-06-18 17:16:32 +02:00
|
|
|
}
|
|
|
|
}
|