This commit is contained in:
Internal-Exception
2022-06-15 20:49:37 -04:00
parent 8e780de2a1
commit ccd2e55fff
13 changed files with 125 additions and 35 deletions

View File

@@ -1,4 +1,4 @@
name: AuxProtectBungee
main: dev.heliosares.auxprotect.bungee.AuxProtectBungee
version: 1.1-pre1
version: 1.1.1
author: Heliosares

View File

@@ -1,5 +1,5 @@
name: AuxProtect
version: 1.1
version: 1.1.1
main: dev.heliosares.auxprotect.AuxProtect
description: A plugin designed to supplement CoreProtect in a few ways.
api-version: 1.13

View File

@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>AuxProtect</groupId>
<artifactId>AuxProtect</artifactId>
<version>1.1</version>
<version>1.1.1</version>
<name>AuxProtect</name>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>

View File

@@ -3,10 +3,10 @@ package dev.heliosares.auxprotect;
import org.bukkit.configuration.file.FileConfiguration;
import dev.heliosares.auxprotect.database.EntryAction;
import net.md_5.bungee.config.Configuration;
public class APConfig {
private final FileConfiguration config;
private boolean privateRelease = false;
public boolean inventoryOnWorldChange;
public boolean checkforupdates;
@@ -19,10 +19,6 @@ public class APConfig {
}
public APConfig(FileConfiguration config) {
this.config = config;
}
public void load() {
privateRelease = config.getBoolean("private");
checkforupdates = config.getBoolean("checkforupdates", true);
inventoryOnWorldChange = config.getBoolean("Actions.inventory.WorldChange", false);
@@ -34,4 +30,16 @@ public class APConfig {
action.setEnabled(enabled);
}
}
public APConfig(Configuration config) {
privateRelease = config.getBoolean("private");
checkforupdates = config.getBoolean("checkforupdates", true);
for (EntryAction action : EntryAction.values()) {
if (!action.isBungee()) {
continue;
}
boolean enabled = config.getBoolean("Actions." + action.toString().toLowerCase() + ".Enabled", true);
action.setEnabled(enabled);
}
}
}

View File

@@ -74,7 +74,6 @@ public class AuxProtect extends JavaPlugin implements IAuxProtect {
debug = getConfig().getInt("debug", 0);
config = new APConfig(this.getConfig());
config.load();
YMLManager langManager = new YMLManager("en-us", this);
langManager.load(true);
@@ -549,4 +548,10 @@ public class AuxProtect extends JavaPlugin implements IAuxProtect {
public int queueSize() {
return dbRunnable.queueSize();
}
@Override
public void reloadConfig() {
super.reloadConfig();
config = new APConfig(this.getConfig());
}
}

View File

@@ -37,4 +37,6 @@ public interface IAuxProtect {
public void runAsync(Runnable run);
public void runSync(Runnable runnable);
public void reloadConfig();
}

View File

@@ -42,7 +42,8 @@ import net.md_5.bungee.config.YamlConfiguration;
@SuppressWarnings("unused")
public class AuxProtectBungee extends Plugin implements Listener, IAuxProtect {
protected Configuration config;
protected Configuration configurationFile;
public APConfig config;
public Language lang;
public int debug;
SQLManager sqlManager;
@@ -64,14 +65,14 @@ public class AuxProtectBungee extends Plugin implements Listener, IAuxProtect {
lang = new Language(langManager.getData());
File sqliteFile = null;
boolean mysql = config.getBoolean("MySQL.use", false);
String user = config.getString("MySQL.username", "");
String pass = config.getString("MySQL.password", "");
boolean mysql = configurationFile.getBoolean("MySQL.use", false);
String user = configurationFile.getString("MySQL.username", "");
String pass = configurationFile.getString("MySQL.password", "");
String uri = "";
if (mysql) {
String host = config.getString("MySQL.host", "localhost");
String port = config.getString("MySQL.port", "3306");
String database = config.getString("MySQL.database", "database");
String host = configurationFile.getString("MySQL.host", "localhost");
String port = configurationFile.getString("MySQL.port", "3306");
String database = configurationFile.getString("MySQL.database", "database");
uri = String.format("jdbc:mysql://%s:%s/%s", host, port, database);
} else {
sqliteFile = new File(getDataFolder(), "database/auxprotect.db");
@@ -95,7 +96,7 @@ public class AuxProtectBungee extends Plugin implements Listener, IAuxProtect {
}
uri = "jdbc:sqlite:" + sqliteFile.getAbsolutePath();
}
sqlManager = new SQLManager(this, uri, config.getString("MySQL.table-prefix"), sqliteFile);
sqlManager = new SQLManager(this, uri, configurationFile.getString("MySQL.table-prefix"), sqliteFile);
runAsync(new Runnable() {
@@ -164,11 +165,13 @@ public class AuxProtectBungee extends Plugin implements Listener, IAuxProtect {
}
}
try {
config = ConfigurationProvider.getProvider(YamlConfiguration.class)
configurationFile = ConfigurationProvider.getProvider(YamlConfiguration.class)
.load(new File(getDataFolder(), "config.yml"));
} catch (IOException e) {
print(e);
}
config = new APConfig(configurationFile);
}
@Override
@@ -230,8 +233,7 @@ public class AuxProtectBungee extends Plugin implements Listener, IAuxProtect {
@Override
public APConfig getAPConfig() {
// TODO Implement APConfig
return null;
return config;
}
@Override
@@ -261,4 +263,9 @@ public class AuxProtectBungee extends Plugin implements Listener, IAuxProtect {
}
return "#null";
}
@Override
public void reloadConfig() {
config = new APConfig(configurationFile);
}
}

View File

@@ -174,7 +174,6 @@ public class APCommand implements CommandExecutor {
// plugin.config.save();
// plugin.saveConfig();
plugin.reloadConfig();
plugin.config.load();
sender.sendMessage("§aConfig reloaded");
return true;
} else if (args[0].equalsIgnoreCase("stats")) {

View File

@@ -34,6 +34,7 @@ public class LookupCommand {
validParams.add("after");
validParams.add("before");
validParams.add("target");
validParams.add("data");
validParams.add("time");
validParams.add("world");
validParams.add("user");

View File

@@ -42,6 +42,7 @@ public class LookupCommandTab implements TabCompleter {
possible.add("action:");
possible.add("world:");
possible.add("user:");
possible.add("data:");
if (currentArg.startsWith("action:") || currentArg.startsWith("a:")) {
String action = currentArg.split(":")[0] + ":";
for (EntryAction eaction : EntryAction.values()) {

View File

@@ -78,13 +78,17 @@ public class Results {
en.getUser()))
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new Text(Instant.ofEpochMilli(en.getTime()).atZone(ZoneId.systemDefault()).format(formatter)
+ "\n§7Click to copy epoch time.")))
+ "\n§7Click to copy epoch time. (" + en.getTime() + "ms)")))
.event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, en.getTime() + "e"));
// message.append(String.format(" §f- §9%s §f%s §9%s§f", en.getUser(),
// en.getAction().getText(plugin, en.getState()),
// en.getTarget())).event((HoverEvent) null);
message.append(" §f- ").event((HoverEvent) null);
String actionColor = "§7-";
if (en.getAction().hasDual) {
actionColor = en.getState() ? "§a+" : "§c-";
}
message.append(" " + actionColor + " ").event((HoverEvent) null);
HoverEvent clickToCopy = new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new Text("Click to copy to clipboard"));
message.append("§9" + en.getUser()).event(clickToCopy)
@@ -111,6 +115,7 @@ public class Results {
String.format(commandPrefix + " inv %d", i)))
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("§fClick to view!")));
}
data = null;// So data doesn't print
} else if (en.getAction().equals(EntryAction.KILL)) {
if (MyPermission.INV.hasPermission(player) && !en.getTarget().startsWith("#")) {
message.append(" §a[View Inv]").event(new ClickEvent(ClickEvent.Action.RUN_COMMAND,
@@ -118,10 +123,9 @@ public class Results {
en.getTarget(), en.getTime() + 50L, en.getTime() - 50L)))
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("§fClick to view!")));
}
message.append(" §7(" + data + ")").event(clickToCopy)
.event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, en.getData()));
} else if (data != null && data.length() > 0) {
message.append(" §7(" + data + ")").event(clickToCopy)
}
if (data != null && data.length() > 0) {
message.append(" §8[§7" + data + "§8]").event(clickToCopy)
.event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, en.getData()));
}
if (en.world != null && !en.world.equals("$null")) {
@@ -129,7 +133,7 @@ public class Results {
if (en.getAction().getTable().hasLook()) {
tpCommand += String.format(" %d %d", en.pitch, en.yaw);
}
message.append("\n §7§l^ ").event((HoverEvent) null).event((ClickEvent) null);
message.append("\n ").event((HoverEvent) null).event((ClickEvent) null);
message.append(String.format("§7(x%d/y%d/z%d/%s)", en.x, en.y, en.z, en.world))
.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, tpCommand))
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("§7" + tpCommand)));

View File

@@ -855,6 +855,8 @@ public class SQLManager {
ArrayList<String> writeParams = new ArrayList<>();
ArrayList<String> targets = new ArrayList<>();
boolean targetNot = false;
ArrayList<String> datas = new ArrayList<>();
boolean dataNot = false;
if (exact && !params.containsKey("radius")) {
if (location == null) {
return null;
@@ -898,13 +900,46 @@ public class SQLManager {
plugin.translate("lookup-action-negate"));
}
}
for (String param : value.split(",")) {
String build = "";
boolean escape = false;
ArrayList<String> values = new ArrayList<>();
for (char current : value.toCharArray()) {
if (current == '\\') {
escape = true;
continue;
}
if (!escape && current == ',') {
values.add(build);
build = "";
continue;
}
if (escape && current != ',') {
build += '\\';
}
build += current;
if (escape) {
escape = false;
}
}
if (escape) {
build += '\\';
}
if (build.length() > 0) {
values.add(build);
}
for (String param : values) {
String theStmt = "";
if (key.equalsIgnoreCase("target")) {
if (not) {
targetNot = true;
}
targets.add(param);
} else if (key.equalsIgnoreCase("data")) {
if (not) {
dataNot = true;
}
datas.add(param);
} else if (key.equalsIgnoreCase("user")) {
int uid = this.getUIDFromUsername(param);
int altuid = this.getUIDFromUUID(param);
@@ -1037,6 +1072,34 @@ public class SQLManager {
dos.put("target", targetArray);
}
}
ArrayList<String> dataArray = new ArrayList<>();
for (String data : datas) {
String theStmt = "";
if (data.contains("*")) {
theStmt = "data LIKE ? OR data LIKE ?";
writeParams.add(data.replaceAll("-", " ").replaceAll("\\*", "%"));
writeParams.add(data.replaceAll("\\*", "%"));
} else {
if (theStmt.length() > 0) {
theStmt += " OR ";
}
theStmt += "lower(data) = ? OR lower(data) = ?";
writeParams.add(data.toLowerCase());
writeParams.add(data.toLowerCase().replaceAll("-", " "));
}
if (theStmt.length() > 0) {
dataArray.add(theStmt);
}
}
if (dataArray.size() > 0) {
if (dataNot) {
donts.put("data", dataArray);
} else {
dos.put("data", dataArray);
}
}
String stmt = "\nWHERE (";
int conditions = 0;
int i = 0;
@@ -1063,7 +1126,7 @@ public class SQLManager {
}
i = 0;
if (donts.size() > 0) {
if (donts.size() > 0) {
if (dos.size() > 0) {
stmt += " AND ";
}
stmt += "NOT (";
@@ -1410,7 +1473,7 @@ public class SQLManager {
plugin.print(e);
}
}
return out;
}

View File

@@ -4,18 +4,18 @@ public class TimeUtil {
public static String millisToString(double millis) {
millis /= 1000.0;
if (millis < 60) {
return padDouble(roundToPlaces(millis, 2)) + "/s";
return padDouble(roundToPlaces(millis, 2)) + "s";
}
millis /= 60.0;
if (millis < 60) {
return padDouble(roundToPlaces(millis, 2)) + "/m";
return padDouble(roundToPlaces(millis, 2)) + "m";
}
millis /= 60.0;
if (millis < 24) {
return padDouble(roundToPlaces(millis, 2)) + "/h";
return padDouble(roundToPlaces(millis, 2)) + "h";
}
millis /= 24.0;
return padDouble(roundToPlaces(millis, 2)) + "/d";
return padDouble(roundToPlaces(millis, 2)) + "d";
}
private static String padDouble(double d) {