diff --git a/build.gradle.kts b/build.gradle.kts index 38d9d68..13f52d2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar plugins { id("java") - id("com.github.johnrengelman.shadow") version "7.1.0" + id("com.github.johnrengelman.shadow") version "8.1.1" } tasks { @@ -20,12 +20,22 @@ repositories { } dependencies { - implementation("com.github.Minestom:Minestom:cb3892255e") - implementation("de.articdive:jnoise-pipeline:4.0.0") + // Minestom + implementation("net.minestom:minestom-snapshots:7daf8d69b7") + + // Randomness + implementation("de.articdive:jnoise-pipeline:4.1.0") + + // Prometheus - logging implementation("io.prometheus:simpleclient:0.16.0") implementation("io.prometheus:simpleclient_hotspot:0.16.0") implementation("io.prometheus:simpleclient_httpserver:0.16.0") - implementation("net.kyori:adventure-text-minimessage:4.12.0") + + // Adventure + implementation("net.kyori:adventure-text-minimessage:4.16.0") + + // Logger + implementation("ch.qos.logback:logback-classic:1.5.2") } tasks.withType { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 41d9927..e644113 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41dfb87..b82aa23 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 index 1b6c787..1aa94a4 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +131,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ @@ -205,6 +214,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd3..25da30d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +41,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/src/main/java/net/minestom/arena/Main.java b/src/main/java/net/minestom/arena/Main.java index 21cf362..5b25273 100644 --- a/src/main/java/net/minestom/arena/Main.java +++ b/src/main/java/net/minestom/arena/Main.java @@ -16,9 +16,9 @@ import net.minestom.server.entity.GameMode; import net.minestom.server.entity.Player; import net.minestom.server.event.GlobalEventHandler; +import net.minestom.server.event.player.AsyncPlayerConfigurationEvent; import net.minestom.server.event.player.PlayerChatEvent; import net.minestom.server.event.player.PlayerDisconnectEvent; -import net.minestom.server.event.player.PlayerLoginEvent; import net.minestom.server.event.player.PlayerSpawnEvent; import net.minestom.server.event.server.ServerTickMonitorEvent; import net.minestom.server.extras.MojangAuth; @@ -69,7 +69,7 @@ public static void main(String[] args) { ServerList.hook(handler); // Login - handler.addListener(PlayerLoginEvent.class, event -> { + handler.addListener(AsyncPlayerConfigurationEvent.class, event -> { final Player player = event.getPlayer(); event.setSpawningInstance(Lobby.INSTANCE); player.setRespawnPoint(new Pos(0.5, 16, 0.5)); @@ -152,6 +152,6 @@ public static void main(String[] args) { } minecraftServer.start(CONFIG.server().address()); - System.out.println("Server startup done! Using configuration " + CONFIG); + LOGGER.info("Server startup done! Using configuration " + CONFIG); } } diff --git a/src/main/java/net/minestom/arena/Metrics.java b/src/main/java/net/minestom/arena/Metrics.java index 2aaa7e8..eae1ac9 100644 --- a/src/main/java/net/minestom/arena/Metrics.java +++ b/src/main/java/net/minestom/arena/Metrics.java @@ -11,8 +11,8 @@ import net.minestom.server.entity.Player; import net.minestom.server.event.entity.EntitySpawnEvent; import net.minestom.server.event.instance.RemoveEntityFromInstanceEvent; +import net.minestom.server.event.player.AsyncPlayerConfigurationEvent; import net.minestom.server.event.player.PlayerDisconnectEvent; -import net.minestom.server.event.player.PlayerLoginEvent; import net.minestom.server.event.player.PlayerPacketEvent; import net.minestom.server.event.player.PlayerPacketOutEvent; @@ -62,7 +62,7 @@ public static void init() { MinecraftServer.getGlobalEventHandler() .addListener(PlayerPacketEvent.class, e -> Metrics.PACKETS.labels("in").inc()) .addListener(PlayerPacketOutEvent.class, e -> Metrics.PACKETS.labels("out").inc()) - .addListener(PlayerLoginEvent.class, e -> Metrics.ONLINE_PLAYERS.inc()) + .addListener(AsyncPlayerConfigurationEvent.class, e -> Metrics.ONLINE_PLAYERS.inc()) .addListener(PlayerDisconnectEvent.class, e -> Metrics.ONLINE_PLAYERS.dec()) .addListener(EntitySpawnEvent.class, e -> { if (!(e.getEntity() instanceof Player)) Metrics.ENTITIES.inc(); diff --git a/src/main/java/net/minestom/arena/feature/CombatFeature.java b/src/main/java/net/minestom/arena/feature/CombatFeature.java index 4871bb1..6f31770 100644 --- a/src/main/java/net/minestom/arena/feature/CombatFeature.java +++ b/src/main/java/net/minestom/arena/feature/CombatFeature.java @@ -2,18 +2,13 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import net.minestom.server.coordinate.Pos; -import net.minestom.server.entity.Entity; -import net.minestom.server.entity.EntityProjectile; -import net.minestom.server.entity.LivingEntity; -import net.minestom.server.entity.Player; +import net.minestom.server.entity.*; import net.minestom.server.entity.damage.DamageType; -import net.minestom.server.entity.hologram.Hologram; +import net.minestom.server.entity.metadata.display.TextDisplayMeta; import net.minestom.server.event.EventNode; import net.minestom.server.event.entity.EntityAttackEvent; import net.minestom.server.event.entity.projectile.ProjectileCollideWithEntityEvent; import net.minestom.server.event.trait.InstanceEvent; -import net.minestom.server.instance.Instance; import net.minestom.server.tag.Tag; import net.minestom.server.utils.MathUtils; import net.minestom.server.utils.time.TimeUnit; @@ -49,7 +44,7 @@ public void hook(@NotNull EventNode node) { float damage = (float) damageFunction.applyAsDouble(projectile, target); - target.damage(DamageType.fromProjectile(projectile.getShooter(), projectile), damage); + target.damage(DamageType.MOB_PROJECTILE, damage); target.setTag(INVULNERABLE_UNTIL_TAG, now + invulnerabilityFunction.applyAsLong(target)); takeKnockbackFromArrow(target, projectile); @@ -72,7 +67,7 @@ public void hook(@NotNull EventNode node) { float damage = (float) damageFunction.applyAsDouble(event.getEntity(), target); - target.damage(DamageType.fromEntity(event.getEntity()), damage); + target.damage(DamageType.MOB_ATTACK, damage); target.setTag(INVULNERABLE_UNTIL_TAG, now + invulnerabilityFunction.applyAsLong(target)); takeKnockback(target, event.getEntity()); @@ -96,27 +91,26 @@ private static void takeKnockbackFromArrow(Entity target, EntityProjectile sourc private static void spawnHologram(Entity target, float damage) { damage = MathUtils.round(damage, 2); - new DamageHologram( - target.getInstance(), - target.getPosition().add(0, target.getEyeHeight(), 0), - Component.text(damage, NamedTextColor.RED) - ); + var hologram = new DamageHologram(Component.text(damage, NamedTextColor.RED)); + hologram.setInstance(target.getInstance(), target.getPosition().add(0, target.getEyeHeight(), 0)); } - private static final class DamageHologram extends Hologram { - private DamageHologram(Instance instance, Pos spawnPosition, Component text) { - super(instance, spawnPosition, text, true, true); - getEntity().getEntityMeta().setHasNoGravity(false); + private static final class DamageHologram extends EntityCreature { + private DamageHologram(Component text) { + super(EntityType.TEXT_DISPLAY); + + TextDisplayMeta hologramMeta = (TextDisplayMeta) this.getEntityMeta(); + hologramMeta.setText(text); Random random = ThreadLocalRandom.current(); - getEntity().setVelocity(getPosition() + this.setVelocity(getPosition() .direction() .withX(random.nextDouble(2)) .withY(3) .withZ(random.nextDouble(2)) .normalize().mul(3)); - getEntity().scheduleRemove(Duration.of(15, TimeUnit.SERVER_TICK)); + this.scheduleRemove(Duration.of(15, TimeUnit.SERVER_TICK)); } } } diff --git a/src/main/java/net/minestom/arena/game/mob/EvokerMob.java b/src/main/java/net/minestom/arena/game/mob/EvokerMob.java index 8c679e7..0d69ecd 100644 --- a/src/main/java/net/minestom/arena/game/mob/EvokerMob.java +++ b/src/main/java/net/minestom/arena/game/mob/EvokerMob.java @@ -11,8 +11,8 @@ import net.minestom.server.entity.ai.target.ClosestEntityTarget; import net.minestom.server.entity.metadata.monster.raider.EvokerMeta; import net.minestom.server.entity.metadata.monster.raider.SpellcasterIllagerMeta; +import net.minestom.server.network.packet.server.play.ParticlePacket; import net.minestom.server.particle.Particle; -import net.minestom.server.particle.ParticleCreator; import net.minestom.server.timer.TaskSchedule; import net.minestom.server.utils.time.Cooldown; import net.minestom.server.utils.time.TimeUnit; @@ -49,10 +49,9 @@ public EvokerMob(MobGenerationContext context) { random.nextFloat(-2, 2) ); silverfish.setInstance(instance, pos); - instance.sendGroupedPacket(ParticleCreator.createParticlePacket( - Particle.POOF, true, pos.x(), pos.y(), pos.z(), - 0.2f, 0.2f, 0.2f, 0.1f, 10, null - )); + + instance.sendGroupedPacket(new ParticlePacket(Particle.POOF, true, pos.x(), pos.y(), pos.z(), + 0.2f, 0.2f, 0.2f, 0.1f, 10)); } ((EvokerMeta) getEntityMeta()).setSpell(SpellcasterIllagerMeta.Spell.NONE); diff --git a/src/main/java/net/minestom/arena/game/mob/MobArena.java b/src/main/java/net/minestom/arena/game/mob/MobArena.java index 5ddb275..cc5c9c0 100644 --- a/src/main/java/net/minestom/arena/game/mob/MobArena.java +++ b/src/main/java/net/minestom/arena/game/mob/MobArena.java @@ -27,7 +27,7 @@ import net.minestom.server.coordinate.Vec; import net.minestom.server.entity.*; import net.minestom.server.entity.damage.DamageType; -import net.minestom.server.entity.metadata.arrow.ArrowMeta; +import net.minestom.server.entity.metadata.projectile.ArrowMeta; import net.minestom.server.event.entity.EntityAttackEvent; import net.minestom.server.event.entity.EntityDeathEvent; import net.minestom.server.event.entity.projectile.ProjectileCollideWithEntityEvent; @@ -39,8 +39,8 @@ import net.minestom.server.instance.Instance; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; +import net.minestom.server.network.packet.server.play.ParticlePacket; import net.minestom.server.particle.Particle; -import net.minestom.server.particle.ParticleCreator; import net.minestom.server.sound.SoundEvent; import net.minestom.server.tag.Tag; import net.minestom.server.timer.TaskSchedule; @@ -600,15 +600,14 @@ public boolean hasOption(@Nullable ArenaOption option) { !instance.getWorldBorder().isInside(pos) || age >= 30) { - explosion(DamageType.fromPlayer(player), instance, pos, 5, 0.5f, 7, 1); + explosion(DamageType.MOB_ATTACK, instance, pos, 5, 0.5f, 7, 1); return TaskSchedule.stop(); } - instance.sendGroupedPacket(ParticleCreator.createParticlePacket( - Particle.FIREWORK, true, pos.x(), pos.y(), pos.z(), - 0.3f, 0.3f, 0.3f, 0.01f, 50, null - )); + instance.sendGroupedPacket(new ParticlePacket(Particle.FIREWORK, pos.x(), pos.y(), pos.z(), + 0.3f, 0.3f, 0.3f, 0.01f, 50)); + instance.playSound( Sound.sound(SoundEvent.ENTITY_AXOLOTL_SWIM, Sound.Source.NEUTRAL, 1, 1), pos.x(), pos.y(), pos.z() @@ -627,14 +626,14 @@ public boolean hasOption(@Nullable ArenaOption option) { final Instance instance = event.getInstance(); final Pos pos = target.getPosition(); - explosion(DamageType.fromProjectile(shooter, projectile), instance, pos, 6, 1, 7, 0.3f); + explosion(DamageType.MOB_PROJECTILE, instance, pos, 6, 1, 7, 0.3f); }).addListener(EntityAttackEvent.class, event -> { if (!(event.getEntity() instanceof Player player)) return; if (!(event.getTarget() instanceof LivingEntity target)) return; final Instance instance = event.getInstance(); final Pos pos = target.getPosition(); - explosion(DamageType.fromPlayer(player), instance, pos, 3, 1f, 3, 0.3f); + explosion(DamageType.MOB_ATTACK, instance, pos, 3, 1f, 3, 0.3f); })); } @@ -642,10 +641,9 @@ public boolean hasOption(@Nullable ArenaOption option) { } private static void explosion(DamageType damageType, Instance instance, Pos pos, int range, float offset, int damage, float volume) { - instance.sendGroupedPacket(ParticleCreator.createParticlePacket( - Particle.EXPLOSION, pos.x(), pos.y(), pos.z(), - offset, offset, offset, 5 - )); + instance.sendGroupedPacket(new ParticlePacket(Particle.EXPLOSION, pos.x(), pos.y(), pos.z(), + offset, offset, offset, 0.01f, 5)); + instance.playSound( Sound.sound(SoundEvent.ENTITY_GENERIC_EXPLODE, Sound.Source.NEUTRAL, volume, 1), pos.x(), pos.y(), pos.z() diff --git a/src/main/java/net/minestom/arena/game/mob/MobTestCommand.java b/src/main/java/net/minestom/arena/game/mob/MobTestCommand.java index 582c846..23283d8 100644 --- a/src/main/java/net/minestom/arena/game/mob/MobTestCommand.java +++ b/src/main/java/net/minestom/arena/game/mob/MobTestCommand.java @@ -83,7 +83,7 @@ public MobTestCommand() { .set(MobArena.MELEE_TAG, 10000).build() ), strong); - addSyntax((sender, context) -> ((Player) sender).damage(DamageType.VOID, 10), damageme); + addSyntax((sender, context) -> ((Player) sender).damage(DamageType.OUT_OF_WORLD, 10), damageme); } private static @NotNull Optional arena(CommandSender sender) { diff --git a/src/main/java/net/minestom/arena/lobby/NPC.java b/src/main/java/net/minestom/arena/lobby/NPC.java index 1e7356a..6a7a594 100644 --- a/src/main/java/net/minestom/arena/lobby/NPC.java +++ b/src/main/java/net/minestom/arena/lobby/NPC.java @@ -151,7 +151,7 @@ public static List spawnNPCs(@NotNull Instance instance) { return List.of( new NPC("Discord", skins.get("Discord"), instance, new Pos(8.5, 15, 8.5), player -> Messenger.info(player, Component.text("Click here to join the Discord server") - .clickEvent(ClickEvent.openUrl("https://discord.gg/minestom")))), + .clickEvent(ClickEvent.openUrl("https://minestom.net/discord")))), new NPC("Website", skins.get("Website"), instance, new Pos(-7.5, 15, 8.5), player -> Messenger.info(player, Component.text("Click here to go to the Minestom website") .clickEvent(ClickEvent.openUrl("https://minestom.net")))), diff --git a/src/main/java/net/minestom/arena/utils/LogbackHighlightConfig.java b/src/main/java/net/minestom/arena/utils/LogbackHighlightConfig.java new file mode 100644 index 0000000..b6e1f81 --- /dev/null +++ b/src/main/java/net/minestom/arena/utils/LogbackHighlightConfig.java @@ -0,0 +1,20 @@ +package net.minestom.arena.utils; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.pattern.color.ANSIConstants; +import ch.qos.logback.core.pattern.color.ForegroundCompositeConverterBase; + +public class LogbackHighlightConfig extends ForegroundCompositeConverterBase { + @Override + protected String getForegroundColorCode(ILoggingEvent event) { + Level level = event.getLevel(); + return switch (level.toInt()) { + case Level.ERROR_INT -> ANSIConstants.BOLD + ANSIConstants.RED_FG; + case Level.WARN_INT -> ANSIConstants.BOLD + ANSIConstants.YELLOW_FG; + case Level.INFO_INT -> ANSIConstants.BLUE_FG; + default -> ANSIConstants.DEFAULT_FG; + }; + } + +} diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..8797e96 --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,14 @@ + + + + + + + %d{HH:mm:ss} %highlightex([%level]): %highlightex(%msg%n) + + + + + + + \ No newline at end of file