Minor cleanup and untested disguise modify commands

This commit is contained in:
libraryaddict 2017-02-20 03:53:03 +13:00
parent 7ab456c7e6
commit 77a7e91766
7 changed files with 284 additions and 170 deletions

View File

@ -1,103 +1,119 @@
name: LibsDisguises
main: me.libraryaddict.disguise.LibsDisguises
description: A disguise plugin with various disguises.
version: ${project.version}
author: libraryaddict
authors: [Byteflux, Navid K.]
softdepend: [ProtocolLib]
commands:
libsdisguises:
permission: libsdisguises.seecmd.libsdisguises
description: Main command for libsdisguises.
disguise:
aliases: [d, dis]
permission: libsdisguises.seecmd.disguise
description: Disguise yourself as an entity.
disguiseentity:
aliases: [dentity, disentity]
permission: libsdisguises.seecmd.disguiseentity
description: Disguise an entity as another entity.
disguisehelp:
aliases: [dhelp, dishelp]
permission: libsdisguises.seecmd.disguisehelp
description: Help command for LibsDisguises.
disguiseplayer:
aliases: [dplayer, displayer]
permission: libsdisguises.seecmd.disguiseplayer
description: Disguise another player as an entity.
disguiseradius:
aliases: [disradius, dradius]
permission: libsdisguises.seecmd.disguiseradius
description: Disguise all entities within a radius as an entity.
undisguise:
aliases: [u, und, undis]
permission: libsdisguises.seecmd.undisguise
description: Undisguise yourself.
undisguiseentity:
aliases: [undisentity, undentity]
permission: libsdisguises.seecmd.undisguiseentity
description: Undisguise an entity.
undisguiseplayer:
aliases: [undisplayer, undplayer]
permission: libsdisguises.seecmd.undisguiseplayer
description: Undisguise a player.
undisguiseradius:
aliases: [undisradius, undradius]
permission: libsdisguises.seecmd.undisguiseradius
description: Undisguise all entities within a radius.
disguiseclone:
aliases: [disguisec, disc, disclone, dclone, clonedisguise, clonedis, cdisguise, cdis]
permission: libsdisguises.seecmd.disguiseclone
description: Copy a disguise (or entity) and use it later.
disguiseviewself:
aliases: [dviewself, dvs, disguisevs, disvs, vsd, viewselfdisguise, viewselfd]
permission: libsdisguises.seecmd.viewself
description: Toggle seeing your own disguise on or off.
permissions:
libsdisguises.reload:
description: Allows the user to reload LibsDisguises.
default: op
libsdisguises.seethrough:
description: Allows player to see through disguises.
default: false
libsdisguises.seecmd:
description: See all commands in tab-completion
default: true
children:
libsdisguises.seecmd.libsdisguises: true
libsdisguises.seecmd.disguise: true
libsdisguises.seecmd.disguiseentity: true
libsdisguises.seecmd.disguisehelp: true
libsdisguises.seecmd.disguiseplayer: true
libsdisguises.seecmd.disguiseradius: true
libsdisguises.seecmd.undisguise: true
libsdisguises.seecmd.undisguiseentity: true
libsdisguises.seecmd.undisguiseplayer: true
libsdisguises.seecmd.undisguiseradius: true
libsdisguises.seecmd.disguiseclone: true
libsdisguises.seecmd.disguiseviewself: true
libsdisguises.seecmd.libsdisguises:
description: See the /libsdisguises command in tab-completion
libsdisguises.seecmd.disguiseviewself:
description: See the /disguiseviewself command in tab-completion
libsdisguises.seecmd.disguise:
description: See the /disguise command in tab-completion
libsdisguises.seecmd.disguiseentity:
description: See the /disguiseentity command in tab-completion
libsdisguises.seecmd.disguisehelp:
description: See the /disguisehelp command in tab-completion
libsdisguises.seecmd.disguiseplayer:
description: See the /disguiseplayer command in tab-completion
libsdisguises.seecmd.disguiseradius:
description: See the /disguiseradius command in tab-completion
libsdisguises.seecmd.undisguise:
description: See the /undisguise command in tab-completion
libsdisguises.seecmd.undisguiseentity:
description: See the /undisguiseentity command in tab-completion
libsdisguises.seecmd.undisguiseplayer:
description: See the /undisguiseplayer command in tab-completion
libsdisguises.seecmd.undisguiseradius:
description: See the /undisguiseradius command in tab-completion
libsdisguises.seecmd.disguiseclone:
description: See the /disguiseclone command in tab-completion
name: LibsDisguises
main: me.libraryaddict.disguise.LibsDisguises
description: A disguise plugin with various disguises.
version: ${project.version}
author: libraryaddict
authors: [Byteflux, Navid K.]
softdepend: [ProtocolLib]
commands:
libsdisguises:
permission: libsdisguises.seecmd.libsdisguises
description: Main command for libsdisguises.
disguise:
aliases: [d, dis]
permission: libsdisguises.seecmd.disguise
description: Disguise yourself as an entity.
disguiseentity:
aliases: [dentity, disentity]
permission: libsdisguises.seecmd.disguiseentity
description: Disguise an entity as another entity.
disguisehelp:
aliases: [dhelp, dishelp]
permission: libsdisguises.seecmd.disguisehelp
description: Help command for LibsDisguises.
disguiseplayer:
aliases: [dplayer, displayer]
permission: libsdisguises.seecmd.disguiseplayer
description: Disguise another player as an entity.
disguiseradius:
aliases: [disradius, dradius]
permission: libsdisguises.seecmd.disguiseradius
description: Disguise all entities within a radius as an entity.
undisguise:
aliases: [u, und, undis]
permission: libsdisguises.seecmd.undisguise
description: Undisguise yourself.
undisguiseentity:
aliases: [undisentity, undentity]
permission: libsdisguises.seecmd.undisguiseentity
description: Undisguise an entity.
undisguiseplayer:
aliases: [undisplayer, undplayer]
permission: libsdisguises.seecmd.undisguiseplayer
description: Undisguise a player.
undisguiseradius:
aliases: [undisradius, undradius]
permission: libsdisguises.seecmd.undisguiseradius
description: Undisguise all entities within a radius.
disguiseclone:
aliases: [disguisec, disc, disclone, dclone, clonedisguise, clonedis, cdisguise, cdis]
permission: libsdisguises.seecmd.disguiseclone
description: Copy a disguise (or entity) and use it later.
disguiseviewself:
aliases: [dviewself, dvs, disguisevs, disvs, vsd, viewselfdisguise, viewselfd]
permission: libsdisguises.seecmd.viewself
description: Toggle seeing your own disguise on or off.
disguisemodify:
aliases: [dmodify]
permission: libsdisguises.seecmd.disguisemodify
description: Modify your own disguise
disguisemodifyplayer:
aliases: [dmodifyplayer]
permission: libsdisguises.seecmd.disguisemodifyplayer
description: Modify the disguise of a player
disguisemodifyradius:
aliases: [dmodifyradius]
permission: libsdisguises.seecmd.disguisemodifyradius
description: Modify disguises in a radius
disguisemodifyentity:
aliases: [dmodifyentity]
permission: libsdisguises.seecmd.disguisemodifyentity
description: Modify a disguise by right clicking them
permissions:
libsdisguises.reload:
description: Allows the user to reload LibsDisguises.
default: op
libsdisguises.seethrough:
description: Allows player to see through disguises.
default: false
libsdisguises.seecmd:
description: See all commands in tab-completion
default: true
children:
libsdisguises.seecmd.libsdisguises: true
libsdisguises.seecmd.disguise: true
libsdisguises.seecmd.disguiseentity: true
libsdisguises.seecmd.disguisehelp: true
libsdisguises.seecmd.disguiseplayer: true
libsdisguises.seecmd.disguiseradius: true
libsdisguises.seecmd.undisguise: true
libsdisguises.seecmd.undisguiseentity: true
libsdisguises.seecmd.undisguiseplayer: true
libsdisguises.seecmd.undisguiseradius: true
libsdisguises.seecmd.disguiseclone: true
libsdisguises.seecmd.disguiseviewself: true
libsdisguises.seecmd.libsdisguises:
description: See the /libsdisguises command in tab-completion
libsdisguises.seecmd.disguiseviewself:
description: See the /disguiseviewself command in tab-completion
libsdisguises.seecmd.disguise:
description: See the /disguise command in tab-completion
libsdisguises.seecmd.disguiseentity:
description: See the /disguiseentity command in tab-completion
libsdisguises.seecmd.disguisehelp:
description: See the /disguisehelp command in tab-completion
libsdisguises.seecmd.disguiseplayer:
description: See the /disguiseplayer command in tab-completion
libsdisguises.seecmd.disguiseradius:
description: See the /disguiseradius command in tab-completion
libsdisguises.seecmd.undisguise:
description: See the /undisguise command in tab-completion
libsdisguises.seecmd.undisguiseentity:
description: See the /undisguiseentity command in tab-completion
libsdisguises.seecmd.undisguiseplayer:
description: See the /undisguiseplayer command in tab-completion
libsdisguises.seecmd.undisguiseradius:
description: See the /undisguiseradius command in tab-completion
libsdisguises.seecmd.disguiseclone:
description: See the /disguiseclone command in tab-completion

View File

@ -1,6 +1,7 @@
package me.libraryaddict.disguise;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@ -41,6 +42,9 @@ import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseParser;
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.ReflectionManager;
import me.libraryaddict.disguise.utilities.UpdateChecker;
@ -50,6 +54,7 @@ public class DisguiseListener implements Listener {
private String currentVersion;
private HashMap<String, Boolean[]> disguiseClone = new HashMap<>();
private HashMap<String, Disguise> disguiseEntity = new HashMap<>();
private HashMap<String, String[]> disguiseModify = new HashMap<>();
private HashMap<String, BukkitRunnable> disguiseRunnable = new HashMap<>();
private String latestVersion;
private LibsDisguises plugin;
@ -310,79 +315,113 @@ public class DisguiseListener implements Listener {
@EventHandler
public void onRightClick(PlayerInteractEntityEvent event) {
if (disguiseEntity.containsKey(event.getPlayer().getName()) || disguiseClone.containsKey(event.getPlayer().getName())) {
Player p = event.getPlayer();
if (!disguiseEntity.containsKey(event.getPlayer().getName()) && !disguiseClone.containsKey(event.getPlayer().getName())) {
return;
}
event.setCancelled(true);
disguiseRunnable.remove(p.getName()).cancel();
Player p = event.getPlayer();
Entity entity = event.getRightClicked();
String entityName;
event.setCancelled(true);
disguiseRunnable.remove(p.getName()).cancel();
if (entity instanceof Player && !disguiseClone.containsKey(p.getName())) {
entityName = entity.getName();
}
else {
entityName = DisguiseType.getType(entity).toReadable();
}
Entity entity = event.getRightClicked();
String entityName;
if (disguiseClone.containsKey(p.getName())) {
Boolean[] options = disguiseClone.remove(p.getName());
if (entity instanceof Player && !disguiseClone.containsKey(p.getName())) {
entityName = entity.getName();
}
else {
entityName = DisguiseType.getType(entity).toReadable();
}
DisguiseUtilities.createClonedDisguise(p, entity, options);
}
else if (disguiseEntity.containsKey(p.getName())) {
Disguise disguise = disguiseEntity.remove(p.getName());
if (disguiseClone.containsKey(p.getName())) {
Boolean[] options = disguiseClone.remove(p.getName());
if (disguise != null) {
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()
&& entity instanceof LivingEntity) {
p.sendMessage(ChatColor.RED
+ "Can't disguise a living entity as a misc disguise. This has been disabled in the config!");
}
else {
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (disguise.getWatcher() instanceof LivingWatcher) {
disguise.getWatcher().setCustomName(((Player) entity).getDisplayName());
DisguiseUtilities.createClonedDisguise(p, entity, options);
}
else if (disguiseEntity.containsKey(p.getName())) {
Disguise disguise = disguiseEntity.remove(p.getName());
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
disguise.getWatcher().setCustomNameVisible(true);
}
}
}
DisguiseAPI.disguiseToAll(entity, disguise);
String disguiseName = "a ";
if (disguise instanceof PlayerDisguise) {
disguiseName = "the player " + ((PlayerDisguise) disguise).getName();
}
else {
disguiseName += disguise.getType().toReadable();
}
if (disguise.isDisguiseInUse()) {
p.sendMessage(ChatColor.RED + "Disguised " + (entity instanceof Player ? "" : "the ") + entityName
+ " as " + disguiseName + "!");
}
else {
p.sendMessage(ChatColor.RED + "Failed to disguise " + (entity instanceof Player ? "" : "the ")
+ entityName + " as " + disguiseName + "!");
}
}
if (disguise != null) {
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()
&& entity instanceof LivingEntity) {
p.sendMessage(ChatColor.RED
+ "Can't disguise a living entity as a misc disguise. This has been disabled in the config!");
}
else {
if (DisguiseAPI.isDisguised(entity)) {
DisguiseAPI.undisguiseToAll(entity);
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (disguise.getWatcher() instanceof LivingWatcher) {
disguise.getWatcher().setCustomName(((Player) entity).getDisplayName());
p.sendMessage(ChatColor.RED + "Undisguised " + (entity instanceof Player ? "" : "the ") + entityName);
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
disguise.getWatcher().setCustomNameVisible(true);
}
}
}
DisguiseAPI.disguiseToAll(entity, disguise);
String disguiseName = "a ";
if (disguise instanceof PlayerDisguise) {
disguiseName = "the player " + ((PlayerDisguise) disguise).getName();
}
else {
p.sendMessage(ChatColor.RED + (entity instanceof Player ? "" : "the") + entityName + " isn't disguised!");
disguiseName += disguise.getType().toReadable();
}
if (disguise.isDisguiseInUse()) {
p.sendMessage(ChatColor.RED + "Disguised " + (entity instanceof Player ? "" : "the ") + entityName
+ " as " + disguiseName + "!");
}
else {
p.sendMessage(ChatColor.RED + "Failed to disguise " + (entity instanceof Player ? "" : "the ")
+ entityName + " as " + disguiseName + "!");
}
}
}
else {
if (DisguiseAPI.isDisguised(entity)) {
DisguiseAPI.undisguiseToAll(entity);
p.sendMessage(ChatColor.RED + "Undisguised " + (entity instanceof Player ? "" : "the ") + entityName);
}
else {
p.sendMessage(ChatColor.RED + (entity instanceof Player ? "" : "the") + entityName + " isn't disguised!");
}
}
}
else if (disguiseModify.containsKey(p.getName())) {
String[] options = disguiseModify.remove(p.getName());
Disguise disguise = DisguiseAPI.getDisguise(p, entity);
if (disguise == null) {
p.sendMessage(ChatColor.RED + entityName + " is not disguised!");
return;
}
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = DisguiseParser.getPermissions(p,
"libsdisguises.disguiseentitymodify.");
if (!perms.containsKey(new DisguisePerm(disguise.getType()))) {
p.sendMessage(ChatColor.RED + "You do not have permission to modify this disguise");
return;
}
try {
DisguiseParser.callMethods(p, disguise, perms.get(new DisguisePerm(disguise.getType())), new ArrayList<String>(),
options);
p.sendMessage(ChatColor.RED + "Modified the disguise!");
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
p.sendMessage(ex.getMessage());
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
@ -538,4 +577,25 @@ public class DisguiseListener implements Listener {
disguiseEntity.put(player, disguise);
}
public void setDisguiseModify(final String player, String[] args) {
if (disguiseRunnable.containsKey(player)) {
BukkitRunnable run = disguiseRunnable.remove(player);
run.cancel();
run.run();
}
BukkitRunnable runnable = new BukkitRunnable() {
@Override
public void run() {
disguiseModify.remove(player);
disguiseRunnable.remove(player);
}
};
runnable.runTaskLater(plugin, 20 * DisguiseConfig.getDisguiseEntityExpire());
disguiseRunnable.put(player, runnable);
disguiseModify.put(player, args);
}
}

View File

@ -26,6 +26,10 @@ import me.libraryaddict.disguise.commands.DisguiseCloneCommand;
import me.libraryaddict.disguise.commands.DisguiseCommand;
import me.libraryaddict.disguise.commands.DisguiseEntityCommand;
import me.libraryaddict.disguise.commands.DisguiseHelpCommand;
import me.libraryaddict.disguise.commands.DisguiseModifyCommand;
import me.libraryaddict.disguise.commands.DisguiseModifyEntityCommand;
import me.libraryaddict.disguise.commands.DisguiseModifyPlayerCommand;
import me.libraryaddict.disguise.commands.DisguiseModifyRadiusCommand;
import me.libraryaddict.disguise.commands.DisguisePlayerCommand;
import me.libraryaddict.disguise.commands.DisguiseRadiusCommand;
import me.libraryaddict.disguise.commands.DisguiseViewSelfCommand;
@ -35,8 +39,8 @@ import me.libraryaddict.disguise.commands.UndisguiseEntityCommand;
import me.libraryaddict.disguise.commands.UndisguisePlayerCommand;
import me.libraryaddict.disguise.commands.UndisguiseRadiusCommand;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ArrowWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher;
@ -116,6 +120,10 @@ public class LibsDisguises extends JavaPlugin {
registerCommand("disguiseclone", new DisguiseCloneCommand());
registerCommand("libsdisguises", new LibsDisguisesCommand());
registerCommand("disguiseviewself", new DisguiseViewSelfCommand());
registerCommand("disguisemodify", new DisguiseModifyCommand());
registerCommand("disguisemodifyentity", new DisguiseModifyEntityCommand());
registerCommand("disguisemodifyplayer", new DisguiseModifyPlayerCommand());
registerCommand("disguisemodifyradius", new DisguiseModifyRadiusCommand(getConfig().getInt("DisguiseRadiusMax")));
try {
Metrics metrics = new Metrics(this);

View File

@ -66,7 +66,7 @@ public abstract class DisguiseBaseCommand implements CommandExecutor {
return newArgs.toArray(new String[0]);
}
public String getPermNode() {
public final String getPermNode() {
if (this instanceof DisguiseCommand) {
return "disguise";
}
@ -79,8 +79,21 @@ public abstract class DisguiseBaseCommand implements CommandExecutor {
else if (this instanceof DisguiseRadiusCommand) {
return "disguiseradius";
}
else
else if (this instanceof DisguiseModifyCommand) {
return "disguisemodify";
}
else if (this instanceof DisguiseModifyEntityCommand) {
return "disguisemodifyentity";
}
else if (this instanceof DisguiseModifyPlayerCommand) {
return "disguisemodifyplayer";
}
else if (this instanceof DisguiseModifyRadiusCommand) {
return "disguisemodifyradius";
}
else {
throw new UnsupportedOperationException("Unknown disguise command, perm node not found");
}
}
protected HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> getPermissions(CommandSender sender) {

View File

@ -11,6 +11,7 @@ import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseAPI;
@ -27,7 +28,7 @@ import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo;
public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
if (!(sender instanceof Entity)) {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}

View File

@ -27,11 +27,16 @@ import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo;
public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}
if (getPermissions(sender).isEmpty()) {
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
return true;
}
if (args.length == 0) {
sendCommandUsage(sender, getPermissions(sender));
return true;
@ -56,7 +61,7 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom
LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), disguise);
sender.sendMessage(ChatColor.RED + "Right click a entity in the next " + DisguiseConfig.getDisguiseEntityExpire()
sender.sendMessage(ChatColor.RED + "Right click an entity in the next " + DisguiseConfig.getDisguiseEntityExpire()
+ " seconds to disguise it as a " + disguise.getType().toReadable() + "!");
return true;
}
@ -64,6 +69,11 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<String>();
if (!(sender instanceof Player)) {
return tabs;
}
String[] args = getArgs(origArgs);
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = getPermissions(sender);

View File

@ -690,8 +690,16 @@ public class DisguiseParser {
// Copy strings to their new range
String[] newArgs = new String[args.length - toSkip];
System.arraycopy(args, toSkip, newArgs, 0, args.length - toSkip);
args = newArgs;
callMethods(sender, disguise, optionPermissions, usedOptions, newArgs);
// Alright. We've constructed our disguise.
return disguise;
}
public static void callMethods(CommandSender sender, Disguise disguise, HashMap<ArrayList<String>, Boolean> optionPermissions,
ArrayList<String> usedOptions, String[] args)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, DisguiseParseException {
Method[] methods = ReflectionFlagWatchers.getDisguiseWatcherMethods(disguise.getWatcher().getClass());
for (int i = 0; i < args.length; i += 2) {
@ -970,8 +978,6 @@ public class DisguiseParser {
methodToUse.invoke(disguise, value);
}
}
// Alright. We've constructed our disguise.
return disguise;
}
private static DisguiseParseException parseToException(String expectedValue, String receivedInstead, String methodName) {