reformatted project

This commit is contained in:
2025-10-16 00:58:52 +02:00
parent cf0499df44
commit 794dc1dbb1
150 changed files with 1594 additions and 1771 deletions

View File

@@ -10,7 +10,7 @@ import java.lang.reflect.Field;
import java.util.concurrent.CompletableFuture;
public class BatchUtil {
public static long[] getAffectedChunks(Batch batch) {
public static long[] getAffectedChunks(Batch<?> batch) {
try {
Field field = batch.getClass().getDeclaredField("chunkBatchesMap");
field.setAccessible(true);
@@ -19,7 +19,7 @@ public class BatchUtil {
Long2ObjectMap<ChunkBatch> chunkBatchesMap = (Long2ObjectMap<ChunkBatch>) field.get(batch);
return chunkBatchesMap.keySet().toLongArray();
} catch (NoSuchFieldException | IllegalAccessException e) {
} catch(NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
@@ -48,7 +48,7 @@ public class BatchUtil {
try {
future.get();
} catch (Exception e) {
} catch(Exception e) {
throw new RuntimeException(e);
}
}

View File

@@ -1,15 +0,0 @@
package eu.mhsl.minenet.minigames.util;
import net.kyori.adventure.text.format.NamedTextColor;
public class ColorUtil {
public static NamedTextColor scoreColor(int score) {
return switch (score) {
case 1 -> NamedTextColor.GOLD;
case 2 -> NamedTextColor.GREEN;
case 3 -> NamedTextColor.DARK_GREEN;
default -> NamedTextColor.GRAY;
};
}
}

View File

@@ -5,13 +5,8 @@ import net.minestom.server.event.trait.CancellableEvent;
public class CommonEventHandles {
/**
* Cancels the given Event
* @param event
*/
public static void cancel(CancellableEvent event) {
event.setCancelled(true);
}
public static void cancel(CancellableEvent event, boolean condition) {
event.setCancelled(condition);
}
}

View File

@@ -6,8 +6,8 @@ import java.util.Map;
public class CommonProperties {
public static Map<String, String> fenceEastWest = new HashMap<>() {
{
put("west", "true");
put("east", "true");
this.put("west", "true");
this.put("east", "true");
}
};
}

View File

@@ -14,8 +14,8 @@ public class GeneratorUtils {
double startZ = unit.absoluteStart().z();
double endZ = unit.absoluteEnd().z() - 1;
for (double x = startX; x <= endX; x++) {
for (double z = startZ; z <= endZ; z++) {
for(double x = startX; x <= endX; x++) {
for(double z = startZ; z <= endZ; z++) {
Point currentPoint = new Pos(x, unit.absoluteStart().y(), z);
bottomPoint.accept(currentPoint);
}
@@ -28,8 +28,8 @@ public class GeneratorUtils {
double startZ = Math.min(start.z(), end.z());
double endZ = Math.max(start.z(), end.z());
for (double x = startX; x <= endX; x++) {
for (double z = startZ; z <= endZ; z++) {
for(double x = startX; x <= endX; x++) {
for(double z = startZ; z <= endZ; z++) {
Point currentPoint = new Pos(x, start.y(), z);
callback.accept(currentPoint);
}
@@ -44,9 +44,9 @@ public class GeneratorUtils {
int minZ = (int) Math.min(pos1.z(), pos2.z());
int maxZ = (int) Math.max(pos1.z(), pos2.z());
for (int x = minX; x <= maxX; x++) {
for (int y = minY; y <= maxY; y++) {
for (int z = minZ; z <= maxZ; z++) {
for(int x = minX; x <= maxX; x++) {
for(int y = minY; y <= maxY; y++) {
for(int z = minZ; z <= maxZ; z++) {
Point point = new Pos(x, y, z);
callback.accept(point);
}
@@ -55,7 +55,8 @@ public class GeneratorUtils {
}
public static void outline(Point pos1, Point pos2, Consumer<Point> outline) {
outline(pos1, pos2, outline, point -> {});
outline(pos1, pos2, outline, point -> {
});
}
public static void outline(Point pos1, Point pos2, Consumer<Point> outline, Consumer<Point> innerFill) {
@@ -67,11 +68,11 @@ public class GeneratorUtils {
int maxY = (int) Math.max(pos1.y(), pos2.y());
int maxZ = (int) Math.max(pos1.z(), pos2.z());
for (int x = minX; x <= maxX; x++) {
for (int y = minY; y <= maxY; y++) {
for (int z = minZ; z <= maxZ; z++) {
for(int x = minX; x <= maxX; x++) {
for(int y = minY; y <= maxY; y++) {
for(int z = minZ; z <= maxZ; z++) {
Point blockPos = new Pos(x, y, z);
if (x == minX || x == maxX || y == minY || y == maxY || z == minZ || z == maxZ) {
if(x == minX || x == maxX || y == minY || y == maxY || z == minZ || z == maxZ) {
outline.accept(blockPos);
}
}

View File

@@ -8,10 +8,10 @@ import net.minestom.server.instance.block.Block;
public class Intersect {
public static boolean withPressurePlate(Instance instance, BlockPallet target, Pos playerPosition) {
Pos[] corners = {
playerPosition.add(0.3-Position.PIXEL, 0, 0.3-Position.PIXEL),
playerPosition.add(0.3-Position.PIXEL, 0, -0.3+Position.PIXEL),
playerPosition.add(-0.3+Position.PIXEL, 0, 0.3-Position.PIXEL),
playerPosition.add(-0.3+Position.PIXEL, 0, -0.3+Position.PIXEL)
playerPosition.add(0.3 - Position.PIXEL, 0, 0.3 - Position.PIXEL),
playerPosition.add(0.3 - Position.PIXEL, 0, -0.3 + Position.PIXEL),
playerPosition.add(-0.3 + Position.PIXEL, 0, 0.3 - Position.PIXEL),
playerPosition.add(-0.3 + Position.PIXEL, 0, -0.3 + Position.PIXEL)
};
for(Pos coroner : corners) {

View File

@@ -24,13 +24,13 @@ public class InventoryItemAlignment {
this.x = 9;
this.y = y;
if(x * y < size) throw new RuntimeException("Not enough space for Item alignment");
if(this.x * y < size) throw new RuntimeException("Not enough space for Item alignment");
}
public ItemOffset next() {
counter++;
this.counter++;
if(this.size < 9) return new ItemOffset(this.row(this.size).get(counter), y > 1 ? 1 : 0);
if(this.size < 9) return new ItemOffset(this.row(this.size).get(this.counter), this.y > 1 ? 1 : 0);
//TODO more items?
return new ItemOffset(0, 0);
@@ -41,89 +41,89 @@ public class InventoryItemAlignment {
return new ArrayList<ArrayList<Integer>>() {
{
//noinspection EmptyClassInitializer
add(new ArrayList<>() {
this.add(new ArrayList<>() {
static {
}
});
add(new ArrayList<>() {
this.add(new ArrayList<>() {
{
add(4);
this.add(4);
}
});
add(new ArrayList<>() {
this.add(new ArrayList<>() {
{
add(3);
add(5);
this.add(3);
this.add(5);
}
});
add(new ArrayList<>() {
this.add(new ArrayList<>() {
{
add(2);
add(4);
add(6);
this.add(2);
this.add(4);
this.add(6);
}
});
add(new ArrayList<>() {
this.add(new ArrayList<>() {
{
add(1);
add(3);
add(5);
add(7);
this.add(1);
this.add(3);
this.add(5);
this.add(7);
}
});
add(new ArrayList<>() {
this.add(new ArrayList<>() {
{
add(2);
add(3);
add(4);
add(5);
add(6);
this.add(2);
this.add(3);
this.add(4);
this.add(5);
this.add(6);
}
});
add(new ArrayList<>() {
this.add(new ArrayList<>() {
{
add(1);
add(2);
add(3);
add(5);
add(6);
add(7);
this.add(1);
this.add(2);
this.add(3);
this.add(5);
this.add(6);
this.add(7);
}
});
add(new ArrayList<>() {
this.add(new ArrayList<>() {
{
add(1);
add(2);
add(3);
add(4);
add(5);
add(6);
add(7);
this.add(1);
this.add(2);
this.add(3);
this.add(4);
this.add(5);
this.add(6);
this.add(7);
}
});
add(new ArrayList<>() {
this.add(new ArrayList<>() {
{
add(0);
add(1);
add(2);
add(3);
add(5);
add(6);
add(7);
add(8);
this.add(0);
this.add(1);
this.add(2);
this.add(3);
this.add(5);
this.add(6);
this.add(7);
this.add(8);
}
});
add(new ArrayList<>() {
this.add(new ArrayList<>() {
{
add(0);
add(1);
add(2);
add(3);
add(4);
add(5);
add(6);
add(7);
add(8);
this.add(0);
this.add(1);
this.add(2);
this.add(3);
this.add(4);
this.add(5);
this.add(6);
this.add(7);
this.add(8);
}
});
}
@@ -133,7 +133,7 @@ public class InventoryItemAlignment {
public record ItemOffset(int x, int z) {
public int get() {
return x + (z * 9);
}
return this.x + (this.z * 9);
}
}
}

View File

@@ -7,12 +7,12 @@ import net.minestom.server.item.Material;
public class InventoryUtil {
public static void removeItemFromPlayer(Player player, Material material, int amount) {
ItemStack[] items = player.getInventory().getItemStacks();
for (int i = 0; i < items.length; i++) {
for(int i = 0; i < items.length; i++) {
ItemStack item = items[i];
if (item.material() != material) continue;
if(item.material() != material) continue;
int stackSize = item.amount();
if (stackSize < amount) {
if(stackSize < amount) {
amount -= stackSize;
player.getInventory().setItemStack(i, ItemStack.AIR);
} else {

View File

@@ -1,6 +1,9 @@
package eu.mhsl.minenet.minigames.util;
import java.util.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class MapUtil {
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) {
@@ -8,7 +11,7 @@ public class MapUtil {
list.sort(Map.Entry.comparingByValue());
Map<K, V> result = new LinkedHashMap<>();
for (Map.Entry<K, V> entry : list) {
for(Map.Entry<K, V> entry : list) {
result.put(entry.getKey(), entry.getValue());
}
@@ -20,7 +23,7 @@ public class MapUtil {
list.sort(Map.Entry.<K, V>comparingByValue().reversed());
Map<K, V> result = new LinkedHashMap<>();
for (Map.Entry<K, V> entry : list) {
for(Map.Entry<K, V> entry : list) {
result.put(entry.getKey(), entry.getValue());
}

View File

@@ -11,7 +11,7 @@ public class Monitoring {
private static final AtomicReference<TickMonitor> lastTick = new AtomicReference<>();
static {
MinecraftServer.getGlobalEventHandler().addListener(ServerTickMonitorEvent .class, event -> lastTick.set(event.getTickMonitor()));
MinecraftServer.getGlobalEventHandler().addListener(ServerTickMonitorEvent.class, event -> lastTick.set(event.getTickMonitor()));
}
public static long getRamUsage() {

View File

@@ -14,6 +14,7 @@ public class MoveInstance {
public static void move(Set<Player> playerList, Spawnable destination) {
playerList.forEach(player -> move(player, destination));
}
public static void move(Entity p, Spawnable destination) {
if(p.getInstance() != destination) p.setInstance((Instance) destination, destination.getSpawn());
}

View File

@@ -2,7 +2,7 @@ package eu.mhsl.minenet.minigames.util;
public class NumberUtil {
public static double map(double oldValue, double oldMin, double oldMax, double newMin, double newMax) {
double out = (((oldValue - oldMin) * (newMax - newMin)) / (oldMax - oldMin)) + newMin;
double out = (((oldValue - oldMin) * (newMax - newMin)) / (oldMax - oldMin)) + newMin;
if(out > newMax) out = newMax;
if(out < newMin) out = newMin;
@@ -10,8 +10,8 @@ public class NumberUtil {
}
public static <T extends Comparable<T>> T clamp(T val, T min, T max) {
if (val.compareTo(min) < 0) return min;
else if (val.compareTo(max) > 0) return max;
if(val.compareTo(min) < 0) return min;
else if(val.compareTo(max) > 0) return max;
else return val;
}
}

View File

@@ -7,6 +7,7 @@ import net.minestom.server.network.packet.server.common.PluginMessagePacket;
public class PluginMessageUtil {
private static final String bungeeTargetSelector = "bungeecord:main";
public static void connect(Player p, String bungeeServerTargetName) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");

View File

@@ -1,5 +1,7 @@
package eu.mhsl.minenet.minigames.util;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
import java.net.URI;
@@ -19,7 +21,7 @@ public final class ResourceUtils {
final URI uri = Objects.requireNonNull(ResourceUtils.class.getResource("/" + source)).toURI();
FileSystem fileSystem = null;
if (uri.toString().startsWith("jar:"))
if(uri.toString().startsWith("jar:"))
fileSystem = FileSystems.newFileSystem(uri, Map.of("create", "true"));
try {
@@ -28,36 +30,36 @@ public final class ResourceUtils {
final Path jarPath = Paths.get(uri);
final Path target = Path.of("resources/" + source);
if (Files.exists(target)) {
if(Files.exists(target)) {
if(keepOutdated) return;
try (Stream<Path> pathStream = Files.walk(target)) {
try(Stream<Path> pathStream = Files.walk(target)) {
pathStream.sorted(Comparator.reverseOrder())
.forEach(path -> {
try {
Files.delete(path);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
.forEach(path -> {
try {
Files.delete(path);
} catch(IOException e) {
throw new RuntimeException(e);
}
});
}
}
Files.walkFileTree(jarPath, new SimpleFileVisitor<>() {
@Override
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException {
public @NotNull FileVisitResult preVisitDirectory(final @NotNull Path dir, final @NotNull BasicFileAttributes attrs) throws IOException {
Path currentTarget = target.resolve(jarPath.relativize(dir).toString());
Files.createDirectories(currentTarget);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
public @NotNull FileVisitResult visitFile(final @NotNull Path file, final @NotNull BasicFileAttributes attrs) throws IOException {
final Path to = target.resolve(jarPath.relativize(file).toString());
Files.copy(file, to, StandardCopyOption.REPLACE_EXISTING);
return FileVisitResult.CONTINUE;
}
});
} finally {
if (fileSystem != null)
if(fileSystem != null)
fileSystem.close();
}
}

View File

@@ -1,18 +1,14 @@
package eu.mhsl.minenet.minigames.util;
public class SingleExecution {
private boolean wasExecuted = false;
public static SingleExecution make() {
return new SingleExecution();
}
private boolean wasExecuted = false;
public void reset() {
this.wasExecuted = false;
}
public void singleRun(Runnable task) {
if(wasExecuted) return;
if(this.wasExecuted) return;
task.run();
this.wasExecuted = true;
}

View File

@@ -1,132 +0,0 @@
package eu.mhsl.minenet.minigames.util;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TextUtil {
public static Component autoWrap(String input, NamedTextColor color) {
return Component.text(wrap(input, 30, "\n", true, "-", " "), color);
}
public static Component autoWrap(String input) {
return autoWrap(input, NamedTextColor.WHITE);
}
/**
* Wraps a source String into a series of lines having a maximum specified length. The source is
* wrapped at: spaces, horizontal tabs, system newLine characters, or a specified newLine character
* sequence. Existing newLine character sequences in the source string, whether they be the system
* newLine or the specified newLine, are honored. Existing whitespace (spaces and horizontal tabs)
* is preserved.
* <p>
* When <tt>wrapLongWords</tt> is true, words having a length greater than the specified
* <tt>lineLength</tt> will be broken, the specified <tt>longWordBreak</tt> terminator appended,
* and a new line initiated with the text of the specified <tt>longWordLinePrefix</tt> string. The
* position of the break will be unceremoniously chosen such that <tt>ineLength</tt> is honored.
* One use of <tt>longWordLinePrefix</tt> is to effect "hanging indents" by specifying a series of
* spaces for this parameter. This parameter can contain the lineFeed character(s). Although
* <tt>longWordLinePrefix</tt> can contain the horizontal tab character, the results are not
* guaranteed because no attempt is made to determine the quantity of character positions occupied by a
* horizontal tab.</p>
* <p>
* Example usage:
* <pre>
* wrap( " A very long word is Abracadabra in my book", 11, "\n", true, "-", " ");</pre>
* returns (note the effect of the single-character lineFeed):
* <pre>
* A very
* long word
* is Abraca-
* dabra in
* my book</pre>
* Whereas, the following:
* <pre>
* wrap( " A very long word is Abracadabra in my book", 11, null, true, null, " ");</pre>
* returns (due to the 2-character system linefeed):
* <pre>
* A very
* long
* word is A
* bracada
* bra in
* my book</pre></p>
*
* @param src the String to be word wrapped, may be null
* @param lineLength the maximum line length, including the length of <tt>newLineStr</tt> and, when
* applicable, <tt>longWordLinePrefix</tt>. If the value is insufficient to accommodate
* these two parameters + 1 character, it will be increased accordingly.
* @param newLineStr the string to insert for a new line, or <code>null</code> to use the value
* reported as the system line separator by the JVM
* @param wrapLongWords when <tt>false</tt>, words longer than <tt>wrapLength</t> will not be broken
* @param longWordBreak string with which to precede <tt>newLineStr</tt> on each line of a broken word,
* excepting the last line, or <tt>null</tt> if this feature is not to be used
* @param longWordLinePrefix string with which to prefix each line of a broken word, subsequent
* to the first line, or <tt>null</tt> if no prefix is to be used
* @return a line with newlines inserted, or <code>null</code> if <tt>src</tt> is null
*/
private static String wrap(String src, int lineLength, String newLineStr, boolean wrapLongWords, String longWordBreak, String longWordLinePrefix) {
// Trivial case
if ( src == null ) return null;
if ( newLineStr == null )
newLineStr = System.getProperty( "line.separator" );
if ( longWordBreak == null )
longWordBreak = "";
if ( longWordLinePrefix == null )
longWordLinePrefix = "";
// Adjust maximum line length to accommodate the newLine string
lineLength -= newLineStr.length();
if ( lineLength < 1 )
lineLength = 1;
// Guard for long word break or prefix that would create an infinite loop
if ( wrapLongWords && lineLength - longWordBreak.length() - longWordLinePrefix.length() < 1 )
lineLength += longWordBreak.length() + longWordLinePrefix.length();
int
remaining = lineLength,
breakLength = longWordBreak.length();
Matcher m = Pattern.compile( ".+?[ \\t]|.+?mis" + newLineStr + "singValue|.+?$" ).matcher( src );
StringBuilder cache = new StringBuilder();
while ( m.find() ) {
String word = m.group();
// Breakup long word
while ( wrapLongWords && word.length() > lineLength ) {
cache
.append(word, 0, remaining - breakLength)
.append( longWordBreak )
.append( newLineStr );
word = longWordLinePrefix + word.substring( remaining - breakLength );
remaining = lineLength;
} // if
// Linefeed if word exceeds remaining space
if ( word.length() > remaining ) {
cache
.append( newLineStr )
.append( word );
remaining = lineLength;
} // if
// Word fits in remaining space
else
cache.append( word );
remaining -= word.length();
} // while
return cache.toString();
} // wrap()
}

View File

@@ -10,7 +10,7 @@ public class UuidUtil {
builder.insert(16, "-");
builder.insert(12, "-");
builder.insert(8, "-");
} catch (StringIndexOutOfBoundsException e) {
} catch(StringIndexOutOfBoundsException e) {
throw new IllegalArgumentException();
}
return UUID.fromString(builder.toString());

View File

@@ -11,15 +11,16 @@ import java.util.Set;
public class WeatherUtils {
private float intensity;
public void startRain(Set<Player> players) {
intensity = 0;
this.intensity = 0;
players.forEach(p -> p.sendPacket(new ChangeGameStatePacket(ChangeGameStatePacket.Reason.BEGIN_RAINING, 0f)));
MinecraftServer.getSchedulerManager().submitTask(() -> {
intensity += 0.1f;
players.forEach(p -> p.sendPacket(new ChangeGameStatePacket(ChangeGameStatePacket.Reason.RAIN_LEVEL_CHANGE, intensity)));
System.out.println(intensity);
if(intensity < 1) {
this.intensity += 0.1f;
players.forEach(p -> p.sendPacket(new ChangeGameStatePacket(ChangeGameStatePacket.Reason.RAIN_LEVEL_CHANGE, this.intensity)));
System.out.println(this.intensity);
if(this.intensity < 1) {
return TaskSchedule.millis(500);
} else {
return TaskSchedule.stop();