Skip to content

Commit

Permalink
Merge pull request #51 from PhantazmNetwork/timer
Browse files Browse the repository at this point in the history
added zombies timer mod + phantazm integration
  • Loading branch information
tahmid-23 authored Jul 15, 2023
2 parents 3cb9322 + 0fab7f2 commit 991a4ff
Show file tree
Hide file tree
Showing 40 changed files with 1,126 additions and 70 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
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>
2 changes: 1 addition & 1 deletion .run/Run server.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<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>
15 changes: 12 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ examination-string = { module = "net.kyori:examination-string", version.ref = "e

caffeine = { module = "com.github.ben-manes.caffeine:caffeine", version = "3.1.1" }

cloth-config = { module = "me.shedaniel.cloth:cloth-config-fabric", version = "11.1.106" }

commons-lang3 = { module = "org.apache.commons:commons-lang3", version = "3.12.0" }

element-core = { module = "com.github.steanky:element-core", version = "0.14.3" }
Expand All @@ -40,7 +42,8 @@ ethylene-yaml = { module = "com.github.steanky:ethylene-yaml", version.ref = "et
ethylene-mapper = { module = "com.github.steanky:ethylene-mapper", version.ref = "ethylene" }

fabric-loader = { module = "net.fabricmc:fabric-loader", version = "0.14.21" }
fabric-api = { module = "net.fabricmc.fabric-api:fabric-api", version = "0.83.0+1.19.4" }
fabric-api-oneNineteen = { module = "net.fabricmc.fabric-api:fabric-api", version = "0.83.0+1.19.4" }
fabric-api-oneTwenty = { module = "net.fabricmc.fabric-api:fabric-api", version = "0.85.0+1.20.1" }

fastutil = { module = "it.unimi.dsi:fastutil", version = "8.5.8" }

Expand All @@ -60,14 +63,18 @@ libgui = { module = "io.github.cottonmc:LibGui", version = "7.1.0+1.19.4" }

mariadb = { module = "org.mariadb.jdbc:mariadb-java-client", version = "3.0.10" }

minecraft = { module = "com.mojang:minecraft", version = "1.19.4" }
minecraft-oneNineteen = { module = "com.mojang:minecraft", version = "1.19.4" }

minecraft-oneTwenty = { module = "com.mojang:minecraft", version = "1.20.1" }

minestom = { module = "org.phantazm.Minestom:Minestom", version.ref = "minestom" }

minestom-testing = { module = "org.phantazm.Minestom:testing", version.ref = "minestom" }

mockito-junit-jupiter = { module = "org.mockito:mockito-junit-jupiter", version = "4.7.0" }

modmenu = { module = "com.terraformersmc:modmenu", version = "7.1.0" }

proxima-core = { module = "com.github.steanky:proxima-core", version = "0.6.4" }

renderer = { module = "com.github.0x3C50:Renderer", version = "e1bb03f45e" }
Expand All @@ -83,7 +90,9 @@ vector-core = { module = "com.github.steanky:vector-core", version = "0.9.2" }

velocity-api = { module = "com.velocitypowered:velocity-api", version = "3.1.2-SNAPSHOT" }

yarn-mappings = { module = "net.fabricmc:yarn", version = "1.19.4+build.2" }
yarn-mappings-oneNineteen = { module = "net.fabricmc:yarn", version = "1.19.4+build.2" }

yarn-mappings-oneTwenty = { module = "net.fabricmc:yarn", version = "1.20.1+build.9" }

[plugins]
fabric-loom = { id = "fabric-loom", version = "1.1.9" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void handleData(@NotNull TOutputReceiver outputReceiver, byte @NotNull []
* @param outputReceiver The output receiver
* @param packet The packet to send
*/
protected void output(@NotNull TOutputReceiver outputReceiver, @NotNull Packet packet) {
public void output(@NotNull TOutputReceiver outputReceiver, @NotNull Packet packet) {
sendToReceiver(outputReceiver, packetSerializer.serializePacket(packet));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.phantazm.messaging.packet.c2s;

import org.jetbrains.annotations.NotNull;
import org.phantazm.messaging.packet.Packet;
import org.phantazm.messaging.serialization.DataReader;
import org.phantazm.messaging.serialization.DataWriter;

import java.util.Objects;

public record RoundStartPacket() implements Packet {

public static final byte ID = 0;

public static @NotNull RoundStartPacket read(@NotNull DataReader reader) {
Objects.requireNonNull(reader, "reader");
return new RoundStartPacket();
}

@Override
public byte getId() {
return ID;
}

@Override
public void write(@NotNull DataWriter dataWriter) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import org.phantazm.messaging.packet.Packet;
import org.phantazm.messaging.packet.c2p.MapDataVersionQueryPacket;
import org.phantazm.messaging.packet.c2p.MapDataVersionResponsePacket;
import org.phantazm.messaging.packet.c2s.RoundStartPacket;

import java.util.Collections;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
Expand All @@ -15,9 +15,12 @@
*/
public final class PacketSerializers {

private static final Map<Byte, Function<DataReader, Packet>> clientToServerDeserializers;

private static final Map<Byte, Function<DataReader, Packet>> clientToProxyDeserializers;

static {
clientToServerDeserializers = Map.of(RoundStartPacket.ID, RoundStartPacket::read);
clientToProxyDeserializers =
Map.of(MapDataVersionQueryPacket.ID, MapDataVersionQueryPacket::read, MapDataVersionResponsePacket.ID,
MapDataVersionResponsePacket::read);
Expand All @@ -29,7 +32,7 @@ private PacketSerializers() {

public static @NotNull PacketSerializer clientToServerSerializer(@NotNull Supplier<DataWriter> writerCreator,
@NotNull Function<byte[], DataReader> readerCreator) {
return new PacketSerializer(Collections.emptyMap(), writerCreator, readerCreator);
return new PacketSerializer(clientToServerDeserializers, writerCreator, readerCreator);
}

public static @NotNull PacketSerializer clientToProxySerializer(@NotNull Supplier<DataWriter> writerCreator,
Expand Down
29 changes: 17 additions & 12 deletions server/src/main/java/org/phantazm/server/MessagingFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.phantazm.messaging.packet.PacketHandler;
import org.phantazm.messaging.serialization.PacketSerializer;
import org.phantazm.messaging.serialization.PacketSerializers;
import org.phantazm.server.config.server.AuthType;
import org.phantazm.server.packet.BinaryDataReader;
import org.phantazm.server.packet.BinaryDataWriter;

Expand All @@ -25,27 +24,30 @@
*/
public final class MessagingFeature {

private static PacketHandler<Player> clientToServerHandler;

private MessagingFeature() {
throw new UnsupportedOperationException();
}

static void initialize(@NotNull EventNode<Event> global, @NotNull AuthType authType) {
static void initialize(@NotNull EventNode<Event> global) {
PacketSerializer clientToServer =
PacketSerializers.clientToServerSerializer(() -> new BinaryDataWriter(new BinaryWriter()),
data -> new BinaryDataReader(new BinaryReader(data)));
Key clientToServerIdentifier = Key.key(Namespaces.PHANTAZM, MessageChannels.CLIENT_TO_SERVER);
Map<String, PacketHandler<Player>> packetHandlers =
Map.of(MessageChannels.CLIENT_TO_SERVER, new PacketHandler<>(clientToServer) {
@Override
protected void handlePacket(@NotNull Player player, @NotNull Packet packet) {
clientToServerHandler = new PacketHandler<>(clientToServer) {
@Override
protected void handlePacket(@NotNull Player player, @NotNull Packet packet) {

}
}

@Override
protected void sendToReceiver(@NotNull Player player, byte @NotNull [] data) {
player.sendPluginMessage(clientToServerIdentifier.toString(), data);
}
});
@Override
protected void sendToReceiver(@NotNull Player player, byte @NotNull [] data) {
player.sendPluginMessage(clientToServerIdentifier.toString(), data);
}
};
Map<String, PacketHandler<Player>> packetHandlers =
Map.of(MessageChannels.CLIENT_TO_SERVER, clientToServerHandler);

global.addListener(PlayerPluginMessageEvent.class, event -> {
String identifier = event.getIdentifier();
Expand All @@ -67,4 +69,7 @@ protected void sendToReceiver(@NotNull Player player, byte @NotNull [] data) {
});
}

public static @NotNull PacketHandler<Player> getClientToServerHandler() {
return FeatureUtils.check(clientToServerHandler);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private static void initializeFeatures(KeyParser keyParser, EventNode<Event> glo
LobbyFeature.initialize(global, viewProvider, lobbiesConfig, contextManager);
ChatFeature.initialize(global, viewProvider, chatConfig, PartyFeature.getPartyHolder().uuidToGuild(),
MinecraftServer.getCommandManager());
MessagingFeature.initialize(global, serverConfig.serverInfoConfig().authType());
MessagingFeature.initialize(global);
CommandFeature.initialize(MinecraftServer.getCommandManager(), routerStore, viewProvider,
LobbyFeature.getFallback());

Expand Down
10 changes: 6 additions & 4 deletions server/src/main/java/org/phantazm/server/ZombiesFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,12 @@ static void initialize(@NotNull EventNode<Event> globalEventNode, @NotNull Conte
return new InstanceClientBlockHandler(instance, dimensionType.getMinY(),
dimensionType.getHeight());
}, globalEventNode), contextManager, keyParser, mobNoPushTeam, corpseTeam, database,
ZombiesFeature.powerups(), new BasicZombiesPlayerSource(database, viewProvider,
EquipmentFeature::createEquipmentCreator, MobFeature.getModels(), contextManager,
keyParser), mapDependencyProvider -> contextManager.makeContext(entry.getValue().corpse())
.provide(mapDependencyProvider), songLoader);
MessagingFeature.getClientToServerHandler(), ZombiesFeature.powerups(),
new BasicZombiesPlayerSource(database, viewProvider,
EquipmentFeature::createEquipmentCreator, MobFeature.getModels(), contextManager,
keyParser),
mapDependencyProvider -> contextManager.makeContext(entry.getValue().corpse())
.provide(mapDependencyProvider), songLoader);
providers.put(entry.getKey(), provider);
}

Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ sequenceOf(
"proxima-minestom",
"server",
"stats",
"zombies-timer",
"velocity",
"zombies",
"zombies-mapdata",
Expand Down
12 changes: 5 additions & 7 deletions zombies-mapeditor/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// https://youtrack.jetbrains.com/issue/KTIJ-19369/False-positive-can-t-be-called-in-this-context-by-implicit-recei
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
id("phantazm.java-library-conventions")
id("phantazm.java-conventions")

alias(libs.plugins.fabric.loom)
}
Expand Down Expand Up @@ -33,16 +33,16 @@ repositories {
}

dependencies {
minecraft(libs.minecraft)
mappings(libs.yarn.mappings) {
minecraft(libs.minecraft.oneNineteen)
mappings(libs.yarn.mappings.oneNineteen) {
artifact {
classifier = "v2"
}
}

modImplementation(libs.fabric.loader)
modImplementation(libs.libgui)
modImplementation(libs.fabric.api)
modImplementation(libs.fabric.api.oneNineteen)
modImplementation(libs.renderer)

implementation(projects.phantazmCommons)
Expand Down Expand Up @@ -83,8 +83,6 @@ tasks.compileJava {

tasks.jar {
from("../LICENSE") {
rename {
"${it}_${base.archivesName.get()}"
}
rename { "${it}_${archiveBaseName.get()}" }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.fabricmc.loader.api.FabricLoader;
import net.kyori.adventure.key.Key;
Expand All @@ -24,7 +25,6 @@
import net.minecraft.client.util.InputUtil;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
Expand All @@ -44,6 +44,7 @@
import org.phantazm.zombies.map.MapSettingsInfo;
import org.phantazm.zombies.mapeditor.client.packet.PacketByteBufDataReader;
import org.phantazm.zombies.mapeditor.client.packet.PacketByteBufDataWriter;
import org.phantazm.zombies.mapeditor.client.packet.PhantazmPacket;
import org.phantazm.zombies.mapeditor.client.render.ObjectRenderer;
import org.phantazm.zombies.mapeditor.client.ui.MainGui;
import org.phantazm.zombies.mapeditor.client.ui.NewObjectGui;
Expand Down Expand Up @@ -89,16 +90,10 @@ public void onInitializeClient() {
TranslationKeys.CATEGORY_MAPEDITOR_ALL));

PacketSerializer clientToProxy = PacketSerializers.clientToProxySerializer(
() -> new PacketByteBufDataWriter(new PacketByteBuf(Unpooled.buffer())),
() -> new PacketByteBufDataWriter(PacketByteBufs.create()),
data -> new PacketByteBufDataReader(new PacketByteBuf(Unpooled.wrappedBuffer(data))));
Identifier clientToProxyIdentifier = Identifier.of(Namespaces.PHANTAZM, MessageChannels.CLIENT_TO_PROXY);
if (clientToProxyIdentifier != null) {
ClientPlayConnectionEvents.JOIN.register(((handler, sender, client) -> {
byte[] data = clientToProxy.serializePacket(new MapDataVersionQueryPacket());
sender.sendPacket(new CustomPayloadC2SPacket(clientToProxyIdentifier,
new PacketByteBuf(Unpooled.wrappedBuffer(data))));
}));

PacketHandler<PacketSender> clientToProxyHandler = new PacketHandler<>(clientToProxy) {
@Override
protected void handlePacket(@NotNull PacketSender packetSender, @NotNull Packet packet) {
Expand All @@ -125,10 +120,12 @@ protected void sendToReceiver(@NotNull PacketSender packetSender, byte @NotNull
packetSender.sendPacket(clientToProxyIdentifier, new PacketByteBuf(Unpooled.wrappedBuffer(data)));
}
};
ClientPlayNetworking.registerGlobalReceiver(clientToProxyIdentifier,
(client, handler, buf, responseSender) -> {
clientToProxyHandler.handleData(responseSender, buf.getWrittenBytes());
});
ClientPlayConnectionEvents.JOIN.register(((handler, sender, client) -> {
clientToProxyHandler.output(sender, new MapDataVersionQueryPacket());
}));
ClientPlayNetworking.registerGlobalReceiver(PhantazmPacket.TYPE, ((packet, player, responseSender) -> {
clientToProxyHandler.handleData(responseSender, packet.data());
}));
}

ClientTickEvents.END_CLIENT_TICK.register(new ClientTickEvents.EndTick() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.phantazm.zombies.mapeditor.client.packet;

import net.fabricmc.fabric.api.networking.v1.FabricPacket;
import net.fabricmc.fabric.api.networking.v1.PacketType;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;
import org.phantazm.commons.Namespaces;
import org.phantazm.messaging.MessageChannels;

public record PhantazmPacket(byte @NotNull [] data) implements FabricPacket {

public static final PacketType<PhantazmPacket> TYPE =
PacketType.create(new Identifier(Namespaces.PHANTAZM, MessageChannels.CLIENT_TO_SERVER),
PhantazmPacket::new);

public PhantazmPacket(PacketByteBuf buf) {
this(buf.getWrittenBytes());
}

@Override
public void write(PacketByteBuf buf) {
buf.writeBytes(data);
}

@Override
public PacketType<?> getType() {
return TYPE;
}

}
Loading

0 comments on commit 991a4ff

Please sign in to comment.