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.io.File;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class DisguiseConfig {
|
public class DisguiseConfig {
|
||||||
public enum DisguisePushing { // This enum has a really bad name..
|
public enum DisguisePushing { // This enum has a really bad name..
|
||||||
@ -379,6 +382,23 @@ public class DisguiseConfig {
|
|||||||
|
|
||||||
loadCustomDisguises();
|
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;
|
int missingConfigs = 0;
|
||||||
|
|
||||||
for (String key : config.getDefaultSection().getKeys(true)) {
|
for (String key : config.getDefaultSection().getKeys(true)) {
|
||||||
@ -416,38 +436,21 @@ public class DisguiseConfig {
|
|||||||
for (String key : section.getKeys(false)) {
|
for (String key : section.getKeys(false)) {
|
||||||
String toParse = section.getString(key);
|
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 {
|
try {
|
||||||
String[] disguiseArgs = DisguiseUtilities.split(toParse);
|
addCustomDisguise(key, 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);
|
|
||||||
}
|
}
|
||||||
catch (DisguiseParseException e) {
|
catch (DisguiseParseException e) {
|
||||||
DisguiseUtilities.getLogger().severe("Error while loading custom disguise '" + key + "'" +
|
|
||||||
(e.getMessage() == null ? "" : ": " + e.getMessage()));
|
|
||||||
|
|
||||||
if (e.getMessage() == null)
|
|
||||||
e.printStackTrace();
|
|
||||||
|
|
||||||
failedCustomDisguises++;
|
failedCustomDisguises++;
|
||||||
|
|
||||||
|
if (e.getMessage() != null) {
|
||||||
|
DisguiseUtilities.getLogger().severe(e.getMessage());
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
|
||||||
|
if (e.getCause() != null) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (failedCustomDisguises > 0) {
|
if (failedCustomDisguises > 0) {
|
||||||
DisguiseUtilities.getLogger().severe("Failed to load " + failedCustomDisguises + " custom disguises");
|
DisguiseUtilities.getLogger().severe("Failed to load " + failedCustomDisguises + " custom disguises");
|
||||||
@ -457,6 +460,33 @@ public class DisguiseConfig {
|
|||||||
(customDisguises.size() == 1 ? "" : "s"));
|
(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() {
|
public static boolean isAnimationPacketsEnabled() {
|
||||||
return animationEnabled;
|
return animationEnabled;
|
||||||
}
|
}
|
||||||
|
@ -1213,7 +1213,10 @@ public class DisguiseUtilities {
|
|||||||
return;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,4 +15,16 @@ public class DisguiseParseException extends Exception {
|
|||||||
public DisguiseParseException(LibsMsg message, String... params) {
|
public DisguiseParseException(LibsMsg message, String... params) {
|
||||||
super(message.get((Object[]) 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