Now can clone a player without clicking on them

This commit is contained in:
libraryaddict 2017-01-21 07:58:51 +13:00
parent 5bc64bdae3
commit d84ec1fd2c
5 changed files with 514 additions and 475 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>LibsDisguises</groupId>
<artifactId>LibsDisguises</artifactId>
<version>9.2.4</version>
<version>9.2.4-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>

View File

@ -156,6 +156,7 @@ public class DisguiseAPI {
}
}
}
return disguise;
}

View File

@ -329,41 +329,7 @@ public class DisguiseListener implements Listener {
if (disguiseClone.containsKey(p.getName())) {
Boolean[] options = disguiseClone.remove(p.getName());
Disguise disguise = DisguiseAPI.getDisguise(p, entity);
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");
}
DisguiseUtilities.createClonedDisguise(p, entity, options);
}
else if (disguiseEntity.containsKey(p.getName())) {
Disguise disguise = disguiseEntity.remove(p.getName());

View File

@ -5,14 +5,17 @@ import java.util.HashMap;
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;
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;
public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabCompleter {
@Override
@ -26,8 +29,14 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp
boolean doEquipment = true;
boolean doSneak = 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")
|| StringUtils.startsWithIgnoreCase(option, "ignoreEnquip")) {
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
});
};
sender.sendMessage(ChatColor.RED + "Right click a entity in the next " + DisguiseConfig.getDisguiseCloneExpire()
+ " seconds to grab the disguise reference!");
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!");
}
}
else {
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) {
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("doSneakSprint");
tabs.add("doSneak");

View File

@ -17,6 +17,7 @@ import java.util.UUID;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
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.ZombieWatcher;
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 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) {
if (DisguiseConfig.getMaxClonedDisguises() > 0) {
if (clonedDisguises.containsKey(key)) {