Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from PlayPro:master #2

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ local.properties
.settings/
.loadpath
.gradle/
.vscode/

# External tool builders
.externalToolBuilders/
Expand Down Expand Up @@ -199,4 +200,6 @@ docs/dev/

# Extensions
/src/main/java/net/coreprotect/extensions/*.java
!/src/main/java/net/coreprotect/extensions/Extensions.java
!/src/main/java/net/coreprotect/extensions/Extensions.java
/.apt_generated/
/.apt_generated_tests/
11 changes: 6 additions & 5 deletions src/main/java/net/coreprotect/CoreProtect.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
import net.coreprotect.thread.NetworkHandler;
import net.coreprotect.thread.Scheduler;
import net.coreprotect.utility.Chat;
import net.coreprotect.utility.ChatUtils;
import net.coreprotect.utility.Color;
import net.coreprotect.utility.Teleport;
import net.coreprotect.utility.Util;
import net.coreprotect.utility.VersionUtils;

public final class CoreProtect extends JavaPlugin {

Expand Down Expand Up @@ -87,7 +88,7 @@ public void onEnable() {

if (start) {
PluginDescriptionFile pluginDescription = this.getDescription();
Util.sendConsoleComponentStartup(Bukkit.getServer().getConsoleSender(), Phrase.build(Phrase.ENABLE_SUCCESS, ConfigHandler.EDITION_NAME));
ChatUtils.sendConsoleComponentStartup(Bukkit.getServer().getConsoleSender(), Phrase.build(Phrase.ENABLE_SUCCESS, ConfigHandler.EDITION_NAME));
if (Config.getGlobal().MYSQL) {
Chat.console(Phrase.build(Phrase.USING_MYSQL));
}
Expand Down Expand Up @@ -137,16 +138,16 @@ public void onDisable() {
private static boolean performVersionChecks() {
try {
String[] bukkitVersion = Bukkit.getServer().getBukkitVersion().split("[-.]");
if (Util.newVersion(bukkitVersion[0] + "." + bukkitVersion[1], ConfigHandler.MINECRAFT_VERSION)) {
if (VersionUtils.newVersion(bukkitVersion[0] + "." + bukkitVersion[1], ConfigHandler.MINECRAFT_VERSION)) {
Chat.console(Phrase.build(Phrase.VERSION_REQUIRED, "Minecraft", ConfigHandler.MINECRAFT_VERSION));
return false;
}
if (Util.newVersion(ConfigHandler.LATEST_VERSION, bukkitVersion[0] + "." + bukkitVersion[1]) && Util.isBranch("master")) {
if (VersionUtils.newVersion(ConfigHandler.LATEST_VERSION, bukkitVersion[0] + "." + bukkitVersion[1]) && VersionUtils.isBranch("master")) {
Chat.console(Phrase.build(Phrase.VERSION_INCOMPATIBLE, "Minecraft", bukkitVersion[0] + "." + bukkitVersion[1]));
return false;
}
String[] javaVersion = (System.getProperty("java.version").replaceAll("[^0-9.]", "") + ".0").split("\\.");
if (Util.newVersion(javaVersion[0] + "." + javaVersion[1], ConfigHandler.JAVA_VERSION)) {
if (VersionUtils.newVersion(javaVersion[0] + "." + javaVersion[1], ConfigHandler.JAVA_VERSION)) {
Chat.console(Phrase.build(Phrase.VERSION_REQUIRED, "Java", ConfigHandler.JAVA_VERSION));
return false;
}
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/net/coreprotect/CoreProtectAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@
import net.coreprotect.database.rollback.Rollback;
import net.coreprotect.language.Phrase;
import net.coreprotect.listener.player.InventoryChangeListener;
import net.coreprotect.utility.BlockUtils;
import net.coreprotect.utility.Chat;
import net.coreprotect.utility.EntityUtils;
import net.coreprotect.utility.MaterialUtils;
import net.coreprotect.utility.StringUtils;
import net.coreprotect.utility.Util;
import net.coreprotect.utility.WorldUtils;

public class CoreProtectAPI extends Queue {

Expand Down Expand Up @@ -102,14 +107,14 @@ public Material getType() {
String typeName;

if (actionID == 3) {
typeName = Util.getEntityType(type).name();
typeName = EntityUtils.getEntityType(type).name();
}
else {
typeName = Util.getType(type).name().toLowerCase(Locale.ROOT);
typeName = Util.nameFilter(typeName, this.getData());
typeName = MaterialUtils.getType(type).name().toLowerCase(Locale.ROOT);
typeName = StringUtils.nameFilter(typeName, this.getData());
}

return Util.getType(typeName);
return MaterialUtils.getType(typeName);
}

public BlockData getBlockData() {
Expand Down Expand Up @@ -145,7 +150,7 @@ public boolean isRolledBack() {
}

public String worldName() {
return Util.getWorldName(Integer.parseInt(parse.length < 13 ? parse[5] : parse[9]));
return WorldUtils.getWorldName(Integer.parseInt(parse.length < 13 ? parse[5] : parse[9]));
}
}

Expand All @@ -158,7 +163,7 @@ private static Map<Object, Boolean> parseList(List<Object> list) {
result.put(value, false);
}
else if (value instanceof Integer) {
Material material = Util.getType((Integer) value);
Material material = MaterialUtils.getType((Integer) value);
result.put(material, false);
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/net/coreprotect/api/BlockAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import net.coreprotect.database.Database;
import net.coreprotect.database.statement.UserStatement;
import net.coreprotect.utility.Util;
import net.coreprotect.utility.WorldUtils;
import net.coreprotect.utility.BlockUtils;
import net.coreprotect.utility.StringUtils;

public class BlockAPI {

Expand All @@ -27,7 +30,7 @@ public static List<String[]> performLookup(Block block, int offset) {
int y = block.getY();
int z = block.getZ();
int time = (int) (System.currentTimeMillis() / 1000L);
int worldId = Util.getWorldId(block.getWorld().getName());
int worldId = WorldUtils.getWorldId(block.getWorld().getName());
int checkTime = 0;
if (offset > 0) {
checkTime = time - offset;
Expand All @@ -38,7 +41,7 @@ public static List<String[]> performLookup(Block block, int offset) {
}

Statement statement = connection.createStatement();
String query = "SELECT time,user,action,type,data,blockdata,rolled_back FROM " + ConfigHandler.prefix + "block " + Util.getWidIndex("block") + "WHERE wid = '" + worldId + "' AND x = '" + x + "' AND z = '" + z + "' AND y = '" + y + "' AND time > '" + checkTime + "' ORDER BY rowid DESC";
String query = "SELECT time,user,action,type,data,blockdata,rolled_back FROM " + ConfigHandler.prefix + "block " + WorldUtils.getWidIndex("block") + "WHERE wid = '" + worldId + "' AND x = '" + x + "' AND z = '" + z + "' AND y = '" + y + "' AND time > '" + checkTime + "' ORDER BY rowid DESC";
ResultSet results = statement.executeQuery(query);

while (results.next()) {
Expand All @@ -53,10 +56,10 @@ public static List<String[]> performLookup(Block block, int offset) {
UserStatement.loadName(connection, resultUserId);
}
String resultUser = ConfigHandler.playerIdCacheReversed.get(resultUserId);
String blockData = Util.byteDataToString(resultBlockData, resultType);
String blockData = BlockUtils.byteDataToString(resultBlockData, resultType);

String[] lookupData = new String[] { resultTime, resultUser, String.valueOf(x), String.valueOf(y), String.valueOf(z), String.valueOf(resultType), resultData, resultAction, resultRolledBack, String.valueOf(worldId), blockData };
String[] lineData = Util.toStringArray(lookupData);
String[] lineData = StringUtils.toStringArray(lookupData);
result.add(lineData);
}
results.close();
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/net/coreprotect/api/QueueLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import net.coreprotect.consumer.Consumer;
import net.coreprotect.consumer.Queue;
import net.coreprotect.consumer.process.Process;
import net.coreprotect.utility.Util;
import net.coreprotect.utility.MaterialUtils;
import net.coreprotect.utility.StringUtils;
import net.coreprotect.utility.WorldUtils;

public class QueueLookup extends Queue {

Expand Down Expand Up @@ -68,12 +70,12 @@ public static List<String[]> performLookup(Block block) {
String user = userData[0];
BlockState blockState = (BlockState) objectData;
Location location = blockState.getLocation();
int wid = Util.getWorldId(location.getWorld().getName());
int resultType = Util.getBlockId(blockType);
int wid = WorldUtils.getWorldId(location.getWorld().getName());
int resultType = MaterialUtils.getBlockId(blockType);
int time = (int) (System.currentTimeMillis() / 1000L);

String[] lookupData = new String[] { String.valueOf(time), user, String.valueOf(location.getBlockX()), String.valueOf(location.getBlockY()), String.valueOf(location.getBlockZ()), String.valueOf(resultType), String.valueOf(legacyData), String.valueOf(action), "0", String.valueOf(wid), blockData };
String[] lineData = Util.toStringArray(lookupData);
String[] lineData = StringUtils.toStringArray(lookupData);
result.add(lineData);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/coreprotect/bukkit/BukkitAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.bukkit.potion.PotionType;

import net.coreprotect.config.ConfigHandler;
import net.coreprotect.utility.BlockUtils;
import net.coreprotect.utility.Util;

public class BukkitAdapter implements BukkitInterface {
Expand Down Expand Up @@ -171,7 +172,7 @@ public boolean isWaxed(Sign sign) {

@Override
public boolean isInvisible(Material material) {
return Util.isAir(material);
return BlockUtils.isAir(material);
}

@Override
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/net/coreprotect/bukkit/Bukkit_v1_17.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import org.bukkit.inventory.meta.ItemMeta;

import net.coreprotect.model.BlockGroup;
import net.coreprotect.utility.Util;
import net.coreprotect.utility.ItemUtils;
import net.coreprotect.utility.MaterialUtils;

public class Bukkit_v1_17 extends BukkitAdapter implements BukkitInterface {

Expand Down Expand Up @@ -59,7 +60,7 @@ public String parseLegacyName(String name) {
public int getLegacyBlockId(Material material) {
switch (material) {
case DIRT_PATH:
return Util.getBlockId("GRASS_PATH", false);
return MaterialUtils.getBlockId("GRASS_PATH", false);
default:
return -1;
}
Expand Down Expand Up @@ -123,7 +124,7 @@ public boolean getItemMeta(ItemMeta itemMeta, List<Map<String, Object>> list, Li
if (subMeta.hasItems()) {
list = new ArrayList<>();
for (ItemStack itemStack : subMeta.getItems()) {
Map<String, Object> itemMap = Util.serializeItemStack(itemStack, null, slot);
Map<String, Object> itemMap = ItemUtils.serializeItemStack(itemStack, null, slot);
if (itemMap.size() > 0) {
list.add(itemMap);
}
Expand All @@ -146,7 +147,7 @@ public boolean setItemMeta(Material rowType, ItemStack itemstack, List<Map<Strin
if ((rowType == Material.BUNDLE)) {
BundleMeta meta = (BundleMeta) itemstack.getItemMeta();
for (Map<String, Object> itemData : map) {
ItemStack itemStack = Util.unserializeItemStack(itemData);
ItemStack itemStack = ItemUtils.unserializeItemStack(itemData);
if (itemStack != null) {
meta.addItem(itemStack);
}
Expand Down
Loading
Loading