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

104 lines
3.8 KiB
Java
Raw Normal View History

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.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
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;
2017-06-19 11:23:02 +02:00
import java.util.ArrayList;
import java.util.List;
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")) {
2017-06-19 19:06:35 +02:00
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
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];
2017-06-21 21:20:12 +02:00
if (StringUtils.startsWithIgnoreCase(option, LibsMsg.DCLONE_EQUIP.get())) {
doEquipment = false;
2017-06-21 21:20:12 +02:00
} else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SNEAKSPRINT.get())) {
doSneak = true;
doSprint = true;
2017-06-21 21:20:12 +02:00
} else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SNEAK.get())) {
doSneak = true;
2017-06-21 21:20:12 +02:00
} else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SPRINT.get())) {
doSprint = true;
2017-06-19 11:23:02 +02:00
} else {
2017-06-19 19:06:35 +02:00
sender.sendMessage(LibsMsg.INVALID_CLONE.get(option));
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
if (player != null) {
DisguiseUtilities.createClonedDisguise((Player) sender, player, options);
2017-06-19 11:23:02 +02:00
} else {
LibsDisguises.getInstance().getListener().setDisguiseClone(sender.getName(), options);
2017-06-19 19:06:35 +02:00
sender.sendMessage(LibsMsg.CLICK_TIMER.get(DisguiseConfig.getDisguiseCloneExpire()));
}
2017-06-19 11:23:02 +02:00
} else {
2017-06-19 19:06:35 +02:00
sender.sendMessage(LibsMsg.NO_PERM.get());
}
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) {
2017-06-19 11:23:02 +02:00
ArrayList<String> tabs = new ArrayList<>();
2016-11-28 15:01:06 +01:00
String[] args = getArgs(origArgs);
if (args.length == 0) {
for (Player player : Bukkit.getOnlinePlayers()) {
// If command user cannot see player online, don't tab-complete name
if (sender instanceof Player && !((Player) sender).canSee(player)) {
continue;
}
tabs.add(player.getName());
}
}
2017-06-21 21:20:12 +02:00
tabs.add(LibsMsg.DCLONE_EQUIP.get());
tabs.add(LibsMsg.DCLONE_SNEAKSPRINT.get());
tabs.add(LibsMsg.DCLONE_SNEAK.get());
tabs.add(LibsMsg.DCLONE_SPRINT.get());
2016-11-28 15:01:06 +01:00
return filterTabs(tabs, origArgs);
}
/**
* Send the player the information
*/
@Override
protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) {
2017-06-19 19:06:35 +02:00
sender.sendMessage(LibsMsg.CLONE_HELP1.get());
sender.sendMessage(LibsMsg.CLONE_HELP2.get());
sender.sendMessage(LibsMsg.CLONE_HELP3.get());
}
}