Now can clone a player without clicking on them
This commit is contained in:
		
							
								
								
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							| @@ -3,7 +3,7 @@ | |||||||
| 	<modelVersion>4.0.0</modelVersion> | 	<modelVersion>4.0.0</modelVersion> | ||||||
| 	<groupId>LibsDisguises</groupId> | 	<groupId>LibsDisguises</groupId> | ||||||
| 	<artifactId>LibsDisguises</artifactId> | 	<artifactId>LibsDisguises</artifactId> | ||||||
| 	<version>9.2.4</version> | 	<version>9.2.4-SNAPSHOT</version> | ||||||
|  |  | ||||||
| 	<build> | 	<build> | ||||||
| 		<sourceDirectory>src</sourceDirectory> | 		<sourceDirectory>src</sourceDirectory> | ||||||
|   | |||||||
| @@ -156,6 +156,7 @@ public class DisguiseAPI { | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return disguise; |         return disguise; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -329,41 +329,7 @@ public class DisguiseListener implements Listener { | |||||||
|             if (disguiseClone.containsKey(p.getName())) { |             if (disguiseClone.containsKey(p.getName())) { | ||||||
|                 Boolean[] options = disguiseClone.remove(p.getName()); |                 Boolean[] options = disguiseClone.remove(p.getName()); | ||||||
|  |  | ||||||
|                 Disguise disguise = DisguiseAPI.getDisguise(p, entity); |                 DisguiseUtilities.createClonedDisguise(p, entity, options); | ||||||
|  |  | ||||||
|                 if (disguise == null) { |  | ||||||
|                     disguise = DisguiseAPI.constructDisguise(entity, options[0], options[1], options[2]); |  | ||||||
|                 } |  | ||||||
|                 else { |  | ||||||
|                     disguise = disguise.clone(); |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray(); |  | ||||||
|  |  | ||||||
|                 String reference = null; |  | ||||||
|                 int referenceLength = Math.max(2, (int) Math.ceil((0.1D + DisguiseConfig.getMaxClonedDisguises()) / 26D)); |  | ||||||
|                 int attempts = 0; |  | ||||||
|  |  | ||||||
|                 while (reference == null && attempts++ < 1000) { |  | ||||||
|                     reference = "@"; |  | ||||||
|  |  | ||||||
|                     for (int i = 0; i < referenceLength; i++) { |  | ||||||
|                         reference += alphabet[DisguiseUtilities.random.nextInt(alphabet.length)]; |  | ||||||
|                     } |  | ||||||
|  |  | ||||||
|                     if (DisguiseUtilities.getClonedDisguise(reference) != null) { |  | ||||||
|                         reference = null; |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 if (reference != null && DisguiseUtilities.addClonedDisguise(reference, disguise)) { |  | ||||||
|                     p.sendMessage(ChatColor.RED + "Constructed a " + entityName + " disguise! Your reference is " + reference); |  | ||||||
|                     p.sendMessage(ChatColor.RED + "Example usage: /disguise " + reference); |  | ||||||
|                 } |  | ||||||
|                 else { |  | ||||||
|                     p.sendMessage( |  | ||||||
|                             ChatColor.RED + "Failed to store the reference due to lack of size. Please set this in the config"); |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|             else if (disguiseEntity.containsKey(p.getName())) { |             else if (disguiseEntity.containsKey(p.getName())) { | ||||||
|                 Disguise disguise = disguiseEntity.remove(p.getName()); |                 Disguise disguise = disguiseEntity.remove(p.getName()); | ||||||
|   | |||||||
| @@ -5,14 +5,17 @@ import java.util.HashMap; | |||||||
| import java.util.List; | import java.util.List; | ||||||
|  |  | ||||||
| import org.apache.commons.lang.StringUtils; | import org.apache.commons.lang.StringUtils; | ||||||
|  | import org.bukkit.Bukkit; | ||||||
| import org.bukkit.ChatColor; | import org.bukkit.ChatColor; | ||||||
| import org.bukkit.command.Command; | import org.bukkit.command.Command; | ||||||
| import org.bukkit.command.CommandSender; | import org.bukkit.command.CommandSender; | ||||||
| import org.bukkit.command.TabCompleter; | import org.bukkit.command.TabCompleter; | ||||||
|  | import org.bukkit.entity.Player; | ||||||
|  |  | ||||||
| import me.libraryaddict.disguise.DisguiseConfig; | import me.libraryaddict.disguise.DisguiseConfig; | ||||||
| import me.libraryaddict.disguise.LibsDisguises; | import me.libraryaddict.disguise.LibsDisguises; | ||||||
| import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; | import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; | ||||||
|  | import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||||
|  |  | ||||||
| public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabCompleter { | public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabCompleter { | ||||||
|     @Override |     @Override | ||||||
| @@ -26,8 +29,14 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp | |||||||
|             boolean doEquipment = true; |             boolean doEquipment = true; | ||||||
|             boolean doSneak = false; |             boolean doSneak = false; | ||||||
|             boolean doSprint = false; |             boolean doSprint = false; | ||||||
|  |             Player player = null; | ||||||
|  |  | ||||||
|             for (String option : args) { |             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") |                 if (StringUtils.startsWithIgnoreCase(option, "ignoreEquip") | ||||||
|                         || StringUtils.startsWithIgnoreCase(option, "ignoreEnquip")) { |                         || StringUtils.startsWithIgnoreCase(option, "ignoreEnquip")) { | ||||||
|                     doEquipment = false; |                     doEquipment = false; | ||||||
| @@ -49,12 +58,19 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             LibsDisguises.getInstance().getListener().setDisguiseClone(sender.getName(), new Boolean[] { |             Boolean[] options = new Boolean[] { | ||||||
|                     doEquipment, doSneak, doSprint |                     doEquipment, doSneak, doSprint | ||||||
|             }); |             }; | ||||||
|  |  | ||||||
|             sender.sendMessage(ChatColor.RED + "Right click a entity in the next " + DisguiseConfig.getDisguiseCloneExpire() |             if (player != null) { | ||||||
|                     + " seconds to grab the disguise reference!"); |                 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!"); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|         else { |         else { | ||||||
|             sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); |             sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); | ||||||
| @@ -67,6 +83,14 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp | |||||||
|     public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { |     public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { | ||||||
|         ArrayList<String> tabs = new ArrayList<String>(); |         ArrayList<String> tabs = new ArrayList<String>(); | ||||||
|  |  | ||||||
|  |         String[] args = getArgs(origArgs); | ||||||
|  |  | ||||||
|  |         if (args.length == 0) { | ||||||
|  |             for (Player player : Bukkit.getOnlinePlayers()) { | ||||||
|  |                 tabs.add(player.getName()); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|         tabs.add("ignoreEquip"); |         tabs.add("ignoreEquip"); | ||||||
|         tabs.add("doSneakSprint"); |         tabs.add("doSneakSprint"); | ||||||
|         tabs.add("doSneak"); |         tabs.add("doSneak"); | ||||||
|   | |||||||
| @@ -17,6 +17,7 @@ import java.util.UUID; | |||||||
| import java.util.regex.Pattern; | import java.util.regex.Pattern; | ||||||
|  |  | ||||||
| import org.bukkit.Bukkit; | import org.bukkit.Bukkit; | ||||||
|  | import org.bukkit.ChatColor; | ||||||
| import org.bukkit.Location; | import org.bukkit.Location; | ||||||
| import org.bukkit.Material; | import org.bukkit.Material; | ||||||
| import org.bukkit.World; | import org.bukkit.World; | ||||||
| @@ -58,6 +59,9 @@ import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; | |||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; | ||||||
| import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets; | import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets; | ||||||
|  | import net.md_5.bungee.api.chat.ClickEvent; | ||||||
|  | import net.md_5.bungee.api.chat.ClickEvent.Action; | ||||||
|  | import net.md_5.bungee.api.chat.ComponentBuilder; | ||||||
|  |  | ||||||
| public class DisguiseUtilities { | public class DisguiseUtilities { | ||||||
|     public static final Random random = new Random(); |     public static final Random random = new Random(); | ||||||
| @@ -143,6 +147,50 @@ public class DisguiseUtilities { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public static void createClonedDisguise(Player player, Entity toClone, Boolean[] options) { | ||||||
|  |         Disguise disguise = DisguiseAPI.getDisguise(player, toClone); | ||||||
|  |  | ||||||
|  |         if (disguise == null) { | ||||||
|  |             disguise = DisguiseAPI.constructDisguise(toClone, options[0], options[1], options[2]); | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             disguise = disguise.clone(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray(); | ||||||
|  |  | ||||||
|  |         String reference = null; | ||||||
|  |         int referenceLength = Math.max(2, (int) Math.ceil((0.1D + DisguiseConfig.getMaxClonedDisguises()) / 26D)); | ||||||
|  |         int attempts = 0; | ||||||
|  |  | ||||||
|  |         while (reference == null && attempts++ < 1000) { | ||||||
|  |             reference = "@"; | ||||||
|  |  | ||||||
|  |             for (int i = 0; i < referenceLength; i++) { | ||||||
|  |                 reference += alphabet[DisguiseUtilities.random.nextInt(alphabet.length)]; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             if (DisguiseUtilities.getClonedDisguise(reference) != null) { | ||||||
|  |                 reference = null; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (reference != null && DisguiseUtilities.addClonedDisguise(reference, disguise)) { | ||||||
|  |             String entityName = DisguiseType.getType(toClone).toReadable(); | ||||||
|  |  | ||||||
|  |             ComponentBuilder text = new ComponentBuilder( | ||||||
|  |                     ChatColor.RED + "Constructed a " + entityName + " disguise! Your reference is "); | ||||||
|  |             text.append(reference).event(new ClickEvent(Action.SUGGEST_COMMAND, reference)); | ||||||
|  |  | ||||||
|  |             player.sendRawMessage(text.toString()); | ||||||
|  |             player.sendMessage(ChatColor.RED + "Example usage: /disguise " + reference); | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             player.sendMessage( | ||||||
|  |                     ChatColor.RED + "Failed to store the reference, too many cloned disguises. Please set this in the config"); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public static boolean addClonedDisguise(String key, Disguise disguise) { |     public static boolean addClonedDisguise(String key, Disguise disguise) { | ||||||
|         if (DisguiseConfig.getMaxClonedDisguises() > 0) { |         if (DisguiseConfig.getMaxClonedDisguises() > 0) { | ||||||
|             if (clonedDisguises.containsKey(key)) { |             if (clonedDisguises.containsKey(key)) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user