Skip to content

Commit 1ce48fc

Browse files
committed
feat: init
0 parents  commit 1ce48fc

File tree

9 files changed

+1048
-0
lines changed

9 files changed

+1048
-0
lines changed

.github/workflows/package.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
on:
2+
push:
3+
paths:
4+
- 'src/**'
5+
workflow_dispatch:
6+
7+
permissions:
8+
contents: read
9+
packages: write
10+
11+
jobs:
12+
deploy:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v6
16+
- uses: actions/setup-java@v5
17+
with:
18+
distribution: temurin
19+
java-version: '17'
20+
server-id: github
21+
server-username: GITHUB_ACTOR
22+
server-password: GITHUB_TOKEN
23+
- run: mvn -B -DskipTests deploy
24+
env:
25+
GITHUB_ACTOR: ${{ github.actor }}
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

LICENSE.md

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.

pom.xml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>xyz.webmc</groupId>
4+
<artifactId>wlib</artifactId>
5+
<version>1.1.0-SNAPSHOT</version>
6+
<properties>
7+
<plugin.name>WLIB</plugin.name>
8+
<plugin.vers>${project.version}</plugin.vers>
9+
<plugin.pckg>${project.groupId}.${project.artifactId}</plugin.pckg>
10+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
11+
<maven.compiler.release>17</maven.compiler.release>
12+
</properties>
13+
<dependencies>
14+
<dependency>
15+
<groupId>org.bukkit</groupId>
16+
<artifactId>bukkit</artifactId>
17+
<version>1.8-R0.1-SNAPSHOT</version>
18+
<scope>provided</scope>
19+
</dependency>
20+
<dependency>
21+
<groupId>dev.colbster937</groupId>
22+
<artifactId>mirror</artifactId>
23+
<version>1.0.0-SNAPSHOT</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>com.tcoded</groupId>
27+
<artifactId>FoliaLib</artifactId>
28+
<version>0.5.1</version>
29+
</dependency>
30+
</dependencies>
31+
<repositories>
32+
<repository>
33+
<id>spigotmc</id>
34+
<url>https://hub.spigotmc.org/nexus/content/repositories/public/</url>
35+
</repository>
36+
<repository>
37+
<id>java-mirror</id>
38+
<url>https://maven.colbster937.dev/colbster937/java-mirror/</url>
39+
</repository>
40+
<repository>
41+
<id>tcoded</id>
42+
<url>https://repo.tcoded.com/releases/</url>
43+
</repository>
44+
</repositories>
45+
<build>
46+
<finalName>${project.artifactId}-${project.version}</finalName>
47+
<resources>
48+
<resource>
49+
<directory>src/main/resources</directory>
50+
<filtering>true</filtering>
51+
</resource>
52+
</resources>
53+
<plugins>
54+
<plugin>
55+
<groupId>org.apache.maven.plugins</groupId>
56+
<artifactId>maven-shade-plugin</artifactId>
57+
<version>3.6.2</version>
58+
<executions>
59+
<execution>
60+
<phase>package</phase>
61+
<goals>
62+
<goal>shade</goal>
63+
</goals>
64+
<configuration>
65+
<createDependencyReducedPom>false</createDependencyReducedPom>
66+
<relocations>
67+
<relocation>
68+
<pattern>dev.colbster937.reflect</pattern>
69+
<shadedPattern>${plugin.pckg}.lib.mirror</shadedPattern>
70+
</relocation>
71+
<relocation>
72+
<pattern>com.tcoded.folialib</pattern>
73+
<shadedPattern>${plugin.pckg}.lib.folialib</shadedPattern>
74+
</relocation>
75+
</relocations>
76+
</configuration>
77+
</execution>
78+
</executions>
79+
</plugin>
80+
</plugins>
81+
</build>
82+
<distributionManagement>
83+
<repository>
84+
<id>github</id>
85+
<url>https://maven.pkg.github.com/WebMCDevelopment/wlib/</url>
86+
</repository>
87+
</distributionManagement>
88+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package xyz.webmc.wlib;
2+
3+
import xyz.webmc.wlib.util.CommandUtil;
4+
import xyz.webmc.wlib.util.EventUtil;
5+
import xyz.webmc.wlib.util.SchedulerUtil;
6+
7+
import org.bukkit.plugin.java.JavaPlugin;
8+
9+
public final class WLIBBukkitPlugin extends JavaPlugin {
10+
@Override
11+
public final void onEnable() {
12+
CommandUtil.init(this);
13+
EventUtil.init(this);
14+
SchedulerUtil.init(this);
15+
}
16+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package xyz.webmc.wlib.util;
2+
3+
import java.util.Map;
4+
5+
import dev.colbster937.reflect.Mirror;
6+
import org.bukkit.Bukkit;
7+
import org.bukkit.command.Command;
8+
import org.bukkit.command.CommandMap;
9+
import org.bukkit.plugin.Plugin;
10+
import org.bukkit.plugin.PluginManager;
11+
12+
public final class CommandUtil {
13+
private static Plugin plugin;
14+
15+
public static final void init(final Plugin plugin) {
16+
CommandUtil.plugin = plugin;
17+
}
18+
19+
public static final void registerCommand(final Plugin plugin, final Command command) {
20+
commandMap().register(plugin.getName(), command);
21+
syncCommands();
22+
}
23+
24+
public static final void registerCommand(final Command command) {
25+
registerCommand(plugin, command);
26+
}
27+
28+
public static final void unregisterCommand(final String commandStr) {
29+
try {
30+
final Command command = knownCommands().remove(commandStr);
31+
if (command != null) {
32+
command.unregister(commandMap());
33+
}
34+
syncCommands();
35+
} catch (final ReflectiveOperationException ex) {
36+
throw new RuntimeException(ex);
37+
}
38+
}
39+
40+
private static final CommandMap commandMap() {
41+
final CommandMap commandMap;
42+
43+
try {
44+
final PluginManager pm = Bukkit.getPluginManager();
45+
commandMap = Mirror.getFieldValue(pm, "commandMap");
46+
} catch (final ReflectiveOperationException ex) {
47+
throw new RuntimeException(ex);
48+
}
49+
50+
return commandMap;
51+
}
52+
53+
private static final Map<String, Command> knownCommands()
54+
throws ReflectiveOperationException {
55+
return Mirror.getFieldValue(commandMap(), "knownCommands");
56+
}
57+
58+
private static final void syncCommands() {
59+
SchedulerUtil.runAsync(() -> {
60+
try {
61+
Mirror.invokeMethod(Bukkit.getServer(), "syncCommands");
62+
} catch (final ReflectiveOperationException ex) {
63+
throw new RuntimeException(ex);
64+
}
65+
});
66+
}
67+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package xyz.webmc.wlib.util;
2+
3+
import org.bukkit.event.Event;
4+
import org.bukkit.event.EventPriority;
5+
import org.bukkit.event.Listener;
6+
import org.bukkit.plugin.EventExecutor;
7+
import org.bukkit.plugin.Plugin;
8+
import org.bukkit.plugin.PluginManager;
9+
10+
public final class EventUtil {
11+
private static PluginManager pm;
12+
private static Plugin plugin;
13+
14+
public static final void init(final Plugin plugin) {
15+
pm = plugin.getServer().getPluginManager();
16+
EventUtil.plugin = plugin;
17+
}
18+
19+
public static final void registerEvents(final Listener listener, final Plugin plugin) {
20+
pm.registerEvents(listener, plugin);
21+
}
22+
23+
public static final void registerEvent(final Class<? extends Event> event, final Listener listener, final EventPriority priority, final EventExecutor executor, final Plugin plugin) {
24+
pm.registerEvent(event, listener, priority, executor, plugin);
25+
}
26+
27+
public static final void registerEvents(final Listener listener) {
28+
registerEvents(listener, plugin);
29+
}
30+
31+
public static final void registerEvent(final Class<? extends Event> event, final Listener listener, final EventPriority priority, final EventExecutor executor) {
32+
pm.registerEvent(event, listener, priority, executor, plugin);
33+
}
34+
35+
public static final void callEvent(final Event ev) {
36+
pm.callEvent(ev);
37+
}
38+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package xyz.webmc.wlib.util;
2+
3+
import java.io.File;
4+
5+
import org.bukkit.plugin.InvalidDescriptionException;
6+
import org.bukkit.plugin.InvalidPluginException;
7+
import org.bukkit.plugin.Plugin;
8+
import org.bukkit.plugin.PluginManager;
9+
import org.bukkit.plugin.UnknownDependencyException;
10+
11+
public final class PluginUtil {
12+
private static PluginManager pm;
13+
14+
public static final void init(final Plugin plugin) {
15+
pm = plugin.getServer().getPluginManager();
16+
}
17+
18+
public static final Plugin getPlugin(final String name) {
19+
return pm.getPlugin(name);
20+
}
21+
22+
public static final Plugin[] getPlugins() {
23+
return pm.getPlugins();
24+
}
25+
26+
public static final boolean isPluginEnabled(final String name) {
27+
return pm.isPluginEnabled(name);
28+
}
29+
30+
public static final boolean isPluginEnabled(final Plugin plugin) {
31+
return pm.isPluginEnabled(plugin);
32+
}
33+
34+
public static final Plugin loadPlugin(final File file)
35+
throws InvalidPluginException, InvalidDescriptionException, UnknownDependencyException {
36+
return pm.loadPlugin(file);
37+
}
38+
39+
public static final Plugin[] loadPlugins(final File dir) {
40+
return pm.loadPlugins(dir);
41+
}
42+
43+
public static final void disablePlugins() {
44+
pm.disablePlugins();
45+
}
46+
47+
public static final void clearPlugins() {
48+
pm.clearPlugins();
49+
}
50+
51+
public static final void enablePlugin(final Plugin plugin) {
52+
pm.enablePlugin(plugin);
53+
}
54+
55+
public static final void disablePlugin(final Plugin plugin) {
56+
pm.disablePlugin(plugin);
57+
}
58+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package xyz.webmc.wlib.util;
2+
3+
import java.util.concurrent.CompletableFuture;
4+
import java.util.concurrent.TimeUnit;
5+
6+
import com.tcoded.folialib.FoliaLib;
7+
import com.tcoded.folialib.impl.PlatformScheduler;
8+
import com.tcoded.folialib.wrapper.task.WrappedTask;
9+
import org.bukkit.Location;
10+
import org.bukkit.entity.Entity;
11+
import org.bukkit.plugin.Plugin;
12+
13+
public final class SchedulerUtil {
14+
private static FoliaLib lib;
15+
private static PlatformScheduler sch;
16+
17+
public static final void init(final Plugin plugin) {
18+
lib = new FoliaLib(plugin);
19+
sch = lib.getScheduler();
20+
}
21+
22+
public static final boolean isFolia() {
23+
return lib.isFolia();
24+
}
25+
26+
public static final boolean isPaper() {
27+
return lib.isPaper();
28+
}
29+
30+
public static final void cancelAllTasks() {
31+
sch.cancelAllTasks();
32+
}
33+
34+
public static final CompletableFuture<Void> runNextTick(final Runnable task) {
35+
return sch.runNextTick(t -> task.run());
36+
}
37+
38+
public static final WrappedTask runLater(final Runnable task, final long delayTicks) {
39+
return sch.runLater(task, delayTicks);
40+
}
41+
42+
public static final WrappedTask runTimer(final Runnable task, final long delayTicks, final long periodTicks) {
43+
return sch.runTimer(task, delayTicks, periodTicks);
44+
}
45+
46+
public static final CompletableFuture<Void> runAsync(final Runnable task) {
47+
return sch.runAsync(t -> task.run());
48+
}
49+
50+
public static final WrappedTask runLaterAsync(final Runnable task, final long delayTicks) {
51+
return sch.runLaterAsync(task, delayTicks);
52+
}
53+
54+
public static final WrappedTask runLaterAsync(final Runnable task, final long delay, final TimeUnit unit) {
55+
return sch.runLaterAsync(task, delay, unit);
56+
}
57+
58+
public static final WrappedTask runTimerAsync(final Runnable task, final long delayTicks, final long periodTicks) {
59+
return sch.runTimerAsync(task, delayTicks, periodTicks);
60+
}
61+
62+
public static final WrappedTask runTimerAsync(final Runnable task, final long delay, final long period, final TimeUnit unit) {
63+
return sch.runTimerAsync(task, delay, period, unit);
64+
}
65+
66+
public static final CompletableFuture<Void> runAtLocation(final Location loc, final Runnable task) {
67+
return sch.runAtLocation(loc, t -> task.run());
68+
}
69+
70+
public static final WrappedTask runAtLocationLater(final Location loc, final Runnable task, final long delayTicks) {
71+
return sch.runAtLocationLater(loc, task, delayTicks);
72+
}
73+
74+
public static final WrappedTask runAtLocationTimer(final Location loc, final Runnable task, final long delayTicks, final long periodTicks) {
75+
return sch.runAtLocationTimer(loc, task, delayTicks, periodTicks);
76+
}
77+
78+
public static final CompletableFuture<?> runAtEntity(final Entity ent, final Runnable task) {
79+
return sch.runAtEntity(ent, t -> task.run());
80+
}
81+
82+
public static final WrappedTask runAtEntityLater(final Entity ent, final Runnable task, final long delayTicks) {
83+
return sch.runAtEntityLater(ent, task, delayTicks);
84+
}
85+
86+
public static final WrappedTask runAtEntityTimer(final Entity ent, final Runnable task, final long delayTicks, final long periodTicks) {
87+
return sch.runAtEntityTimer(ent, task, delayTicks, periodTicks);
88+
}
89+
}

src/main/resources/plugin.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: ${plugin.name}
2+
version: ${plugin.vers}
3+
main: ${plugin.pckg}.${plugin.name}BukkitPlugin
4+
folia-supported: true
5+
load: STARTUP

0 commit comments

Comments
 (0)