Skip to content

Commit e2c2505

Browse files
committed
Split up utility class
1 parent 828af84 commit e2c2505

File tree

97 files changed

+2369
-2104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+2369
-2104
lines changed

src/main/java/net/coreprotect/CoreProtect.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
import net.coreprotect.thread.NetworkHandler;
2828
import net.coreprotect.thread.Scheduler;
2929
import net.coreprotect.utility.Chat;
30+
import net.coreprotect.utility.ChatUtils;
3031
import net.coreprotect.utility.Color;
3132
import net.coreprotect.utility.Teleport;
32-
import net.coreprotect.utility.Util;
33+
import net.coreprotect.utility.VersionUtils;
3334

3435
public final class CoreProtect extends JavaPlugin {
3536

@@ -87,7 +88,7 @@ public void onEnable() {
8788

8889
if (start) {
8990
PluginDescriptionFile pluginDescription = this.getDescription();
90-
Util.sendConsoleComponentStartup(Bukkit.getServer().getConsoleSender(), Phrase.build(Phrase.ENABLE_SUCCESS, ConfigHandler.EDITION_NAME));
91+
ChatUtils.sendConsoleComponentStartup(Bukkit.getServer().getConsoleSender(), Phrase.build(Phrase.ENABLE_SUCCESS, ConfigHandler.EDITION_NAME));
9192
if (Config.getGlobal().MYSQL) {
9293
Chat.console(Phrase.build(Phrase.USING_MYSQL));
9394
}
@@ -137,16 +138,16 @@ public void onDisable() {
137138
private static boolean performVersionChecks() {
138139
try {
139140
String[] bukkitVersion = Bukkit.getServer().getBukkitVersion().split("[-.]");
140-
if (Util.newVersion(bukkitVersion[0] + "." + bukkitVersion[1], ConfigHandler.MINECRAFT_VERSION)) {
141+
if (VersionUtils.newVersion(bukkitVersion[0] + "." + bukkitVersion[1], ConfigHandler.MINECRAFT_VERSION)) {
141142
Chat.console(Phrase.build(Phrase.VERSION_REQUIRED, "Minecraft", ConfigHandler.MINECRAFT_VERSION));
142143
return false;
143144
}
144-
if (Util.newVersion(ConfigHandler.LATEST_VERSION, bukkitVersion[0] + "." + bukkitVersion[1]) && Util.isBranch("master")) {
145+
if (VersionUtils.newVersion(ConfigHandler.LATEST_VERSION, bukkitVersion[0] + "." + bukkitVersion[1]) && VersionUtils.isBranch("master")) {
145146
Chat.console(Phrase.build(Phrase.VERSION_INCOMPATIBLE, "Minecraft", bukkitVersion[0] + "." + bukkitVersion[1]));
146147
return false;
147148
}
148149
String[] javaVersion = (System.getProperty("java.version").replaceAll("[^0-9.]", "") + ".0").split("\\.");
149-
if (Util.newVersion(javaVersion[0] + "." + javaVersion[1], ConfigHandler.JAVA_VERSION)) {
150+
if (VersionUtils.newVersion(javaVersion[0] + "." + javaVersion[1], ConfigHandler.JAVA_VERSION)) {
150151
Chat.console(Phrase.build(Phrase.VERSION_REQUIRED, "Java", ConfigHandler.JAVA_VERSION));
151152
return false;
152153
}

src/main/java/net/coreprotect/CoreProtectAPI.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@
2828
import net.coreprotect.database.rollback.Rollback;
2929
import net.coreprotect.language.Phrase;
3030
import net.coreprotect.listener.player.InventoryChangeListener;
31+
import net.coreprotect.utility.BlockUtils;
3132
import net.coreprotect.utility.Chat;
33+
import net.coreprotect.utility.EntityUtils;
34+
import net.coreprotect.utility.MaterialUtils;
35+
import net.coreprotect.utility.StringUtils;
3236
import net.coreprotect.utility.Util;
37+
import net.coreprotect.utility.WorldUtils;
3338

3439
public class CoreProtectAPI extends Queue {
3540

@@ -102,14 +107,14 @@ public Material getType() {
102107
String typeName;
103108

104109
if (actionID == 3) {
105-
typeName = Util.getEntityType(type).name();
110+
typeName = EntityUtils.getEntityType(type).name();
106111
}
107112
else {
108-
typeName = Util.getType(type).name().toLowerCase(Locale.ROOT);
109-
typeName = Util.nameFilter(typeName, this.getData());
113+
typeName = MaterialUtils.getType(type).name().toLowerCase(Locale.ROOT);
114+
typeName = StringUtils.nameFilter(typeName, this.getData());
110115
}
111116

112-
return Util.getType(typeName);
117+
return MaterialUtils.getType(typeName);
113118
}
114119

115120
public BlockData getBlockData() {
@@ -145,7 +150,7 @@ public boolean isRolledBack() {
145150
}
146151

147152
public String worldName() {
148-
return Util.getWorldName(Integer.parseInt(parse.length < 13 ? parse[5] : parse[9]));
153+
return WorldUtils.getWorldName(Integer.parseInt(parse.length < 13 ? parse[5] : parse[9]));
149154
}
150155
}
151156

@@ -158,7 +163,7 @@ private static Map<Object, Boolean> parseList(List<Object> list) {
158163
result.put(value, false);
159164
}
160165
else if (value instanceof Integer) {
161-
Material material = Util.getType((Integer) value);
166+
Material material = MaterialUtils.getType((Integer) value);
162167
result.put(material, false);
163168
}
164169
}

src/main/java/net/coreprotect/api/BlockAPI.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import net.coreprotect.database.Database;
1313
import net.coreprotect.database.statement.UserStatement;
1414
import net.coreprotect.utility.Util;
15+
import net.coreprotect.utility.WorldUtils;
16+
import net.coreprotect.utility.BlockUtils;
17+
import net.coreprotect.utility.StringUtils;
1518

1619
public class BlockAPI {
1720

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

4043
Statement statement = connection.createStatement();
41-
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";
44+
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";
4245
ResultSet results = statement.executeQuery(query);
4346

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

5861
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 };
59-
String[] lineData = Util.toStringArray(lookupData);
62+
String[] lineData = StringUtils.toStringArray(lookupData);
6063
result.add(lineData);
6164
}
6265
results.close();

src/main/java/net/coreprotect/api/QueueLookup.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
import net.coreprotect.consumer.Consumer;
1616
import net.coreprotect.consumer.Queue;
1717
import net.coreprotect.consumer.process.Process;
18-
import net.coreprotect.utility.Util;
18+
import net.coreprotect.utility.MaterialUtils;
19+
import net.coreprotect.utility.StringUtils;
20+
import net.coreprotect.utility.WorldUtils;
1921

2022
public class QueueLookup extends Queue {
2123

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

7577
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 };
76-
String[] lineData = Util.toStringArray(lookupData);
78+
String[] lineData = StringUtils.toStringArray(lookupData);
7779
result.add(lineData);
7880
}
7981
}

src/main/java/net/coreprotect/bukkit/BukkitAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.bukkit.potion.PotionType;
3131

3232
import net.coreprotect.config.ConfigHandler;
33+
import net.coreprotect.utility.BlockUtils;
3334
import net.coreprotect.utility.Util;
3435

3536
public class BukkitAdapter implements BukkitInterface {
@@ -171,7 +172,7 @@ public boolean isWaxed(Sign sign) {
171172

172173
@Override
173174
public boolean isInvisible(Material material) {
174-
return Util.isAir(material);
175+
return BlockUtils.isAir(material);
175176
}
176177

177178
@Override

src/main/java/net/coreprotect/bukkit/Bukkit_v1_17.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
import org.bukkit.inventory.meta.ItemMeta;
2626

2727
import net.coreprotect.model.BlockGroup;
28-
import net.coreprotect.utility.Util;
28+
import net.coreprotect.utility.ItemUtils;
29+
import net.coreprotect.utility.MaterialUtils;
2930

3031
public class Bukkit_v1_17 extends BukkitAdapter implements BukkitInterface {
3132

@@ -59,7 +60,7 @@ public String parseLegacyName(String name) {
5960
public int getLegacyBlockId(Material material) {
6061
switch (material) {
6162
case DIRT_PATH:
62-
return Util.getBlockId("GRASS_PATH", false);
63+
return MaterialUtils.getBlockId("GRASS_PATH", false);
6364
default:
6465
return -1;
6566
}
@@ -123,7 +124,7 @@ public boolean getItemMeta(ItemMeta itemMeta, List<Map<String, Object>> list, Li
123124
if (subMeta.hasItems()) {
124125
list = new ArrayList<>();
125126
for (ItemStack itemStack : subMeta.getItems()) {
126-
Map<String, Object> itemMap = Util.serializeItemStack(itemStack, null, slot);
127+
Map<String, Object> itemMap = ItemUtils.serializeItemStack(itemStack, null, slot);
127128
if (itemMap.size() > 0) {
128129
list.add(itemMap);
129130
}
@@ -146,7 +147,7 @@ public boolean setItemMeta(Material rowType, ItemStack itemstack, List<Map<Strin
146147
if ((rowType == Material.BUNDLE)) {
147148
BundleMeta meta = (BundleMeta) itemstack.getItemMeta();
148149
for (Map<String, Object> itemData : map) {
149-
ItemStack itemStack = Util.unserializeItemStack(itemData);
150+
ItemStack itemStack = ItemUtils.unserializeItemStack(itemData);
150151
if (itemStack != null) {
151152
meta.addItem(itemStack);
152153
}

src/main/java/net/coreprotect/command/CommandHandler.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
import net.coreprotect.thread.NetworkHandler;
3232
import net.coreprotect.utility.Chat;
3333
import net.coreprotect.utility.Color;
34-
import net.coreprotect.utility.Util;
34+
import net.coreprotect.utility.EntityUtils;
35+
import net.coreprotect.utility.MaterialUtils;
36+
import net.coreprotect.utility.VersionUtils;
37+
import net.coreprotect.utility.WorldUtils;
3538

3639
public class CommandHandler implements CommandExecutor {
3740
private static CommandHandler instance;
@@ -210,7 +213,7 @@ else if (cCount == 2) {
210213
}
211214
if (cCount > 1) {
212215
if (location == null && worldId > 0) {
213-
location = new Location(Bukkit.getWorld(Util.getWorldName(worldId)), 0, 0, 0);
216+
location = new Location(Bukkit.getWorld(WorldUtils.getWorldName(worldId)), 0, 0, 0);
214217
}
215218
if (location != null) {
216219
int worldMaxHeight = location.getWorld().getMaxHeight() - 1;
@@ -279,12 +282,12 @@ else if (next == 5 || argument.startsWith("e:") || argument.startsWith("exclude:
279282
String[] i2 = argument.split(",");
280283
for (String i3 : i2) {
281284
if (!checkTags(i3, excluded)) {
282-
Material i3_material = Util.getType(i3);
285+
Material i3_material = MaterialUtils.getType(i3);
283286
if (i3_material != null && (i3_material.isBlock() || argAction.contains(4))) {
284287
excluded.put(i3_material, false);
285288
}
286289
else {
287-
EntityType i3_entity = Util.getEntityType(i3);
290+
EntityType i3_entity = EntityUtils.getEntityType(i3);
288291
if (i3_entity != null) {
289292
excluded.put(i3_entity, false);
290293
}
@@ -303,12 +306,12 @@ else if (i3_material != null) {
303306
}
304307
else {
305308
if (!checkTags(argument, excluded)) {
306-
Material iMaterial = Util.getType(argument);
309+
Material iMaterial = MaterialUtils.getType(argument);
307310
if (iMaterial != null && (iMaterial.isBlock() || argAction.contains(4))) {
308311
excluded.put(iMaterial, false);
309312
}
310313
else {
311-
EntityType iEntity = Util.getEntityType(argument);
314+
EntityType iEntity = EntityUtils.getEntityType(argument);
312315
if (iEntity != null) {
313316
excluded.put(iEntity, false);
314317
}
@@ -354,12 +357,12 @@ else if (next == 5 || argument.startsWith("e:") || argument.startsWith("exclude:
354357
isBlock = true;
355358
}
356359
else {
357-
Material i3_material = Util.getType(i3);
360+
Material i3_material = MaterialUtils.getType(i3);
358361
if (i3_material != null) {
359362
isBlock = true;
360363
}
361364
else {
362-
EntityType i3Entity = Util.getEntityType(i3);
365+
EntityType i3Entity = EntityUtils.getEntityType(i3);
363366
if (i3Entity != null) {
364367
isBlock = true;
365368
}
@@ -382,12 +385,12 @@ else if (next == 5 || argument.startsWith("e:") || argument.startsWith("exclude:
382385
isBlock = true;
383386
}
384387
else {
385-
Material iMaterial = Util.getType(argument);
388+
Material iMaterial = MaterialUtils.getType(argument);
386389
if (iMaterial != null) {
387390
isBlock = true;
388391
}
389392
else {
390-
EntityType entityType = Util.getEntityType(argument);
393+
EntityType entityType = EntityUtils.getEntityType(argument);
391394
if (entityType != null) {
392395
isBlock = true;
393396
}
@@ -429,7 +432,7 @@ else if (next == 2 || argument.startsWith("r:") || argument.startsWith("radius:"
429432
result = true;
430433
}
431434
else if (argument.startsWith("#")) {
432-
int worldId = Util.matchWorld(argument);
435+
int worldId = WorldUtils.matchWorld(argument);
433436
if (worldId > 0) {
434437
result = true;
435438
}
@@ -622,12 +625,12 @@ else if (next == 4 || argument.startsWith("i:") || argument.startsWith("include:
622625
String[] i2 = argument.split(",");
623626
for (String i3 : i2) {
624627
if (!checkTags(argument, restricted)) {
625-
Material i3_material = Util.getType(i3);
628+
Material i3_material = MaterialUtils.getType(i3);
626629
if (i3_material != null && (i3_material.isBlock() || argAction.contains(4))) {
627630
restricted.add(i3_material);
628631
}
629632
else {
630-
EntityType i3_entity = Util.getEntityType(i3);
633+
EntityType i3_entity = EntityUtils.getEntityType(i3);
631634
if (i3_entity != null) {
632635
restricted.add(i3_entity);
633636
}
@@ -651,12 +654,12 @@ else if (i3_material != null) {
651654
}
652655
else {
653656
if (!checkTags(argument, restricted)) {
654-
Material material = Util.getType(argument);
657+
Material material = MaterialUtils.getType(argument);
655658
if (material != null && (material.isBlock() || argAction.contains(4))) {
656659
restricted.add(material);
657660
}
658661
else {
659-
EntityType entityType = Util.getEntityType(argument);
662+
EntityType entityType = EntityUtils.getEntityType(argument);
660663
if (entityType != null) {
661664
restricted.add(entityType);
662665
}
@@ -1041,7 +1044,7 @@ else if (next == 2 || inputProcessed.startsWith("r:") || inputProcessed.startsWi
10411044
world_id = 0;
10421045
}
10431046
else if (inputProcessed.startsWith("#")) {
1044-
world_id = Util.matchWorld(inputProcessed);
1047+
world_id = WorldUtils.matchWorld(inputProcessed);
10451048
if (world_id == -1 && !requireLoaded) {
10461049
world_id = ConfigHandler.worlds.getOrDefault(argument.replaceFirst("#", ""), -1);
10471050
}
@@ -1275,7 +1278,7 @@ else if (corecommand.equals("network-debug")) {
12751278
NetworkDebugCommand.runCommand(user, permission, argumentArray);
12761279
}
12771280
else if (corecommand.equals("migrate-db")) {
1278-
if (!Util.validDonationKey()) {
1281+
if (!VersionUtils.validDonationKey()) {
12791282
Chat.sendMessage(user, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.DONATION_KEY_REQUIRED));
12801283
}
12811284
else {
@@ -1300,7 +1303,7 @@ class updateAlert implements Runnable {
13001303
public void run() {
13011304
try {
13021305
Thread.sleep(5000);
1303-
Chat.sendMessage(user, Color.WHITE + "----- " + Color.DARK_AQUA + Phrase.build(Phrase.UPDATE_HEADER, "CoreProtect" + (Util.isCommunityEdition() ? " " + ConfigHandler.COMMUNITY_EDITION : "")) + Color.WHITE + " -----");
1306+
Chat.sendMessage(user, Color.WHITE + "----- " + Color.DARK_AQUA + Phrase.build(Phrase.UPDATE_HEADER, "CoreProtect" + (VersionUtils.isCommunityEdition() ? " " + ConfigHandler.COMMUNITY_EDITION : "")) + Color.WHITE + " -----");
13041307
if (latestVersion != null) {
13051308
Chat.sendMessage(user, Color.DARK_AQUA + Phrase.build(Phrase.UPDATE_NOTICE, Color.WHITE, "CoreProtect CE v" + latestVersion));
13061309
Chat.sendMessage(user, Color.DARK_AQUA + Phrase.build(Phrase.LINK_DOWNLOAD, Color.WHITE, "www.coreprotect.net/download/"));

0 commit comments

Comments
 (0)