Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nukkit Support #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions nukkit/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2016-2021 Daniel Ennis (Aikar) - MIT License
~
~ Permission is hereby granted, free of charge, to any person obtaining
~ a copy of this software and associated documentation files (the
~ "Software"), to deal in the Software without restriction, including
~ without limitation the rights to use, copy, modify, merge, publish,
~ distribute, sublicense, and/or sell copies of the Software, and to
~ permit persons to whom the Software is furnished to do so, subject to
~ the following conditions:
~
~ The above copyright notice and this permission notice shall be
~ included in all copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
~ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
~ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
~ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
~ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
~ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
~ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>co.aikar</groupId>
<artifactId>taskchain-parent</artifactId>
<version><!--VERSION-->3.7.3-SNAPSHOT<!--VERSION--></version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>taskchain-nukkit</artifactId>
<version><!--VERSION-->3.7.3-SNAPSHOT<!--VERSION--></version>
<packaging>jar</packaging>
<name>TaskChain (Nukkit)</name>

<repositories>
<repository>
<id>opencollab-repo-snapshot</id>
<url>https://repo.opencollab.dev/maven-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>co.aikar</groupId>
<artifactId>taskchain-core</artifactId>
<version><!--VERSION-->3.7.3-SNAPSHOT<!--VERSION--></version>
</dependency>
<dependency>
<groupId>cn.nukkit</groupId>
<artifactId>nukkit</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
112 changes: 112 additions & 0 deletions nukkit/src/main/java/co/aikar/taskchain/NukkitTaskChainFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (c) 2016-2021 Daniel Ennis (Aikar) - MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package co.aikar.taskchain;

import cn.nukkit.Player;
import cn.nukkit.event.EventHandler;
import cn.nukkit.event.Listener;
import cn.nukkit.event.plugin.PluginDisableEvent;
import cn.nukkit.plugin.Plugin;

import java.util.concurrent.TimeUnit;

public class NukkitTaskChainFactory extends TaskChainFactory {

private NukkitTaskChainFactory(Plugin plugin, AsyncQueue asyncQueue) {
super(new NukkitGameInterface(plugin, asyncQueue));
}

public static TaskChainFactory create(Plugin plugin) {
return new NukkitTaskChainFactory(plugin, new TaskChainAsyncQueue());
}

private static class NukkitGameInterface implements GameInterface {

private final Plugin plugin;

private final AsyncQueue asyncQueue;

private NukkitGameInterface(Plugin plugin, AsyncQueue asyncQueue) {
this.plugin = plugin;
this.asyncQueue = asyncQueue;
}

@Override
public boolean isMainThread() {
return this.plugin.getServer().isPrimaryThread();
}

@Override
public AsyncQueue getAsyncQueue() {
return this.asyncQueue;
}

@Override
public void postToMain(Runnable run) {
if (this.plugin.isEnabled()) {
this.plugin.getServer().getScheduler().scheduleTask(this.plugin, run);
return;
}

run.run();
}

@Override
public void scheduleTask(int gameUnits, Runnable run) {
if (this.plugin.isEnabled()) {
this.plugin.getServer().getScheduler().scheduleDelayedTask(this.plugin, run, gameUnits);
return;
}

run.run();
}

@Override
public void registerShutdownHandler(TaskChainFactory factory) {
this.plugin.getServer().getPluginManager().registerEvents(new Listener() {
@EventHandler
public void onPluginDisable(PluginDisableEvent event) {
if (event.getPlugin().equals(NukkitGameInterface.this.plugin))
factory.shutdown(60, TimeUnit.SECONDS);
}
}, this.plugin);
}

public static final TaskChainAbortAction<Player, String, ?> MESSAGE = new TaskChainAbortAction<Player, String, Object>() {
@Override
public void onAbort(TaskChain<?> chain, Player player, String message) {
player.sendMessage(message);
}
};

public static final TaskChainAbortAction<Player, String, ?> COLOR_MESSAGE = new TaskChainAbortAction<Player, String, Object>() {
@Override
public void onAbort(TaskChain<?> chain, Player player, String message) {
player.sendMessage(message.replaceAll("&", "§"));
}
};

}

}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,6 @@
<module>core</module>
<module>bukkit</module>
<module>sponge</module>
<module>nukkit</module>
</modules>
</project>
2 changes: 1 addition & 1 deletion sponge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<repository>
<id>sponge-maven-repo</id>
<name>Sponge maven repo</name>
<url>http://repo.spongepowered.org/maven</url>
<url>https://repo.spongepowered.org/maven</url>
<releases>
<enabled>true</enabled>
</releases>
Expand Down