Skip to content

Commit

Permalink
Merge pull request #54 from PhantazmNetwork/dev
Browse files Browse the repository at this point in the history
Dev --> Main
  • Loading branch information
Steanky authored Jul 30, 2023
2 parents 6780702 + 9abfe6f commit c4ce21f
Show file tree
Hide file tree
Showing 429 changed files with 10,983 additions and 3,198 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
cache: 'gradle'
distribution: 'adopt'
- name: Set up server
run: ./gradlew -PskipBuild=zombies-mapeditor :phantazm-server:setupServer
run: ./gradlew -PskipBuild=zombies-mapeditor,zombies-timer :phantazm-server:setupServer
- name: Build & copy jar
run: ./gradlew -PskipBuild=zombies-mapeditor :phantazm-server:copyJar
run: ./gradlew -PskipBuild=zombies-mapeditor,zombies-timer :phantazm-server:copyJar
- name: Zip server files
run: |
cd ./run/server-1
Expand Down
34 changes: 18 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
name: Test PhantazmServer

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
cache: 'gradle'
distribution: 'adopt'
- name: Run tests
run: ./gradlew test
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
cache: 'gradle'
distribution: 'adopt'
- name: Run tests
run: ./gradlew test
25 changes: 11 additions & 14 deletions .run/Run Velocity.run.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run Velocity" type="JarApplication">
<option name="JAR_PATH" value="$PROJECT_DIR$/run/velocity/velocity.jar"/>
<option name="VM_PARAMETERS"
value="-Xms512M -Xmx512M -XX:+UseG1GC -XX:G1HeapRegionSize=4M -XX:+UnlockExperimentalVMOptions -XX:+ParallelRefProcEnabled -XX:+AlwaysPreTouch -Dfile.encoding=UTF-8"/>
<option name="WORKING_DIRECTORY" value="$ProjectFileDir$\run\velocity"/>
<option name="ALTERNATIVE_JRE_PATH"/>
<method v="2">
<option name="Gradle.BeforeRunTask" enabled="false" tasks="setupServer"
externalProjectPath="$PROJECT_DIR$/server" vmOptions="" scriptParameters=""/>
<option name="Gradle.BeforeRunTask" enabled="true" tasks="copyJar"
externalProjectPath="$PROJECT_DIR$/velocity" vmOptions="" scriptParameters=""/>
</method>
</configuration>
</component>
<configuration default="false" name="Run Velocity" type="JarApplication">
<option name="JAR_PATH" value="$PROJECT_DIR$/run/velocity/velocity.jar" />
<option name="VM_PARAMETERS" value="-Xms512M -Xmx512M -XX:+UseG1GC -XX:G1HeapRegionSize=4M -XX:+UnlockExperimentalVMOptions -XX:+ParallelRefProcEnabled -XX:+AlwaysPreTouch -Dfile.encoding=UTF-8" />
<option name="WORKING_DIRECTORY" value="$ProjectFileDir$/run/velocity" />
<option name="ALTERNATIVE_JRE_PATH" />
<method v="2">
<option name="Gradle.BeforeRunTask" enabled="false" tasks="setupServer" externalProjectPath="$PROJECT_DIR$/server" vmOptions="" scriptParameters="" />
<option name="Gradle.BeforeRunTask" enabled="true" tasks="copyJar" externalProjectPath="$PROJECT_DIR$/velocity" vmOptions="" scriptParameters="" />
</method>
</configuration>
</component>
4 changes: 2 additions & 2 deletions .run/Run server.run.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run server" type="JarApplication">
<option name="JAR_PATH" value="$PROJECT_DIR$/run/server-1/server.jar" />
<option name="VM_PARAMETERS" value="-Dfile.encoding=UTF-8 -Dminestom.packet-queue-size=-1" />
<option name="VM_PARAMETERS" value="-Dfile.encoding=UTF-8 -Dminestom.packet-queue-size=-1 -Dminestom.keep-alive-kick=-1" />
<option name="PROGRAM_PARAMETERS" value="unsafe" />
<option name="WORKING_DIRECTORY" value="$ProjectFileDir$/run/server-1" />
<option name="ALTERNATIVE_JRE_PATH" />
<method v="2">
<option name="Gradle.BeforeRunTask" enabled="false" tasks="setupServer copyJar" externalProjectPath="$PROJECT_DIR$/server" vmOptions="" scriptParameters="-PskipBuild=zombies-mapeditor" />
<option name="Gradle.BeforeRunTask" enabled="false" tasks="setupServer copyJar" externalProjectPath="$PROJECT_DIR$/server" vmOptions="" scriptParameters="-PskipBuild=zombies-mapeditor,zombies-timer" />
</method>
</configuration>
</component>
4 changes: 4 additions & 0 deletions commons/src/main/java/org/phantazm/commons/MathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ private MathUtils() {
throw new UnsupportedOperationException();
}

public static boolean fuzzyEquals(double a, double b, double epsilon) {
return Math.abs(a - b) < epsilon;
}

public static long randomInterval(long min, long max) {
return (long)(Math.random() * (min - max)) + min;
}
Expand Down
29 changes: 29 additions & 0 deletions commons/src/main/java/org/phantazm/commons/TickableTask.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
package org.phantazm.commons;

import org.jetbrains.annotations.NotNull;

public interface TickableTask extends Tickable {
boolean isFinished();

default void end() {

}

static @NotNull TickableTask afterTicks(long ticks, @NotNull Runnable action, @NotNull Runnable endAction) {
long start = System.currentTimeMillis();
return new TickableTask() {
private boolean finished;

@Override
public boolean isFinished() {
return finished;
}

@Override
public void tick(long time) {
if ((time - start) / 50 >= ticks) {
finished = true;
action.run();
}
}

@Override
public void end() {
if (!finished) {
endAction.run();
}
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.phantazm.commons.chat;

public enum ChatDestination {
TITLE,
SUBTITLE,
CHAT,
ACTION_BAR
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.phantazm.commons.chat;

import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;

public record MessageWithDestination(@NotNull Component component, @NotNull ChatDestination destination) {

}
1 change: 1 addition & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {

dependencies {
api(projects.phantazmCommons)
api(projects.phantazmMessaging)
api(libs.ethylene.core)
api(libs.ethylene.mapper)
api(libs.commons.lang3)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
package org.phantazm.core;

import net.minestom.server.event.Event;
import net.minestom.server.event.EventFilter;
import net.minestom.server.event.EventNode;
import net.minestom.server.event.instance.InstanceUnregisterEvent;
import net.minestom.server.event.trait.InstanceEvent;
import net.minestom.server.instance.Instance;
import net.minestom.server.world.DimensionType;
import org.jetbrains.annotations.NotNull;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

/**
* Standard implementation of {@link ClientBlockHandlerSource}.
*/
public class BasicClientBlockHandlerSource implements ClientBlockHandlerSource {
private final Function<? super Instance, ? extends ClientBlockHandler> blockHandlerFunction;
private final Map<UUID, ClientBlockHandler> map;

/**
* Creates a new instance of this class given the provided {@link ClientBlockHandler}-producing function. This
* function must never return null.
*
* @param handlerFunction the handler function, which should never return null
*/
public BasicClientBlockHandlerSource(
@NotNull Function<? super Instance, ? extends ClientBlockHandler> handlerFunction,
@NotNull EventNode<Event> globalNode) {
this.blockHandlerFunction = Objects.requireNonNull(handlerFunction, "handlerFunction");
private final EventNode<Event> rootNode;
private final Map<UUID, Node> map;

private record Node(@NotNull ClientBlockHandler handler, @NotNull EventNode<InstanceEvent> node) {
}

public BasicClientBlockHandlerSource(@NotNull EventNode<Event> rootNode) {
this.rootNode = rootNode;
this.map = new ConcurrentHashMap<>();

globalNode.addListener(InstanceUnregisterEvent.class, this::onInstanceUnregister);
rootNode.addListener(InstanceUnregisterEvent.class, this::onInstanceUnregister);
}

@Override
Expand All @@ -39,11 +36,24 @@ public BasicClientBlockHandlerSource(
throw new IllegalArgumentException("Cannot hold an unregistered instance");
}

return Objects.requireNonNull(this.blockHandlerFunction.apply(instance), "handler");
});
EventNode<InstanceEvent> instanceNode =
EventNode.type("client_block_handler_" + instance.getUniqueId(), EventFilter.INSTANCE,
(e, v) -> v == instance);
DimensionType type = instance.getDimensionType();
Node node =
new Node(new InstanceClientBlockHandler(instance, type.getMinY(), type.getHeight(), instanceNode),
instanceNode);

rootNode.addChild(instanceNode);

return node;
}).handler;
}

private void onInstanceUnregister(InstanceUnregisterEvent event) {
map.remove(event.getInstance().getUniqueId());
Node node = map.remove(event.getInstance().getUniqueId());
if (node != null) {
rootNode.removeChild(node.node);
}
}
}
27 changes: 0 additions & 27 deletions core/src/main/java/org/phantazm/core/ComponentUtils.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ public class InstanceClientBlockHandler implements ClientBlockHandler {
* @param instance the instance this handler is bound to
* @param chunkFloor the minimum y-coordinate of chunks in this instance
*/
public InstanceClientBlockHandler(@NotNull Instance instance, int chunkFloor, int chunkHeight) {
public InstanceClientBlockHandler(@NotNull Instance instance, int chunkFloor, int chunkHeight,
@NotNull EventNode<InstanceEvent> instanceNode) {
this.instance = Objects.requireNonNull(instance, "instance");
this.clientData = new Long2ObjectOpenHashMap<>();
this.chunkFloor = chunkFloor;
this.chunkHeight = chunkHeight;

EventNode<InstanceEvent> node = instance.eventNode();
node.addListener(PreBlockChangeEvent.class, this::onPreBlockChange);
node.addListener(PlayerBlockBreakEvent.class, this::onPlayerBlockBreak);
node.addListener(PrePlayerStartDiggingEvent.class, this::onPrePlayerStartDigging);
node.addListener(PreSendChunkEvent.class, this::onPreSendChunk);
node.addListener(InstanceChunkUnloadEvent.class, this::onChunkUnload);
instanceNode.addListener(PreBlockChangeEvent.class, this::onPreBlockChange);
instanceNode.addListener(PlayerBlockBreakEvent.class, this::onPlayerBlockBreak);
instanceNode.addListener(PrePlayerStartDiggingEvent.class, this::onPrePlayerStartDigging);
instanceNode.addListener(PreSendChunkEvent.class, this::onPreSendChunk);
instanceNode.addListener(InstanceChunkUnloadEvent.class, this::onChunkUnload);
}

@Override
Expand Down
44 changes: 44 additions & 0 deletions core/src/main/java/org/phantazm/core/ItemStackUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.phantazm.core;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import org.jglrxavpok.hephaistos.nbt.NBTException;
import org.jglrxavpok.hephaistos.parser.SNBTParser;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

public final class ItemStackUtils {
public static @NotNull ItemStack buildItem(@NotNull Material material, @Nullable String tag,
@Nullable String displayName, @Nullable List<String> lore, @NotNull TagResolver @NotNull ... tags) {
ItemStack.Builder builder = ItemStack.builder(material);
if (tag != null) {
try {
builder.meta((NBTCompound)new SNBTParser(new StringReader(tag)).parse());
}
catch (NBTException ignored) {
}
}

if (displayName != null) {
builder.displayName(MiniMessage.miniMessage().deserialize(displayName, tags));
}

if (lore != null) {
List<Component> components = new ArrayList<>(lore.size());
for (String format : lore) {
components.add(MiniMessage.miniMessage().deserialize(format, tags));
}
builder.lore(components);
}

return builder.build();
}
}
9 changes: 9 additions & 0 deletions core/src/main/java/org/phantazm/core/Tags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.phantazm.core;

import net.minestom.server.tag.Tag;

import java.util.UUID;

public final class Tags {
public static final Tag<UUID> LAST_MELEE_HIT_TAG = Tag.UUID("last_melee_hit");
}
Loading

0 comments on commit c4ce21f

Please sign in to comment.