Update BookBuilder
This commit is contained in:
		@@ -6,7 +6,7 @@ plugins {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
group = 'me.skymc'
 | 
			
		||||
version = '5.22'
 | 
			
		||||
version = '5.23'
 | 
			
		||||
 | 
			
		||||
sourceCompatibility = 1.8
 | 
			
		||||
targetCompatibility = 1.8
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@ package io.izzel.taboolib;
 | 
			
		||||
import com.google.common.collect.Lists;
 | 
			
		||||
import com.google.common.collect.Maps;
 | 
			
		||||
import com.google.common.collect.Sets;
 | 
			
		||||
import io.izzel.taboolib.common.loader.StartupLoader;
 | 
			
		||||
import io.izzel.taboolib.module.command.TCommandHandler;
 | 
			
		||||
import io.izzel.taboolib.module.config.TConfig;
 | 
			
		||||
import io.izzel.taboolib.module.config.TConfigWatcher;
 | 
			
		||||
@@ -29,6 +30,8 @@ public abstract class PluginLoader {
 | 
			
		||||
    private static List<PluginLoader> registerLoader = Lists.newArrayList();
 | 
			
		||||
    private static Set<String> plugins = Sets.newHashSet();
 | 
			
		||||
    private static Map<String, Object> redefine = Maps.newHashMap();
 | 
			
		||||
    private static boolean firstLoading = false;
 | 
			
		||||
    private static boolean firstStarting = false;
 | 
			
		||||
 | 
			
		||||
    static {
 | 
			
		||||
        registerLoader.add(new PluginLoader() {
 | 
			
		||||
@@ -43,6 +46,11 @@ public abstract class PluginLoader {
 | 
			
		||||
                TabooLibLoader.setupClasses(plugin);
 | 
			
		||||
                // 加载插件类
 | 
			
		||||
                TabooLibLoader.preLoadClass(plugin, TabooLibLoader.getPluginClassSafely(plugin));
 | 
			
		||||
                // 首次运行
 | 
			
		||||
                if (!firstLoading) {
 | 
			
		||||
                    firstLoading = true;
 | 
			
		||||
                    StartupLoader.onLoading();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
@@ -53,6 +61,11 @@ public abstract class PluginLoader {
 | 
			
		||||
                TabooLibLoader.postLoadClass(plugin, TabooLibLoader.getPluginClassSafely(plugin));
 | 
			
		||||
                // 注册插件命令
 | 
			
		||||
                TCommandHandler.registerCommand(plugin);
 | 
			
		||||
                // 首次运行
 | 
			
		||||
                if (!firstStarting) {
 | 
			
		||||
                    firstStarting = true;
 | 
			
		||||
                    StartupLoader.onStarting();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -1,28 +1,35 @@
 | 
			
		||||
package io.izzel.taboolib.common.listener;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.Lists;
 | 
			
		||||
import io.izzel.taboolib.TabooLib;
 | 
			
		||||
import io.izzel.taboolib.TabooLibAPI;
 | 
			
		||||
import io.izzel.taboolib.common.loader.Startup;
 | 
			
		||||
import io.izzel.taboolib.common.loader.StartupLoader;
 | 
			
		||||
import io.izzel.taboolib.module.command.lite.CommandBuilder;
 | 
			
		||||
import io.izzel.taboolib.module.db.local.Local;
 | 
			
		||||
import io.izzel.taboolib.module.db.local.LocalPlayer;
 | 
			
		||||
import io.izzel.taboolib.module.hologram.Hologram;
 | 
			
		||||
import io.izzel.taboolib.module.hologram.THologram;
 | 
			
		||||
import io.izzel.taboolib.module.inject.TListener;
 | 
			
		||||
import io.izzel.taboolib.module.locale.TLocale;
 | 
			
		||||
import io.izzel.taboolib.module.locale.logger.TLogger;
 | 
			
		||||
import io.izzel.taboolib.module.tellraw.TellrawJson;
 | 
			
		||||
import io.izzel.taboolib.util.Files;
 | 
			
		||||
import io.izzel.taboolib.util.book.BookFormatter;
 | 
			
		||||
import io.izzel.taboolib.util.item.Items;
 | 
			
		||||
import io.izzel.taboolib.util.lite.Signs;
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.Location;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.event.EventHandler;
 | 
			
		||||
import org.bukkit.event.EventPriority;
 | 
			
		||||
import org.bukkit.event.Listener;
 | 
			
		||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
 | 
			
		||||
import org.bukkit.event.server.ServerCommandEvent;
 | 
			
		||||
import org.bukkit.inventory.meta.BookMeta;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author sky
 | 
			
		||||
@@ -30,31 +37,55 @@ import java.util.Arrays;
 | 
			
		||||
@TListener
 | 
			
		||||
public class ListenerCommand implements Listener {
 | 
			
		||||
 | 
			
		||||
    @EventHandler
 | 
			
		||||
    public void cmd(PlayerCommandPreprocessEvent e) {
 | 
			
		||||
        if (e.getMessage().equalsIgnoreCase("/tabooLib")) {
 | 
			
		||||
            e.setCancelled(true);
 | 
			
		||||
            TLocale.Display.sendTitle(e.getPlayer(), "§fTabooLib", "§7TabooLib Enabled.");
 | 
			
		||||
    static {
 | 
			
		||||
        StartupLoader.register(ListenerCommand.class);
 | 
			
		||||
    }
 | 
			
		||||
        if (e.getMessage().equalsIgnoreCase("/tellrawTest") && e.getPlayer().hasPermission("*")) {
 | 
			
		||||
            e.setCancelled(true);
 | 
			
		||||
 | 
			
		||||
    abstract class Module {
 | 
			
		||||
 | 
			
		||||
        abstract public String[] name();
 | 
			
		||||
 | 
			
		||||
        abstract public void run(Player player);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    List<Module> testUtil = Lists.newArrayList(
 | 
			
		||||
            new Module() {
 | 
			
		||||
                @Override
 | 
			
		||||
                public String[] name() {
 | 
			
		||||
                    return new String[] {"json", "tellrawJson"};
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                @Override
 | 
			
		||||
                public void run(Player player) {
 | 
			
		||||
                    TellrawJson.create()
 | 
			
		||||
                    .append("§8[§3§lTabooLib§8] §7TellrawJson Test: §f[")
 | 
			
		||||
                    .append(Items.getName(e.getPlayer().getItemInHand())).hoverItem(e.getPlayer().getItemInHand())
 | 
			
		||||
                            .append("§8[§fTabooLib§8] §7TellrawJson: §f[")
 | 
			
		||||
                            .append(Items.getName(player.getItemInHand())).hoverItem(player.getItemInHand())
 | 
			
		||||
                            .append("§f]")
 | 
			
		||||
                    .send(e.getPlayer());
 | 
			
		||||
                            .send(player);
 | 
			
		||||
                }
 | 
			
		||||
        if (e.getMessage().equalsIgnoreCase("/fakesignTest") && e.getPlayer().hasPermission("*")) {
 | 
			
		||||
            e.setCancelled(true);
 | 
			
		||||
            Signs.fakeSign(e.getPlayer(), lines -> {
 | 
			
		||||
                e.getPlayer().sendMessage("§8[§3§lTabooLib§8] §7FakeSign Lines: §f" + Arrays.toString(lines));
 | 
			
		||||
            });
 | 
			
		||||
            },
 | 
			
		||||
            new Module() {
 | 
			
		||||
                @Override
 | 
			
		||||
                public String[] name() {
 | 
			
		||||
                    return new String[] {"sign", "fakeSign"};
 | 
			
		||||
                }
 | 
			
		||||
        if (e.getMessage().equalsIgnoreCase("/hologramTest") && e.getPlayer().hasPermission("*")) {
 | 
			
		||||
            e.setCancelled(true);
 | 
			
		||||
            e.getPlayer().sendMessage("§8[§3§lTabooLib§8] §7Hologram Test.");
 | 
			
		||||
            Location location = e.getPlayer().getEyeLocation().add(e.getPlayer().getLocation().getDirection());
 | 
			
		||||
            Hologram hologram = THologram.create(location, "TabooLib", e.getPlayer())
 | 
			
		||||
 | 
			
		||||
                @Override
 | 
			
		||||
                public void run(Player player) {
 | 
			
		||||
                    Signs.fakeSign(player, lines -> player.sendMessage("§8[§fTabooLib§8] §7FakeSign: §f" + Arrays.toString(lines)));
 | 
			
		||||
                }
 | 
			
		||||
            },
 | 
			
		||||
            new Module() {
 | 
			
		||||
                @Override
 | 
			
		||||
                public String[] name() {
 | 
			
		||||
                    return new String[] {"hd", "hologram"};
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                @Override
 | 
			
		||||
                public void run(Player player) {
 | 
			
		||||
                    player.sendMessage("§8[§fTabooLib§8] §7Hologram.");
 | 
			
		||||
                    Location location = player.getEyeLocation().add(player.getLocation().getDirection());
 | 
			
		||||
                    Hologram hologram = THologram.create(location, "TabooLib", player)
 | 
			
		||||
                            .flash(Lists.newArrayList(
 | 
			
		||||
                                    "§bT§fabooLib",
 | 
			
		||||
                                    "§bTa§fbooLib",
 | 
			
		||||
@@ -74,6 +105,53 @@ public class ListenerCommand implements Listener {
 | 
			
		||||
                                    "§fTabooLib"
 | 
			
		||||
                            ), 1).deleteOn(30);
 | 
			
		||||
                }
 | 
			
		||||
            },
 | 
			
		||||
            new Module() {
 | 
			
		||||
                @Override
 | 
			
		||||
                public String[] name() {
 | 
			
		||||
                    return new String[] {"book", "bookBuilder"};
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                @Override
 | 
			
		||||
                public void run(Player player) {
 | 
			
		||||
                    BookFormatter.writtenBook()
 | 
			
		||||
                            .generation(BookMeta.Generation.COPY_OF_COPY)
 | 
			
		||||
                            .addPage(TellrawJson.create()
 | 
			
		||||
                                    .append("BookBuilder")
 | 
			
		||||
                                    .hoverText("HoverText"))
 | 
			
		||||
                            .open(player);
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
    @Startup.Starting
 | 
			
		||||
    public void init() {
 | 
			
		||||
        // 版本命令
 | 
			
		||||
        CommandBuilder.create("taboolib", TabooLib.getPlugin())
 | 
			
		||||
                .aliases("lib")
 | 
			
		||||
                .execute((sender, args) -> {
 | 
			
		||||
                    sender.sendMessage("§8[§fTabooLib§8] §7Currently Version: §fv" + TabooLib.getVersion());
 | 
			
		||||
                }).build();
 | 
			
		||||
        // 调试命令
 | 
			
		||||
        CommandBuilder.create("taboolibtest", TabooLib.getPlugin())
 | 
			
		||||
                .permission("*")
 | 
			
		||||
                .aliases("libtest")
 | 
			
		||||
                .tab((sender, args) -> testUtil.stream().flatMap(module -> Arrays.stream(module.name())).filter(name -> name.toLowerCase().startsWith(args[0])).collect(Collectors.toList()))
 | 
			
		||||
                .execute((sender, args) -> {
 | 
			
		||||
                    if (sender instanceof Player) {
 | 
			
		||||
                        if (args.length == 0) {
 | 
			
		||||
                            sender.sendMessage("§8[§fTabooLib§8] §7/libtest §8[...]");
 | 
			
		||||
                            return;
 | 
			
		||||
                        }
 | 
			
		||||
                        for (Module module : testUtil) {
 | 
			
		||||
                            for (String name : module.name()) {
 | 
			
		||||
                                if (name.equalsIgnoreCase(args[0])) {
 | 
			
		||||
                                    module.run((Player) sender);
 | 
			
		||||
                                    return;
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }).build();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler(priority = EventPriority.LOWEST)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										21
									
								
								src/main/scala/io/izzel/taboolib/common/loader/Startup.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/main/scala/io/izzel/taboolib/common/loader/Startup.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
package io.izzel.taboolib.common.loader;
 | 
			
		||||
 | 
			
		||||
import java.lang.annotation.ElementType;
 | 
			
		||||
import java.lang.annotation.Retention;
 | 
			
		||||
import java.lang.annotation.RetentionPolicy;
 | 
			
		||||
import java.lang.annotation.Target;
 | 
			
		||||
 | 
			
		||||
public @interface Startup {
 | 
			
		||||
 | 
			
		||||
    @Target(ElementType.METHOD)
 | 
			
		||||
    @Retention(RetentionPolicy.RUNTIME)
 | 
			
		||||
    @interface Loading {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Target(ElementType.METHOD)
 | 
			
		||||
    @Retention(RetentionPolicy.RUNTIME)
 | 
			
		||||
    @interface Starting {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,47 @@
 | 
			
		||||
package io.izzel.taboolib.common.loader;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.Lists;
 | 
			
		||||
import io.izzel.taboolib.TabooLib;
 | 
			
		||||
import io.izzel.taboolib.module.inject.TInjectHelper;
 | 
			
		||||
 | 
			
		||||
import java.lang.annotation.Annotation;
 | 
			
		||||
import java.lang.reflect.Method;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @Author sky
 | 
			
		||||
 * @Since 2020-03-24 23:54
 | 
			
		||||
 */
 | 
			
		||||
public class StartupLoader {
 | 
			
		||||
 | 
			
		||||
    static List<Class<?>> classList = Lists.newArrayList();
 | 
			
		||||
 | 
			
		||||
    public static void register(Class<?> clazz) {
 | 
			
		||||
        classList.add(clazz);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void onLoading() {
 | 
			
		||||
        run(Startup.Loading.class);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void onStarting() {
 | 
			
		||||
        run(Startup.Starting.class);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static void run(Class<? extends Annotation> annotation) {
 | 
			
		||||
        for (Class pluginClass : classList) {
 | 
			
		||||
            for (Method declaredMethod : pluginClass.getDeclaredMethods()) {
 | 
			
		||||
                if (declaredMethod.isAnnotationPresent(annotation)) {
 | 
			
		||||
                    declaredMethod.setAccessible(true);
 | 
			
		||||
                    for (Object instance : TInjectHelper.getInstance(declaredMethod, pluginClass, TabooLib.getPlugin())) {
 | 
			
		||||
                        try {
 | 
			
		||||
                            declaredMethod.invoke(instance);
 | 
			
		||||
                        } catch (Throwable t) {
 | 
			
		||||
                            t.printStackTrace();
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -3,7 +3,7 @@ package io.izzel.taboolib.util.book;
 | 
			
		||||
import io.izzel.taboolib.module.nms.NMS;
 | 
			
		||||
import io.izzel.taboolib.util.book.builder.BookBuilder;
 | 
			
		||||
import io.izzel.taboolib.util.book.builder.PageBuilder;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import io.izzel.taboolib.util.lite.Materials;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
 | 
			
		||||
@@ -27,11 +27,11 @@ public class BookFormatter {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static BookBuilder writtenBook() {
 | 
			
		||||
        return new BookBuilder(new ItemStack(Material.WRITTEN_BOOK));
 | 
			
		||||
        return new BookBuilder(Materials.WRITTEN_BOOK.parseItem(), "null", "null");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static BookBuilder writtenBook(String title, String author) {
 | 
			
		||||
        return new BookBuilder(new ItemStack(Material.WRITTEN_BOOK), title, author);
 | 
			
		||||
        return new BookBuilder(Materials.WRITTEN_BOOK.parseItem(), title, author);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static ItemStack writeToBook(List<String> lines) {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,8 +2,10 @@ package io.izzel.taboolib.util.book.builder;
 | 
			
		||||
 | 
			
		||||
import io.izzel.taboolib.module.tellraw.TellrawJson;
 | 
			
		||||
import io.izzel.taboolib.util.book.BookAsm;
 | 
			
		||||
import io.izzel.taboolib.util.book.BookFormatter;
 | 
			
		||||
import io.izzel.taboolib.util.chat.BaseComponent;
 | 
			
		||||
import io.izzel.taboolib.util.chat.ComponentSerializer;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
import org.bukkit.inventory.meta.BookMeta;
 | 
			
		||||
 | 
			
		||||
@@ -133,6 +135,14 @@ public class BookBuilder {
 | 
			
		||||
        return book;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public BookBuilder open(Player... players) {
 | 
			
		||||
        ItemStack build = build();
 | 
			
		||||
        for (Player player : players) {
 | 
			
		||||
            BookFormatter.forceOpen(player, build);
 | 
			
		||||
        }
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public BookMeta getMeta() {
 | 
			
		||||
        return meta;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@ package io.izzel.taboolib.util.item;
 | 
			
		||||
import io.izzel.taboolib.Version;
 | 
			
		||||
import io.izzel.taboolib.module.locale.TLocale;
 | 
			
		||||
import io.izzel.taboolib.util.ArrayUtil;
 | 
			
		||||
import io.izzel.taboolib.util.lite.Materials;
 | 
			
		||||
import org.bukkit.Color;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.OfflinePlayer;
 | 
			
		||||
@@ -46,12 +47,12 @@ public class ItemBuilder {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ItemBuilder(OfflinePlayer player) {
 | 
			
		||||
        this(Material.SKULL_ITEM, 1, 3);
 | 
			
		||||
        this(Materials.PLAYER_HEAD.parseMaterial(), 1, 3);
 | 
			
		||||
        this.skullOwner(player.getName());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ItemBuilder material(int id) {
 | 
			
		||||
        itemStack.setType(Material.getMaterial(id));
 | 
			
		||||
        itemStack.setType(Items.asMaterial(String.valueOf(id)));
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user