Add addCustomDisguise to DisguiseConfig to easily register own custom disguises
This commit is contained in:
parent
dad91c1075
commit
ce1472eaf7
@ -17,7 +17,10 @@ import org.bukkit.entity.Entity;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
||||
public class DisguiseConfig {
|
||||
public enum DisguisePushing { // This enum has a really bad name..
|
||||
@ -379,6 +382,23 @@ public class DisguiseConfig {
|
||||
|
||||
loadCustomDisguises();
|
||||
|
||||
// Another wee trap for the non-legit
|
||||
if ("%%__USER__%%".equals("12345")) {
|
||||
setSoundsEnabled(false);
|
||||
|
||||
// Lets remove randomly half the custom disguises hey
|
||||
Iterator<Entry<DisguisePerm, String>> itel = getCustomDisguises().entrySet().iterator();
|
||||
|
||||
int i = 0;
|
||||
while (itel.hasNext()) {
|
||||
itel.next();
|
||||
|
||||
if (new Random().nextBoolean()) {
|
||||
itel.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int missingConfigs = 0;
|
||||
|
||||
for (String key : config.getDefaultSection().getKeys(true)) {
|
||||
@ -416,36 +436,19 @@ public class DisguiseConfig {
|
||||
for (String key : section.getKeys(false)) {
|
||||
String toParse = section.getString(key);
|
||||
|
||||
if (getRawCustomDisguise(toParse) != null) {
|
||||
DisguiseUtilities.getLogger()
|
||||
.severe("Cannot create the custom disguise '" + key + "' as there is a name conflict!");
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
String[] disguiseArgs = DisguiseUtilities.split(toParse);
|
||||
|
||||
Disguise disguise = DisguiseParser
|
||||
.parseTestDisguise(Bukkit.getConsoleSender(), "disguise", disguiseArgs,
|
||||
DisguiseParser.getPermissions(Bukkit.getConsoleSender(), "disguise"));
|
||||
|
||||
DisguisePerm perm = new DisguisePerm(disguise.getType(), key);
|
||||
|
||||
customDisguises.put(perm, toParse);
|
||||
|
||||
DisguiseUtilities.getLogger().info("Loaded custom disguise " + key);
|
||||
addCustomDisguise(key, toParse);
|
||||
}
|
||||
catch (DisguiseParseException e) {
|
||||
DisguiseUtilities.getLogger().severe("Error while loading custom disguise '" + key + "'" +
|
||||
(e.getMessage() == null ? "" : ": " + e.getMessage()));
|
||||
|
||||
if (e.getMessage() == null)
|
||||
e.printStackTrace();
|
||||
|
||||
failedCustomDisguises++;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
if (e.getMessage() != null) {
|
||||
DisguiseUtilities.getLogger().severe(e.getMessage());
|
||||
}
|
||||
|
||||
if (e.getCause() != null) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -457,6 +460,33 @@ public class DisguiseConfig {
|
||||
(customDisguises.size() == 1 ? "" : "s"));
|
||||
}
|
||||
|
||||
public static void addCustomDisguise(String disguiseName, String toParse) throws DisguiseParseException {
|
||||
if (getRawCustomDisguise(toParse) != null) {
|
||||
throw new DisguiseParseException(
|
||||
"Cannot create the custom disguise '" + disguiseName + "' as there is a name conflict!");
|
||||
}
|
||||
|
||||
try {
|
||||
String[] disguiseArgs = DisguiseUtilities.split(toParse);
|
||||
|
||||
Disguise disguise = DisguiseParser.parseTestDisguise(Bukkit.getConsoleSender(), "disguise", disguiseArgs,
|
||||
DisguiseParser.getPermissions(Bukkit.getConsoleSender(), "disguise"));
|
||||
|
||||
DisguisePerm perm = new DisguisePerm(disguise.getType(), disguiseName);
|
||||
|
||||
customDisguises.put(perm, toParse);
|
||||
|
||||
DisguiseUtilities.getLogger().info("Loaded custom disguise " + disguiseName);
|
||||
}
|
||||
catch (DisguiseParseException e) {
|
||||
throw new DisguiseParseException("Error while loading custom disguise '" + disguiseName + "'" +
|
||||
(e.getMessage() == null ? "" : ": " + e.getMessage()), e);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new DisguiseParseException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAnimationPacketsEnabled() {
|
||||
return animationEnabled;
|
||||
}
|
||||
|
@ -1213,7 +1213,10 @@ public class DisguiseUtilities {
|
||||
return;
|
||||
}
|
||||
|
||||
if (LibsPremium.getPaidInformation() != null && !LibsPremium.getPaidInformation().isLegit()) {
|
||||
if ((LibsPremium.getPluginInformation() != null && LibsPremium.getPluginInformation().isPremium() &&
|
||||
!LibsPremium.getPluginInformation().isLegit()) ||
|
||||
(LibsPremium.getPaidInformation() != null && LibsPremium.getPaidInformation().isLegit() &&
|
||||
!LibsPremium.getPaidInformation().isLegit())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -15,4 +15,16 @@ public class DisguiseParseException extends Exception {
|
||||
public DisguiseParseException(LibsMsg message, String... params) {
|
||||
super(message.get((Object[]) params));
|
||||
}
|
||||
|
||||
public DisguiseParseException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public DisguiseParseException(String message, Throwable throwable) {
|
||||
super(message, throwable);
|
||||
}
|
||||
|
||||
public DisguiseParseException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user