forked from LogBlock/LogBlock
Error message if entity logging is enabled, but no compatible WorldEdit is found
This commit is contained in:
@@ -188,7 +188,14 @@ public class LogBlock extends JavaPlugin {
|
|||||||
if (isLogging(Logging.DRAGONEGGTELEPORT)) {
|
if (isLogging(Logging.DRAGONEGGTELEPORT)) {
|
||||||
pm.registerEvents(new DragonEggLogging(this), this);
|
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);
|
pm.registerEvents(new AdvancedEntityLogging(this), this);
|
||||||
|
getLogger().info("Entity logging enabled!");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -328,6 +328,15 @@ public class Config {
|
|||||||
final WorldConfig wcfg = worldConfigs.get(world.getName());
|
final WorldConfig wcfg = worldConfigs.get(world.getName());
|
||||||
return wcfg != null && wcfg.isLogging(logging, entity);
|
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 {
|
class LoggingEnabledMapping {
|
||||||
|
@@ -34,7 +34,7 @@ public class WorldConfig extends LoggingEnabledMapping {
|
|||||||
public final String insertEntityStatementString;
|
public final String insertEntityStatementString;
|
||||||
public final String updateEntityUUIDString;
|
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 {
|
public WorldConfig(String world, File file) throws IOException {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
@@ -55,7 +55,7 @@ public class WorldConfig extends LoggingEnabledMapping {
|
|||||||
if (!(config.get("entity." + el.name().toLowerCase()) instanceof List)) {
|
if (!(config.get("entity." + el.name().toLowerCase()) instanceof List)) {
|
||||||
config.set("entity." + el.name().toLowerCase(), el.getDefaultEnabled());
|
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);
|
config.save(file);
|
||||||
table = config.getString("table");
|
table = config.getString("table");
|
||||||
@@ -75,14 +75,23 @@ public class WorldConfig extends LoggingEnabledMapping {
|
|||||||
return entityLogging.get(logging).isLogging(entity);
|
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 EnumSet<EntityType> logged = EnumSet.noneOf(EntityType.class);
|
||||||
private final boolean logAll;
|
private final boolean logAll;
|
||||||
private final boolean logAnimals;
|
private final boolean logAnimals;
|
||||||
private final boolean logMonsters;
|
private final boolean logMonsters;
|
||||||
private final boolean logLiving;
|
private final boolean logLiving;
|
||||||
|
|
||||||
public EntitiyLoggingList(List<String> types) {
|
public EntityLoggingList(List<String> types) {
|
||||||
boolean all = false;
|
boolean all = false;
|
||||||
boolean animals = false;
|
boolean animals = false;
|
||||||
boolean monsters = false;
|
boolean monsters = false;
|
||||||
@@ -130,5 +139,9 @@ public class WorldConfig extends LoggingEnabledMapping {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isLoggingAnyEntities() {
|
||||||
|
return logAll || logAnimals || logLiving || logMonsters || !logged.isEmpty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,9 +3,11 @@ package de.diddiz.worldedit;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@@ -23,8 +25,11 @@ import com.sk89q.jnbt.NamedTag;
|
|||||||
import com.sk89q.jnbt.ShortTag;
|
import com.sk89q.jnbt.ShortTag;
|
||||||
import com.sk89q.jnbt.Tag;
|
import com.sk89q.jnbt.Tag;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||||
import com.sk89q.worldedit.entity.BaseEntity;
|
import com.sk89q.worldedit.entity.BaseEntity;
|
||||||
|
|
||||||
|
import de.diddiz.LogBlock.LogBlock;
|
||||||
|
|
||||||
public class WorldEditHelper {
|
public class WorldEditHelper {
|
||||||
private static boolean checkedForWorldEdit;
|
private static boolean checkedForWorldEdit;
|
||||||
private static boolean hasWorldEdit;
|
private static boolean hasWorldEdit;
|
||||||
@@ -39,6 +44,10 @@ public class WorldEditHelper {
|
|||||||
return hasWorldEdit;
|
return hasWorldEdit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean hasFullWorldEdit() {
|
||||||
|
return hasWorldEdit && Internal.hasBukkitImplAdapter();
|
||||||
|
}
|
||||||
|
|
||||||
public static byte[] serializeEntity(Entity entity) {
|
public static byte[] serializeEntity(Entity entity) {
|
||||||
if (!hasWorldEdit()) {
|
if (!hasWorldEdit()) {
|
||||||
return null;
|
return null;
|
||||||
@@ -51,10 +60,29 @@ public class WorldEditHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class Internal {
|
private static class Internal {
|
||||||
// private static WorldEditPlugin worldEdit;
|
private static WorldEditPlugin worldEdit;
|
||||||
|
private static Method getBukkitImplAdapter;
|
||||||
|
|
||||||
public static void setWorldEdit(Plugin worldEdit) {
|
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) {
|
public static Entity restoreEntity(Location location, EntityType type, byte[] serialized) {
|
||||||
|
Reference in New Issue
Block a user