Reformatting
This commit is contained in:
@@ -73,11 +73,6 @@ public class BungeeConfigAdapter extends ConfigAdapter {
|
||||
config.set(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformType getPlatform() {
|
||||
return PlatformType.BUNGEE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getKeys(boolean recur) {
|
||||
return config.getKeys().stream().collect(Collectors.toUnmodifiableSet());
|
||||
@@ -141,11 +136,6 @@ public class BungeeConfigAdapter extends ConfigAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNull() {
|
||||
return config == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getStringList(String key) {
|
||||
return config.getStringList(key);
|
||||
@@ -155,4 +145,14 @@ public class BungeeConfigAdapter extends ConfigAdapter {
|
||||
protected ConfigAdapter fromInputStream(InputStream stream) {
|
||||
return new BungeeConfigAdapter(stream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformType getPlatform() {
|
||||
return PlatformType.BUNGEE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNull() {
|
||||
return config == null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,11 +43,6 @@ public abstract class ConfigAdapter {
|
||||
this.in = in;
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
if (file == null) return null;
|
||||
return file.get();
|
||||
}
|
||||
|
||||
public abstract String getString(String key);
|
||||
|
||||
public abstract String getString(String key, String def);
|
||||
@@ -72,8 +67,6 @@ public abstract class ConfigAdapter {
|
||||
|
||||
public abstract boolean isSection(String key);
|
||||
|
||||
public abstract PlatformType getPlatform();
|
||||
|
||||
public abstract Set<String> getKeys(boolean recur);
|
||||
|
||||
public abstract Set<String> getKeys(String key, boolean recur);
|
||||
@@ -123,6 +116,17 @@ public abstract class ConfigAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract List<String> getStringList(String key);
|
||||
|
||||
protected abstract ConfigAdapter fromInputStream(InputStream stream);
|
||||
|
||||
public File getFile() {
|
||||
if (file == null) return null;
|
||||
return file.get();
|
||||
}
|
||||
|
||||
public abstract PlatformType getPlatform();
|
||||
|
||||
public ConfigAdapter getDefaults() throws IOException {
|
||||
if (defaults == null) return null;
|
||||
try (InputStream in = defaults.apply(path)) {
|
||||
@@ -135,8 +139,4 @@ public abstract class ConfigAdapter {
|
||||
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
public abstract boolean isNull();
|
||||
|
||||
public abstract List<String> getStringList(String key);
|
||||
|
||||
protected abstract ConfigAdapter fromInputStream(InputStream stream);
|
||||
}
|
||||
|
||||
@@ -73,11 +73,6 @@ public class EmptyConfigAdapter extends ConfigAdapter {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformType getPlatform() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getKeys(boolean recur) {
|
||||
return new HashSet<>();
|
||||
@@ -96,16 +91,6 @@ public class EmptyConfigAdapter extends ConfigAdapter {
|
||||
public void save(File file) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigAdapter getDefaults() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNull() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getStringList(String key) {
|
||||
return new ArrayList<>();
|
||||
@@ -115,4 +100,19 @@ public class EmptyConfigAdapter extends ConfigAdapter {
|
||||
protected ConfigAdapter fromInputStream(InputStream stream) {
|
||||
return new EmptyConfigAdapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformType getPlatform() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigAdapter getDefaults() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNull() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,11 +75,6 @@ public class SpigotConfigAdapter extends ConfigAdapter {
|
||||
config.set(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformType getPlatform() {
|
||||
return PlatformType.SPIGOT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getKeys(boolean recur) {
|
||||
return config.getKeys(recur).stream().collect(Collectors.toUnmodifiableSet());
|
||||
@@ -143,11 +138,6 @@ public class SpigotConfigAdapter extends ConfigAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNull() {
|
||||
return config == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getStringList(String key) {
|
||||
return config.getStringList(key);
|
||||
@@ -157,4 +147,14 @@ public class SpigotConfigAdapter extends ConfigAdapter {
|
||||
protected ConfigAdapter fromInputStream(InputStream stream) {
|
||||
return new SpigotConfigAdapter(stream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformType getPlatform() {
|
||||
return PlatformType.SPIGOT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNull() {
|
||||
return config == null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,17 @@ package dev.heliosares.auxprotect.adapters.location;
|
||||
|
||||
public abstract class LocationAdapter {
|
||||
|
||||
public double distance(LocationAdapter other) {
|
||||
return Math.sqrt(distanceSq(other));
|
||||
}
|
||||
|
||||
public double distanceSq(LocationAdapter other) {
|
||||
if (other == null || !other.getWorld().equals(getWorld())) {
|
||||
throw new IllegalArgumentException("Locations in different worlds");
|
||||
}
|
||||
return Math.pow(getX() - other.getX(), 2) + Math.pow(getY() - other.getY(), 2) + Math.pow(getZ() - other.getZ(), 2);
|
||||
}
|
||||
|
||||
public abstract String getWorld();
|
||||
|
||||
public abstract double getX();
|
||||
@@ -13,15 +24,4 @@ public abstract class LocationAdapter {
|
||||
public abstract float getPitch();
|
||||
|
||||
public abstract float getYaw();
|
||||
|
||||
public double distance(LocationAdapter other) {
|
||||
return Math.sqrt(distanceSq(other));
|
||||
}
|
||||
|
||||
public double distanceSq(LocationAdapter other) {
|
||||
if (other == null || !other.getWorld().equals(getWorld())) {
|
||||
throw new IllegalArgumentException("Locations in different worlds");
|
||||
}
|
||||
return Math.pow(getX() - other.getX(), 2) + Math.pow(getY() - other.getY(), 2) + Math.pow(getZ() - other.getZ(), 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,17 @@ public class BungeeSenderAdapter extends SenderAdapter {
|
||||
return sender.hasPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeCommand(String command) {
|
||||
plugin.getProxy().getPluginManager().dispatchCommand(sender, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(String world, double x, double y, double z, int pitch, int yaw)
|
||||
throws NullPointerException, UnsupportedOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return sender.getName();
|
||||
}
|
||||
@@ -53,19 +64,8 @@ public class BungeeSenderAdapter extends SenderAdapter {
|
||||
return PlatformType.BUNGEE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeCommand(String command) {
|
||||
plugin.getProxy().getPluginManager().dispatchCommand(sender, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConsole() {
|
||||
return sender.equals(plugin.getProxy().getConsole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(String world, double x, double y, double z, int pitch, int yaw)
|
||||
throws NullPointerException, UnsupportedOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,30 +20,6 @@ public class FakeSenderAdapter extends SenderAdapter {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getSender() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (name == null)
|
||||
return "null";
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUniqueId() {
|
||||
if (uuid == null)
|
||||
return UUID.fromString("00000000-0000-0000-0000-000000000001");
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformType getPlatform() {
|
||||
return platform == null ? PlatformType.NONE : platform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(BaseComponent... message) {
|
||||
StringBuilder line = new StringBuilder();
|
||||
@@ -68,6 +44,35 @@ public class FakeSenderAdapter extends SenderAdapter {
|
||||
sendMessageRaw("**Executing " + command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(String world, double x, double y, double z, int pitch, int yaw)
|
||||
throws NullPointerException, UnsupportedOperationException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getSender() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (name == null)
|
||||
return "null";
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUniqueId() {
|
||||
if (uuid == null)
|
||||
return UUID.fromString("00000000-0000-0000-0000-000000000001");
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformType getPlatform() {
|
||||
return platform == null ? PlatformType.NONE : platform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConsole() {
|
||||
return false;
|
||||
@@ -77,9 +82,4 @@ public class FakeSenderAdapter extends SenderAdapter {
|
||||
return console;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(String world, double x, double y, double z, int pitch, int yaw)
|
||||
throws NullPointerException, UnsupportedOperationException {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,14 +7,6 @@ import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class SenderAdapter {
|
||||
public abstract Object getSender();
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public abstract UUID getUniqueId();
|
||||
|
||||
public abstract PlatformType getPlatform();
|
||||
|
||||
public void sendLang(Language.L lang, Object... format) {
|
||||
sendMessageRaw(lang.translate(format));
|
||||
}
|
||||
@@ -27,8 +19,16 @@ public abstract class SenderAdapter {
|
||||
|
||||
public abstract void executeCommand(String command);
|
||||
|
||||
public abstract boolean isConsole();
|
||||
|
||||
public abstract void teleport(String world, double x, double y, double z, int pitch, int yaw)
|
||||
throws NullPointerException, UnsupportedOperationException;
|
||||
|
||||
public abstract Object getSender();
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public abstract UUID getUniqueId();
|
||||
|
||||
public abstract PlatformType getPlatform();
|
||||
|
||||
public abstract boolean isConsole();
|
||||
}
|
||||
|
||||
@@ -35,27 +35,6 @@ public class SpigotSenderAdapter extends SenderAdapter {
|
||||
return sender.hasPermission(node);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return sender.getName();
|
||||
}
|
||||
|
||||
public UUID getUniqueId() {
|
||||
if (sender instanceof Player player) {
|
||||
return player.getUniqueId();
|
||||
}
|
||||
return UUID.fromString("00000000-0000-0000-0000-000000000000");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformType getPlatform() {
|
||||
return PlatformType.SPIGOT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeCommand(String command) {
|
||||
plugin.runSync(() -> {
|
||||
@@ -63,11 +42,6 @@ public class SpigotSenderAdapter extends SenderAdapter {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConsole() {
|
||||
return sender.equals(plugin.getServer().getConsoleSender());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(String worldname, double x, double y, double z, int pitch, int yaw)
|
||||
throws NullPointerException, UnsupportedOperationException {
|
||||
@@ -94,4 +68,30 @@ public class SpigotSenderAdapter extends SenderAdapter {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return sender.getName();
|
||||
}
|
||||
|
||||
public UUID getUniqueId() {
|
||||
if (sender instanceof Player player) {
|
||||
return player.getUniqueId();
|
||||
}
|
||||
return UUID.fromString("00000000-0000-0000-0000-000000000000");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformType getPlatform() {
|
||||
return PlatformType.SPIGOT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConsole() {
|
||||
return sender.equals(plugin.getServer().getConsoleSender());
|
||||
}
|
||||
}
|
||||
@@ -34,8 +34,8 @@ import java.util.stream.Collectors;
|
||||
public class AuxProtectBungee extends Plugin implements IAuxProtect {
|
||||
private static final DateTimeFormatter ERROR_TIME_FORMAT = DateTimeFormatter.ofPattern("HH:mm:ss.SSS");
|
||||
private static AuxProtectBungee instance;
|
||||
private final APConfig config = new APConfig();
|
||||
final Set<Integer> stackHashHistory = new HashSet<>();
|
||||
private final APConfig config = new APConfig();
|
||||
protected DatabaseRunnable dbRunnable;
|
||||
SQLManager sqlManager;
|
||||
private boolean isShuttingDown;
|
||||
@@ -185,20 +185,11 @@ public class AuxProtectBungee extends Plugin implements IAuxProtect {
|
||||
info("Done disabling.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShuttingDown() {
|
||||
return isShuttingDown;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResource(String string) {
|
||||
return getResourceAsStream(string);
|
||||
}
|
||||
|
||||
public SQLManager getSqlManager() {
|
||||
return sqlManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String string) {
|
||||
this.getLogger().info(string);
|
||||
@@ -232,25 +223,6 @@ public class AuxProtectBungee extends Plugin implements IAuxProtect {
|
||||
logToStackLog(stack);
|
||||
}
|
||||
|
||||
private void logToStackLog(String msg) {
|
||||
stackLog += "[" + LocalDateTime.now().format(ERROR_TIME_FORMAT) + "] " + msg + "\n";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStackLog() {
|
||||
return stackLog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformType getPlatform() {
|
||||
return PlatformType.BUNGEE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public APConfig getAPConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(DbEntry dbEntry) {
|
||||
dbRunnable.add(dbEntry);
|
||||
@@ -266,16 +238,6 @@ public class AuxProtectBungee extends Plugin implements IAuxProtect {
|
||||
runAsync(run);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandPrefix() {
|
||||
return "auxprotectbungee";
|
||||
}
|
||||
|
||||
@Override
|
||||
public SenderAdapter getConsoleSender() {
|
||||
return new BungeeSenderAdapter(this, this.getProxy().getConsole());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public SenderAdapter getSenderAdapter(String name) {
|
||||
@@ -290,21 +252,6 @@ public class AuxProtectBungee extends Plugin implements IAuxProtect {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getRootDirectory() {
|
||||
return getDataFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlatformVersion() {
|
||||
return getProxy().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginVersion() {
|
||||
return this.getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public APPlayer getAPPlayer(SenderAdapter sender) {
|
||||
throw new UnsupportedOperationException();
|
||||
@@ -320,16 +267,6 @@ public class AuxProtectBungee extends Plugin implements IAuxProtect {
|
||||
return getProxy().getPlayers().stream().map(CommandSender::getName).collect(Collectors.toUnmodifiableSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandAlias() {
|
||||
return "apb";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRemoveEntryListener(Consumer<DbEntry> consumer, boolean add) {
|
||||
dbRunnable.addRemoveEntryListener(consumer, add);
|
||||
@@ -339,4 +276,67 @@ public class AuxProtectBungee extends Plugin implements IAuxProtect {
|
||||
public void broadcast(String msg, APPermission node) {
|
||||
getProxy().getPlayers().stream().filter(player -> player.hasPermission(node.node)).forEach(player -> player.sendMessage(TextComponent.fromLegacyText(msg)));
|
||||
}
|
||||
|
||||
private void logToStackLog(String msg) {
|
||||
stackLog += "[" + LocalDateTime.now().format(ERROR_TIME_FORMAT) + "] " + msg + "\n";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShuttingDown() {
|
||||
return isShuttingDown;
|
||||
}
|
||||
|
||||
public SQLManager getSqlManager() {
|
||||
return sqlManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStackLog() {
|
||||
return stackLog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformType getPlatform() {
|
||||
return PlatformType.BUNGEE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public APConfig getAPConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandPrefix() {
|
||||
return "auxprotectbungee";
|
||||
}
|
||||
|
||||
@Override
|
||||
public SenderAdapter getConsoleSender() {
|
||||
return new BungeeSenderAdapter(this, this.getProxy().getConsole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getRootDirectory() {
|
||||
return getDataFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlatformVersion() {
|
||||
return getProxy().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginVersion() {
|
||||
return this.getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandAlias() {
|
||||
return "apb";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +105,26 @@ public class APConfig {
|
||||
config.save();
|
||||
}
|
||||
|
||||
public boolean shouldCheckForUpdates() {
|
||||
return checkforupdates;
|
||||
}
|
||||
|
||||
public boolean doSkipV6Migration() {
|
||||
return skipV6Migration;
|
||||
}
|
||||
|
||||
public boolean doAutoPurge() {
|
||||
return autopurge;
|
||||
}
|
||||
|
||||
public boolean doLogIncrementalPosition() {
|
||||
return logIncrementalPosition;
|
||||
}
|
||||
|
||||
public boolean doDisableVacuum() {
|
||||
return disableVacuum;
|
||||
}
|
||||
|
||||
private long getAutoPurgeInterval(String table, long autopurgeinterval) {
|
||||
String interval = config.getString("AutoPurge." + table);
|
||||
if (interval == null) interval = "default";
|
||||
@@ -159,10 +179,6 @@ public class APConfig {
|
||||
return inventoryOnWorldChange;
|
||||
}
|
||||
|
||||
public boolean shouldCheckForUpdates() {
|
||||
return checkforupdates;
|
||||
}
|
||||
|
||||
public long getPosInterval() {
|
||||
return posInterval;
|
||||
}
|
||||
@@ -199,10 +215,6 @@ public class APConfig {
|
||||
return overrideCommands;
|
||||
}
|
||||
|
||||
public boolean doSkipV6Migration() {
|
||||
return skipV6Migration;
|
||||
}
|
||||
|
||||
public ConfigAdapter getConfig() {
|
||||
return config;
|
||||
}
|
||||
@@ -248,18 +260,6 @@ public class APConfig {
|
||||
return tablePrefix;
|
||||
}
|
||||
|
||||
public boolean doAutoPurge() {
|
||||
return autopurge;
|
||||
}
|
||||
|
||||
public boolean doLogIncrementalPosition() {
|
||||
return logIncrementalPosition;
|
||||
}
|
||||
|
||||
public boolean doDisableVacuum() {
|
||||
return disableVacuum;
|
||||
}
|
||||
|
||||
public boolean isDemoMode() {
|
||||
return demoMode;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ public class APPermission {
|
||||
public static final APPermission NONE = new APPermission(null);
|
||||
public static final APPermission NOTIFY_INACTIVE = new APPermission("inactive.notify");
|
||||
public static final APPermission BYPASS_INACTIVE = new APPermission("inactive.bypass");
|
||||
private static final APPermission ROOT = new APPermission("auxprotect");
|
||||
public static final APPermission ADMIN = ROOT.dot("admin");
|
||||
public static final APPermission PURGE = ROOT.dot("purge");
|
||||
public static final APPermission TP = ROOT.dot("tp");
|
||||
@@ -16,7 +15,6 @@ public class APPermission {
|
||||
public static final APPermission LOOKUP_ACTION = LOOKUP.dot("action");
|
||||
public static final APPermission LOOKUP_GROUP = LOOKUP.dot("group");
|
||||
public static final APPermission LOOKUP_XRAY = LOOKUP.dot("xray");
|
||||
|
||||
public static final APPermission LOOKUP_XRAY_BULK = LOOKUP_XRAY.dot("bulk");
|
||||
public static final APPermission LOOKUP_PLAYTIME = LOOKUP.dot("playtime");
|
||||
public static final APPermission LOOKUP_ACTIVITY = LOOKUP.dot("activity");
|
||||
@@ -32,7 +30,7 @@ public class APPermission {
|
||||
public static final APPermission INV_RECOVER = INV.dot("recover");
|
||||
public static final APPermission INV_NOTIFY = INV.dot("notify");
|
||||
public static final APPermission WATCH = ROOT.dot("watch");
|
||||
|
||||
private static final APPermission ROOT = new APPermission("auxprotect");
|
||||
public final String node;
|
||||
|
||||
private APPermission(String node) {
|
||||
|
||||
@@ -9,9 +9,9 @@ import java.util.List;
|
||||
public abstract class Command {
|
||||
protected final IAuxProtect plugin;
|
||||
protected final String label;
|
||||
private final boolean async;
|
||||
protected final String[] aliases;
|
||||
protected final APPermission permission;
|
||||
private final boolean async;
|
||||
protected boolean tabComplete = true;
|
||||
|
||||
public Command(IAuxProtect plugin, String label, APPermission permission, boolean async, String... aliases) {
|
||||
@@ -26,14 +26,6 @@ public abstract class Command {
|
||||
|
||||
public abstract @Nullable List<String> onTabComplete(SenderAdapter sender, String label, String[] args);
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public String[] getAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
public boolean hasPermission(SenderAdapter sender) {
|
||||
return permission.hasPermission(sender);
|
||||
}
|
||||
@@ -65,6 +57,14 @@ public abstract class Command {
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
public abstract boolean exists();
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public String[] getAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
public boolean isAsync() {
|
||||
return async;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,6 @@ import java.util.function.Consumer;
|
||||
|
||||
public interface IAuxProtect {
|
||||
|
||||
File getDataFolder();
|
||||
|
||||
InputStream getResource(String string);
|
||||
|
||||
void info(String msg);
|
||||
@@ -26,48 +24,50 @@ public interface IAuxProtect {
|
||||
|
||||
void print(Throwable t);
|
||||
|
||||
PlatformType getPlatform();
|
||||
|
||||
SQLManager getSqlManager();
|
||||
|
||||
APConfig getAPConfig();
|
||||
|
||||
void add(DbEntry dbEntry);
|
||||
|
||||
void runAsync(Runnable run);
|
||||
|
||||
void runSync(Runnable runnable);
|
||||
|
||||
@Nullable
|
||||
SenderAdapter getSenderAdapter(String name);
|
||||
|
||||
boolean isHooked(String name);
|
||||
|
||||
APPlayer getAPPlayer(SenderAdapter sender);
|
||||
|
||||
int queueSize();
|
||||
|
||||
Set<String> listPlayers();
|
||||
|
||||
void addRemoveEntryListener(Consumer<DbEntry> consumer, boolean add);
|
||||
|
||||
void broadcast(String msg, APPermission node);
|
||||
|
||||
File getDataFolder();
|
||||
|
||||
PlatformType getPlatform();
|
||||
|
||||
SQLManager getSqlManager();
|
||||
|
||||
APConfig getAPConfig();
|
||||
|
||||
String getCommandPrefix();
|
||||
|
||||
String getCommandAlias();
|
||||
|
||||
SenderAdapter getConsoleSender();
|
||||
|
||||
@Nullable
|
||||
SenderAdapter getSenderAdapter(String name);
|
||||
|
||||
boolean isShuttingDown();
|
||||
|
||||
boolean isHooked(String name);
|
||||
|
||||
File getRootDirectory();
|
||||
|
||||
String getPlatformVersion();
|
||||
|
||||
String getPluginVersion();
|
||||
|
||||
APPlayer getAPPlayer(SenderAdapter sender);
|
||||
|
||||
int queueSize();
|
||||
|
||||
String getStackLog();
|
||||
|
||||
Set<String> listPlayers();
|
||||
|
||||
boolean isEnabled();
|
||||
|
||||
void addRemoveEntryListener(Consumer<DbEntry> consumer, boolean add);
|
||||
|
||||
void broadcast(String msg, APPermission node);
|
||||
}
|
||||
|
||||
@@ -93,6 +93,12 @@ public class Language {
|
||||
return ColorTranslate.cc(s);
|
||||
}
|
||||
|
||||
public static String getOptionalS(String name) {
|
||||
if (name == null) return "";
|
||||
if (name.toLowerCase().endsWith("s")) return "";
|
||||
return "s";
|
||||
}
|
||||
|
||||
public enum L {
|
||||
ACTIONS,
|
||||
ACTION_DISABLED,
|
||||
@@ -285,10 +291,4 @@ public class Language {
|
||||
return message.stream().map(Language::convert).toList();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getOptionalS(String name) {
|
||||
if (name == null) return "";
|
||||
if (name.toLowerCase().endsWith("s")) return "";
|
||||
return "s";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,15 +59,15 @@ public class Parameters implements Cloneable {
|
||||
// ------------------- CONSTRUCTORS -------------------
|
||||
// ----------------------------------------------------
|
||||
|
||||
private Parameters() {
|
||||
plugin = AuxProtectAPI.getInstance();
|
||||
}
|
||||
|
||||
public Parameters(Table table) {
|
||||
this();
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
private Parameters() {
|
||||
plugin = AuxProtectAPI.getInstance();
|
||||
}
|
||||
|
||||
// -----------------------------------------------
|
||||
// ---------------- COMMAND BASED ----------------
|
||||
// -----------------------------------------------
|
||||
@@ -684,79 +684,6 @@ public class Parameters implements Cloneable {
|
||||
// ------------------- GETTERS -------------------
|
||||
// -----------------------------------------------
|
||||
|
||||
public long getAfter() {
|
||||
return after;
|
||||
}
|
||||
|
||||
public long getBefore() {
|
||||
return before;
|
||||
}
|
||||
|
||||
public Set<Long> getExactTime() {
|
||||
return exactTime;
|
||||
}
|
||||
|
||||
public boolean isNegateUser() {
|
||||
return negateUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is only used in a select few places. Parameters#getUIDS matters more
|
||||
*
|
||||
* @return the set of users
|
||||
*/
|
||||
public Set<String> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public Set<String> getUIDs() {
|
||||
return uids;
|
||||
}
|
||||
|
||||
public Set<Integer> getActions() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
public boolean isNegateTarget() {
|
||||
return negateTarget;
|
||||
}
|
||||
|
||||
public Set<String> getTargets() {
|
||||
return targets;
|
||||
}
|
||||
|
||||
public boolean isNegateData() {
|
||||
return negateData;
|
||||
}
|
||||
|
||||
public Set<String> getDatas() {
|
||||
return datas;
|
||||
}
|
||||
|
||||
public Table getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
public HashMap<Integer, Boolean> getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
public int getWorldID() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public Parameters setLocation(String world, int x, int y, int z) throws ParseException {
|
||||
int wid = plugin.getSqlManager().getWID(world);
|
||||
if (wid < 0) throw new ParseException(L.COMMAND__LOOKUP__UNKNOWN_WORLD);
|
||||
@@ -772,40 +699,11 @@ public class Parameters implements Cloneable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isNegateWorld() {
|
||||
return negateWorld;
|
||||
}
|
||||
|
||||
public Parameters setNegateWorld(boolean negateWorld) {
|
||||
this.negateWorld = negateWorld;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Set<Integer> getWorld() {
|
||||
return worlds;
|
||||
}
|
||||
|
||||
public Set<Flag> getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
public Set<Short> getRatings() {
|
||||
return ratings;
|
||||
}
|
||||
|
||||
public double getGroupRange() {
|
||||
return groupRange;
|
||||
}
|
||||
|
||||
public boolean hasFlag(Flag flag) {
|
||||
if (!flag.isEnabled()) return false;
|
||||
return flags.contains(flag);
|
||||
}
|
||||
|
||||
// -----------------------------------------------
|
||||
// ------------------- PRIVATE -------------------
|
||||
// -----------------------------------------------
|
||||
|
||||
public String[] toSQL(IAuxProtect plugin) {
|
||||
if (table == null) {
|
||||
throw new IllegalStateException();
|
||||
@@ -996,6 +894,41 @@ public class Parameters implements Cloneable {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("MethodDoesntCallSuperMethod")
|
||||
@Override
|
||||
public Parameters clone() {
|
||||
Parameters clone = new Parameters();
|
||||
|
||||
clone.exactTime.addAll(exactTime);
|
||||
clone.uids.addAll(uids);
|
||||
clone.targets.addAll(targets);
|
||||
clone.users.addAll(users);
|
||||
clone.actions.addAll(actions);
|
||||
clone.datas.addAll(datas);
|
||||
clone.worlds.addAll(worlds);
|
||||
clone.flags.addAll(flags);
|
||||
clone.ratings.addAll(ratings);
|
||||
clone.radius.putAll(radius);
|
||||
|
||||
clone.negateUser = negateUser;
|
||||
clone.negateTarget = negateTarget;
|
||||
clone.negateData = negateData;
|
||||
clone.negateWorld = negateWorld;
|
||||
|
||||
clone.after = after;
|
||||
clone.before = Long.MAX_VALUE;
|
||||
clone.table = table;
|
||||
|
||||
clone.groupRange = groupRange;
|
||||
|
||||
clone.world = world;
|
||||
clone.x = x;
|
||||
clone.y = y;
|
||||
clone.z = z;
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
private Parameters time(String param, boolean before) throws ParseException {
|
||||
try {
|
||||
long time = TimeUtil.stringToMillis(param);
|
||||
@@ -1040,41 +973,6 @@ public class Parameters implements Cloneable {
|
||||
return stmt + ")";
|
||||
}
|
||||
|
||||
@SuppressWarnings("MethodDoesntCallSuperMethod")
|
||||
@Override
|
||||
public Parameters clone() {
|
||||
Parameters clone = new Parameters();
|
||||
|
||||
clone.exactTime.addAll(exactTime);
|
||||
clone.uids.addAll(uids);
|
||||
clone.targets.addAll(targets);
|
||||
clone.users.addAll(users);
|
||||
clone.actions.addAll(actions);
|
||||
clone.datas.addAll(datas);
|
||||
clone.worlds.addAll(worlds);
|
||||
clone.flags.addAll(flags);
|
||||
clone.ratings.addAll(ratings);
|
||||
clone.radius.putAll(radius);
|
||||
|
||||
clone.negateUser = negateUser;
|
||||
clone.negateTarget = negateTarget;
|
||||
clone.negateData = negateData;
|
||||
clone.negateWorld = negateWorld;
|
||||
|
||||
clone.after = after;
|
||||
clone.before = Long.MAX_VALUE;
|
||||
clone.table = table;
|
||||
|
||||
clone.groupRange = groupRange;
|
||||
|
||||
clone.world = world;
|
||||
clone.x = x;
|
||||
clone.y = y;
|
||||
clone.z = z;
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
public enum Flag {
|
||||
COUNT(null), COUNT_ONLY(null), PLAYTIME(APPermission.LOOKUP_PLAYTIME), XRAY(APPermission.LOOKUP_XRAY), COMBINE_USER_TARGET(null),
|
||||
MONEY(APPermission.LOOKUP_MONEY), ACTIVITY(APPermission.LOOKUP_ACTIVITY), PLAYBACK(APPermission.LOOKUP_PLAYBACK), INCREMENTAL_POS(APPermission.LOOKUP_PLAYBACK),
|
||||
@@ -1101,4 +999,106 @@ public class Parameters implements Cloneable {
|
||||
}
|
||||
}
|
||||
|
||||
public long getAfter() {
|
||||
return after;
|
||||
}
|
||||
|
||||
public long getBefore() {
|
||||
return before;
|
||||
}
|
||||
|
||||
public Set<Long> getExactTime() {
|
||||
return exactTime;
|
||||
}
|
||||
|
||||
public boolean isNegateUser() {
|
||||
return negateUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is only used in a select few places. Parameters#getUIDS matters more
|
||||
*
|
||||
* @return the set of users
|
||||
*/
|
||||
public Set<String> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public Set<String> getUIDs() {
|
||||
return uids;
|
||||
}
|
||||
|
||||
public Set<Integer> getActions() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
public boolean isNegateTarget() {
|
||||
return negateTarget;
|
||||
}
|
||||
|
||||
public Set<String> getTargets() {
|
||||
return targets;
|
||||
}
|
||||
|
||||
public boolean isNegateData() {
|
||||
return negateData;
|
||||
}
|
||||
|
||||
public Set<String> getDatas() {
|
||||
return datas;
|
||||
}
|
||||
|
||||
public Table getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
public HashMap<Integer, Boolean> getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
public int getWorldID() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
// -----------------------------------------------
|
||||
// ------------------- PRIVATE -------------------
|
||||
// -----------------------------------------------
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public boolean isNegateWorld() {
|
||||
return negateWorld;
|
||||
}
|
||||
|
||||
public Parameters setNegateWorld(boolean negateWorld) {
|
||||
this.negateWorld = negateWorld;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Set<Integer> getWorld() {
|
||||
return worlds;
|
||||
}
|
||||
|
||||
public Set<Flag> getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
public Set<Short> getRatings() {
|
||||
return ratings;
|
||||
}
|
||||
|
||||
public double getGroupRange() {
|
||||
return groupRange;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -196,15 +196,6 @@ public class APCommand extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
private void sendInfo(SenderAdapter sender) {
|
||||
sender.sendMessageRaw("&9AuxProtect"
|
||||
+ (APPermission.ADMIN.hasPermission(sender) ? (" &7v" + plugin.getPluginVersion()) : ""));
|
||||
sender.sendMessageRaw("&7" + Language.L.COMMAND__AP__DEVELOPED_BY.translate() + " &9Heliosares");
|
||||
if (APPermission.ADMIN.hasPermission(sender)) {
|
||||
sender.sendMessageRaw("&7&ohttps://www.spigotmc.org/resources/auxprotect.99147/");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return true;
|
||||
@@ -246,4 +237,13 @@ public class APCommand extends Command {
|
||||
final String currentArg_ = currentArg.toLowerCase();
|
||||
return out.stream().filter((s) -> s.toLowerCase().startsWith(currentArg_)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void sendInfo(SenderAdapter sender) {
|
||||
sender.sendMessageRaw("&9AuxProtect"
|
||||
+ (APPermission.ADMIN.hasPermission(sender) ? (" &7v" + plugin.getPluginVersion()) : ""));
|
||||
sender.sendMessageRaw("&7" + Language.L.COMMAND__AP__DEVELOPED_BY.translate() + " &9Heliosares");
|
||||
if (APPermission.ADMIN.hasPermission(sender)) {
|
||||
sender.sendMessageRaw("&7&ohttps://www.spigotmc.org/resources/auxprotect.99147/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package dev.heliosares.auxprotect.core.commands;
|
||||
|
||||
import dev.heliosares.auxprotect.adapters.sender.SenderAdapter;
|
||||
import dev.heliosares.auxprotect.adapters.sender.SpigotSenderAdapter;
|
||||
import dev.heliosares.auxprotect.core.*;
|
||||
import dev.heliosares.auxprotect.exceptions.CommandException;
|
||||
import dev.heliosares.auxprotect.exceptions.SyntaxException;
|
||||
|
||||
@@ -257,6 +257,17 @@ public class XrayCommand extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return plugin.getPlatform() == PlatformType.SPIGOT && plugin.getAPConfig().isPrivate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(SenderAdapter sender, String label, String[] args) {
|
||||
// TODO This whole thing...
|
||||
return null;
|
||||
}
|
||||
|
||||
private void nextEntry(AuxProtectSpigot plugin, SenderAdapter player, boolean auto) {
|
||||
XrayEntry en = plugin.getVeinManager().next(player.getUniqueId());
|
||||
if (en == null) {
|
||||
@@ -273,15 +284,4 @@ public class XrayCommand extends Command {
|
||||
player.sendLang(Language.L.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return plugin.getPlatform() == PlatformType.SPIGOT && plugin.getAPConfig().isPrivate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(SenderAdapter sender, String label, String[] args) {
|
||||
// TODO This whole thing...
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
public class BlobManager {
|
||||
protected final HashMap<Integer, BlobCache> cache = new HashMap<>();
|
||||
private final SQLManager sql;
|
||||
private final IAuxProtect plugin;
|
||||
protected final HashMap<Integer, BlobCache> cache = new HashMap<>();
|
||||
private final Table table;
|
||||
private long nextBlobID = 1;
|
||||
private long lastcleanup;
|
||||
@@ -28,6 +28,68 @@ public class BlobManager {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public byte[] getBlob(DbEntry entry) throws SQLException, BusyException {
|
||||
if (entry.getBlobID() <= 0) {// TODO does this break skipV6?
|
||||
return null;
|
||||
}
|
||||
byte[] blob = sql.executeReturn(connection -> {
|
||||
try (PreparedStatement pstmt = connection.prepareStatement("SELECT ablob FROM " + table + " WHERE blobid=" + entry.getBlobID())) {
|
||||
try (ResultSet rs = pstmt.executeQuery()) {
|
||||
if (rs.next()) {
|
||||
return sql.getBlob(rs, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}, 30000L, byte[].class);
|
||||
|
||||
if (blob == null && plugin.getAPConfig().doSkipV6Migration()) {
|
||||
boolean hasblob = false;
|
||||
String data = entry.getData();
|
||||
if (data.contains(InvSerialization.ITEM_SEPARATOR)) {
|
||||
data = data.substring(
|
||||
data.indexOf(InvSerialization.ITEM_SEPARATOR) + InvSerialization.ITEM_SEPARATOR.length());
|
||||
hasblob = true;
|
||||
}
|
||||
if (entry.getAction().id == EntryAction.INVENTORY.id && data.length() > 20) {
|
||||
plugin.info("Migrating inventory in place to v6: " + entry.getTime());
|
||||
try {
|
||||
blob = InvSerialization.playerToByteArray(InvSerialization.toPlayer(data));
|
||||
} catch (Exception e) {
|
||||
plugin.warning("Failed to migrate inventory " + entry.getTime() + ".");
|
||||
}
|
||||
} else if (hasblob) {
|
||||
plugin.info("Migrating item in place to v6: " + entry.getTime());
|
||||
blob = Base64Coder.decodeLines(data);
|
||||
} else {
|
||||
plugin.info("Attempted to migrate invalid log");
|
||||
return null;
|
||||
}
|
||||
final byte[] blob_ = blob;
|
||||
long blobid = sql.executeReturn(connection -> getBlobId(connection, blob_), 3000L, Long.class);
|
||||
sql.execute("UPDATE " + Table.AUXPROTECT_INVENTORY + " SET blobid=?, data = '' where time=?", 30000L, blobid, entry.getTime());
|
||||
|
||||
}
|
||||
return blob;
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
synchronized (cache) {
|
||||
if (System.currentTimeMillis() - lastcleanup < 300000) {
|
||||
return;
|
||||
}
|
||||
lastcleanup = System.currentTimeMillis();
|
||||
Iterator<Map.Entry<Integer, BlobCache>> it = cache.entrySet().iterator();
|
||||
for (Map.Entry<Integer, BlobCache> other; it.hasNext(); ) {
|
||||
other = it.next();
|
||||
if (System.currentTimeMillis() - other.getValue().lastused > 600000L) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void createTable(Connection connection) throws SQLException {
|
||||
sql.execute("CREATE TABLE IF NOT EXISTS " + table + " (blobid BIGINT, ablob MEDIUMBLOB, hash INT);", connection);
|
||||
}
|
||||
@@ -92,68 +154,6 @@ public class BlobManager {
|
||||
return id;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public byte[] getBlob(DbEntry entry) throws SQLException, BusyException {
|
||||
if (entry.getBlobID() <= 0) {// TODO does this break skipV6?
|
||||
return null;
|
||||
}
|
||||
byte[] blob = sql.executeReturn(connection -> {
|
||||
try (PreparedStatement pstmt = connection.prepareStatement("SELECT ablob FROM " + table + " WHERE blobid=" + entry.getBlobID())) {
|
||||
try (ResultSet rs = pstmt.executeQuery()) {
|
||||
if (rs.next()) {
|
||||
return sql.getBlob(rs, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}, 30000L, byte[].class);
|
||||
|
||||
if (blob == null && plugin.getAPConfig().doSkipV6Migration()) {
|
||||
boolean hasblob = false;
|
||||
String data = entry.getData();
|
||||
if (data.contains(InvSerialization.ITEM_SEPARATOR)) {
|
||||
data = data.substring(
|
||||
data.indexOf(InvSerialization.ITEM_SEPARATOR) + InvSerialization.ITEM_SEPARATOR.length());
|
||||
hasblob = true;
|
||||
}
|
||||
if (entry.getAction().id == EntryAction.INVENTORY.id && data.length() > 20) {
|
||||
plugin.info("Migrating inventory in place to v6: " + entry.getTime());
|
||||
try {
|
||||
blob = InvSerialization.playerToByteArray(InvSerialization.toPlayer(data));
|
||||
} catch (Exception e) {
|
||||
plugin.warning("Failed to migrate inventory " + entry.getTime() + ".");
|
||||
}
|
||||
} else if (hasblob) {
|
||||
plugin.info("Migrating item in place to v6: " + entry.getTime());
|
||||
blob = Base64Coder.decodeLines(data);
|
||||
} else {
|
||||
plugin.info("Attempted to migrate invalid log");
|
||||
return null;
|
||||
}
|
||||
final byte[] blob_ = blob;
|
||||
long blobid = sql.executeReturn(connection -> getBlobId(connection, blob_), 3000L, Long.class);
|
||||
sql.execute("UPDATE " + Table.AUXPROTECT_INVENTORY + " SET blobid=?, data = '' where time=?", 30000L, blobid, entry.getTime());
|
||||
|
||||
}
|
||||
return blob;
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
synchronized (cache) {
|
||||
if (System.currentTimeMillis() - lastcleanup < 300000) {
|
||||
return;
|
||||
}
|
||||
lastcleanup = System.currentTimeMillis();
|
||||
Iterator<Map.Entry<Integer, BlobCache>> it = cache.entrySet().iterator();
|
||||
for (Map.Entry<Integer, BlobCache> other; it.hasNext(); ) {
|
||||
other = it.next();
|
||||
if (System.currentTimeMillis() - other.getValue().lastused > 600000L) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class BlobCache {
|
||||
final long blobid;
|
||||
final byte[] ablob;
|
||||
|
||||
@@ -46,11 +46,6 @@ public class ConnectionPool {
|
||||
checkDriver();
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ConnectionSupplier {
|
||||
Connection get() throws SQLException;
|
||||
}
|
||||
|
||||
public static int getExpiredConnections() {
|
||||
return expired;
|
||||
}
|
||||
@@ -123,44 +118,6 @@ public class ConnectionPool {
|
||||
timeConnected = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public long getLockedSince() {
|
||||
return lockedSince;
|
||||
}
|
||||
|
||||
public long getTimeConnected() {
|
||||
return timeConnected;
|
||||
}
|
||||
|
||||
public StackTraceElement[] getWhoHasLock() {
|
||||
return whoHasLock;
|
||||
}
|
||||
|
||||
private void checkDriver() throws ClassNotFoundException {
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
return;
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
return;
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
return;
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
throw new ClassNotFoundException("SQL Driver not found");
|
||||
}
|
||||
|
||||
private void checkAsync() throws IllegalStateException {
|
||||
if (skipAsyncCheck) return;
|
||||
if (plugin.getPlatform() == PlatformType.SPIGOT && Bukkit.isPrimaryThread()) {
|
||||
throw new IllegalStateException("Synchronous call to database.");
|
||||
}
|
||||
}
|
||||
|
||||
@OverridingMethodsMustInvokeSuper
|
||||
public void close() {
|
||||
if (closed) {
|
||||
@@ -254,10 +211,6 @@ public class ConnectionPool {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMySQL() {
|
||||
return mysql;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PreparedStatement#execute()
|
||||
*/
|
||||
@@ -337,7 +290,6 @@ public class ConnectionPool {
|
||||
plugin.debug(stmt, 5);
|
||||
}
|
||||
|
||||
|
||||
public void setBlob(Connection connection, PreparedStatement statement, int index, byte[] bytes) throws SQLException {
|
||||
if (isMySQL()) {
|
||||
Blob ablob = connection.createBlob();
|
||||
@@ -372,6 +324,14 @@ public class ConnectionPool {
|
||||
}
|
||||
}
|
||||
|
||||
public String concat(String s1, String s2) {
|
||||
if (isMySQL()) {
|
||||
return "CONCAT(" + s1 + "," + s2 + ")";
|
||||
} else {
|
||||
return s1 + "||" + s2;
|
||||
}
|
||||
}
|
||||
|
||||
protected int count(Connection connection, String table) throws SQLException {
|
||||
String stmtStr = getCountStmt(table);
|
||||
plugin.debug(stmtStr, 5);
|
||||
@@ -418,6 +378,53 @@ public class ConnectionPool {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDriver() throws ClassNotFoundException {
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
return;
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
return;
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
return;
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
throw new ClassNotFoundException("SQL Driver not found");
|
||||
}
|
||||
|
||||
private void checkAsync() throws IllegalStateException {
|
||||
if (skipAsyncCheck) return;
|
||||
if (plugin.getPlatform() == PlatformType.SPIGOT && Bukkit.isPrimaryThread()) {
|
||||
throw new IllegalStateException("Synchronous call to database.");
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ConnectionSupplier {
|
||||
Connection get() throws SQLException;
|
||||
}
|
||||
|
||||
public long getLockedSince() {
|
||||
return lockedSince;
|
||||
}
|
||||
|
||||
public long getTimeConnected() {
|
||||
return timeConnected;
|
||||
}
|
||||
|
||||
public StackTraceElement[] getWhoHasLock() {
|
||||
return whoHasLock;
|
||||
}
|
||||
|
||||
public boolean isMySQL() {
|
||||
return mysql;
|
||||
}
|
||||
|
||||
private boolean isConnectionValid() {
|
||||
if (connection == null) return false;
|
||||
if (!isMySQL()) return true;
|
||||
@@ -434,12 +441,4 @@ public class ConnectionPool {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String concat(String s1, String s2) {
|
||||
if (isMySQL()) {
|
||||
return "CONCAT(" + s1 + "," + s2 + ")";
|
||||
} else {
|
||||
return s1 + "||" + s2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ public class DatabaseRunnable implements Runnable {
|
||||
private final IAuxProtect plugin;
|
||||
private final ConcurrentLinkedQueue<PickupEntry> pickups = new ConcurrentLinkedQueue<>();
|
||||
private final ConcurrentLinkedQueue<JobsEntry> jobsentries = new ConcurrentLinkedQueue<>();
|
||||
private final Set<Consumer<DbEntry>> listeners = new HashSet<>();
|
||||
private long lastWarn = 0;
|
||||
private long lockedSince;
|
||||
|
||||
@@ -98,6 +99,13 @@ public class DatabaseRunnable implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
public void addRemoveEntryListener(Consumer<DbEntry> consumer, boolean add) {
|
||||
synchronized (listeners) {
|
||||
if (add) listeners.add(consumer);
|
||||
else listeners.remove(consumer);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkCache(boolean force) {
|
||||
synchronized (pickups) {
|
||||
Iterator<PickupEntry> itr = pickups.iterator();
|
||||
@@ -152,13 +160,4 @@ public class DatabaseRunnable implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private final Set<Consumer<DbEntry>> listeners = new HashSet<>();
|
||||
|
||||
public void addRemoveEntryListener(Consumer<DbEntry> consumer, boolean add) {
|
||||
synchronized (listeners) {
|
||||
if (add) listeners.add(consumer);
|
||||
else listeners.remove(consumer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,20 +8,6 @@ import java.sql.SQLException;
|
||||
|
||||
public class DbEntry {
|
||||
|
||||
protected SQLManager getSql() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
void setSql(SQLManager sql) {
|
||||
this.sql = sql;
|
||||
}
|
||||
|
||||
public void deResolveUIDs() {
|
||||
uid = -1;
|
||||
target_id = -1;
|
||||
}
|
||||
|
||||
protected SQLManager sql;
|
||||
protected final String world;
|
||||
protected final int x;
|
||||
protected final int y;
|
||||
@@ -31,35 +17,17 @@ public class DbEntry {
|
||||
protected final EntryAction action;
|
||||
protected final boolean state;
|
||||
private final long time;
|
||||
protected SQLManager sql;
|
||||
protected String data;
|
||||
protected String userLabel;
|
||||
protected String user;
|
||||
protected int uid;
|
||||
|
||||
protected String targetLabel;
|
||||
protected String target;
|
||||
protected int target_id;
|
||||
|
||||
private long blobid = -1;
|
||||
private byte[] blob;
|
||||
|
||||
private DbEntry(String userLabel, EntryAction action, boolean state, String world, int x, int y, int z, int pitch,
|
||||
int yaw, String targetLabel, String data, SQLManager sql) {
|
||||
this.time = DatabaseRunnable.getTime(action.getTable());
|
||||
this.userLabel = userLabel;
|
||||
this.action = action;
|
||||
this.state = state;
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.pitch = pitch;
|
||||
this.yaw = yaw;
|
||||
this.targetLabel = targetLabel;
|
||||
this.data = data;
|
||||
this.sql = sql;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -79,17 +47,11 @@ public class DbEntry {
|
||||
* @param data Extra data about your entry. This is stored as plain text
|
||||
* so use sparingly.
|
||||
*/
|
||||
public DbEntry(String userLabel, EntryAction action, boolean state, @Nullable Location location, String targetLabel,
|
||||
String data) throws NullPointerException {
|
||||
this(userLabel, action, state, location == null ? null : location.getWorld().getName(),
|
||||
location == null ? 0 : location.getBlockX(), location == null ? 0 : location.getBlockY(),
|
||||
location == null ? 0 : location.getBlockZ(),
|
||||
location == null ? 0 : Math.round(location.getPitch()),
|
||||
location == null ? 0 : Math.round(location.getYaw()), targetLabel, data, SQLManager.getInstance());
|
||||
public DbEntry(String userLabel, EntryAction action, boolean state, @Nullable Location location, String targetLabel, String data) throws NullPointerException {
|
||||
this(userLabel, action, state, location == null ? null : location.getWorld().getName(), location == null ? 0 : location.getBlockX(), location == null ? 0 : location.getBlockY(), location == null ? 0 : location.getBlockZ(), location == null ? 0 : Math.round(location.getPitch()), location == null ? 0 : Math.round(location.getYaw()), targetLabel, data, SQLManager.getInstance());
|
||||
}
|
||||
|
||||
protected DbEntry(long time, int uid, EntryAction action, boolean state, String world, int x, int y, int z,
|
||||
int pitch, int yaw, String target, int target_id, String data, SQLManager sql) {
|
||||
protected DbEntry(long time, int uid, EntryAction action, boolean state, String world, int x, int y, int z, int pitch, int yaw, String target, int target_id, String data, SQLManager sql) {
|
||||
this.time = time;
|
||||
this.uid = uid;
|
||||
this.action = action;
|
||||
@@ -106,6 +68,99 @@ public class DbEntry {
|
||||
this.sql = sql;
|
||||
}
|
||||
|
||||
private DbEntry(String userLabel, EntryAction action, boolean state, String world, int x, int y, int z, int pitch, int yaw, String targetLabel, String data, SQLManager sql) {
|
||||
this.time = DatabaseRunnable.getTime(action.getTable());
|
||||
this.userLabel = userLabel;
|
||||
this.action = action;
|
||||
this.state = state;
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.pitch = pitch;
|
||||
this.yaw = yaw;
|
||||
this.targetLabel = targetLabel;
|
||||
this.data = data;
|
||||
this.sql = sql;
|
||||
}
|
||||
|
||||
public void deResolveUIDs() {
|
||||
uid = -1;
|
||||
target_id = -1;
|
||||
}
|
||||
|
||||
public String getUser(boolean resolve) throws SQLException, BusyException {
|
||||
if (user != null || !resolve) return user;
|
||||
|
||||
if (!getUserUUID().startsWith("$") || getUserUUID().length() != 37) {
|
||||
return user = getUserUUID();
|
||||
}
|
||||
user = sql.getUserManager().getUsernameFromUID(getUid(), false);
|
||||
if (user == null) {
|
||||
user = getUserUUID();
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
public String getTarget(boolean resolve) throws SQLException, BusyException {
|
||||
if (target != null || !resolve) return target;
|
||||
|
||||
if (action.getTable().hasStringTarget() || !getTargetUUID().startsWith("$") || getTargetUUID().length() != 37) {
|
||||
return target = getTargetUUID();
|
||||
}
|
||||
target = sql.getUserManager().getUsernameFromUID(getTargetId(), false);
|
||||
if (target == null) {
|
||||
target = getTargetUUID();
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
public double getBoxDistance(DbEntry entry) {
|
||||
if (!entry.getWorld().equals(getWorld())) {
|
||||
return -1;
|
||||
}
|
||||
return Math.max(Math.max(Math.abs(entry.getX() - getX()), Math.abs(entry.getY() - getY())), Math.abs(entry.getZ() - getZ()));
|
||||
}
|
||||
|
||||
public double getDistance(DbEntry entry) {
|
||||
return Math.sqrt(getDistanceSq(entry));
|
||||
}
|
||||
|
||||
public double getDistanceSq(DbEntry entry) {
|
||||
return Math.pow(getX() - entry.getX(), 2) + Math.pow(getY() - entry.getY(), 2) + Math.pow(getZ() - entry.getZ(), 2);
|
||||
}
|
||||
|
||||
public boolean hasBlob() {
|
||||
return blob != null || blobid >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String out;
|
||||
try {
|
||||
out = String.format("%s %s(%d) %s ", getUser(), getAction().getText(getState()), getAction().getId(getState()), getTarget());
|
||||
} catch (SQLException | BusyException e) {
|
||||
out = "ERROR ";
|
||||
}
|
||||
if (getData() != null && !getData().isEmpty()) {
|
||||
String data = getData();
|
||||
if (data.length() > 64) {
|
||||
data = data.substring(0, 64) + "...";
|
||||
}
|
||||
out += "(" + data + ")";
|
||||
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
protected SQLManager getSql() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
void setSql(SQLManager sql) {
|
||||
this.sql = sql;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
@@ -147,36 +202,10 @@ public class DbEntry {
|
||||
return getUser(true);
|
||||
}
|
||||
|
||||
public String getUser(boolean resolve) throws SQLException, BusyException {
|
||||
if (user != null || !resolve) return user;
|
||||
|
||||
if (!getUserUUID().startsWith("$") || getUserUUID().length() != 37) {
|
||||
return user = getUserUUID();
|
||||
}
|
||||
user = sql.getUserManager().getUsernameFromUID(getUid(), false);
|
||||
if (user == null) {
|
||||
user = getUserUUID();
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
public String getTarget() throws SQLException, BusyException {
|
||||
return getTarget(true);
|
||||
}
|
||||
|
||||
public String getTarget(boolean resolve) throws SQLException, BusyException {
|
||||
if (target != null || !resolve) return target;
|
||||
|
||||
if (action.getTable().hasStringTarget() || !getTargetUUID().startsWith("$") || getTargetUUID().length() != 37) {
|
||||
return target = getTargetUUID();
|
||||
}
|
||||
target = sql.getUserManager().getUsernameFromUID(getTargetId(), false);
|
||||
if (target == null) {
|
||||
target = getTargetUUID();
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
public String getTargetUUID() throws SQLException, BusyException {
|
||||
if (targetLabel != null) {
|
||||
return targetLabel;
|
||||
@@ -207,21 +236,6 @@ public class DbEntry {
|
||||
return userLabel;
|
||||
}
|
||||
|
||||
public double getBoxDistance(DbEntry entry) {
|
||||
if (!entry.getWorld().equals(getWorld())) {
|
||||
return -1;
|
||||
}
|
||||
return Math.max(Math.max(Math.abs(entry.getX() - getX()), Math.abs(entry.getY() - getY())), Math.abs(entry.getZ() - getZ()));
|
||||
}
|
||||
|
||||
public double getDistance(DbEntry entry) {
|
||||
return Math.sqrt(getDistanceSq(entry));
|
||||
}
|
||||
|
||||
public double getDistanceSq(DbEntry entry) {
|
||||
return Math.pow(getX() - entry.getX(), 2) + Math.pow(getY() - entry.getY(), 2) + Math.pow(getZ() - entry.getZ(), 2);
|
||||
}
|
||||
|
||||
public byte[] getBlob() throws SQLException, BusyException {
|
||||
if (blob == null) blob = sql.getBlob(this);
|
||||
return blob;
|
||||
@@ -231,10 +245,6 @@ public class DbEntry {
|
||||
this.blob = blob;
|
||||
}
|
||||
|
||||
public boolean hasBlob() {
|
||||
return blob != null || blobid >= 0;
|
||||
}
|
||||
|
||||
public long getBlobID() {
|
||||
return blobid;
|
||||
}
|
||||
@@ -243,26 +253,6 @@ public class DbEntry {
|
||||
this.blobid = blobid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String out;
|
||||
try {
|
||||
out = String.format("%s %s(%d) %s ", getUser(), getAction().getText(getState()),
|
||||
getAction().getId(getState()), getTarget());
|
||||
} catch (SQLException | BusyException e) {
|
||||
out = "ERROR ";
|
||||
}
|
||||
if (getData() != null && !getData().isEmpty()) {
|
||||
String data = getData();
|
||||
if (data.length() > 64) {
|
||||
data = data.substring(0, 64) + "...";
|
||||
}
|
||||
out += "(" + data + ")";
|
||||
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public String getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@@ -10,24 +10,18 @@ import dev.heliosares.auxprotect.core.PlatformType;
|
||||
import java.util.*;
|
||||
|
||||
public class EntryAction {
|
||||
private static final HashMap<String, EntryAction> values = new HashMap<>();
|
||||
private static final Set<Integer> usedids = new HashSet<>();
|
||||
private static final Set<String> usednames = new HashSet<>();
|
||||
|
||||
// START PLACEHOLDERS
|
||||
public static final EntryAction GROUPING = new EntryAction("grouping", -1001);
|
||||
// END PLACEHOLDERS
|
||||
|
||||
// START MAIN (0)
|
||||
public static final EntryAction LEASH = new EntryAction("leash", 2, 3);
|
||||
public static final EntryAction SESSION = new EntryAction("session", 4, 5);
|
||||
public static final EntryAction KICK = new EntryAction("kick", 6);
|
||||
// END PLACEHOLDERS
|
||||
public static final EntryAction SHOP = new EntryAction("shop", 8, 9);
|
||||
// SKIPPED 10/11
|
||||
public static final EntryAction MOUNT = new EntryAction("mount", 12, 13);
|
||||
public static final EntryAction PLUGINLOAD = new EntryAction("pluginload", 14, 15);
|
||||
public static final EntryAction ENTITY = new EntryAction("entity", 16, 17);
|
||||
|
||||
public static final EntryAction ALERT = new EntryAction("alert", 128);
|
||||
public static final EntryAction RESPAWN = new EntryAction("respawn", 129);
|
||||
// SKIPPED 130
|
||||
@@ -46,87 +40,74 @@ public class EntryAction {
|
||||
public static final EntryAction LIGHTNING = new EntryAction("lightning", 142);
|
||||
public static final EntryAction EXPLODE = new EntryAction("explode", 143);
|
||||
public static final EntryAction NAMETAG = new EntryAction("nametag", 144);
|
||||
// END MAIN (255)
|
||||
|
||||
// START SPAM(256)
|
||||
// SKIPPED 256
|
||||
public static final EntryAction HURT = new EntryAction("hurt", 257);
|
||||
public static final EntryAction INV = new EntryAction("inv", 258, 259);
|
||||
// SKIPPED 260
|
||||
public static final EntryAction KILL = new EntryAction("kill", 261);
|
||||
// END MAIN (255)
|
||||
public static final EntryAction LAND = new EntryAction("land", 262);
|
||||
public static final EntryAction ELYTRA = new EntryAction("elytra", 263, 264);
|
||||
public static final EntryAction ACTIVITY = new EntryAction("activity", 265);
|
||||
public static final EntryAction TOTEM = new EntryAction("totem", 266);
|
||||
public static final EntryAction RAIDTRIGGER = new EntryAction("raidtrigger", 267);
|
||||
public static final EntryAction RAIDSPAWN = new EntryAction("raidspawn", 268);
|
||||
// END SPAM(511)
|
||||
|
||||
// START IGNOREABANDONED(512)
|
||||
public static final EntryAction IGNOREABANDONED = new EntryAction("ignoreabandoned", 512);
|
||||
// END IGNOREABANDONED(767)
|
||||
|
||||
// START LONGTERM (768)
|
||||
public static final EntryAction IP = new EntryAction("ip", 768);
|
||||
public static final EntryAction USERNAME = new EntryAction("username", 769);
|
||||
// END SPAM(511)
|
||||
public static final EntryAction TOWNYNAME = new EntryAction("townyname", 770);
|
||||
// END LONGTERM (1023)
|
||||
|
||||
// END IGNOREABANDONED(767)
|
||||
// START INVENTORY (1024)
|
||||
public static final EntryAction INVENTORY = new EntryAction("inventory", 1024);
|
||||
public static final EntryAction LAUNCH = new EntryAction("launch", 1025);
|
||||
public static final EntryAction GRAB = new EntryAction("grab", 1026);
|
||||
// END LONGTERM (1023)
|
||||
public static final EntryAction DROP = new EntryAction("drop", 1027);
|
||||
public static final EntryAction PICKUP = new EntryAction("pickup", 1028);
|
||||
public static final EntryAction AUCTIONLIST = new EntryAction("auctionlist", 1029);
|
||||
public static final EntryAction AUCTIONBUY = new EntryAction("auctionbuy", 1030);
|
||||
// public static final EntryAction AUCTIONBID = new EntryAction("auctionbid", 1031);
|
||||
public static final EntryAction BREAKITEM = new EntryAction("breakitem", 1032);
|
||||
|
||||
public static final EntryAction ITEMFRAME = new EntryAction("itemframe", 1152, 1153);
|
||||
|
||||
public static final EntryAction CRAFT = new EntryAction("craft", 1154);
|
||||
|
||||
public static final EntryAction ANVIL = new EntryAction("anvil", 1155);
|
||||
|
||||
public static final EntryAction ENCHANT = new EntryAction("enchant", 1156);
|
||||
|
||||
public static final EntryAction SMITH = new EntryAction("smith", 1157);
|
||||
public static final EntryAction BUCKET = new EntryAction("bucket", 1158, 1159);
|
||||
// END INVENTORY(1279)
|
||||
|
||||
// COMMANDS (1280)
|
||||
public static final EntryAction COMMAND = new EntryAction("command", 1280);
|
||||
|
||||
// CHAT (1285)
|
||||
public static final EntryAction CHAT = new EntryAction("chat", 1285);
|
||||
|
||||
// START POSITION (1290)
|
||||
public static final EntryAction POS = new EntryAction("pos", 1290);
|
||||
// END INVENTORY(1279)
|
||||
public static final EntryAction TP = new EntryAction("tp", 1291, 1292);
|
||||
// END POSITION(1299)
|
||||
|
||||
// START XRAY (1300)
|
||||
public static final EntryAction VEIN = new EntryAction("vein", 1300);
|
||||
// END XRAY(1309)
|
||||
|
||||
// START TOWNY (1310)
|
||||
public static final EntryAction TOWNCREATE = new EntryAction("towncreate", 1310);
|
||||
public static final EntryAction TOWNRENAME = new EntryAction("townrename", 1311);
|
||||
// END POSITION(1299)
|
||||
public static final EntryAction TOWNDELETE = new EntryAction("towndelete", 1312);
|
||||
// END XRAY(1309)
|
||||
public static final EntryAction TOWNJOIN = new EntryAction("townjoin", 1313, 1314);
|
||||
public static final EntryAction TOWNCLAIM = new EntryAction("townclaim", 1315, 1316);
|
||||
// public static final EntryAction TOWNMERGE = new EntryAction("townmerge", 1317);
|
||||
public static final EntryAction TOWNMAYOR = new EntryAction("townmayor", 1318);
|
||||
public static final EntryAction TOWNBANK = new EntryAction("townbank", 1319, 1320);
|
||||
|
||||
public static final EntryAction NATIONCREATE = new EntryAction("nationcreate", 1400);
|
||||
public static final EntryAction NATIONRENAME = new EntryAction("nationrename", 1401);
|
||||
public static final EntryAction NATIONDELETE = new EntryAction("nationdelete", 1402);
|
||||
public static final EntryAction NATIONJOIN = new EntryAction("nationjoin", 1403, 1404);
|
||||
public static final EntryAction NATIONBANK = new EntryAction("nationbank", 1405, 1406);
|
||||
private static final HashMap<String, EntryAction> values = new HashMap<>();
|
||||
private static final Set<Integer> usedids = new HashSet<>();
|
||||
private static final Set<String> usednames = new HashSet<>();
|
||||
// END TOWNY (1499)
|
||||
|
||||
public final boolean hasDual;
|
||||
public final int id;
|
||||
public final int idPos;
|
||||
@@ -191,18 +172,6 @@ public class EntryAction {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void validateID(String name, int id, int idPos) throws IllegalArgumentException {
|
||||
if (!usedids.add(id)) {
|
||||
throw new IllegalArgumentException("Duplicate entry id: " + id + " from action: " + name);
|
||||
}
|
||||
if (idPos > 0 && !usedids.add(idPos)) {
|
||||
throw new IllegalArgumentException("Duplicate entry id: " + idPos + " from action: " + name);
|
||||
}
|
||||
if (!usednames.add(name)) {
|
||||
throw new IllegalArgumentException("Duplicate action name: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
public String getText(boolean state) {
|
||||
if (hasDual) {
|
||||
if (state) {
|
||||
@@ -222,13 +191,6 @@ public class EntryAction {
|
||||
return Language.L.ACTIONS.translateSubcategory(getLang(state));
|
||||
}
|
||||
|
||||
private String getLang(boolean state) {
|
||||
if (hasDual) {
|
||||
return toString().toLowerCase() + "." + (state ? "p" : "n");
|
||||
}
|
||||
return toString().toLowerCase();
|
||||
}
|
||||
|
||||
public boolean exists() {
|
||||
IAuxProtect plugin = AuxProtectAPI.getInstance();
|
||||
if (plugin.getAPConfig().isDemoMode()) {
|
||||
@@ -256,6 +218,49 @@ public class EntryAction {
|
||||
throw new UnsupportedOperationException("Unknown platform " + plugin.getPlatform());
|
||||
}
|
||||
|
||||
public int getId(boolean state) {
|
||||
if (state) {
|
||||
return idPos;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other instanceof EntryAction otherEntry) {
|
||||
return this.id == otherEntry.id && this.idPos == otherEntry.idPos;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasPermission(SenderAdapter sender) {
|
||||
return APPermission.LOOKUP_ACTION.dot(toString().toLowerCase()).hasPermission(sender);
|
||||
}
|
||||
|
||||
private void validateID(String name, int id, int idPos) throws IllegalArgumentException {
|
||||
if (!usedids.add(id)) {
|
||||
throw new IllegalArgumentException("Duplicate entry id: " + id + " from action: " + name);
|
||||
}
|
||||
if (idPos > 0 && !usedids.add(idPos)) {
|
||||
throw new IllegalArgumentException("Duplicate entry id: " + idPos + " from action: " + name);
|
||||
}
|
||||
if (!usednames.add(name)) {
|
||||
throw new IllegalArgumentException("Duplicate action name: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
private String getLang(boolean state) {
|
||||
if (hasDual) {
|
||||
return toString().toLowerCase() + "." + (state ? "p" : "n");
|
||||
}
|
||||
return toString().toLowerCase();
|
||||
}
|
||||
|
||||
public Table getTable() {
|
||||
if (id < 256) return Table.AUXPROTECT_MAIN;
|
||||
if (id < 512) return Table.AUXPROTECT_SPAM;
|
||||
@@ -272,13 +277,6 @@ public class EntryAction {
|
||||
throw new IllegalArgumentException("Action with unknown table: " + this + ", id=" + id);
|
||||
}
|
||||
|
||||
public int getId(boolean state) {
|
||||
if (state) {
|
||||
return idPos;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
if (!exists()) {
|
||||
return false;
|
||||
@@ -294,19 +292,6 @@ public class EntryAction {
|
||||
this.enabled = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other instanceof EntryAction otherEntry) {
|
||||
return this.id == otherEntry.id && this.idPos == otherEntry.idPos;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isLowestpriority() {
|
||||
return lowestpriority;
|
||||
}
|
||||
@@ -318,8 +303,4 @@ public class EntryAction {
|
||||
public String getNode() {
|
||||
return APPermission.LOOKUP_ACTION.dot(toString().toLowerCase()).node;
|
||||
}
|
||||
|
||||
public boolean hasPermission(SenderAdapter sender) {
|
||||
return APPermission.LOOKUP_ACTION.dot(toString().toLowerCase()).hasPermission(sender);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,35 +70,6 @@ public class InvDiffManager extends BlobManager {
|
||||
queue.add(new InvDiffRecord(uuid, slot, qty, item));
|
||||
}
|
||||
|
||||
protected void put(Connection connection) {
|
||||
for (InvDiffRecord diff; (diff = queue.poll()) != null; ) {
|
||||
byte[] blob = null;
|
||||
final long time = System.currentTimeMillis();
|
||||
Integer damage = null;
|
||||
if (diff.qty() != 0 && diff.item() != null) {
|
||||
if (diff.item().getItemMeta() != null && diff.item().getItemMeta() instanceof Damageable meta) {
|
||||
damage = meta.getDamage();
|
||||
meta.setDamage(0);
|
||||
diff.item().setItemMeta(meta);
|
||||
}
|
||||
try {
|
||||
blob = InvSerialization.toByteArraySingle(diff.item());
|
||||
} catch (IOException e) {
|
||||
plugin.print(e);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
try {
|
||||
long blobid = getBlobId(connection, blob);
|
||||
String stmt = "INSERT INTO " + Table.AUXPROTECT_INVDIFF + " (time, uid, slot, qty, blobid, damage) VALUES (?,?,?,?,?,?)";
|
||||
|
||||
sql.execute(stmt, connection, time, sql.getUserManager().getUIDFromUUID("$" + diff.uuid(), false), diff.slot(), diff.qty() >= 0 ? diff.qty() : null, blobid >= 0 ? blobid : null, damage);
|
||||
} catch (SQLException | BusyException e) {
|
||||
plugin.print(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DiffInventoryRecord getContentsAt(int uid, final long time) throws SQLException, IOException, ClassNotFoundException, BusyException {
|
||||
long after = 0;
|
||||
|
||||
@@ -186,6 +157,35 @@ public class InvDiffManager extends BlobManager {
|
||||
}
|
||||
}
|
||||
|
||||
protected void put(Connection connection) {
|
||||
for (InvDiffRecord diff; (diff = queue.poll()) != null; ) {
|
||||
byte[] blob = null;
|
||||
final long time = System.currentTimeMillis();
|
||||
Integer damage = null;
|
||||
if (diff.qty() != 0 && diff.item() != null) {
|
||||
if (diff.item().getItemMeta() != null && diff.item().getItemMeta() instanceof Damageable meta) {
|
||||
damage = meta.getDamage();
|
||||
meta.setDamage(0);
|
||||
diff.item().setItemMeta(meta);
|
||||
}
|
||||
try {
|
||||
blob = InvSerialization.toByteArraySingle(diff.item());
|
||||
} catch (IOException e) {
|
||||
plugin.print(e);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
try {
|
||||
long blobid = getBlobId(connection, blob);
|
||||
String stmt = "INSERT INTO " + Table.AUXPROTECT_INVDIFF + " (time, uid, slot, qty, blobid, damage) VALUES (?,?,?,?,?,?)";
|
||||
|
||||
sql.execute(stmt, connection, time, sql.getUserManager().getUIDFromUUID("$" + diff.uuid(), false), diff.slot(), diff.qty() >= 0 ? diff.qty() : null, blobid >= 0 ? blobid : null, damage);
|
||||
} catch (SQLException | BusyException e) {
|
||||
plugin.print(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public record InvDiffRecord(UUID uuid, int slot, int qty, ItemStack item) {
|
||||
}
|
||||
|
||||
|
||||
@@ -20,15 +20,19 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class LookupManager {
|
||||
private static final BidiMapCache<Long, Parameters> groupParameterCache = new BidiMapCache<>(3 * 3600000L, 3 * 3600000L, true);
|
||||
private final SQLManager sql;
|
||||
private final IAuxProtect plugin;
|
||||
private static final BidiMapCache<Long, Parameters> groupParameterCache = new BidiMapCache<>(3 * 3600000L, 3 * 3600000L, true);
|
||||
|
||||
public LookupManager(SQLManager sql, IAuxProtect plugin) {
|
||||
this.sql = sql;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public static Parameters getParametersForGroup(long groupHash) {
|
||||
return groupParameterCache.get(groupHash);
|
||||
}
|
||||
|
||||
public List<DbEntry> lookup(Parameters param) throws LookupException {
|
||||
String[] sqlstmts = param.toSQL(plugin);
|
||||
|
||||
@@ -67,10 +71,6 @@ public class LookupManager {
|
||||
return out;
|
||||
}
|
||||
|
||||
public static Parameters getParametersForGroup(long groupHash) {
|
||||
return groupParameterCache.get(groupHash);
|
||||
}
|
||||
|
||||
public int count(Parameters... params) throws LookupException {
|
||||
try {
|
||||
return sql.executeReturn(connection -> {
|
||||
|
||||
@@ -459,39 +459,6 @@ public class MigrationManager {
|
||||
}
|
||||
}
|
||||
|
||||
public int getComplete() {
|
||||
return complete;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public String getProgressString() {
|
||||
if (!isMigrating()) return null;
|
||||
if (migratingToVersion <= 0) return null;
|
||||
int progressPercentage = (int) Math.floor((double) getComplete() / getTotal() * 100);
|
||||
return String.format("Migration to v%d %d%% complete. (%d/%d). DO NOT INTERRUPT", migratingToVersion, progressPercentage, getComplete(), getTotal());
|
||||
}
|
||||
|
||||
public int getOriginalVersion() {
|
||||
return originalVersion;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
private void setVersion(int version) throws SQLException {
|
||||
sql.execute("INSERT INTO " + Table.AUXPROTECT_VERSION + " (time,version) VALUES ("
|
||||
+ System.currentTimeMillis() + "," + (this.version = version) + ")", connection);
|
||||
plugin.info("Done migrating to version " + version);
|
||||
}
|
||||
|
||||
boolean isMigrating() {
|
||||
return isMigrating;
|
||||
}
|
||||
|
||||
void preTables() throws SQLException, BusyException {
|
||||
sql.execute("CREATE TABLE IF NOT EXISTS " + Table.AUXPROTECT_VERSION + " (time BIGINT,version INTEGER);", connection);
|
||||
|
||||
@@ -682,7 +649,6 @@ public class MigrationManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
interface MigrateRunnable {
|
||||
void run() throws SQLException, BusyException;
|
||||
@@ -691,4 +657,37 @@ public class MigrationManager {
|
||||
private record MigrationAction(boolean necessary, @Nullable MigrateRunnable preTableAction,
|
||||
@Nullable MigrateRunnable postTableAction) {
|
||||
}
|
||||
|
||||
public int getComplete() {
|
||||
return complete;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public String getProgressString() {
|
||||
if (!isMigrating()) return null;
|
||||
if (migratingToVersion <= 0) return null;
|
||||
int progressPercentage = (int) Math.floor((double) getComplete() / getTotal() * 100);
|
||||
return String.format("Migration to v%d %d%% complete. (%d/%d). DO NOT INTERRUPT", migratingToVersion, progressPercentage, getComplete(), getTotal());
|
||||
}
|
||||
|
||||
public int getOriginalVersion() {
|
||||
return originalVersion;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
private void setVersion(int version) throws SQLException {
|
||||
sql.execute("INSERT INTO " + Table.AUXPROTECT_VERSION + " (time,version) VALUES ("
|
||||
+ System.currentTimeMillis() + "," + (this.version = version) + ")", connection);
|
||||
plugin.info("Done migrating to version " + version);
|
||||
}
|
||||
|
||||
boolean isMigrating() {
|
||||
return isMigrating;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,6 @@ public class PosEntry extends DbEntry {
|
||||
this.z = Math.round(location.getZ() * 8D) / 8D;
|
||||
}
|
||||
|
||||
protected PosEntry(long time, int uid, EntryAction action, boolean state, String world, int x, int y, int z, byte increment, int pitch, int yaw, String target, int target_id, String data) {
|
||||
super(time, uid, action, state, world, x, y, z, pitch, yaw, target, target_id, data, SQLManager.getInstance());
|
||||
double[] dInc = byteToFractions(increment);
|
||||
this.x = x + dInc[0];
|
||||
this.y = y + dInc[1];
|
||||
this.z = z + dInc[2];
|
||||
}
|
||||
|
||||
public PosEntry(long time, int uid, Location location) {
|
||||
super(time, uid, EntryAction.POS, false, Objects.requireNonNull(location.getWorld()).getName(),
|
||||
(int) Math.round(location.getX()), (int) Math.round(location.getY()), (int) Math.round(location.getZ()),
|
||||
@@ -35,6 +27,14 @@ public class PosEntry extends DbEntry {
|
||||
this.z = location.getZ();
|
||||
}
|
||||
|
||||
protected PosEntry(long time, int uid, EntryAction action, boolean state, String world, int x, int y, int z, byte increment, int pitch, int yaw, String target, int target_id, String data) {
|
||||
super(time, uid, action, state, world, x, y, z, pitch, yaw, target, target_id, data, SQLManager.getInstance());
|
||||
double[] dInc = byteToFractions(increment);
|
||||
this.x = x + dInc[0];
|
||||
this.y = y + dInc[1];
|
||||
this.z = z + dInc[2];
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the fraction of the x/y/z values into a single byte. The structure is as follows
|
||||
* 0b X X X Y Y Z Z Z
|
||||
|
||||
@@ -47,14 +47,6 @@ public class ResultMap {
|
||||
results = Collections.unmodifiableList(results_);
|
||||
}
|
||||
|
||||
public List<String> getLabels() {
|
||||
return labels;
|
||||
}
|
||||
|
||||
public List<Result> getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
public static class Result {
|
||||
private final ResultMap parent;
|
||||
private final List<Object> values;
|
||||
@@ -88,4 +80,12 @@ public class ResultMap {
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getLabels() {
|
||||
return labels;
|
||||
}
|
||||
|
||||
public List<Result> getResults() {
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,10 +183,6 @@ public class Results {
|
||||
player.sendMessage(message.create());
|
||||
}
|
||||
|
||||
public List<DbEntry> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
public DbEntry get(int i) {
|
||||
return getEntries().get(i);
|
||||
}
|
||||
@@ -280,6 +276,10 @@ public class Results {
|
||||
return (int) Math.ceil(getEntries().size() / (double) perpage);
|
||||
}
|
||||
|
||||
public List<DbEntry> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return getEntries().size();
|
||||
}
|
||||
|
||||
@@ -73,43 +73,6 @@ public class SQLManager extends ConnectionPool {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public String getTablePrefix() {
|
||||
return tablePrefix;
|
||||
}
|
||||
|
||||
public SQLUserManager getUserManager() {
|
||||
return usermanager;
|
||||
}
|
||||
|
||||
public LookupManager getLookupManager() {
|
||||
return lookupmanager;
|
||||
}
|
||||
|
||||
public InvDiffManager getInvDiffManager() {
|
||||
return invdiffmanager;
|
||||
}
|
||||
|
||||
public TownyManager getTownyManager() {
|
||||
return townymanager;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return rowcount;
|
||||
}
|
||||
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
public boolean isConnected() {
|
||||
return isConnected;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return migrationmanager.getVersion();
|
||||
}
|
||||
|
||||
public int getOriginalVersion() {
|
||||
return migrationmanager.getOriginalVersion();
|
||||
}
|
||||
|
||||
public void connect() throws SQLException, BusyException {
|
||||
plugin.info("Connecting to database...");
|
||||
|
||||
@@ -202,110 +165,6 @@ public class SQLManager extends ConnectionPool {
|
||||
return backup.getAbsolutePath();
|
||||
}
|
||||
|
||||
private void init(Connection connection) throws SQLException, BusyException {
|
||||
startTransaction(connection);
|
||||
try {
|
||||
this.migrationmanager = new MigrationManager(this, connection, plugin);
|
||||
migrationmanager.preTables();
|
||||
|
||||
if (invdiffmanager != null) {
|
||||
invdiffmanager.createTable(connection);
|
||||
}
|
||||
|
||||
if (invblobmanager != null) {
|
||||
invblobmanager.createTable(connection);
|
||||
}
|
||||
|
||||
for (Table table : Table.values()) {
|
||||
if (table.hasAPEntries()) {
|
||||
execute(table.getSQLCreateString(plugin), connection);
|
||||
}
|
||||
}
|
||||
String stmt;
|
||||
if (plugin.getPlatform() == PlatformType.SPIGOT) {
|
||||
stmt = "CREATE TABLE IF NOT EXISTS " + Table.AUXPROTECT_INVDIFF;
|
||||
stmt += " (time BIGINT, uid INT, slot INT, qty INT, blobid BIGINT, damage INT);";
|
||||
execute(stmt, connection);
|
||||
|
||||
stmt = "CREATE TABLE IF NOT EXISTS " + Table.AUXPROTECT_WORLDS;
|
||||
stmt += " (name varchar(255), wid SMALLINT);";
|
||||
execute(stmt, connection);
|
||||
|
||||
stmt = "SELECT * FROM " + Table.AUXPROTECT_WORLDS + ";";
|
||||
debugSQLStatement(stmt);
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
try (ResultSet results = statement.executeQuery(stmt)) {
|
||||
while (results.next()) {
|
||||
String world = results.getString("name");
|
||||
int wid = results.getInt("wid");
|
||||
worlds.put(world, wid);
|
||||
if (wid >= nextWid) {
|
||||
nextWid = wid + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stmt = "CREATE TABLE IF NOT EXISTS " + Table.AUXPROTECT_LASTS;
|
||||
stmt += " (name SMALLINT PRIMARY KEY, value BIGINT);";
|
||||
execute(stmt, connection);
|
||||
for (LastKeys key : LastKeys.values()) {
|
||||
try {
|
||||
execute("INSERT INTO " + Table.AUXPROTECT_LASTS + " (name, value) VALUES (?,?)", connection, key.id);
|
||||
} catch (SQLException ignored) {
|
||||
// Ensures each LastKeys has a value, so we can just UPDATE later
|
||||
}
|
||||
}
|
||||
|
||||
stmt = "CREATE TABLE IF NOT EXISTS " + Table.AUXPROTECT_API_ACTIONS
|
||||
+ " (name varchar(255), nid SMALLINT, pid SMALLINT, ntext varchar(255), ptext varchar(255));";
|
||||
execute(stmt, connection);
|
||||
|
||||
stmt = "SELECT * FROM " + Table.AUXPROTECT_API_ACTIONS + ";";
|
||||
debugSQLStatement(stmt);
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
try (ResultSet results = statement.executeQuery(stmt)) {
|
||||
while (results.next()) {
|
||||
String key = results.getString("name");
|
||||
int nid = results.getInt("nid");
|
||||
int pid = results.getInt("pid");
|
||||
String ntext = results.getString("ntext");
|
||||
String ptext = results.getString("ptext");
|
||||
nextActionId = Math.max(nextActionId, Math.max(nid, pid) + 1);
|
||||
new EntryAction(key, nid, pid, ntext, ptext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
usermanager.init(connection);
|
||||
|
||||
migrationmanager.postTables();
|
||||
|
||||
if (invdiffmanager != null) {
|
||||
invdiffmanager.init(connection);
|
||||
}
|
||||
|
||||
if (invblobmanager != null) {
|
||||
invblobmanager.init(connection);
|
||||
}
|
||||
|
||||
if (getLast(LastKeys.LEGACY_POSITIONS, connection) == 0)
|
||||
setLast(LastKeys.LEGACY_POSITIONS, System.currentTimeMillis(), connection);
|
||||
|
||||
execute("COMMIT", connection);
|
||||
plugin.debug("init done.");
|
||||
} catch (Throwable t) {
|
||||
plugin.warning("An error occurred during initialization. Rolling back changes.");
|
||||
execute("ROLLBACK", connection);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
private void startTransaction(Connection connection) throws SQLException {
|
||||
execute((isMySQL() ? "START" : "BEGIN") + " TRANSACTION", connection);
|
||||
}
|
||||
|
||||
public int purgeUIDs() throws SQLException, BusyException {
|
||||
int count = executeReturn(connection -> {
|
||||
startTransaction(connection);
|
||||
@@ -370,115 +229,6 @@ public class SQLManager extends ConnectionPool {
|
||||
setLast(LastKeys.VACUUM, System.currentTimeMillis(), connection);
|
||||
}
|
||||
|
||||
|
||||
protected void put(Connection connection, Table table) throws SQLException, BusyException {
|
||||
long start = System.nanoTime();
|
||||
int count;
|
||||
List<DbEntry> entries = new ArrayList<>();
|
||||
|
||||
DbEntry entry;
|
||||
while ((entry = table.queue.poll()) != null) {
|
||||
entries.add(entry);
|
||||
}
|
||||
count = entries.size();
|
||||
if (count == 0) {
|
||||
return;
|
||||
}
|
||||
StringBuilder stmt = new StringBuilder("INSERT INTO " + table + " ");
|
||||
int numColumns = table.getNumColumns(plugin.getPlatform());
|
||||
String inc = Table.getValuesTemplate(numColumns);
|
||||
final boolean hasLocation = plugin.getPlatform() == PlatformType.SPIGOT && table.hasLocation();
|
||||
final boolean hasData = table.hasData();
|
||||
final boolean hasAction = table.hasActionId();
|
||||
final boolean hasLook = table.hasLook();
|
||||
stmt.append(table.getValuesHeader(plugin.getPlatform()));
|
||||
stmt.append(" VALUES");
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
stmt.append("\n").append(inc);
|
||||
if (i + 1 == entries.size()) {
|
||||
stmt.append(";");
|
||||
} else {
|
||||
stmt.append(",");
|
||||
}
|
||||
}
|
||||
try (PreparedStatement statement = connection.prepareStatement(stmt.toString())) {
|
||||
|
||||
int i = 1;
|
||||
for (DbEntry dbEntry : entries) {
|
||||
int prior = i;
|
||||
statement.setLong(i++, dbEntry.getTime());
|
||||
statement.setInt(i++, dbEntry.getUid());
|
||||
int action = dbEntry.getState() ? dbEntry.getAction().idPos : dbEntry.getAction().id;
|
||||
|
||||
if (hasAction) {
|
||||
statement.setInt(i++, action);
|
||||
}
|
||||
if (hasLocation) {
|
||||
statement.setInt(i++, getWID(dbEntry.getWorld()));
|
||||
statement.setInt(i++, dbEntry.getX());
|
||||
statement.setInt(i++, Math.max(Math.min(dbEntry.getY(), Short.MAX_VALUE), Short.MIN_VALUE));
|
||||
statement.setInt(i++, dbEntry.getZ());
|
||||
|
||||
if (dbEntry instanceof PosEntry posEntry) statement.setByte(i++, posEntry.getIncrement());
|
||||
else if (table == Table.AUXPROTECT_POSITION) statement.setByte(i++, (byte) 0);
|
||||
}
|
||||
if (hasLook) {
|
||||
statement.setInt(i++, dbEntry.getPitch());
|
||||
statement.setInt(i++, dbEntry.getYaw());
|
||||
}
|
||||
if (table.hasStringTarget()) {
|
||||
String target = sanitize(dbEntry.getTargetUUID());
|
||||
statement.setString(i++, target);
|
||||
if (table == Table.AUXPROTECT_LONGTERM) {
|
||||
statement.setInt(i++, target.toLowerCase().hashCode());
|
||||
}
|
||||
} else {
|
||||
statement.setInt(i++, dbEntry.getTargetId());
|
||||
}
|
||||
if (dbEntry instanceof XrayEntry) {
|
||||
statement.setShort(i++, ((XrayEntry) dbEntry).getRating());
|
||||
}
|
||||
if (hasData) {
|
||||
statement.setString(i++, sanitize(dbEntry.getData()));
|
||||
}
|
||||
if (table.hasBlob()) {
|
||||
if (dbEntry.hasBlob() && dbEntry.getBlob() != null) {
|
||||
setBlob(connection, statement, i++, dbEntry.getBlob());
|
||||
} else statement.setNull(i++, Types.NULL);
|
||||
} else if (table.hasBlobID()) {
|
||||
if (dbEntry.hasBlob() && dbEntry.getBlob() != null) {
|
||||
long blobid = invblobmanager.getBlobId(connection, dbEntry.getBlob());
|
||||
statement.setLong(i++, blobid);
|
||||
} else statement.setNull(i++, Types.NULL);
|
||||
if (table.hasItemMeta()) {
|
||||
if (dbEntry instanceof SingleItemEntry sientry && sientry.getItem() != null) {
|
||||
statement.setInt(i++, sientry.getQty());
|
||||
statement.setInt(i++, sientry.getDamage());
|
||||
} else {
|
||||
statement.setNull(i++, Types.NULL);
|
||||
statement.setNull(i++, Types.NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i - prior != numColumns) {
|
||||
plugin.warning("Incorrect number of columns provided inserting action "
|
||||
+ dbEntry.getAction().toString() + " into " + table);
|
||||
plugin.warning(i - prior + " =/= " + numColumns);
|
||||
plugin.warning("Statement: " + stmt);
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
rowcount += entries.size();
|
||||
|
||||
double elapsed = (System.nanoTime() - start) / 1000000.0;
|
||||
plugin.debug(table + ": Logged " + count + " entrie(s) in " + (Math.round(elapsed * 10.0) / 10.0) + "ms. ("
|
||||
+ (Math.round(elapsed / count * 10.0) / 10.0) + "ms each)", 3);
|
||||
}
|
||||
|
||||
public int purge(Table table, long time) throws SQLException, BusyException {
|
||||
if (!isConnected)
|
||||
return 0;
|
||||
@@ -603,22 +353,6 @@ public class SQLManager extends ConnectionPool {
|
||||
return action;
|
||||
}
|
||||
|
||||
private void count() {
|
||||
int total = 0;
|
||||
plugin.debug("Counting rows..");
|
||||
for (Table table : Table.values()) {
|
||||
if (!table.exists(plugin) || !table.hasAPEntries()) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
total += count(table);
|
||||
} catch (SQLException | BusyException ignored) {
|
||||
}
|
||||
}
|
||||
plugin.debug("Counted all tables. " + total + " rows.");
|
||||
rowcount = total;
|
||||
}
|
||||
|
||||
public int count(Table table) throws SQLException, BusyException {
|
||||
return executeReturn(connection -> count(connection, table.toString()), 30000L, Integer.class);
|
||||
}
|
||||
@@ -664,10 +398,6 @@ public class SQLManager extends ConnectionPool {
|
||||
}, 30000L);
|
||||
}
|
||||
|
||||
protected void incrementRows() {
|
||||
rowcount++;
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
usermanager.cleanup();
|
||||
if (townymanager != null) {
|
||||
@@ -729,12 +459,237 @@ public class SQLManager extends ConnectionPool {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getMigrationStatus() {
|
||||
if (migrationmanager == null) return null;
|
||||
return migrationmanager.getProgressString();
|
||||
protected void put(Connection connection, Table table) throws SQLException, BusyException {
|
||||
long start = System.nanoTime();
|
||||
int count;
|
||||
List<DbEntry> entries = new ArrayList<>();
|
||||
|
||||
DbEntry entry;
|
||||
while ((entry = table.queue.poll()) != null) {
|
||||
entries.add(entry);
|
||||
}
|
||||
count = entries.size();
|
||||
if (count == 0) {
|
||||
return;
|
||||
}
|
||||
StringBuilder stmt = new StringBuilder("INSERT INTO " + table + " ");
|
||||
int numColumns = table.getNumColumns(plugin.getPlatform());
|
||||
String inc = Table.getValuesTemplate(numColumns);
|
||||
final boolean hasLocation = plugin.getPlatform() == PlatformType.SPIGOT && table.hasLocation();
|
||||
final boolean hasData = table.hasData();
|
||||
final boolean hasAction = table.hasActionId();
|
||||
final boolean hasLook = table.hasLook();
|
||||
stmt.append(table.getValuesHeader(plugin.getPlatform()));
|
||||
stmt.append(" VALUES");
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
stmt.append("\n").append(inc);
|
||||
if (i + 1 == entries.size()) {
|
||||
stmt.append(";");
|
||||
} else {
|
||||
stmt.append(",");
|
||||
}
|
||||
}
|
||||
try (PreparedStatement statement = connection.prepareStatement(stmt.toString())) {
|
||||
|
||||
int i = 1;
|
||||
for (DbEntry dbEntry : entries) {
|
||||
int prior = i;
|
||||
statement.setLong(i++, dbEntry.getTime());
|
||||
statement.setInt(i++, dbEntry.getUid());
|
||||
int action = dbEntry.getState() ? dbEntry.getAction().idPos : dbEntry.getAction().id;
|
||||
|
||||
if (hasAction) {
|
||||
statement.setInt(i++, action);
|
||||
}
|
||||
if (hasLocation) {
|
||||
statement.setInt(i++, getWID(dbEntry.getWorld()));
|
||||
statement.setInt(i++, dbEntry.getX());
|
||||
statement.setInt(i++, Math.max(Math.min(dbEntry.getY(), Short.MAX_VALUE), Short.MIN_VALUE));
|
||||
statement.setInt(i++, dbEntry.getZ());
|
||||
|
||||
if (dbEntry instanceof PosEntry posEntry) statement.setByte(i++, posEntry.getIncrement());
|
||||
else if (table == Table.AUXPROTECT_POSITION) statement.setByte(i++, (byte) 0);
|
||||
}
|
||||
if (hasLook) {
|
||||
statement.setInt(i++, dbEntry.getPitch());
|
||||
statement.setInt(i++, dbEntry.getYaw());
|
||||
}
|
||||
if (table.hasStringTarget()) {
|
||||
String target = sanitize(dbEntry.getTargetUUID());
|
||||
statement.setString(i++, target);
|
||||
if (table == Table.AUXPROTECT_LONGTERM) {
|
||||
statement.setInt(i++, target.toLowerCase().hashCode());
|
||||
}
|
||||
} else {
|
||||
statement.setInt(i++, dbEntry.getTargetId());
|
||||
}
|
||||
if (dbEntry instanceof XrayEntry) {
|
||||
statement.setShort(i++, ((XrayEntry) dbEntry).getRating());
|
||||
}
|
||||
if (hasData) {
|
||||
statement.setString(i++, sanitize(dbEntry.getData()));
|
||||
}
|
||||
if (table.hasBlob()) {
|
||||
if (dbEntry.hasBlob() && dbEntry.getBlob() != null) {
|
||||
setBlob(connection, statement, i++, dbEntry.getBlob());
|
||||
} else statement.setNull(i++, Types.NULL);
|
||||
} else if (table.hasBlobID()) {
|
||||
if (dbEntry.hasBlob() && dbEntry.getBlob() != null) {
|
||||
long blobid = invblobmanager.getBlobId(connection, dbEntry.getBlob());
|
||||
statement.setLong(i++, blobid);
|
||||
} else statement.setNull(i++, Types.NULL);
|
||||
if (table.hasItemMeta()) {
|
||||
if (dbEntry instanceof SingleItemEntry sientry && sientry.getItem() != null) {
|
||||
statement.setInt(i++, sientry.getQty());
|
||||
statement.setInt(i++, sientry.getDamage());
|
||||
} else {
|
||||
statement.setNull(i++, Types.NULL);
|
||||
statement.setNull(i++, Types.NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i - prior != numColumns) {
|
||||
plugin.warning("Incorrect number of columns provided inserting action "
|
||||
+ dbEntry.getAction().toString() + " into " + table);
|
||||
plugin.warning(i - prior + " =/= " + numColumns);
|
||||
plugin.warning("Statement: " + stmt);
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
rowcount += entries.size();
|
||||
|
||||
double elapsed = (System.nanoTime() - start) / 1000000.0;
|
||||
plugin.debug(table + ": Logged " + count + " entrie(s) in " + (Math.round(elapsed * 10.0) / 10.0) + "ms. ("
|
||||
+ (Math.round(elapsed / count * 10.0) / 10.0) + "ms each)", 3);
|
||||
}
|
||||
|
||||
protected void incrementRows() {
|
||||
rowcount++;
|
||||
}
|
||||
|
||||
private void init(Connection connection) throws SQLException, BusyException {
|
||||
startTransaction(connection);
|
||||
try {
|
||||
this.migrationmanager = new MigrationManager(this, connection, plugin);
|
||||
migrationmanager.preTables();
|
||||
|
||||
if (invdiffmanager != null) {
|
||||
invdiffmanager.createTable(connection);
|
||||
}
|
||||
|
||||
if (invblobmanager != null) {
|
||||
invblobmanager.createTable(connection);
|
||||
}
|
||||
|
||||
for (Table table : Table.values()) {
|
||||
if (table.hasAPEntries()) {
|
||||
execute(table.getSQLCreateString(plugin), connection);
|
||||
}
|
||||
}
|
||||
String stmt;
|
||||
if (plugin.getPlatform() == PlatformType.SPIGOT) {
|
||||
stmt = "CREATE TABLE IF NOT EXISTS " + Table.AUXPROTECT_INVDIFF;
|
||||
stmt += " (time BIGINT, uid INT, slot INT, qty INT, blobid BIGINT, damage INT);";
|
||||
execute(stmt, connection);
|
||||
|
||||
stmt = "CREATE TABLE IF NOT EXISTS " + Table.AUXPROTECT_WORLDS;
|
||||
stmt += " (name varchar(255), wid SMALLINT);";
|
||||
execute(stmt, connection);
|
||||
|
||||
stmt = "SELECT * FROM " + Table.AUXPROTECT_WORLDS + ";";
|
||||
debugSQLStatement(stmt);
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
try (ResultSet results = statement.executeQuery(stmt)) {
|
||||
while (results.next()) {
|
||||
String world = results.getString("name");
|
||||
int wid = results.getInt("wid");
|
||||
worlds.put(world, wid);
|
||||
if (wid >= nextWid) {
|
||||
nextWid = wid + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stmt = "CREATE TABLE IF NOT EXISTS " + Table.AUXPROTECT_LASTS;
|
||||
stmt += " (name SMALLINT PRIMARY KEY, value BIGINT);";
|
||||
execute(stmt, connection);
|
||||
for (LastKeys key : LastKeys.values()) {
|
||||
try {
|
||||
execute("INSERT INTO " + Table.AUXPROTECT_LASTS + " (name, value) VALUES (?,?)", connection, key.id);
|
||||
} catch (SQLException ignored) {
|
||||
// Ensures each LastKeys has a value, so we can just UPDATE later
|
||||
}
|
||||
}
|
||||
|
||||
stmt = "CREATE TABLE IF NOT EXISTS " + Table.AUXPROTECT_API_ACTIONS
|
||||
+ " (name varchar(255), nid SMALLINT, pid SMALLINT, ntext varchar(255), ptext varchar(255));";
|
||||
execute(stmt, connection);
|
||||
|
||||
stmt = "SELECT * FROM " + Table.AUXPROTECT_API_ACTIONS + ";";
|
||||
debugSQLStatement(stmt);
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
try (ResultSet results = statement.executeQuery(stmt)) {
|
||||
while (results.next()) {
|
||||
String key = results.getString("name");
|
||||
int nid = results.getInt("nid");
|
||||
int pid = results.getInt("pid");
|
||||
String ntext = results.getString("ntext");
|
||||
String ptext = results.getString("ptext");
|
||||
nextActionId = Math.max(nextActionId, Math.max(nid, pid) + 1);
|
||||
new EntryAction(key, nid, pid, ntext, ptext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
usermanager.init(connection);
|
||||
|
||||
migrationmanager.postTables();
|
||||
|
||||
if (invdiffmanager != null) {
|
||||
invdiffmanager.init(connection);
|
||||
}
|
||||
|
||||
if (invblobmanager != null) {
|
||||
invblobmanager.init(connection);
|
||||
}
|
||||
|
||||
if (getLast(LastKeys.LEGACY_POSITIONS, connection) == 0)
|
||||
setLast(LastKeys.LEGACY_POSITIONS, System.currentTimeMillis(), connection);
|
||||
|
||||
execute("COMMIT", connection);
|
||||
plugin.debug("init done.");
|
||||
} catch (Throwable t) {
|
||||
plugin.warning("An error occurred during initialization. Rolling back changes.");
|
||||
execute("ROLLBACK", connection);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
private void startTransaction(Connection connection) throws SQLException {
|
||||
execute((isMySQL() ? "START" : "BEGIN") + " TRANSACTION", connection);
|
||||
}
|
||||
|
||||
private void count() {
|
||||
int total = 0;
|
||||
plugin.debug("Counting rows..");
|
||||
for (Table table : Table.values()) {
|
||||
if (!table.exists(plugin) || !table.hasAPEntries()) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
total += count(table);
|
||||
} catch (SQLException | BusyException ignored) {
|
||||
}
|
||||
}
|
||||
plugin.debug("Counted all tables. " + total + " rows.");
|
||||
rowcount = total;
|
||||
}
|
||||
|
||||
public enum LastKeys {
|
||||
AUTO_PURGE(1), VACUUM(2), TELEMETRY(3), LEGACY_POSITIONS(4);
|
||||
@@ -746,4 +701,47 @@ public class SQLManager extends ConnectionPool {
|
||||
this.id = (short) id;
|
||||
}
|
||||
}
|
||||
|
||||
public String getTablePrefix() {
|
||||
return tablePrefix;
|
||||
}
|
||||
|
||||
public SQLUserManager getUserManager() {
|
||||
return usermanager;
|
||||
}
|
||||
|
||||
public LookupManager getLookupManager() {
|
||||
return lookupmanager;
|
||||
}
|
||||
|
||||
public InvDiffManager getInvDiffManager() {
|
||||
return invdiffmanager;
|
||||
}
|
||||
|
||||
public TownyManager getTownyManager() {
|
||||
return townymanager;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return rowcount;
|
||||
}
|
||||
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
public boolean isConnected() {
|
||||
return isConnected;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return migrationmanager.getVersion();
|
||||
}
|
||||
|
||||
public int getOriginalVersion() {
|
||||
return migrationmanager.getOriginalVersion();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getMigrationStatus() {
|
||||
if (migrationmanager == null) return null;
|
||||
return migrationmanager.getProgressString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@ import dev.heliosares.auxprotect.exceptions.BusyException;
|
||||
import dev.heliosares.auxprotect.utils.BidiMapCache;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class SQLUserManager {
|
||||
@@ -231,10 +234,6 @@ public class SQLUserManager {
|
||||
}, wait ? 300000L : 3000L, String.class);
|
||||
}
|
||||
|
||||
public Collection<String> getCachedUsernames() {
|
||||
return Collections.unmodifiableCollection(usernames.values());
|
||||
}
|
||||
|
||||
public byte[] getPendingInventory(int uid) throws SQLException, BusyException {
|
||||
if (uid <= 0) {
|
||||
return null;
|
||||
@@ -272,11 +271,6 @@ public class SQLUserManager {
|
||||
}
|
||||
}
|
||||
|
||||
protected void cleanup() {
|
||||
usernames.cleanup();
|
||||
uuids.cleanup();
|
||||
}
|
||||
|
||||
public void init(Connection connection) throws SQLException {
|
||||
String stmt = "CREATE TABLE IF NOT EXISTS " + Table.AUXPROTECT_UIDS;
|
||||
if (sql.isMySQL()) {
|
||||
@@ -294,4 +288,13 @@ public class SQLUserManager {
|
||||
usernames.clear();
|
||||
uuids.clear();
|
||||
}
|
||||
|
||||
protected void cleanup() {
|
||||
usernames.cleanup();
|
||||
uuids.cleanup();
|
||||
}
|
||||
|
||||
public Collection<String> getCachedUsernames() {
|
||||
return Collections.unmodifiableCollection(usernames.values());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,10 +36,6 @@ public enum Table {
|
||||
return SQLManager.getInstance().getTablePrefix() + super.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public boolean exists(IAuxProtect plugin) {
|
||||
if (plugin.getPlatform() == PlatformType.BUNGEE) {
|
||||
return switch (this) {
|
||||
@@ -225,6 +221,14 @@ public enum Table {
|
||||
return this == AUXPROTECT_POSITION;
|
||||
}
|
||||
|
||||
public boolean hasItemMeta() {
|
||||
return this == AUXPROTECT_INVENTORY || this == AUXPROTECT_INVDIFF;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public long getAutoPurgeInterval() {
|
||||
if (!canPurge()) {
|
||||
throw new UnsupportedOperationException();
|
||||
@@ -238,8 +242,4 @@ public enum Table {
|
||||
}
|
||||
this.autopurgeinterval = autopurgeinterval;
|
||||
}
|
||||
|
||||
public boolean hasItemMeta() {
|
||||
return this == AUXPROTECT_INVENTORY || this == AUXPROTECT_INVDIFF;
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,19 @@ public class XrayEntry extends DbEntry {
|
||||
return this.add(entry, new ArrayList<>());
|
||||
}
|
||||
|
||||
public void setRating(short rating, @Nullable String rater) {
|
||||
if (rater != null) {
|
||||
String data = getData();
|
||||
if (data.length() > 0) {
|
||||
data += "; ";
|
||||
}
|
||||
String ratedBy = LocalDateTime.now().format(XrayCommand.ratedByDateFormatter) + ": " + rater + " rated " + rating;
|
||||
data += ratedBy;
|
||||
setData(data);
|
||||
}
|
||||
this.rating = rating;
|
||||
}
|
||||
|
||||
private boolean add(XrayEntry other, ArrayList<XrayEntry> visited) {
|
||||
if (!visited.add(this)) {
|
||||
return false;
|
||||
@@ -51,17 +64,4 @@ public class XrayEntry extends DbEntry {
|
||||
public short getRating() {
|
||||
return rating;
|
||||
}
|
||||
|
||||
public void setRating(short rating, @Nullable String rater) {
|
||||
if (rater != null) {
|
||||
String data = getData();
|
||||
if (data.length() > 0) {
|
||||
data += "; ";
|
||||
}
|
||||
String ratedBy = LocalDateTime.now().format(XrayCommand.ratedByDateFormatter) + ": " + rater + " rated " + rating;
|
||||
data += ratedBy;
|
||||
setData(data);
|
||||
}
|
||||
this.rating = rating;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class XrayResults {
|
||||
|
||||
message.append("" + ChatColor.COLOR_CHAR + "7" + ChatColor.COLOR_CHAR + "l[0-All]")
|
||||
.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ap xray zero " + en.getUserUUID().substring(1)))
|
||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("" + ChatColor.COLOR_CHAR + "7Rate all entries from " + en.getUser() + " as 0.")));
|
||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(ChatColor.COLOR_CHAR + "7Rate all entries from " + en.getUser() + " as 0.")));
|
||||
}
|
||||
|
||||
sender.sendMessage(message.create());
|
||||
|
||||
@@ -45,10 +45,10 @@ public class AuxProtectSpigot extends JavaPlugin implements IAuxProtect {
|
||||
private static final DateTimeFormatter ERROR_TIME_FORMAT = DateTimeFormatter.ofPattern("HH:mm:ss.SSS");
|
||||
private static AuxProtectSpigot instance;
|
||||
private static SQLManager sqlManager;
|
||||
final Set<Integer> stackHashHistory = new HashSet<>();
|
||||
private final APConfig config = new APConfig();
|
||||
private final Set<String> hooks = new HashSet<>();
|
||||
private final HashMap<UUID, APPlayer> apPlayers = new HashMap<>();
|
||||
final Set<Integer> stackHashHistory = new HashSet<>();
|
||||
public String update;
|
||||
protected DatabaseRunnable dbRunnable;
|
||||
long lastCheckedForUpdate;
|
||||
@@ -89,18 +89,6 @@ public class AuxProtectSpigot extends JavaPlugin implements IAuxProtect {
|
||||
return "#null";
|
||||
}
|
||||
|
||||
public ClaimInvCommand getClaiminvcommand() {
|
||||
return claiminvcommand;
|
||||
}
|
||||
|
||||
public APSCommand getApcommand() {
|
||||
return apcommand;
|
||||
}
|
||||
|
||||
public int getCompatabilityVersion() {
|
||||
return SERVER_VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
@@ -509,43 +497,10 @@ public class AuxProtectSpigot extends JavaPlugin implements IAuxProtect {
|
||||
dbRunnable.add(new DbEntry("#console", EntryAction.PLUGINLOAD, true, "AuxProtect", ""));
|
||||
}
|
||||
|
||||
private boolean hook(Supplier<Listener> listener, String... names) {
|
||||
boolean hook;
|
||||
try {
|
||||
Plugin plugin = null;
|
||||
for (String name : names) {
|
||||
plugin = getPlugin(name);
|
||||
if (plugin != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
hook = plugin != null && plugin.isEnabled();
|
||||
if (hook) {
|
||||
getServer().getPluginManager().registerEvents(listener.get(), this);
|
||||
hooks.add(plugin.getName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
warning("Exception while hooking " + names[0]);
|
||||
print(e);
|
||||
hook = false;
|
||||
}
|
||||
Telemetry.reportHook(this, names[0], hook);
|
||||
return hook;
|
||||
}
|
||||
|
||||
public boolean isHooked(String name) {
|
||||
return hooks.contains(name);
|
||||
}
|
||||
|
||||
private Plugin getPlugin(String name) {
|
||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
if (plugin.getName().equalsIgnoreCase(name)) {
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public APPlayer getAPPlayer(Player player) {
|
||||
synchronized (apPlayers) {
|
||||
if (apPlayers.containsKey(player.getUniqueId())) {
|
||||
@@ -594,23 +549,6 @@ public class AuxProtectSpigot extends JavaPlugin implements IAuxProtect {
|
||||
info("Done disabling.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShuttingDown() {
|
||||
return isShuttingDown;
|
||||
}
|
||||
|
||||
private boolean setupEconomy() {
|
||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
return false;
|
||||
}
|
||||
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
return false;
|
||||
}
|
||||
econ = rsp.getProvider();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String string) {
|
||||
this.getLogger().info(string);
|
||||
@@ -629,14 +567,6 @@ public class AuxProtectSpigot extends JavaPlugin implements IAuxProtect {
|
||||
}
|
||||
}
|
||||
|
||||
public SQLManager getSqlManager() {
|
||||
return sqlManager;
|
||||
}
|
||||
|
||||
public Economy getEconomy() {
|
||||
return econ;
|
||||
}
|
||||
|
||||
public String formatMoney(double d) {
|
||||
if (!Double.isFinite(d) || Double.isNaN(d)) {
|
||||
return "NaN";
|
||||
@@ -666,24 +596,6 @@ public class AuxProtectSpigot extends JavaPlugin implements IAuxProtect {
|
||||
logToStackLog(stack);
|
||||
}
|
||||
|
||||
private void logToStackLog(String msg) {
|
||||
stackLog += "[" + LocalDateTime.now().format(ERROR_TIME_FORMAT) + "] " + msg + "\n";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStackLog() {
|
||||
return stackLog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformType getPlatform() {
|
||||
return PlatformType.SPIGOT;
|
||||
}
|
||||
|
||||
public APConfig getAPConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(DbEntry entry) {
|
||||
// This is only async because veinManager performs SQL lookups
|
||||
@@ -697,10 +609,6 @@ public class AuxProtectSpigot extends JavaPlugin implements IAuxProtect {
|
||||
});
|
||||
}
|
||||
|
||||
public VeinManager getVeinManager() {
|
||||
return veinManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAsync(Runnable run) {
|
||||
getServer().getScheduler().runTaskAsynchronously(this, run);
|
||||
@@ -715,16 +623,6 @@ public class AuxProtectSpigot extends JavaPlugin implements IAuxProtect {
|
||||
return dbRunnable.queueSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandPrefix() {
|
||||
return "auxprotect";
|
||||
}
|
||||
|
||||
@Override
|
||||
public SenderAdapter getConsoleSender() {
|
||||
return new SpigotSenderAdapter(this, this.getServer().getConsoleSender());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public SenderAdapter getSenderAdapter(String name) {
|
||||
@@ -733,21 +631,6 @@ public class AuxProtectSpigot extends JavaPlugin implements IAuxProtect {
|
||||
return new SpigotSenderAdapter(this, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getRootDirectory() {
|
||||
return getDataFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlatformVersion() {
|
||||
return getServer().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginVersion() {
|
||||
return this.getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public APPlayer getAPPlayer(SenderAdapter sender) {
|
||||
return getAPPlayer((Player) sender.getSender());
|
||||
@@ -768,6 +651,123 @@ public class AuxProtectSpigot extends JavaPlugin implements IAuxProtect {
|
||||
Bukkit.broadcast(msg, node.node);
|
||||
}
|
||||
|
||||
private boolean hook(Supplier<Listener> listener, String... names) {
|
||||
boolean hook;
|
||||
try {
|
||||
Plugin plugin = null;
|
||||
for (String name : names) {
|
||||
plugin = getPlugin(name);
|
||||
if (plugin != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
hook = plugin != null && plugin.isEnabled();
|
||||
if (hook) {
|
||||
getServer().getPluginManager().registerEvents(listener.get(), this);
|
||||
hooks.add(plugin.getName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
warning("Exception while hooking " + names[0]);
|
||||
print(e);
|
||||
hook = false;
|
||||
}
|
||||
Telemetry.reportHook(this, names[0], hook);
|
||||
return hook;
|
||||
}
|
||||
|
||||
private Plugin getPlugin(String name) {
|
||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
if (plugin.getName().equalsIgnoreCase(name)) {
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean setupEconomy() {
|
||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
return false;
|
||||
}
|
||||
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
return false;
|
||||
}
|
||||
econ = rsp.getProvider();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void logToStackLog(String msg) {
|
||||
stackLog += "[" + LocalDateTime.now().format(ERROR_TIME_FORMAT) + "] " + msg + "\n";
|
||||
}
|
||||
|
||||
public ClaimInvCommand getClaiminvcommand() {
|
||||
return claiminvcommand;
|
||||
}
|
||||
|
||||
public APSCommand getApcommand() {
|
||||
return apcommand;
|
||||
}
|
||||
|
||||
public int getCompatabilityVersion() {
|
||||
return SERVER_VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShuttingDown() {
|
||||
return isShuttingDown;
|
||||
}
|
||||
|
||||
public SQLManager getSqlManager() {
|
||||
return sqlManager;
|
||||
}
|
||||
|
||||
public Economy getEconomy() {
|
||||
return econ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStackLog() {
|
||||
return stackLog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformType getPlatform() {
|
||||
return PlatformType.SPIGOT;
|
||||
}
|
||||
|
||||
public APConfig getAPConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public VeinManager getVeinManager() {
|
||||
return veinManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandPrefix() {
|
||||
return "auxprotect";
|
||||
}
|
||||
|
||||
@Override
|
||||
public SenderAdapter getConsoleSender() {
|
||||
return new SpigotSenderAdapter(this, this.getServer().getConsoleSender());
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getRootDirectory() {
|
||||
return getDataFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlatformVersion() {
|
||||
return getServer().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginVersion() {
|
||||
return this.getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandAlias() {
|
||||
return "ap";
|
||||
|
||||
@@ -120,21 +120,6 @@ public class Metrics {
|
||||
builder.appendField("pluginVersion", plugin.getDescription().getVersion());
|
||||
}
|
||||
|
||||
private int getPlayerAmount() {
|
||||
try {
|
||||
// Around MC 1.8 the return type was changed from an array to a collection,
|
||||
// This fixes java.lang.NoSuchMethodError:
|
||||
// org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
||||
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
||||
return onlinePlayersMethod.getReturnType().equals(Collection.class)
|
||||
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
|
||||
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
||||
} catch (Exception e) {
|
||||
// Just use the new method if the reflection failed
|
||||
return Bukkit.getOnlinePlayers().size();
|
||||
}
|
||||
}
|
||||
|
||||
public static class MetricsBase {
|
||||
|
||||
/**
|
||||
@@ -800,6 +785,20 @@ public class Metrics {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the JSON string and invalidates this builder.
|
||||
*
|
||||
* @return The built JSON string.
|
||||
*/
|
||||
public JsonObject build() {
|
||||
if (builder == null) {
|
||||
throw new IllegalStateException("JSON has already been built");
|
||||
}
|
||||
JsonObject object = new JsonObject(builder.append("}").toString());
|
||||
builder = null;
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a field to the object.
|
||||
*
|
||||
@@ -820,20 +819,6 @@ public class Metrics {
|
||||
hasAtLeastOneField = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the JSON string and invalidates this builder.
|
||||
*
|
||||
* @return The built JSON string.
|
||||
*/
|
||||
public JsonObject build() {
|
||||
if (builder == null) {
|
||||
throw new IllegalStateException("JSON has already been built");
|
||||
}
|
||||
JsonObject object = new JsonObject(builder.append("}").toString());
|
||||
builder = null;
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* A super simple representation of a JSON object.
|
||||
*
|
||||
@@ -856,4 +841,19 @@ public class Metrics {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getPlayerAmount() {
|
||||
try {
|
||||
// Around MC 1.8 the return type was changed from an array to a collection,
|
||||
// This fixes java.lang.NoSuchMethodError:
|
||||
// org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
||||
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
||||
return onlinePlayersMethod.getReturnType().equals(Collection.class)
|
||||
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
|
||||
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
||||
} catch (Exception e) {
|
||||
// Just use the new method if the reflection failed
|
||||
return Bukkit.getOnlinePlayers().size();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,12 +44,6 @@ public class EntityListener implements Listener {
|
||||
blacklistedDamageCauses.add(DamageCause.ENTITY_SWEEP_ATTACK);
|
||||
}
|
||||
|
||||
protected static void itemBreak(IAuxProtect plugin, String cause, ItemStack item, Location location) {
|
||||
DbEntry entry = new SingleItemEntry(cause, EntryAction.BREAKITEM, false, location,
|
||||
AuxProtectSpigot.getLabel(item.getType()), "", item);
|
||||
plugin.add(entry);
|
||||
}
|
||||
|
||||
public static boolean isChartMap(ItemStack item) {
|
||||
if (item.getType() == Material.FILLED_MAP && item.hasItemMeta()) {
|
||||
if (item.getItemMeta() instanceof MapMeta meta) {
|
||||
@@ -63,6 +57,12 @@ public class EntityListener implements Listener {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static void itemBreak(IAuxProtect plugin, String cause, ItemStack item, Location location) {
|
||||
DbEntry entry = new SingleItemEntry(cause, EntryAction.BREAKITEM, false, location,
|
||||
AuxProtectSpigot.getLabel(item.getType()), "", item);
|
||||
plugin.add(entry);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEntityDismountEvent(EntityDismountEvent e) {
|
||||
DbEntry entry = new DbEntry(AuxProtectSpigot.getLabel(e.getEntity()), EntryAction.MOUNT, false,
|
||||
@@ -262,6 +262,13 @@ public class EntityListener implements Listener {
|
||||
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onTame(EntityTameEvent e) {
|
||||
DbEntry entry = new DbEntry(AuxProtectSpigot.getLabel(e.getOwner()), EntryAction.TAME, false,
|
||||
e.getEntity().getLocation(), AuxProtectSpigot.getLabel(e.getEntity()), "");
|
||||
plugin.add(entry);
|
||||
}
|
||||
|
||||
private void drop(Entity entity, Location loc, ItemStack item, boolean drop) {
|
||||
DbEntry entry;
|
||||
if (InvSerialization.isCustom(item)) {
|
||||
@@ -274,11 +281,4 @@ public class EntityListener implements Listener {
|
||||
plugin.add(entry);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onTame(EntityTameEvent e) {
|
||||
DbEntry entry = new DbEntry(AuxProtectSpigot.getLabel(e.getOwner()), EntryAction.TAME, false,
|
||||
e.getEntity().getLocation(), AuxProtectSpigot.getLabel(e.getEntity()), "");
|
||||
plugin.add(entry);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,29 +38,6 @@ public class InventoryListener implements Listener {
|
||||
log(e.getPlayer(), e.getInventory(), false);
|
||||
}
|
||||
|
||||
private void log(HumanEntity player, Inventory inv, boolean state) {
|
||||
int count = 0;
|
||||
for (ItemStack item : inv.getContents()) {
|
||||
if (item == null)
|
||||
continue;
|
||||
count += item.getAmount();
|
||||
}
|
||||
String label = AuxProtectSpigot.getLabel(inv.getHolder());
|
||||
if (label.equals("#null")) {
|
||||
if (inv.getLocation() != null) {
|
||||
Block block = inv.getLocation().getBlock();
|
||||
label = "#" + block.getType().toString().toLowerCase();
|
||||
}
|
||||
}
|
||||
Location location = inv.getLocation();
|
||||
if (location == null) {
|
||||
location = player.getLocation();
|
||||
}
|
||||
DbEntry entry = new DbEntry(AuxProtectSpigot.getLabel(player), EntryAction.INV, state, location, label,
|
||||
count + " items in inventory.");
|
||||
plugin.add(entry);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEnchantItemEvent(EnchantItemEvent e) {
|
||||
ItemStack item = e.getItem().clone();
|
||||
@@ -163,4 +140,27 @@ public class InventoryListener implements Listener {
|
||||
plugin.add(entry);
|
||||
}
|
||||
|
||||
private void log(HumanEntity player, Inventory inv, boolean state) {
|
||||
int count = 0;
|
||||
for (ItemStack item : inv.getContents()) {
|
||||
if (item == null)
|
||||
continue;
|
||||
count += item.getAmount();
|
||||
}
|
||||
String label = AuxProtectSpigot.getLabel(inv.getHolder());
|
||||
if (label.equals("#null")) {
|
||||
if (inv.getLocation() != null) {
|
||||
Block block = inv.getLocation().getBlock();
|
||||
label = "#" + block.getType().toString().toLowerCase();
|
||||
}
|
||||
}
|
||||
Location location = inv.getLocation();
|
||||
if (location == null) {
|
||||
location = player.getLocation();
|
||||
}
|
||||
DbEntry entry = new DbEntry(AuxProtectSpigot.getLabel(player), EntryAction.INV, state, location, label,
|
||||
count + " items in inventory.");
|
||||
plugin.add(entry);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -73,11 +73,6 @@ public class JobsListener implements Listener {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getData() {
|
||||
return type + "" + Math.round(value * 100f) / 100f;
|
||||
}
|
||||
|
||||
public boolean add(JobsEntry other) {
|
||||
if (userLabel.equals(other.userLabel) && type == other.type) {
|
||||
this.value += other.value;
|
||||
@@ -85,5 +80,10 @@ public class JobsListener implements Listener {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getData() {
|
||||
return type + "" + Math.round(value * 100f) / 100f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class PlayerListener implements Listener {
|
||||
plugin.getSqlManager().getUserManager().updateUsernameAndIP(e.getPlayer().getUniqueId(),
|
||||
e.getPlayer().getName(), ip);
|
||||
} catch (BusyException ex) {
|
||||
plugin.warning("Database Busy: Unable to update username/ip for " + e.getPlayer().getName()+", this may cause issues with lookups but will resolve when they relog and the database is not busy.");
|
||||
plugin.warning("Database Busy: Unable to update username/ip for " + e.getPlayer().getName() + ", this may cause issues with lookups but will resolve when they relog and the database is not busy.");
|
||||
} catch (SQLException ex) {
|
||||
plugin.print(ex);
|
||||
}
|
||||
@@ -298,11 +298,6 @@ public class PlayerListener implements Listener {
|
||||
e.getPlayer().getLocation(), "", e.getReason()));
|
||||
}
|
||||
|
||||
protected void logSession(Player player, boolean login, String supp) {
|
||||
plugin.add(new DbEntry(AuxProtectSpigot.getLabel(player), EntryAction.SESSION, login, player.getLocation(), "",
|
||||
supp));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerLeashEntityEvent(PlayerLeashEntityEvent e) {
|
||||
DbEntry entry = new DbEntry(AuxProtectSpigot.getLabel(e.getPlayer()), EntryAction.LEASH, true,
|
||||
@@ -363,4 +358,9 @@ public class PlayerListener implements Listener {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected void logSession(Player player, boolean login, String supp) {
|
||||
plugin.add(new DbEntry(AuxProtectSpigot.getLabel(player), EntryAction.SESSION, login, player.getLocation(), "",
|
||||
supp));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,11 @@ public class TownyListener implements Listener {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public static String getLabel(Government gov) {
|
||||
if (gov == null || gov.getUUID() == null) return "#null";
|
||||
return "#" + (gov instanceof Nation ? "N" : "T") + gov.getUUID().toString();
|
||||
}
|
||||
|
||||
private static Location toLoc(Resident res) {
|
||||
if (res == null || res.getPlayer() == null) {
|
||||
return null;
|
||||
@@ -32,6 +37,8 @@ public class TownyListener implements Listener {
|
||||
return res.getPlayer().getLocation();
|
||||
}
|
||||
|
||||
// Towns
|
||||
|
||||
private static Location toLoc(Coord coord) {
|
||||
if (coord instanceof WorldCoord c) {
|
||||
return new Location(c.getBukkitWorld(), c.getX() * 16, 128, c.getZ() * 16);
|
||||
@@ -39,13 +46,6 @@ public class TownyListener implements Listener {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Towns
|
||||
|
||||
public static String getLabel(Government gov) {
|
||||
if (gov == null || gov.getUUID() == null) return "#null";
|
||||
return "#" + (gov instanceof Nation ? "N" : "T") + gov.getUUID().toString();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void on(NewDayEvent e) {
|
||||
e.getFallenTowns().forEach((t) -> {
|
||||
@@ -56,33 +56,6 @@ public class TownyListener implements Listener {
|
||||
});
|
||||
}
|
||||
|
||||
private void handleDeleted(String name, boolean nation) {
|
||||
int uid;
|
||||
try {
|
||||
uid = plugin.getSqlManager().getTownyManager().getIDFromName(name, true);
|
||||
} catch (SQLException | BusyException e) {
|
||||
plugin.print(e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (uid <= 0) {
|
||||
plugin.info("Unknown town/nation " + name);
|
||||
return;
|
||||
}
|
||||
String uuid = null;
|
||||
try {
|
||||
uuid = plugin.getSqlManager().getUserManager().getUUIDFromUID(uid, true);
|
||||
} catch (SQLException | BusyException ignored) {
|
||||
//Unlikely
|
||||
}
|
||||
if (uuid == null) {
|
||||
plugin.info("Unknown town/nation " + name + " with uid " + uid);
|
||||
return;
|
||||
}
|
||||
plugin.add(
|
||||
new TownyEntry("#server", nation ? EntryAction.NATIONDELETE : EntryAction.TOWNDELETE, false, uuid, ""));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void on(NewTownEvent e) {
|
||||
plugin.getSqlManager().getTownyManager().updateName(e.getTown(), true);
|
||||
@@ -155,24 +128,6 @@ public class TownyListener implements Listener {
|
||||
handleBank(e, e.getTown(), EntryAction.TOWNBANK);
|
||||
}
|
||||
|
||||
// Nations
|
||||
|
||||
private void handleBank(BankTransactionEvent e, Government g, EntryAction action) {
|
||||
String user = "#server";
|
||||
Location loc = null;
|
||||
if (e.getTransaction().getPlayer() != null) {
|
||||
user = AuxProtectSpigot.getLabel(e.getTransaction().getPlayer());
|
||||
loc = e.getTransaction().getPlayer().getLocation();
|
||||
}
|
||||
boolean state = switch (e.getTransaction().getType()) {
|
||||
case ADD, DEPOSIT -> true;
|
||||
default -> false;
|
||||
};
|
||||
String data = plugin.formatMoney(e.getTransaction().getAmount()) + ", Bal: "
|
||||
+ plugin.formatMoney(e.getAccount().getHoldingBalance());
|
||||
plugin.add(new TownyEntry(user, action, state, loc, TownyManager.getLabel(g), data));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void on(NewNationEvent e) {
|
||||
Player king = e.getNation().getKing().getPlayer();
|
||||
@@ -181,6 +136,8 @@ public class TownyListener implements Listener {
|
||||
toLoc(e.getNation().getKing()), TownyManager.getLabel(e.getNation()), null));
|
||||
}
|
||||
|
||||
// Nations
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void on(RenameNationEvent e) {
|
||||
plugin.getSqlManager().getTownyManager().updateName(e.getNation(), true);
|
||||
@@ -211,4 +168,47 @@ public class TownyListener implements Listener {
|
||||
public void on(NationTransactionEvent e) {
|
||||
handleBank(e, e.getNation(), EntryAction.NATIONBANK);
|
||||
}
|
||||
|
||||
private void handleDeleted(String name, boolean nation) {
|
||||
int uid;
|
||||
try {
|
||||
uid = plugin.getSqlManager().getTownyManager().getIDFromName(name, true);
|
||||
} catch (SQLException | BusyException e) {
|
||||
plugin.print(e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (uid <= 0) {
|
||||
plugin.info("Unknown town/nation " + name);
|
||||
return;
|
||||
}
|
||||
String uuid = null;
|
||||
try {
|
||||
uuid = plugin.getSqlManager().getUserManager().getUUIDFromUID(uid, true);
|
||||
} catch (SQLException | BusyException ignored) {
|
||||
//Unlikely
|
||||
}
|
||||
if (uuid == null) {
|
||||
plugin.info("Unknown town/nation " + name + " with uid " + uid);
|
||||
return;
|
||||
}
|
||||
plugin.add(
|
||||
new TownyEntry("#server", nation ? EntryAction.NATIONDELETE : EntryAction.TOWNDELETE, false, uuid, ""));
|
||||
}
|
||||
|
||||
private void handleBank(BankTransactionEvent e, Government g, EntryAction action) {
|
||||
String user = "#server";
|
||||
Location loc = null;
|
||||
if (e.getTransaction().getPlayer() != null) {
|
||||
user = AuxProtectSpigot.getLabel(e.getTransaction().getPlayer());
|
||||
loc = e.getTransaction().getPlayer().getLocation();
|
||||
}
|
||||
boolean state = switch (e.getTransaction().getType()) {
|
||||
case ADD, DEPOSIT -> true;
|
||||
default -> false;
|
||||
};
|
||||
String data = plugin.formatMoney(e.getTransaction().getAmount()) + ", Bal: "
|
||||
+ plugin.formatMoney(e.getAccount().getHoldingBalance());
|
||||
plugin.add(new TownyEntry(user, action, state, loc, TownyManager.getLabel(g), data));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,12 +97,12 @@ public class ActivitySolver {
|
||||
|
||||
int activity = counter[i];
|
||||
|
||||
String hovertext = "" + ChatColor.COLOR_CHAR + "9" + time.format(formatterDateTime) + "\n";
|
||||
String hovertext = ChatColor.COLOR_CHAR + "9" + time.format(formatterDateTime) + "\n";
|
||||
|
||||
if (activity < 0) {
|
||||
hovertext += "" + ChatColor.COLOR_CHAR + "7Offline";
|
||||
} else if (activity > 0) {
|
||||
hovertext += "" + ChatColor.COLOR_CHAR + "7Activity Level " + ChatColor.COLOR_CHAR + "9" + activity;
|
||||
hovertext += ChatColor.COLOR_CHAR + "7Activity Level " + ChatColor.COLOR_CHAR + "9" + activity;
|
||||
} else {
|
||||
hovertext += "" + ChatColor.COLOR_CHAR + "cNo Activity";
|
||||
}
|
||||
|
||||
@@ -18,13 +18,12 @@ public class ChartRenderer extends MapRenderer {
|
||||
public static final int yShift = 12;
|
||||
public static final int xSize = 100;
|
||||
public static final int ySize = 100;
|
||||
public final double xScale = 1;
|
||||
private final double[] values;
|
||||
private final Color bgColor;
|
||||
private final String title;
|
||||
private final int xDivs;
|
||||
|
||||
private final AuxProtectSpigot plugin;
|
||||
public final double xScale = 1;
|
||||
private final Color[][] map = new Color[128][128];
|
||||
public double yScale = 1;
|
||||
|
||||
@@ -100,7 +99,7 @@ public class ChartRenderer extends MapRenderer {
|
||||
case 2 -> 'M';
|
||||
default -> ' ';
|
||||
};
|
||||
canvas.drawText(1, yPos - 4, MinecraftFont.Font, doubleToString(number) + "" + suffix);
|
||||
canvas.drawText(1, yPos - 4, MinecraftFont.Font, doubleToString(number) + suffix);
|
||||
setPixelColor(canvas, xShift - 2, yPos, Color.BLACK);
|
||||
}
|
||||
drawXDivs(view, canvas, player);
|
||||
@@ -113,27 +112,6 @@ public class ChartRenderer extends MapRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
private int[] getCoordsForData(double x, double y) {
|
||||
x *= xScale;
|
||||
y *= yScale;
|
||||
|
||||
if (x > xSize + 1) {
|
||||
x = xSize + 1;
|
||||
}
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if (y > ySize + 1) {
|
||||
y = ySize + 1;
|
||||
}
|
||||
if (y < 0) {
|
||||
y = 0;
|
||||
}
|
||||
|
||||
return new int[]{xShift + (int) Math.round(x), yShift + 100 - (int) Math.round(y)};
|
||||
}
|
||||
|
||||
public ItemStack asItem(Player player) {
|
||||
MapView view = Bukkit.createMap(player.getWorld());
|
||||
for (MapRenderer renderer : view.getRenderers())
|
||||
@@ -160,4 +138,25 @@ public class ChartRenderer extends MapRenderer {
|
||||
canvas.setPixel(x, y, MapPalette.matchColor(color));
|
||||
}
|
||||
}
|
||||
|
||||
private int[] getCoordsForData(double x, double y) {
|
||||
x *= xScale;
|
||||
y *= yScale;
|
||||
|
||||
if (x > xSize + 1) {
|
||||
x = xSize + 1;
|
||||
}
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if (y > ySize + 1) {
|
||||
y = ySize + 1;
|
||||
}
|
||||
if (y < 0) {
|
||||
y = 0;
|
||||
}
|
||||
|
||||
return new int[]{xShift + (int) Math.round(x), yShift + 100 - (int) Math.round(y)};
|
||||
}
|
||||
}
|
||||
@@ -196,13 +196,13 @@ public class FakePlayer {
|
||||
packet.getIntegers().write(0, id);
|
||||
}
|
||||
|
||||
public long getLastMoved() {
|
||||
return lastMoved;
|
||||
}
|
||||
|
||||
public record Skin(UUID uuid, String skin, String signature) {
|
||||
public WrappedSignedProperty wrap() {
|
||||
return new WrappedSignedProperty("textures", skin, signature);
|
||||
}
|
||||
}
|
||||
|
||||
public long getLastMoved() {
|
||||
return lastMoved;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +88,21 @@ public class MoneySolver extends ChartRenderer {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static void showMoney(IAuxProtect plugin, Player player, List<DbEntry> results, int time,
|
||||
String users) {
|
||||
if (!(plugin instanceof AuxProtectSpigot)) {
|
||||
return;
|
||||
}
|
||||
plugin.runSync(() -> {
|
||||
try {
|
||||
MoneySolver solver = new MoneySolver((AuxProtectSpigot) plugin, player, results, time, users);
|
||||
player.getInventory().addItem(solver.asItem(player));
|
||||
} catch (IllegalArgumentException e) {
|
||||
player.sendMessage(Language.translate(Language.L.COMMAND__LOOKUP__NORESULTS));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private static double sigDigRounder(double value, int nSigDig, int dir) {
|
||||
double d1 = Math.pow(10, Math.floor(Math.log10(Math.abs(value))) - (nSigDig - 1));
|
||||
@@ -104,21 +119,6 @@ public class MoneySolver extends ChartRenderer {
|
||||
|
||||
}
|
||||
|
||||
public static void showMoney(IAuxProtect plugin, Player player, List<DbEntry> results, int time,
|
||||
String users) {
|
||||
if (!(plugin instanceof AuxProtectSpigot)) {
|
||||
return;
|
||||
}
|
||||
plugin.runSync(() -> {
|
||||
try {
|
||||
MoneySolver solver = new MoneySolver((AuxProtectSpigot) plugin, player, results, time, users);
|
||||
player.getInventory().addItem(solver.asItem(player));
|
||||
} catch (IllegalArgumentException e) {
|
||||
player.sendMessage(Language.translate(Language.L.COMMAND__LOOKUP__NORESULTS));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getValue(int x) {
|
||||
return values[x];
|
||||
|
||||
@@ -35,17 +35,6 @@ public class Pane implements InventoryHolder {
|
||||
});
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public void setInventory(Inventory inventory) {
|
||||
this.inventory = inventory;
|
||||
buttons = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addButton(int slot, Material type, Runnable action, String name) {
|
||||
addButton(slot, type, action, name, null);
|
||||
}
|
||||
@@ -103,6 +92,24 @@ public class Pane implements InventoryHolder {
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
CLAIM, SHOW
|
||||
}
|
||||
|
||||
private record Button(Runnable run, int index) {
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public void setInventory(Inventory inventory) {
|
||||
this.inventory = inventory;
|
||||
buttons = new ArrayList<>();
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
@@ -110,11 +117,4 @@ public class Pane implements InventoryHolder {
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
CLAIM, SHOW
|
||||
}
|
||||
|
||||
private record Button(Runnable run, int index) {
|
||||
}
|
||||
}
|
||||
@@ -37,10 +37,9 @@ public class PlaybackSolver extends BukkitRunnable {
|
||||
private final ProtocolManager protocol;
|
||||
private final Player audience;
|
||||
private final Map<UUID, FakePlayer.Skin> skins = new HashMap<>();
|
||||
private boolean closed;
|
||||
private final List<BlockAction> blockActions;
|
||||
|
||||
private final Set<Location> modified = new HashSet<>();
|
||||
private boolean closed;
|
||||
|
||||
public PlaybackSolver(IAuxProtect plugin, SenderAdapter sender, List<DbEntry> entries, long startTime, @Nullable List<BlockAction> blockActions) throws SQLException, LookupException, BusyException {
|
||||
if (plugin.getPlatform() != PlatformType.SPIGOT) throw new UnsupportedOperationException();
|
||||
@@ -223,7 +222,6 @@ public class PlaybackSolver extends BukkitRunnable {
|
||||
swing.forEach(FakePlayer::swingArm);
|
||||
|
||||
|
||||
|
||||
for (Iterator<FakePlayer> it = actors.values().iterator(); it.hasNext(); ) {
|
||||
if (closed) return;
|
||||
FakePlayer pl = it.next();
|
||||
@@ -255,10 +253,6 @@ public class PlaybackSolver extends BukkitRunnable {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
return closed;
|
||||
}
|
||||
|
||||
public record PosPoint(long time, UUID uuid, String name, int uid, Location location, boolean inc,
|
||||
@Nullable PosEncoder.Posture posture) {
|
||||
}
|
||||
@@ -271,4 +265,8 @@ public class PlaybackSolver extends BukkitRunnable {
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
return closed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,70 @@ public class PosEncoder {
|
||||
posture.equals(lastPosture) ? null : posture);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes all components with an incremental byte array according to {@link PosEncoder#decodeSingle(byte[], int)}
|
||||
*
|
||||
* @param bytes The incremental byte array
|
||||
* @return A list of records representing the presence and value of each component of position.
|
||||
*/
|
||||
public static List<PositionIncrement> decode(byte[] bytes) {
|
||||
List<PositionIncrement> out = new ArrayList<>();
|
||||
for (int i = 0, safety = 0; i < bytes.length && safety < bytes.length; safety++) {
|
||||
PositionIncrement decoded = decodeSingle(bytes, i);
|
||||
i += decoded.bytes;
|
||||
out.add(decoded);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static byte setBit(byte b, int index, boolean value) {
|
||||
if (index > 7 || index < 0) throw new IndexOutOfBoundsException(index + " is not a valid byte index.");
|
||||
byte val = (byte) (1 << index);
|
||||
if (value) b |= val;
|
||||
else b &= ~val;
|
||||
return b;
|
||||
}
|
||||
|
||||
public static boolean getBit(byte b, int index) {
|
||||
return ((b >> index) & 1) == 1;
|
||||
}
|
||||
|
||||
public static List<PosEncoder.PositionIncrement> decodeLegacy(byte[] bytes) {
|
||||
List<PosEncoder.PositionIncrement> out = new ArrayList<>();
|
||||
for (int offset = 0, safety = 0; offset < bytes.length && safety < bytes.length; safety++) {
|
||||
double[] doubles = new double[5];
|
||||
byte hdr = bytes[offset];
|
||||
|
||||
boolean yaw = hdr < 0;
|
||||
if (yaw) hdr += 128;
|
||||
|
||||
int xlen = hdr & 0b11;
|
||||
int ylen = (hdr >> 2) & 0b11;
|
||||
int zlen = (hdr >> 4) & 0b11;
|
||||
|
||||
if (xlen > 0) doubles[0] = toDouble(bytes, offset + 1, xlen);
|
||||
if (xlen == 3) xlen = 1;
|
||||
if (ylen > 0) doubles[1] = toDouble(bytes, offset + 1 + xlen, ylen);
|
||||
if (ylen == 3) ylen = 1;
|
||||
if (zlen > 0) doubles[2] = toDouble(bytes, offset + 1 + xlen + ylen, zlen);
|
||||
if (zlen == 3) zlen = 1;
|
||||
|
||||
boolean pitch = (hdr >> 6 & 1) == 1;
|
||||
if (pitch) doubles[3] = bytes[offset + 1 + xlen + ylen + zlen];
|
||||
if (yaw) doubles[4] = (double) bytes[offset + 1 + xlen + ylen + zlen + (pitch ? 1 : 0)] / 127.0 * 180;
|
||||
|
||||
PosEncoder.PositionIncrement decod = new PosEncoder.PositionIncrement(
|
||||
xlen > 0, doubles[0],
|
||||
ylen > 0, doubles[1],
|
||||
zlen > 0, doubles[2], pitch && yaw, (float) doubles[3], (float) doubles[4],
|
||||
false, null,
|
||||
1 + xlen + ylen + zlen + (yaw ? 1 : 0) + (pitch ? 1 : 0));
|
||||
offset += decod.bytes();
|
||||
out.add(decod);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static byte[] encode(double diffX_, double diffY_, double diffZ_, boolean doLook, float pitch_, float yaw_, @Nullable Posture posture) {
|
||||
IncrementalByte diffX = simplify(diffX_);
|
||||
IncrementalByte diffY = simplify(diffY_);
|
||||
@@ -71,22 +135,6 @@ public class PosEncoder {
|
||||
return bb.array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes all components with an incremental byte array according to {@link PosEncoder#decodeSingle(byte[], int)}
|
||||
*
|
||||
* @param bytes The incremental byte array
|
||||
* @return A list of records representing the presence and value of each component of position.
|
||||
*/
|
||||
public static List<PositionIncrement> decode(byte[] bytes) {
|
||||
List<PositionIncrement> out = new ArrayList<>();
|
||||
for (int i = 0, safety = 0; i < bytes.length && safety < bytes.length; safety++) {
|
||||
PositionIncrement decoded = decodeSingle(bytes, i);
|
||||
i += decoded.bytes;
|
||||
out.add(decoded);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Coverts a byte array, offset by a value, into a decoded position increment.
|
||||
*
|
||||
@@ -187,16 +235,6 @@ public class PosEncoder {
|
||||
return new IncrementalByte(new byte[]{(byte) (s >> 8), lower}, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array The data
|
||||
* @param fine Whether the value is stored in hundredths or tenths. true indicates hundredths.
|
||||
*/
|
||||
record IncrementalByte(byte[] array, boolean fine) {
|
||||
public int getBytesNeeded() {
|
||||
return fine ? 3 : array.length;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Posture {
|
||||
STANDING(0), SNEAKING(1), SWIMMING(2), GLIDING(3), SITTING(4), CRAWLING(5), SLEEPING(6);
|
||||
private final byte id;
|
||||
@@ -205,10 +243,6 @@ public class PosEncoder {
|
||||
this.id = (byte) id;
|
||||
}
|
||||
|
||||
public byte getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static Posture fromPlayer(Player player) {
|
||||
if (player.isSwimming()) return SWIMMING;
|
||||
if (player.isGliding()) return GLIDING;
|
||||
@@ -223,6 +257,20 @@ public class PosEncoder {
|
||||
for (Posture posture : values()) if (posture.id == id) return posture;
|
||||
throw new IllegalArgumentException("Unknown posture: " + id);
|
||||
}
|
||||
|
||||
public byte getID() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array The data
|
||||
* @param fine Whether the value is stored in hundredths or tenths. true indicates hundredths.
|
||||
*/
|
||||
record IncrementalByte(byte[] array, boolean fine) {
|
||||
public int getBytesNeeded() {
|
||||
return fine ? 3 : array.length;
|
||||
}
|
||||
}
|
||||
|
||||
public record PositionIncrement(boolean hasX, double x, boolean hasY, double y, boolean hasZ, double z,
|
||||
@@ -233,52 +281,4 @@ public class PosEncoder {
|
||||
return "X=" + (hasX ? x : "none") + " Y=" + (hasY ? y : "none") + " Z=" + (hasZ ? z : "none") + " Pitch=" + pitch + " Yaw=" + yaw + " Posture=" + posture;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte setBit(byte b, int index, boolean value) {
|
||||
if (index > 7 || index < 0) throw new IndexOutOfBoundsException(index + " is not a valid byte index.");
|
||||
byte val = (byte) (1 << index);
|
||||
if (value) b |= val;
|
||||
else b &= ~val;
|
||||
return b;
|
||||
}
|
||||
|
||||
public static boolean getBit(byte b, int index) {
|
||||
return ((b >> index) & 1) == 1;
|
||||
}
|
||||
|
||||
public static List<PosEncoder.PositionIncrement> decodeLegacy(byte[] bytes) {
|
||||
List<PosEncoder.PositionIncrement> out = new ArrayList<>();
|
||||
for (int offset = 0, safety = 0; offset < bytes.length && safety < bytes.length; safety++) {
|
||||
double[] doubles = new double[5];
|
||||
byte hdr = bytes[offset];
|
||||
|
||||
boolean yaw = hdr < 0;
|
||||
if (yaw) hdr += 128;
|
||||
|
||||
int xlen = hdr & 0b11;
|
||||
int ylen = (hdr >> 2) & 0b11;
|
||||
int zlen = (hdr >> 4) & 0b11;
|
||||
|
||||
if (xlen > 0) doubles[0] = toDouble(bytes, offset + 1, xlen);
|
||||
if (xlen == 3) xlen = 1;
|
||||
if (ylen > 0) doubles[1] = toDouble(bytes, offset + 1 + xlen, ylen);
|
||||
if (ylen == 3) ylen = 1;
|
||||
if (zlen > 0) doubles[2] = toDouble(bytes, offset + 1 + xlen + ylen, zlen);
|
||||
if (zlen == 3) zlen = 1;
|
||||
|
||||
boolean pitch = (hdr >> 6 & 1) == 1;
|
||||
if (pitch) doubles[3] = bytes[offset + 1 + xlen + ylen + zlen];
|
||||
if (yaw) doubles[4] = (double) bytes[offset + 1 + xlen + ylen + zlen + (pitch ? 1 : 0)] / 127.0 * 180;
|
||||
|
||||
PosEncoder.PositionIncrement decod = new PosEncoder.PositionIncrement(
|
||||
xlen > 0, doubles[0],
|
||||
ylen > 0, doubles[1],
|
||||
zlen > 0, doubles[2], pitch && yaw, (float) doubles[3], (float) doubles[4],
|
||||
false, null,
|
||||
1 + xlen + ylen + zlen + (yaw ? 1 : 0) + (pitch ? 1 : 0));
|
||||
offset += decod.bytes();
|
||||
out.add(decod);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,20 +10,6 @@ public class TimeUtil {
|
||||
|
||||
public static final DateTimeFormatter entryTimeFormat = DateTimeFormatter.ofPattern("ddMMMyy HH:mm:ss.SSS");
|
||||
|
||||
private static String padDouble(double d) {
|
||||
String[] split = (d + "").split("\\.");
|
||||
while (split[0].length() < 2) {
|
||||
split[0] = "0" + split[0];
|
||||
}
|
||||
if (split.length == 1) {
|
||||
return split[0] + ".00";
|
||||
}
|
||||
while (split[1].length() < 2) {
|
||||
split[1] += "0";
|
||||
}
|
||||
return split[0] + "." + split[1];
|
||||
}
|
||||
|
||||
public static double roundToPlaces(double value, int places) {
|
||||
double factor = Math.pow(10, places);
|
||||
return Math.round(value * factor) / factor;
|
||||
@@ -121,4 +107,18 @@ public class TimeUtil {
|
||||
public static String format(long millis, DateTimeFormatter formatter) {
|
||||
return Instant.ofEpochMilli(millis).atZone(ZoneId.systemDefault()).format(formatter);
|
||||
}
|
||||
|
||||
private static String padDouble(double d) {
|
||||
String[] split = (d + "").split("\\.");
|
||||
while (split[0].length() < 2) {
|
||||
split[0] = "0" + split[0];
|
||||
}
|
||||
if (split.length == 1) {
|
||||
return split[0] + ".00";
|
||||
}
|
||||
while (split[1].length() < 2) {
|
||||
split[1] += "0";
|
||||
}
|
||||
return split[0] + "." + split[1];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user