mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-19 06:59:26 +00:00
work
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -5,6 +5,9 @@ target/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### Unfinished ###
|
||||
platforms/sponge/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
|
||||
@@ -29,6 +29,7 @@ import net.momirealms.customnameplates.api.feature.image.ImageManager;
|
||||
import net.momirealms.customnameplates.api.feature.nameplate.NameplateManager;
|
||||
import net.momirealms.customnameplates.api.feature.pack.ResourcePackManager;
|
||||
import net.momirealms.customnameplates.api.feature.tag.UnlimitedTagManager;
|
||||
import net.momirealms.customnameplates.api.helper.VersionHelper;
|
||||
import net.momirealms.customnameplates.api.network.PacketSender;
|
||||
import net.momirealms.customnameplates.api.network.PipelineInjector;
|
||||
import net.momirealms.customnameplates.api.placeholder.PlaceholderManager;
|
||||
@@ -81,6 +82,13 @@ public abstract class CustomNameplates implements NameplatesPlugin {
|
||||
protected ResourcePackManager resourcePackManager;
|
||||
protected CustomNameplatesAPI api;
|
||||
|
||||
private String buildByBit = "%%__BUILTBYBIT__%%";
|
||||
private String polymart = "%%__POLYMART__%%";
|
||||
private String time = "%%__TIMESTAMP__%%";
|
||||
private String user = "%%__USER__%%";
|
||||
private String username = "%%__USERNAME__%%";
|
||||
private boolean isLatest = false;
|
||||
|
||||
protected CustomNameplates() {
|
||||
instance = this;
|
||||
}
|
||||
@@ -97,6 +105,36 @@ public abstract class CustomNameplates implements NameplatesPlugin {
|
||||
@Override
|
||||
public abstract void disable();
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
boolean downloadFromPolymart = polymart.equals("1");
|
||||
boolean downloadFromBBB = buildByBit.equals("true");
|
||||
if (ConfigManager.checkUpdate()) {
|
||||
VersionHelper.UPDATE_CHECKER.apply(this).thenAccept(result -> {
|
||||
String link;
|
||||
if (downloadFromPolymart) {
|
||||
link = "https://polymart.org/resource/2543/";
|
||||
} else if (downloadFromBBB) {
|
||||
link = "https://builtbybit.com/resources/36359/";
|
||||
} else {
|
||||
link = "https://github.com/Xiao-MoMi/Custom-Nameplates/";
|
||||
}
|
||||
if (!result) {
|
||||
this.getPluginLogger().info("You are using the latest version.");
|
||||
isLatest = true;
|
||||
} else {
|
||||
this.getPluginLogger().warn("Update is available: " + link);
|
||||
isLatest = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpToDate() {
|
||||
return isLatest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs debug messages through the provided supplier.
|
||||
*
|
||||
|
||||
@@ -26,7 +26,7 @@ subprojects {
|
||||
expand(rootProject.properties)
|
||||
}
|
||||
|
||||
filesMatching(arrayListOf("*.yml", "*/*.yml")) {
|
||||
filesMatching(arrayListOf("*.yml", "*/*.yml", "META-INF/sponge_plugins.json")) {
|
||||
expand(
|
||||
Pair("project_version", rootProject.properties["project_version"]),
|
||||
Pair("config_version", rootProject.properties["config_version"])
|
||||
|
||||
@@ -113,6 +113,14 @@ public enum Dependency {
|
||||
Relocation.of("cloud", "org{}incendo{}cloud"),
|
||||
Relocation.of("geantyref", "io{}leangen{}geantyref")
|
||||
),
|
||||
CLOUD_SPONGE(
|
||||
"org{}incendo",
|
||||
"cloud-sponge7",
|
||||
"maven",
|
||||
"cloud-sponge7",
|
||||
Relocation.of("cloud", "org{}incendo{}cloud"),
|
||||
Relocation.of("geantyref", "io{}leangen{}geantyref")
|
||||
),
|
||||
CLOUD_MINECRAFT_EXTRAS(
|
||||
"org{}incendo",
|
||||
"cloud-minecraft-extras",
|
||||
@@ -226,6 +234,18 @@ public enum Dependency {
|
||||
return Dependency.BSTATS_BASE.getVersion();
|
||||
}
|
||||
},
|
||||
BSTATS_SPONGE(
|
||||
"org{}bstats",
|
||||
"bstats-sponge",
|
||||
"maven",
|
||||
"bstats-sponge",
|
||||
Relocation.of("bstats", "org{}bstats")
|
||||
) {
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return Dependency.BSTATS_BASE.getVersion();
|
||||
}
|
||||
},
|
||||
GSON(
|
||||
"com.google.code.gson",
|
||||
"gson",
|
||||
|
||||
@@ -46,7 +46,7 @@ dependencies {
|
||||
|
||||
tasks {
|
||||
shadowJar {
|
||||
archiveFileName = "CustomNameplates-${rootProject.properties["project_version"]}-bukkit.jar"
|
||||
archiveFileName = "CustomNameplates-Bukkit-${rootProject.properties["project_version"]}.jar"
|
||||
destinationDirectory.set(file("$rootDir/target"))
|
||||
relocate("net.kyori", "net.momirealms.customnameplates.libraries")
|
||||
relocate("org.incendo", "net.momirealms.customnameplates.libraries")
|
||||
|
||||
@@ -18,13 +18,11 @@
|
||||
package net.momirealms.customnameplates.bukkit;
|
||||
|
||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||
import net.momirealms.customnameplates.common.plugin.NameplatesPlugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class BukkitBootstrap extends JavaPlugin {
|
||||
|
||||
private CustomNameplates nameplates;
|
||||
private NameplatesPlugin plugin;
|
||||
private CustomNameplates plugin;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
|
||||
@@ -94,14 +94,6 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener
|
||||
|
||||
private boolean loaded = false;
|
||||
|
||||
private String buildByBit = "%%__BUILTBYBIT__%%";
|
||||
private String polymart = "%%__POLYMART__%%";
|
||||
private String time = "%%__TIMESTAMP__%%";
|
||||
private String user = "%%__USER__%%";
|
||||
private String username = "%%__USERNAME__%%";
|
||||
|
||||
private boolean isLatest = false;
|
||||
|
||||
public BukkitCustomNameplates(JavaPlugin bootstrap) {
|
||||
this.bootstrap = bootstrap;
|
||||
VersionHelper.init(getServerVersion());
|
||||
@@ -212,29 +204,6 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener
|
||||
}
|
||||
}
|
||||
|
||||
boolean downloadFromPolymart = polymart.equals("1");
|
||||
boolean downloadFromBBB = buildByBit.equals("true");
|
||||
|
||||
if (ConfigManager.checkUpdate()) {
|
||||
VersionHelper.UPDATE_CHECKER.apply(this).thenAccept(result -> {
|
||||
String link;
|
||||
if (downloadFromPolymart) {
|
||||
link = "https://polymart.org/resource/2543/";
|
||||
} else if (downloadFromBBB) {
|
||||
link = "https://builtbybit.com/resources/36359/";
|
||||
} else {
|
||||
link = "https://github.com/Xiao-MoMi/Custom-Nameplates/";
|
||||
}
|
||||
if (!result) {
|
||||
this.getPluginLogger().info("You are using the latest version.");
|
||||
isLatest = true;
|
||||
} else {
|
||||
this.getPluginLogger().warn("Update is available: " + link);
|
||||
isLatest = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (VersionHelper.isFolia()) {
|
||||
this.foliaTrackerTask = getScheduler().asyncRepeating(() -> {
|
||||
for (CNPlayer player : getOnlinePlayers()) {
|
||||
@@ -264,6 +233,8 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener
|
||||
}
|
||||
}, 200, 200, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
super.enable();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -335,10 +306,6 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener
|
||||
this.scheduledMainTask = getScheduler().asyncRepeating(mainTask, 50, 50, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpToDate() {
|
||||
return isLatest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceStream(String filePath) {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package net.momirealms.customnameplates.sponge;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||
import org.spongepowered.api.Server;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.Order;
|
||||
import org.spongepowered.api.event.lifecycle.ConstructPluginEvent;
|
||||
import org.spongepowered.api.event.lifecycle.StoppingEngineEvent;
|
||||
import org.spongepowered.plugin.builtin.jvm.Plugin;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Plugin("customnameplates")
|
||||
public class SpongeBootstrap implements Supplier<Injector> {
|
||||
|
||||
private final CustomNameplates plugin;
|
||||
private final Injector injector;
|
||||
|
||||
@Inject
|
||||
public SpongeBootstrap(Injector injector) {
|
||||
this.injector = injector;
|
||||
this.plugin = new SpongeCustomNameplates(this);
|
||||
}
|
||||
|
||||
@Listener(order = Order.FIRST)
|
||||
public void onEnable(ConstructPluginEvent event) {
|
||||
this.plugin.load();
|
||||
this.plugin.enable();
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onDisable(StoppingEngineEvent<Server> event) {
|
||||
this.plugin.disable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Injector get() {
|
||||
return this.injector;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package net.momirealms.customnameplates.sponge;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||
import net.momirealms.customnameplates.api.helper.VersionHelper;
|
||||
import net.momirealms.customnameplates.common.dependency.Dependency;
|
||||
import net.momirealms.customnameplates.common.plugin.classpath.ClassPathAppender;
|
||||
import net.momirealms.customnameplates.common.plugin.classpath.ReflectionClassPathAppender;
|
||||
import net.momirealms.customnameplates.common.plugin.logging.Log4jPluginLogger;
|
||||
import net.momirealms.customnameplates.common.plugin.logging.PluginLogger;
|
||||
import net.momirealms.customnameplates.common.plugin.scheduler.AbstractJavaScheduler;
|
||||
import net.momirealms.customnameplates.common.plugin.scheduler.SchedulerAdapter;
|
||||
import net.momirealms.customnameplates.sponge.scheduler.SpongeSchedulerAdaptor;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.api.Game;
|
||||
import org.spongepowered.api.Platform;
|
||||
import org.spongepowered.plugin.PluginContainer;
|
||||
import org.spongepowered.plugin.metadata.PluginMetadata;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class SpongeCustomNameplates extends CustomNameplates {
|
||||
|
||||
private final AbstractJavaScheduler<Void> scheduler;
|
||||
private Supplier<Injector> loader;
|
||||
private final PluginContainer pluginContainer;
|
||||
private final PluginLogger logger;
|
||||
private final ClassPathAppender classPathAppender;
|
||||
private final Game game;
|
||||
|
||||
public SpongeCustomNameplates(Supplier<Injector> loader) {
|
||||
this.loader = loader;
|
||||
Injector injector = loader.get();
|
||||
this.logger = new Log4jPluginLogger(injector.getInstance(Logger.class));
|
||||
this.game = injector.getInstance(Game.class);
|
||||
this.pluginContainer = injector.getInstance(PluginContainer.class);
|
||||
injector.injectMembers(this);
|
||||
this.scheduler = new SpongeSchedulerAdaptor(this);
|
||||
this.classPathAppender = new ReflectionClassPathAppender(getClass().getClassLoader());
|
||||
}
|
||||
|
||||
public PluginContainer pluginContainer() {
|
||||
return pluginContainer;
|
||||
}
|
||||
|
||||
public Game game() {
|
||||
return game;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
if (!VersionHelper.isVersionNewerThan1_19_4()) {
|
||||
getPluginLogger().severe("CustomNameplates only supports 1.19.4+ servers");
|
||||
return;
|
||||
}
|
||||
super.enable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
this.dependencyManager.loadDependencies(
|
||||
List.of(
|
||||
Dependency.BOOSTED_YAML,
|
||||
Dependency.BSTATS_BASE, Dependency.BSTATS_SPONGE,
|
||||
Dependency.CAFFEINE,
|
||||
Dependency.GEANTY_REF,
|
||||
Dependency.CLOUD_CORE, Dependency.CLOUD_SERVICES, Dependency.CLOUD_SPONGE, Dependency.CLOUD_BRIGADIER, Dependency.CLOUD_MINECRAFT_EXTRAS,
|
||||
Dependency.GSON,
|
||||
Dependency.COMMONS_POOL_2,
|
||||
Dependency.JEDIS,
|
||||
Dependency.MYSQL_DRIVER, Dependency.MARIADB_DRIVER,
|
||||
Dependency.SQLITE_DRIVER, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE,
|
||||
Dependency.H2_DRIVER,
|
||||
Dependency.MONGODB_DRIVER_CORE, Dependency.MONGODB_DRIVER_SYNC, Dependency.MONGODB_DRIVER_BSON,
|
||||
Dependency.HIKARI_CP,
|
||||
Dependency.BYTE_BUDDY,
|
||||
Dependency.COMMONS_IO,
|
||||
Dependency.LWJGL, Dependency.LWJGL_NATIVES, Dependency.LWJGL_FREETYPE, Dependency.LWJGL_FREETYPE_NATIVES
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceStream(String filePath) {
|
||||
return getClass().getClassLoader().getResourceAsStream(filePath.replace("\\", "/"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginLogger getPluginLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassPathAppender getClassPathAppender() {
|
||||
return this.classPathAppender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchedulerAdapter<?> getScheduler() {
|
||||
return this.scheduler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getDataDirectory() {
|
||||
return this.game.gameDirectory().toAbsolutePath().resolve("customnameplates");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerVersion() {
|
||||
PluginMetadata api = this.game.platform().container(Platform.Component.API).metadata();
|
||||
PluginMetadata impl = this.game.platform().container(Platform.Component.IMPLEMENTATION).metadata();
|
||||
return api.name().orElse("API") + ": " + api.version() + " - " + impl.name().orElse("Impl") + ": " + impl.version();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginVersion() {
|
||||
return this.pluginContainer.metadata().version().toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package net.momirealms.customnameplates.sponge.scheduler;
|
||||
|
||||
import net.momirealms.customnameplates.common.plugin.scheduler.AbstractJavaScheduler;
|
||||
import net.momirealms.customnameplates.common.plugin.scheduler.RegionExecutor;
|
||||
import net.momirealms.customnameplates.common.plugin.scheduler.SchedulerTask;
|
||||
import net.momirealms.customnameplates.sponge.SpongeCustomNameplates;
|
||||
import org.spongepowered.api.scheduler.Task;
|
||||
import org.spongepowered.api.util.Ticks;
|
||||
|
||||
public class SpongeSchedulerAdaptor extends AbstractJavaScheduler<Void> {
|
||||
|
||||
private final SpongeExecutor executor;
|
||||
|
||||
public SpongeSchedulerAdaptor(SpongeCustomNameplates plugin) {
|
||||
super(plugin);
|
||||
this.executor = new SpongeExecutor(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegionExecutor<Void> sync() {
|
||||
return executor;
|
||||
}
|
||||
|
||||
public static class SpongeExecutor implements RegionExecutor<Void> {
|
||||
|
||||
private final SpongeCustomNameplates plugin;
|
||||
|
||||
public SpongeExecutor(SpongeCustomNameplates plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Runnable r, Void l) {
|
||||
this.plugin.game().server().scheduler().submit(Task.builder()
|
||||
.plugin(plugin.pluginContainer())
|
||||
.execute(r)
|
||||
.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchedulerTask runLater(Runnable r, long delayTicks, Void l) {
|
||||
return new SpongeTask(
|
||||
this.plugin.game().server().scheduler().submit(Task.builder()
|
||||
.plugin(plugin.pluginContainer())
|
||||
.execute(r)
|
||||
.delay(Ticks.of(delayTicks))
|
||||
.build())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchedulerTask runRepeating(Runnable r, long delayTicks, long period, Void l) {
|
||||
return new SpongeTask(
|
||||
this.plugin.game().server().scheduler().submit(Task.builder()
|
||||
.plugin(plugin.pluginContainer())
|
||||
.execute(r)
|
||||
.delay(Ticks.of(delayTicks))
|
||||
.interval(Ticks.of(period))
|
||||
.build())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.momirealms.customnameplates.sponge.scheduler;
|
||||
|
||||
import net.momirealms.customnameplates.common.plugin.scheduler.SchedulerTask;
|
||||
import org.spongepowered.api.scheduler.ScheduledTask;
|
||||
|
||||
public class SpongeTask implements SchedulerTask {
|
||||
|
||||
private final ScheduledTask task;
|
||||
|
||||
public SpongeTask(final ScheduledTask task) {
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
this.task.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cancelled() {
|
||||
return this.task.isCancelled();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"loader": {
|
||||
"name": "java_plain",
|
||||
"version": "1.0"
|
||||
},
|
||||
"license": "GPLv3",
|
||||
"plugins": [
|
||||
{
|
||||
"id": "customnameplates",
|
||||
"name": "CustomNameplates",
|
||||
"version": "${project_version}",
|
||||
"entrypoint": "net.momirealms.customnameplates.sponge.SpongeBootstrap",
|
||||
"description": "A Unique Way to Customize Name Tags",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "XiaoMoMi",
|
||||
"description": "Developer"
|
||||
}
|
||||
],
|
||||
"dependencies": [
|
||||
{
|
||||
"id": "spongeapi",
|
||||
"version": "8.0.0"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
rootProject.name = "CustomNameplates"
|
||||
include(":api")
|
||||
include(":platforms:bukkit")
|
||||
include(":common")
|
||||
include(":backend")
|
||||
include(":platforms:bukkit")
|
||||
include(":platforms:bukkit:compatibility")
|
||||
|
||||
Reference in New Issue
Block a user