mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-28 19:39:11 +00:00
move other plugins to compatibility module
This commit is contained in:
@@ -7,8 +7,7 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.dejvokep.boostedyaml.YamlDocument;
|
||||
import net.momirealms.craftengine.bukkit.block.worldedit.WorldEditBlockRegister;
|
||||
import net.momirealms.craftengine.bukkit.block.worldedit.WorldEditCommandHelper;
|
||||
import net.momirealms.craftengine.bukkit.compatibility.worldedit.WorldEditBlockRegister;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.plugin.injector.BukkitInjector;
|
||||
import net.momirealms.craftengine.bukkit.plugin.network.PacketConsumers;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.momirealms.craftengine.bukkit.block.worldedit;
|
||||
package net.momirealms.craftengine.bukkit.block;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
||||
import net.momirealms.craftengine.core.block.BlockStateParser;
|
||||
@@ -1,24 +0,0 @@
|
||||
package net.momirealms.craftengine.bukkit.block.worldedit;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitBlockRegistry;
|
||||
import com.sk89q.worldedit.util.concurrency.LazyReference;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ReflectionUtils;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class WorldEditBlockRegister {
|
||||
private static final Field field$BlockType$blockMaterial;
|
||||
|
||||
static {
|
||||
field$BlockType$blockMaterial = ReflectionUtils.getDeclaredField(BlockType.class, "blockMaterial");
|
||||
}
|
||||
|
||||
public static void register(Key id) throws ReflectiveOperationException {
|
||||
BlockType blockType = new BlockType(id.toString(), blockState -> blockState);
|
||||
field$BlockType$blockMaterial.set(blockType, LazyReference.from(() -> new BukkitBlockRegistry.BukkitBlockMaterial(null, Material.STONE)));
|
||||
BlockType.REGISTRY.register(id.toString(), blockType);
|
||||
}
|
||||
}
|
||||
@@ -17,13 +17,13 @@ import net.momirealms.craftengine.bukkit.plugin.command.BukkitSenderFactory;
|
||||
import net.momirealms.craftengine.bukkit.plugin.gui.BukkitGuiManager;
|
||||
import net.momirealms.craftengine.bukkit.plugin.injector.BukkitInjector;
|
||||
import net.momirealms.craftengine.bukkit.plugin.network.BukkitNetworkManager;
|
||||
import net.momirealms.craftengine.bukkit.plugin.papi.ImageExpansion;
|
||||
import net.momirealms.craftengine.bukkit.plugin.papi.ShiftExpansion;
|
||||
import net.momirealms.craftengine.bukkit.compatibility.papi.ImageExpansion;
|
||||
import net.momirealms.craftengine.bukkit.compatibility.papi.ShiftExpansion;
|
||||
import net.momirealms.craftengine.bukkit.plugin.scheduler.BukkitSchedulerAdapter;
|
||||
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
|
||||
import net.momirealms.craftengine.bukkit.sound.BukkitSoundManager;
|
||||
import net.momirealms.craftengine.bukkit.util.EventUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.PlaceholderAPIUtils;
|
||||
import net.momirealms.craftengine.bukkit.compatibility.papi.PlaceholderAPIUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||
import net.momirealms.craftengine.bukkit.world.BukkitWorldManager;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
@@ -176,8 +176,7 @@ public class BukkitCraftEngine extends CraftEngine {
|
||||
// compatibility
|
||||
// register expansion
|
||||
if (this.isPluginEnabled("PlaceholderAPI")) {
|
||||
new ShiftExpansion(this).register();
|
||||
new ImageExpansion(this).register();
|
||||
PlaceholderAPIUtils.registerExpansions(this);
|
||||
this.hasPlaceholderAPI = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.papi;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import net.momirealms.craftengine.core.font.BitmapImage;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.FormatUtils;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class ImageExpansion extends PlaceholderExpansion {
|
||||
private final CraftEngine plugin;
|
||||
|
||||
public ImageExpansion(CraftEngine plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "image";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return "XiaoMoMi";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
return "1.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||
String[] split = params.split("_", 2);
|
||||
if (split.length != 2) return null;
|
||||
String[] param = split[1].split(":", 4);
|
||||
if (param.length < 2) return null;
|
||||
Key key;
|
||||
try {
|
||||
key = Key.of(param[0], param[1]);
|
||||
} catch (IllegalArgumentException e) {
|
||||
plugin.logger().warn("Invalid image namespaced key: " + param[0] + ":" + param[1]);
|
||||
return null;
|
||||
}
|
||||
Optional<BitmapImage> optional = plugin.imageManager().bitmapImageByImageId(key);
|
||||
if (optional.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
BitmapImage image = optional.get();
|
||||
int codepoint;
|
||||
if (param.length == 4) {
|
||||
codepoint = image.codepointAt(Integer.parseInt(param[2]), Integer.parseInt(param[3]));
|
||||
} else if (param.length == 2) {
|
||||
codepoint = image.codepointAt(0,0);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
switch (split[0]) {
|
||||
case "mm", "minimessage", "mini" -> {
|
||||
return FormatUtils.miniMessageFont(new String(Character.toChars(codepoint)), image.font().toString());
|
||||
}
|
||||
case "md", "minedown" -> {
|
||||
return FormatUtils.mineDownFont(new String(Character.toChars(codepoint)), image.font().toString());
|
||||
}
|
||||
case "raw" -> {
|
||||
return new String(Character.toChars(codepoint));
|
||||
}
|
||||
default -> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.papi;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ShiftExpansion extends PlaceholderExpansion {
|
||||
private final CraftEngine plugin;
|
||||
|
||||
public ShiftExpansion(CraftEngine plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "shift";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return "XiaoMoMi";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
return "1.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||
String[] split = params.split("_", 2);
|
||||
switch (split[0]) {
|
||||
case "mini", "minimessage", "mm" -> {
|
||||
if (split.length != 2) return null;
|
||||
try {
|
||||
return plugin.imageManager().createMiniMessageOffsets(Integer.parseInt(split[1]));
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
case "md", "minedown" -> {
|
||||
if (split.length != 2) return null;
|
||||
try {
|
||||
return plugin.imageManager().createMineDownOffsets(Integer.parseInt(split[1]));
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
case "raw" -> {
|
||||
if (split.length != 2) return null;
|
||||
try {
|
||||
return plugin.imageManager().createRawOffsets(Integer.parseInt(split[1]));
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
if (split.length != 1) return null;
|
||||
try {
|
||||
return plugin.imageManager().createMiniMessageOffsets(Integer.parseInt(split[0]));
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package net.momirealms.craftengine.bukkit.util;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public class PlaceholderAPIUtils {
|
||||
|
||||
private PlaceholderAPIUtils() {}
|
||||
|
||||
public static String parse(OfflinePlayer player, String text) {
|
||||
return PlaceholderAPI.setPlaceholders(player, text);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user