Add Disguise Clone command to clone a entity to look like them

This commit is contained in:
libraryaddict 2014-06-02 04:08:54 +12:00
parent fb1f7a698c
commit 4262221133
6 changed files with 124 additions and 19 deletions

View File

@ -22,4 +22,6 @@ commands:
undisguiseplayer: undisguiseplayer:
aliases: [undisplayer, undplayer] aliases: [undisplayer, undplayer]
undisguiseradius: undisguiseradius:
aliases: [undisradius, undradius] aliases: [undisradius, undradius]
disguiseclone:
aliases: [disguisec, disc, disclone, dclone, clonedisguise, clonedis, cdisguise, cdis]

View File

@ -30,8 +30,9 @@ import org.bukkit.scheduler.BukkitRunnable;
public class DisguiseListener implements Listener { public class DisguiseListener implements Listener {
private String currentVersion; private String currentVersion;
private HashMap<String, Boolean[]> disguiseClone = new HashMap<String, Boolean[]>();
private HashMap<String, Disguise> disguiseEntity = new HashMap<String, Disguise>();
private HashMap<String, BukkitRunnable> disguiseRunnable = new HashMap<String, BukkitRunnable>(); private HashMap<String, BukkitRunnable> disguiseRunnable = new HashMap<String, BukkitRunnable>();
private HashMap<String, Disguise> disguiseSlap = new HashMap<String, Disguise>();
private String latestVersion; private String latestVersion;
private LibsDisguises plugin; private LibsDisguises plugin;
private String updateMessage = ChatColor.RED + "[LibsDisguises] " + ChatColor.DARK_RED private String updateMessage = ChatColor.RED + "[LibsDisguises] " + ChatColor.DARK_RED
@ -120,10 +121,9 @@ public class DisguiseListener implements Listener {
@EventHandler @EventHandler
public void onRightClick(PlayerInteractEntityEvent event) { public void onRightClick(PlayerInteractEntityEvent event) {
if (disguiseSlap.containsKey(event.getPlayer().getName())) { if (disguiseEntity.containsKey(event.getPlayer().getName()) || disguiseClone.containsKey(event.getPlayer().getName())) {
Player p = event.getPlayer(); Player p = event.getPlayer();
event.setCancelled(true); event.setCancelled(true);
Disguise disguise = disguiseSlap.remove(p.getName());
disguiseRunnable.remove(p.getName()).cancel(); disguiseRunnable.remove(p.getName()).cancel();
Entity entity = event.getRightClicked(); Entity entity = event.getRightClicked();
String entityName = ""; String entityName = "";
@ -138,21 +138,36 @@ public class DisguiseListener implements Listener {
} }
} }
} }
Disguise disguise = null;
Entity disguiseTarget = null;
if (disguiseClone.containsKey(p.getName())) {
Boolean[] options = disguiseClone.remove(p.getName());
disguiseTarget = p;
disguise = DisguiseAPI.getDisguise(p, entity);
if (disguise == null) {
disguise = DisguiseAPI.constructDisguise(entity, options[0], options[1], options[2]);
} else {
disguise = disguise.clone();
}
} else if (disguiseEntity.containsKey(p.getName())) {
disguiseTarget = entity;
disguise = disguiseEntity.remove(p.getName());
}
if (disguise != null) { if (disguise != null) {
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()
&& entity instanceof LivingEntity) { && disguiseTarget instanceof LivingEntity) {
p.sendMessage(ChatColor.RED p.sendMessage(ChatColor.RED
+ "Can't disguise a living entity as a misc disguise. This has been disabled in the config!"); + "Can't disguise a living entity as a misc disguise. This has been disabled in the config!");
} else { } else {
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) { if (disguiseTarget instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (disguise.getWatcher() instanceof LivingWatcher) { if (disguise.getWatcher() instanceof LivingWatcher) {
((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) entity).getDisplayName()); ((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) disguiseTarget).getDisplayName());
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) { if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true); ((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true);
} }
} }
} }
DisguiseAPI.disguiseToAll(entity, disguise); DisguiseAPI.disguiseToAll(disguiseTarget, disguise);
String disguiseName = "a "; String disguiseName = "a ";
if (disguise instanceof PlayerDisguise) { if (disguise instanceof PlayerDisguise) {
disguiseName = "the player " + ((PlayerDisguise) disguise).getName(); disguiseName = "the player " + ((PlayerDisguise) disguise).getName();
@ -165,8 +180,13 @@ public class DisguiseListener implements Listener {
} }
} }
} }
p.sendMessage(ChatColor.RED + "Disguised " + (entity instanceof Player ? "" : "the ") + entityName + " as " if (disguiseTarget == p) {
+ disguiseName + "!"); p.sendMessage(ChatColor.RED + "Disguised yourself" + " as " + (entity instanceof Player ? "" : "a ")
+ entityName + "!");
} else {
p.sendMessage(ChatColor.RED + "Disguised " + (entity instanceof Player ? "" : "the ") + entityName
+ " as " + disguiseName + "!");
}
} }
} else { } else {
if (DisguiseAPI.isDisguised(entity)) { if (DisguiseAPI.isDisguised(entity)) {
@ -222,20 +242,38 @@ public class DisguiseListener implements Listener {
} }
} }
public void setSlap(final String player, Disguise disguise) { public void setDisguiseClone(final String player, Boolean[] options) {
if (disguiseSlap.containsKey(player)) { if (disguiseRunnable.containsKey(player)) {
disguiseSlap.remove(player); BukkitRunnable run = disguiseRunnable.remove(player);
disguiseRunnable.remove(player).cancel(); run.cancel();
run.run();
} }
BukkitRunnable runnable = new BukkitRunnable() { BukkitRunnable runnable = new BukkitRunnable() {
public void run() { public void run() {
disguiseSlap.remove(player); disguiseClone.remove(player);
disguiseRunnable.remove(player); disguiseRunnable.remove(player);
} }
}; };
runnable.runTaskLater(plugin, 20 * 10); runnable.runTaskLater(plugin, 20 * 10);
disguiseRunnable.put(player, runnable); disguiseRunnable.put(player, runnable);
disguiseSlap.put(player, disguise); disguiseClone.put(player, options);
}
public void setDisguiseEntity(final String player, Disguise disguise) {
if (disguiseRunnable.containsKey(player)) {
BukkitRunnable run = disguiseRunnable.remove(player);
run.cancel();
run.run();
}
BukkitRunnable runnable = new BukkitRunnable() {
public void run() {
disguiseEntity.remove(player);
disguiseRunnable.remove(player);
}
};
runnable.runTaskLater(plugin, 20 * 10);
disguiseRunnable.put(player, runnable);
disguiseEntity.put(player, disguise);
} }
} }

View File

@ -138,6 +138,7 @@ public class LibsDisguises extends JavaPlugin {
getCommand("disguiseradius").setExecutor(new DisguiseRadiusCommand(getConfig().getInt("DisguiseRadiusMax"))); getCommand("disguiseradius").setExecutor(new DisguiseRadiusCommand(getConfig().getInt("DisguiseRadiusMax")));
getCommand("undisguiseradius").setExecutor(new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax"))); getCommand("undisguiseradius").setExecutor(new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax")));
getCommand("disguisehelp").setExecutor(new DisguiseHelpCommand()); getCommand("disguisehelp").setExecutor(new DisguiseHelpCommand());
getCommand("disguiseclone").setExecutor(new DisguiseCloneCommand(listener));
getCommand("libsdisguises").setExecutor(new LibsDisguisesCommand()); getCommand("libsdisguises").setExecutor(new LibsDisguisesCommand());
registerValues(); registerValues();
} }

View File

@ -0,0 +1,64 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseListener;
import me.libraryaddict.disguise.utilities.BaseDisguiseCommand;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
public class DisguiseCloneCommand extends BaseDisguiseCommand {
private DisguiseListener listener;
public DisguiseCloneCommand(DisguiseListener listener) {
this.listener = listener;
}
@Override
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;
}
if (sender.hasPermission("libsdisguises.disguise.disguiseclone")) {
boolean doEnquipment = true;
boolean doSneak = false;
boolean doSprint = false;
for (String option : args) {
if (StringUtils.startsWithIgnoreCase(option, "ignoreEnquip")) {
doEnquipment = false;
} else if (option.equalsIgnoreCase("doSneakSprint")) {
doSneak = true;
doSprint = true;
} else if (option.equalsIgnoreCase("doSneak")) {
doSneak = true;
} else if (option.equalsIgnoreCase("doSprint")) {
doSprint = true;
} else {
sender.sendMessage(ChatColor.DARK_RED + "Unknown option '" + option
+ "' - Valid options are 'IgnoreEnquipment' 'DoSneakSprint' 'DoSneak' 'DoSprint'");
return true;
}
}
listener.setDisguiseClone(sender.getName(), new Boolean[] { doEnquipment, doSneak, doSprint });
sender.sendMessage(ChatColor.RED + "Right click a entity in the next 10 seconds to disguise as it!");
} else {
sender.sendMessage(ChatColor.RED + "There was once a curious little boy,"
+ " he liked to try out these strange sounding commands."
+ " One day, that curious little boy tried out the wrong command and was set on fire!" + " Aka.");
sender.sendMessage(ChatColor.DARK_RED + "You are forbidden to use this command.");
}
return true;
}
/**
* Send the player the information
*/
protected void sendCommandUsage(CommandSender sender) {
sender.sendMessage(ChatColor.DARK_GREEN + "Disguise as the entity you right click! Or as their disguise!");
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseclone IgnoreEnquipment" + ChatColor.DARK_GREEN + "("
+ ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")");
}
}

View File

@ -35,7 +35,7 @@ public class DisguiseEntityCommand extends BaseDisguiseCommand {
} }
return true; return true;
} }
listener.setSlap(sender.getName(), disguise); listener.setDisguiseEntity(sender.getName(), disguise);
sender.sendMessage(ChatColor.RED + "Right click a entity in the next 10 seconds to disguise it as a " sender.sendMessage(ChatColor.RED + "Right click a entity in the next 10 seconds to disguise it as a "
+ disguise.getType().toReadable() + "!"); + disguise.getType().toReadable() + "!");
return true; return true;

View File

@ -21,10 +21,10 @@ public class UndisguiseEntityCommand implements CommandExecutor {
return true; return true;
} }
if (sender.hasPermission("libsdisguises.undisguiseentity")) { if (sender.hasPermission("libsdisguises.undisguiseentity")) {
listener.setSlap(sender.getName(), null); listener.setDisguiseEntity(sender.getName(), null);
sender.sendMessage(ChatColor.RED + "Right click a disguised entity to undisguise them!"); sender.sendMessage(ChatColor.RED + "Right click a disguised entity to undisguise them!");
} else } else
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command!"); sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
return true; return true;
} }
} }