LibsDisguises/src/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java

115 lines
4.4 KiB
Java
Raw Normal View History

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