Skip to content

Commit

Permalink
Merge pull request #49 from PhantazmNetwork/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
Steanky authored Jun 26, 2023
2 parents 7e95d7e + 813ba8a commit 4337aa9
Show file tree
Hide file tree
Showing 263 changed files with 6,405 additions and 2,327 deletions.
16 changes: 3 additions & 13 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
Expand Down Expand Up @@ -48,16 +50,4 @@ jobs:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
script: |
tmux -S /home/prod/tmux_sockets/prod send-keys -t prod 'stop' Enter
rm -rf /home/prod/archive/config
rm -rf /home/prod/archive/build
mkdir /home/prod/archive/config
mkdir /home/prod/archive/build
git clone [email protected]:PhantazmNetwork/Configuration.git /home/prod/archive/config
tar -xf /home/prod/archive/server.tar.gz -C /home/prod/archive/build
rsync -ac --delete /home/prod/archive/build/ /home/prod/servers/prod
rsync -ac /home/prod/archive/config/ /home/prod/servers/prod
rsync -ac /home/prod/archive/persistent/ /home/prod/servers/prod
tmux -S /home/prod/tmux_sockets/prod send-keys -t prod 'cd /home/prod/servers/prod' Enter
tmux -S /home/prod/tmux_sockets/prod send-keys -t prod 'chmod +x ./start.sh' Enter
tmux -S /home/prod/tmux_sockets/prod send-keys -t prod './start.sh' Enter
/home/prod/archive/sync.sh
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "minestom"]
path = minestom
url = https://github.com/PhantazmNetwork/Minestom
branch = master
2 changes: 1 addition & 1 deletion .run/Run server.run.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<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" />
<option name="VM_PARAMETERS" value="-Dfile.encoding=UTF-8 -Dminestom.packet-queue-size=-1" />
<option name="PROGRAM_PARAMETERS" value="unsafe" />
<option name="WORKING_DIRECTORY" value="$ProjectFileDir$/run/server-1" />
<option name="ALTERNATIVE_JRE_PATH" />
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This project started out of a perceived lack of PvE-focused Minecraft servers. W
## Install

To build Phantazm binaries from source, run the following commands: \
`git clone https://github.com/PhantazmNetwork/PhantazmServer.git` \
`git clone --recurse-submodules https://github.com/PhantazmNetwork/PhantazmServer.git` \
`cd PhantazmServer` \
`./gradlew build`

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ repositories {

kotlin {
jvmToolchain {
(this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(17))
languageVersion.set(JavaLanguageVersion.of(17))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.gradle.api.tasks.TaskAction
import java.io.File

abstract class SetupServer : DefaultTask() {
var dataFolder: File = project.rootDir.resolve("runData")
var dataFolder: File = project.rootDir.resolve("defaultRunData")
@Internal get

@TaskAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void scheduleTaskNow(@NotNull TickableTask tickableTask) {

@Override
public void scheduleTaskAfter(@NotNull TickableTask tickableTask, long millis) {
Objects.requireNonNull(tickableTask, "tickableTask");
long startTime = System.currentTimeMillis();
tickableTasks.add(new TickableTask() {
private boolean finished;
Expand All @@ -41,6 +42,15 @@ public void tick(long time) {
});
}

@Override
public void end() {
for (TickableTask tickableTask : tickableTasks) {
tickableTask.end();
}

tickableTasks.clear();
}

@Override
public void tick(long time) {
Iterator<TickableTask> taskIterator = tickableTasks.iterator();
Expand Down
37 changes: 37 additions & 0 deletions commons/src/main/java/org/phantazm/commons/CancellableState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.phantazm.commons;

import org.jetbrains.annotations.NotNull;

import java.util.Objects;
import java.util.UUID;

public interface CancellableState {
void start();

void end();

@NotNull UUID id();

static @NotNull CancellableState named(@NotNull UUID id, @NotNull Runnable start, @NotNull Runnable end) {
Objects.requireNonNull(id, "id");
Objects.requireNonNull(start, "start");
Objects.requireNonNull(end, "end");

return new CancellableState() {
@Override
public void start() {
start.run();
}

@Override
public void end() {
end.run();
}

@Override
public @NotNull UUID id() {
return id;
}
};
}
}
42 changes: 42 additions & 0 deletions commons/src/main/java/org/phantazm/commons/MiniMessageUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.phantazm.commons;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.jetbrains.annotations.NotNull;

public class MiniMessageUtils {

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

public static @NotNull TagResolver optional(@NotNull String key, boolean present) {
return TagResolver.resolver(key, (argumentQueue, context) -> {
String message = argumentQueue.pop().value();
Component result;
if (present) {
result = context.deserialize(message);
} else {
result = Component.empty();
}

return Tag.selfClosingInserting(result);
});
}

public static @NotNull TagResolver list(@NotNull String key,
@NotNull Iterable<? extends ComponentLike> components) {
return TagResolver.resolver(key, (argumentQueue, context) -> {
String separatorString = argumentQueue.pop().value();
Component separator = context.deserialize(separatorString);

Component result = Component.join(JoinConfiguration.separator(separator), components);
return Tag.inserting(result);
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ public interface TickTaskScheduler extends Tickable {
void scheduleTaskNow(@NotNull TickableTask tickableTask);

void scheduleTaskAfter(@NotNull TickableTask tickableTask, long millis);

void end();
}
4 changes: 4 additions & 0 deletions commons/src/main/java/org/phantazm/commons/TickableTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

public interface TickableTask extends Tickable {
boolean isFinished();

default void end() {

}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package org.phantazm.core;

import net.minestom.server.event.Event;
import net.minestom.server.event.EventNode;
import net.minestom.server.event.instance.InstanceUnregisterEvent;
import net.minestom.server.instance.Instance;
import org.jetbrains.annotations.NotNull;

import java.util.Map;
import java.util.Objects;
import java.util.WeakHashMap;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

/**
* Standard implementation of {@link ClientBlockHandlerSource}. Does not maintain strong references to Instance objects.
* Standard implementation of {@link ClientBlockHandlerSource}.
*/
public class BasicClientBlockHandlerSource implements ClientBlockHandlerSource {
private final Function<? super Instance, ? extends ClientBlockHandler> blockHandlerFunction;
private final Map<Instance, ClientBlockHandler> map;
private final Object sync;
private final Map<UUID, ClientBlockHandler> map;

/**
* Creates a new instance of this class given the provided {@link ClientBlockHandler}-producing function. This
Expand All @@ -23,17 +24,26 @@ public class BasicClientBlockHandlerSource implements ClientBlockHandlerSource {
* @param handlerFunction the handler function, which should never return null
*/
public BasicClientBlockHandlerSource(
@NotNull Function<? super Instance, ? extends ClientBlockHandler> handlerFunction) {
@NotNull Function<? super Instance, ? extends ClientBlockHandler> handlerFunction,
@NotNull EventNode<Event> globalNode) {
this.blockHandlerFunction = Objects.requireNonNull(handlerFunction, "handlerFunction");
this.map = new WeakHashMap<>();
this.sync = new Object();
this.map = new ConcurrentHashMap<>();

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

@Override
public @NotNull ClientBlockHandler forInstance(@NotNull Instance instance) {
synchronized (sync) {
return map.computeIfAbsent(Objects.requireNonNull(instance, "instance"),
world -> Objects.requireNonNull(this.blockHandlerFunction.apply(world), "handler"));
}
return map.computeIfAbsent(instance.getUniqueId(), ignored -> {
if (!instance.isRegistered()) {
throw new IllegalArgumentException("Cannot hold an unregistered instance");
}

return Objects.requireNonNull(this.blockHandlerFunction.apply(instance), "handler");
});
}

private void onInstanceUnregister(InstanceUnregisterEvent event) {
map.remove(event.getInstance().getUniqueId());
}
}
27 changes: 27 additions & 0 deletions core/src/main/java/org/phantazm/core/ComponentUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.phantazm.core;

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

import java.util.IllegalFormatException;
import java.util.Objects;

public final class ComponentUtils {
private ComponentUtils() {
}

public static @NotNull Component tryFormat(@NotNull String formatString, Object... objects) {
Objects.requireNonNull(formatString, "formatString");

String message;
try {
message = String.format(formatString, objects);
}
catch (IllegalFormatException ignored) {
message = formatString;
}

return MiniMessage.miniMessage().deserialize(message);
}
}
Loading

0 comments on commit 4337aa9

Please sign in to comment.