Error message if entity logging is enabled, but no compatible WorldEdit is found

This commit is contained in:
Brokkonaut
2018-11-09 17:31:39 +01:00
parent 8a1897e102
commit 27c72b43c1
4 changed files with 65 additions and 8 deletions

View File

@@ -188,7 +188,14 @@ public class LogBlock extends JavaPlugin {
if (isLogging(Logging.DRAGONEGGTELEPORT)) {
pm.registerEvents(new DragonEggLogging(this), this);
}
if (Config.isLoggingAnyEntities()) {
if (!WorldEditHelper.hasFullWorldEdit()) {
getLogger().severe("No compatible WorldEdit found, entity logging will not work!");
} else {
pm.registerEvents(new AdvancedEntityLogging(this), this);
getLogger().info("Entity logging enabled!");
}
}
}
@Override

View File

@@ -328,6 +328,15 @@ public class Config {
final WorldConfig wcfg = worldConfigs.get(world.getName());
return wcfg != null && wcfg.isLogging(logging, entity);
}
public static boolean isLoggingAnyEntities() {
for (WorldConfig worldConfig : worldConfigs.values()) {
if (worldConfig.isLoggingAnyEntities()) {
return true;
}
}
return false;
}
}
class LoggingEnabledMapping {

View File

@@ -34,7 +34,7 @@ public class WorldConfig extends LoggingEnabledMapping {
public final String insertEntityStatementString;
public final String updateEntityUUIDString;
private final EnumMap<EntityLogging, EntitiyLoggingList> entityLogging = new EnumMap<>(EntityLogging.class);
private final EnumMap<EntityLogging, EntityLoggingList> entityLogging = new EnumMap<>(EntityLogging.class);
public WorldConfig(String world, File file) throws IOException {
this.world = world;
@@ -55,7 +55,7 @@ public class WorldConfig extends LoggingEnabledMapping {
if (!(config.get("entity." + el.name().toLowerCase()) instanceof List)) {
config.set("entity." + el.name().toLowerCase(), el.getDefaultEnabled());
}
entityLogging.put(el, new EntitiyLoggingList(config.getStringList("entity." + el.name().toLowerCase())));
entityLogging.put(el, new EntityLoggingList(config.getStringList("entity." + el.name().toLowerCase())));
}
config.save(file);
table = config.getString("table");
@@ -75,14 +75,23 @@ public class WorldConfig extends LoggingEnabledMapping {
return entityLogging.get(logging).isLogging(entity);
}
private class EntitiyLoggingList {
public boolean isLoggingAnyEntities() {
for (EntityLoggingList list : entityLogging.values()) {
if (list.isLoggingAnyEntities()) {
return true;
}
}
return false;
}
private class EntityLoggingList {
private final EnumSet<EntityType> logged = EnumSet.noneOf(EntityType.class);
private final boolean logAll;
private final boolean logAnimals;
private final boolean logMonsters;
private final boolean logLiving;
public EntitiyLoggingList(List<String> types) {
public EntityLoggingList(List<String> types) {
boolean all = false;
boolean animals = false;
boolean monsters = false;
@@ -130,5 +139,9 @@ public class WorldConfig extends LoggingEnabledMapping {
}
return false;
}
public boolean isLoggingAnyEntities() {
return logAll || logAnimals || logLiving || logMonsters || !logged.isEmpty();
}
}
}

View File

@@ -3,9 +3,11 @@ package de.diddiz.worldedit;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.UUID;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -23,8 +25,11 @@ import com.sk89q.jnbt.NamedTag;
import com.sk89q.jnbt.ShortTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.entity.BaseEntity;
import de.diddiz.LogBlock.LogBlock;
public class WorldEditHelper {
private static boolean checkedForWorldEdit;
private static boolean hasWorldEdit;
@@ -39,6 +44,10 @@ public class WorldEditHelper {
return hasWorldEdit;
}
public static boolean hasFullWorldEdit() {
return hasWorldEdit && Internal.hasBukkitImplAdapter();
}
public static byte[] serializeEntity(Entity entity) {
if (!hasWorldEdit()) {
return null;
@@ -51,10 +60,29 @@ public class WorldEditHelper {
}
private static class Internal {
// private static WorldEditPlugin worldEdit;
private static WorldEditPlugin worldEdit;
private static Method getBukkitImplAdapter;
public static void setWorldEdit(Plugin worldEdit) {
// Internal.worldEdit = (WorldEditPlugin) worldEdit;
Internal.worldEdit = (WorldEditPlugin) worldEdit;
}
public static boolean hasBukkitImplAdapter() {
if (getBukkitImplAdapter == null) {
try {
getBukkitImplAdapter = WorldEditPlugin.class.getDeclaredMethod("getBukkitImplAdapter");
getBukkitImplAdapter.setAccessible(true);
} catch (Exception e) {
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Exception while checking for BukkitImplAdapter", e);
return false;
}
}
try {
return getBukkitImplAdapter.invoke(worldEdit) != null;
} catch (Exception e) {
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Exception while checking for BukkitImplAdapter", e);
return false;
}
}
public static Entity restoreEntity(Location location, EntityType type, byte[] serialized) {