mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 14:38:48 +00:00
Add common module
This commit is contained in:
1 parent
dd5aca28fb
commit
28ffa3d3e9
9 files changed
+109
-84
No files matched your search
@@ -2,7 +2,6 @@ package net.draycia.carbon.api;
|
||||
|
||||
import net.draycia.carbon.api.events.CarbonEventHandler;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.event.HoverEventSource;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -10,9 +9,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.WHITE;
|
||||
|
||||
public interface CarbonChat {
|
||||
|
||||
@NonNull Logger logger();
|
||||
@@ -21,20 +17,9 @@ public interface CarbonChat {
|
||||
|
||||
@NonNull Component createItemHoverComponent(final @NonNull UUID uuid);
|
||||
|
||||
// TODO: Move this to Common
|
||||
default @NonNull Component createItemHoverComponent(
|
||||
@NonNull Component createItemHoverComponent(
|
||||
final @NonNull Component displayName,
|
||||
final @NonNull HoverEventSource<HoverEvent.ShowItem> itemStack
|
||||
) {
|
||||
final TextComponent.Builder builder = text(); // Empty root - prevents style leaking.
|
||||
|
||||
builder.hoverEvent(itemStack); // Let this be inherited by all coming components.
|
||||
|
||||
builder.append(text("[", WHITE));
|
||||
builder.append(displayName);
|
||||
builder.append(text("]", WHITE));
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@ plugins {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.carbonchatApi)
|
||||
implementation(projects.carbonchatCommon)
|
||||
|
||||
// Server
|
||||
compileOnly(libs.paperApi)
|
||||
@@ -39,7 +39,7 @@ tasks {
|
||||
bukkit {
|
||||
name = rootProject.name
|
||||
version = project.version as String
|
||||
main = "net.draycia.carbon.bukkit.CarbonChatBukkit"
|
||||
main = "net.draycia.carbon.bukkit.CarbonChatBukkitEntry"
|
||||
apiVersion = "1.13"
|
||||
author = "Draycia"
|
||||
depend = listOf("PlaceholderAPI", "Vault")
|
||||
|
||||
@@ -1,60 +1,19 @@
|
||||
package net.draycia.carbon.bukkit;
|
||||
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.events.CarbonEventHandler;
|
||||
import net.draycia.carbon.common.CarbonChatCommon;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static java.util.Objects.requireNonNullElseGet;
|
||||
import static net.kyori.adventure.text.Component.empty;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
private final Logger logger = LogManager.getLogger("CarbonChat");
|
||||
private final CarbonEventHandler eventHandler = new CarbonEventHandler();
|
||||
|
||||
private static final int BSTATS_PLUGIN_ID = 8720;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if (!PaperLib.isPaper()) {
|
||||
this.logger.error("*");
|
||||
this.logger.error("* CarbonChat makes extensive use of APIs added by Paper.");
|
||||
this.logger.error("* For this reason, CarbonChat is not compatible with Spigot or CraftBukkit servers.");
|
||||
this.logger.error("* Upgrade your server to Paper in order to use CarbonChat.");
|
||||
this.logger.error("*");
|
||||
PaperLib.suggestPaper(this, Level.SEVERE);
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
}
|
||||
|
||||
final Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Logger logger() {
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CarbonEventHandler eventHandler() {
|
||||
// TODO: move to common
|
||||
return this.eventHandler;
|
||||
}
|
||||
public final class CarbonChatBukkit extends CarbonChatCommon {
|
||||
|
||||
@Override
|
||||
public @NonNull Component createItemHoverComponent(final @NonNull UUID uuid) {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package net.draycia.carbon.bukkit;
|
||||
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class CarbonChatBukkitEntry extends JavaPlugin {
|
||||
|
||||
private static final int BSTATS_PLUGIN_ID = 8720;
|
||||
|
||||
private CarbonChatBukkit carbon;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.carbon = new CarbonChatBukkit();
|
||||
|
||||
if (!PaperLib.isPaper()) {
|
||||
this.carbon.logger().error("*");
|
||||
this.carbon.logger().error("* CarbonChat makes extensive use of APIs added by Paper.");
|
||||
this.carbon.logger().error("* For this reason, CarbonChat is not compatible with Spigot or CraftBukkit servers.");
|
||||
this.carbon.logger().error("* Upgrade your server to Paper in order to use CarbonChat.");
|
||||
this.carbon.logger().error("*");
|
||||
PaperLib.suggestPaper(this, Level.SEVERE);
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
}
|
||||
|
||||
final Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID);
|
||||
|
||||
this.carbon.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
dependencies {
|
||||
api(projects.carbonchatApi)
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package net.draycia.carbon.common;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.events.CarbonEventHandler;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.event.HoverEventSource;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.WHITE;
|
||||
|
||||
public abstract class CarbonChatCommon implements CarbonChat {
|
||||
|
||||
protected final Logger logger = LogManager.getLogger("CarbonChat");
|
||||
private final CarbonEventHandler eventHandler = new CarbonEventHandler();
|
||||
|
||||
public void initialize() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Logger logger() {
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CarbonEventHandler eventHandler() {
|
||||
return this.eventHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Component createItemHoverComponent(
|
||||
final @NonNull Component displayName,
|
||||
final @NonNull HoverEventSource<HoverEvent.ShowItem> itemStack
|
||||
) {
|
||||
final TextComponent.Builder builder = text(); // Empty root - prevents style leaking.
|
||||
|
||||
builder.hoverEvent(itemStack); // Let this be inherited by all coming components.
|
||||
|
||||
builder.append(text("[", WHITE));
|
||||
builder.append(displayName);
|
||||
builder.append(text("]", WHITE));
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
||||
+4
-1
@@ -4,7 +4,7 @@ enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven("https://repo.stellardrift.ca/repository/snapshots/") // todo: polyglot-version-catalogs is not relased on the gradle plugin portal yet
|
||||
maven("https://repo.stellardrift.ca/repository/snapshots/") // todo: polyglot-version-catalogs is not released on the gradle plugin portal yet
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@ rootProject.name = "CarbonChat"
|
||||
setupSubproject("carbonchat-api") {
|
||||
projectDir = file("api")
|
||||
}
|
||||
setupSubproject("carbonchat-common") {
|
||||
projectDir = file("common")
|
||||
}
|
||||
setupSubproject("carbonchat-bukkit") {
|
||||
projectDir = file("bukkit")
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ plugins {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.carbonchatApi)
|
||||
implementation(projects.carbonchatCommon)
|
||||
implementation(libs.cloudSponge)
|
||||
//implementation(libs.bstatsSponge) // not updated for api 8 yet
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package net.draycia.carbon.sponge;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.events.CarbonEventHandler;
|
||||
import net.draycia.carbon.common.CarbonChatCommon;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.data.Keys;
|
||||
@@ -19,36 +18,22 @@ import java.util.UUID;
|
||||
import static net.kyori.adventure.text.Component.empty;
|
||||
|
||||
@Plugin("carbonchat")
|
||||
public class CarbonChatSponge implements CarbonChat {
|
||||
private final PluginContainer pluginContainer;
|
||||
private final Logger logger;
|
||||
private final CarbonEventHandler eventHandler = new CarbonEventHandler();
|
||||
public class CarbonChatSponge extends CarbonChatCommon {
|
||||
|
||||
private final PluginContainer pluginContainer;
|
||||
private static final int BSTATS_PLUGIN_ID = 11279;
|
||||
|
||||
@Inject
|
||||
public CarbonChatSponge(
|
||||
//final Metrics.@NonNull Factory metricsFactory,
|
||||
final @NonNull PluginContainer pluginContainer,
|
||||
final @NonNull Logger logger
|
||||
final @NonNull PluginContainer pluginContainer
|
||||
) {
|
||||
this.pluginContainer = pluginContainer;
|
||||
this.logger = logger;
|
||||
this.initialize();
|
||||
|
||||
//metricsFactory.make(BSTATS_PLUGIN_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Logger logger() {
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CarbonEventHandler eventHandler() {
|
||||
// TODO: move to common
|
||||
return this.eventHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Component createItemHoverComponent(final @NonNull UUID uuid) {
|
||||
final ServerPlayer player = Sponge.server().player(uuid).orElse(null);
|
||||
|
||||
Reference in new issue
Block a user