版本更新至:3.73
重写:Language2 模块重写,允许单项语言多种类型 新增:Language2 工具新增 [sound] 类型! 新增:BookFormatter 工具,代码来自其他开源项目,代码已经过 60% 的重新开发。
This commit is contained in:
parent
97b73ad1b3
commit
dbc200561f
@ -0,0 +1,63 @@
|
|||||||
|
package me.skymc.taboolib.bookformatter;
|
||||||
|
|
||||||
|
import org.bukkit.Achievement;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import static org.bukkit.Achievement.*;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public final class BookAchievement {
|
||||||
|
|
||||||
|
private static final HashMap<Achievement, String> achievements = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
achievements.put(OPEN_INVENTORY, "openInventory");
|
||||||
|
achievements.put(MINE_WOOD, "mineWood");
|
||||||
|
achievements.put(BUILD_WORKBENCH, "buildWorkBench");
|
||||||
|
achievements.put(BUILD_PICKAXE, "buildPickaxe");
|
||||||
|
achievements.put(BUILD_FURNACE, "buildFurnace");
|
||||||
|
achievements.put(ACQUIRE_IRON, "aquireIron");
|
||||||
|
achievements.put(BUILD_HOE, "buildHoe");
|
||||||
|
achievements.put(MAKE_BREAD, "makeBread");
|
||||||
|
achievements.put(BAKE_CAKE,"bakeCake");
|
||||||
|
achievements.put(BUILD_BETTER_PICKAXE,"buildBetterPickaxe");
|
||||||
|
achievements.put(COOK_FISH,"cookFish");
|
||||||
|
achievements.put(ON_A_RAIL,"onARail");
|
||||||
|
achievements.put(BUILD_SWORD,"buildSword");
|
||||||
|
achievements.put(KILL_ENEMY,"killEnemy");
|
||||||
|
achievements.put(KILL_COW,"killCow");
|
||||||
|
achievements.put(FLY_PIG,"flyPig");
|
||||||
|
achievements.put(SNIPE_SKELETON,"snipeSkeleton");
|
||||||
|
achievements.put(GET_DIAMONDS,"diamonds");
|
||||||
|
achievements.put(NETHER_PORTAL,"portal");
|
||||||
|
achievements.put(GHAST_RETURN,"ghast");
|
||||||
|
achievements.put(GET_BLAZE_ROD,"blazerod");
|
||||||
|
achievements.put(BREW_POTION,"potion");
|
||||||
|
achievements.put(END_PORTAL,"thEnd");
|
||||||
|
achievements.put(THE_END,"theEnd2");
|
||||||
|
achievements.put(ENCHANTMENTS,"enchantments");
|
||||||
|
achievements.put(OVERKILL,"overkill");
|
||||||
|
achievements.put(BOOKCASE,"bookacase");
|
||||||
|
achievements.put(EXPLORE_ALL_BIOMES,"exploreAllBiomes");
|
||||||
|
achievements.put(SPAWN_WITHER,"spawnWither");
|
||||||
|
achievements.put(KILL_WITHER,"killWither");
|
||||||
|
achievements.put(FULL_BEACON,"fullBeacon");
|
||||||
|
achievements.put(BREED_COW,"breedCow");
|
||||||
|
achievements.put(DIAMONDS_TO_YOU,"diamondsToYou");
|
||||||
|
achievements.put(OVERPOWERED, "overpowered");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the json id from the bukkit achievement passed as argument
|
||||||
|
* @param achievement the achievement
|
||||||
|
* @return the achievement's id or null if not found
|
||||||
|
*/
|
||||||
|
public static String toId(Achievement achievement) {
|
||||||
|
return achievements.get(achievement);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BookAchievement(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
package me.skymc.taboolib.bookformatter;
|
||||||
|
|
||||||
|
import me.skymc.taboolib.bookformatter.builder.BookBuilder;
|
||||||
|
import me.skymc.taboolib.events.CustomBookOpenEvent;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public final class BookFormatter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a book GUI to the player
|
||||||
|
* @param p the player
|
||||||
|
* @param book the book to be opened
|
||||||
|
*/
|
||||||
|
public static void openPlayer(Player p, ItemStack book) {
|
||||||
|
CustomBookOpenEvent event = new CustomBookOpenEvent(p, book, false);
|
||||||
|
//Call the CustomBookOpenEvent
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
//Check if it's cancelled
|
||||||
|
if(event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Close inventory currently
|
||||||
|
p.closeInventory();
|
||||||
|
//Store the previous item
|
||||||
|
ItemStack hand = p.getItemInHand();
|
||||||
|
p.setItemInHand(event.getBook());
|
||||||
|
|
||||||
|
//Opening the GUI
|
||||||
|
BookReflection.openBook(p, event.getBook(), event.getHand() == CustomBookOpenEvent.Hand.OFF_HAND);
|
||||||
|
|
||||||
|
//Returning whatever was on hand.
|
||||||
|
p.setItemInHand(hand);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a book GUI to the player, Bypass the {@link CustomBookOpenEvent}
|
||||||
|
* @param p the player
|
||||||
|
* @param book the book to be opened
|
||||||
|
*/
|
||||||
|
public static void forceOpen(Player p, ItemStack book) {
|
||||||
|
//Close inventory currently
|
||||||
|
p.closeInventory();
|
||||||
|
//Store the previous item
|
||||||
|
ItemStack hand = p.getItemInHand();
|
||||||
|
p.setItemInHand(book);
|
||||||
|
|
||||||
|
//Opening the GUI
|
||||||
|
BookReflection.openBook(p, book, false);
|
||||||
|
|
||||||
|
//Returning whatever was on hand.
|
||||||
|
p.setItemInHand(hand);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a BookBuilder instance with a written book as the Itemstack's type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static BookBuilder writtenBook() {
|
||||||
|
return new BookBuilder(new ItemStack(Material.WRITTEN_BOOK));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a BookBuilder instance with a written book as the Itemstack's type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static BookBuilder writtenBook(String title, String author) {
|
||||||
|
return new BookBuilder(new ItemStack(Material.WRITTEN_BOOK), title, author);
|
||||||
|
}
|
||||||
|
}
|
297
src/main/src/me/skymc/taboolib/bookformatter/BookReflection.java
Normal file
297
src/main/src/me/skymc/taboolib/bookformatter/BookReflection.java
Normal file
@ -0,0 +1,297 @@
|
|||||||
|
package me.skymc.taboolib.bookformatter;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.chat.ComponentSerializer;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The NMS helper for all the Book-API
|
||||||
|
*/
|
||||||
|
public final class BookReflection {
|
||||||
|
|
||||||
|
private static final String version;
|
||||||
|
private static final boolean doubleHands;
|
||||||
|
|
||||||
|
private static final Class<?> craftMetaBookClass;
|
||||||
|
private static final Field craftMetaBookField;
|
||||||
|
private static final Method chatSerializerA;
|
||||||
|
|
||||||
|
private static final Method craftPlayerGetHandle;
|
||||||
|
|
||||||
|
//This method takes an enum that represents the player's hand only in versions >= 1.9
|
||||||
|
//In the other versions it only takes the nms item
|
||||||
|
private static final Method entityPlayerOpenBook;
|
||||||
|
|
||||||
|
//only version >= 1.9
|
||||||
|
private static final Object[] hands;
|
||||||
|
|
||||||
|
//Older versions
|
||||||
|
/*private static final Field entityHumanPlayerConnection;
|
||||||
|
private static final Method playerConnectionSendPacket;
|
||||||
|
|
||||||
|
private static final Constructor<?> packetPlayOutCustomPayloadConstructor;
|
||||||
|
private static final Constructor<?> packetDataSerializerConstructor;*/
|
||||||
|
|
||||||
|
private static final Method nmsItemStackSave;
|
||||||
|
private static final Constructor<?> nbtTagCompoundConstructor;
|
||||||
|
|
||||||
|
private static final Method craftItemStackAsNMSCopy;
|
||||||
|
|
||||||
|
static {
|
||||||
|
version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||||
|
final int major, minor;
|
||||||
|
Pattern pattern = Pattern.compile("v([0-9]+)_([0-9]+)");
|
||||||
|
Matcher m = pattern.matcher(version);
|
||||||
|
if(m.find()) {
|
||||||
|
major = Integer.parseInt(m.group(1));
|
||||||
|
minor = Integer.parseInt(m.group(2));
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException("Cannot parse version \"" + version + "\", make sure it follows \"v<major>_<minor>...\"");
|
||||||
|
}
|
||||||
|
doubleHands = major <= 1 && minor >= 9;
|
||||||
|
try {
|
||||||
|
craftMetaBookClass = getCraftClass("inventory.CraftMetaBook");
|
||||||
|
craftMetaBookField = craftMetaBookClass.getDeclaredField("pages");
|
||||||
|
craftMetaBookField.setAccessible(true);
|
||||||
|
Class<?> chatSerializer = getNmsClass("IChatBaseComponent$ChatSerializer", false);
|
||||||
|
if(chatSerializer == null)
|
||||||
|
chatSerializer = getNmsClass("ChatSerializer");
|
||||||
|
|
||||||
|
chatSerializerA = chatSerializer.getDeclaredMethod("a", String.class);
|
||||||
|
|
||||||
|
final Class<?> craftPlayerClass = getCraftClass("entity.CraftPlayer");
|
||||||
|
craftPlayerGetHandle = craftPlayerClass.getMethod("getHandle");
|
||||||
|
|
||||||
|
final Class<?> entityPlayerClass = getNmsClass("EntityPlayer");
|
||||||
|
final Class<?> itemStackClass = getNmsClass("ItemStack");
|
||||||
|
if(doubleHands) {
|
||||||
|
final Class<?> enumHandClass = getNmsClass("EnumHand");
|
||||||
|
entityPlayerOpenBook = entityPlayerClass.getMethod("a", itemStackClass, enumHandClass);
|
||||||
|
hands = enumHandClass.getEnumConstants();
|
||||||
|
} else {
|
||||||
|
entityPlayerOpenBook = entityPlayerClass.getMethod("openBook", itemStackClass);
|
||||||
|
hands = null;
|
||||||
|
}
|
||||||
|
//Older versions
|
||||||
|
/*entityHumanPlayerConnection = entityPlayerClass.getField("playerConnection");
|
||||||
|
final Class<?> playerConnectionClass = getNmsClass("PlayerConnection");
|
||||||
|
playerConnectionSendPacket = playerConnectionClass.getMethod("sendPacket", getNmsClass("Packet"));
|
||||||
|
|
||||||
|
final Class<?> packetDataSerializerClasss = getNmsClass("PacketDataSerializer");
|
||||||
|
packetPlayOutCustomPayloadConstructor = getNmsClass("PacketPlayOutCustomPayload").getConstructor(String.class, packetDataSerializerClasss);
|
||||||
|
packetDataSerializerConstructor = packetDataSerializerClasss.getConstructor(ByteBuf.class);*/
|
||||||
|
|
||||||
|
final Class<?> craftItemStackClass = getCraftClass("inventory.CraftItemStack");
|
||||||
|
craftItemStackAsNMSCopy = craftItemStackClass.getMethod("asNMSCopy", ItemStack.class);
|
||||||
|
Class<?> nmsItemStackClazz = getNmsClass("ItemStack");
|
||||||
|
Class<?> nbtTagCompoundClazz = getNmsClass("NBTTagCompound");
|
||||||
|
nmsItemStackSave = nmsItemStackClazz.getMethod("save", nbtTagCompoundClazz);
|
||||||
|
nbtTagCompoundConstructor = nbtTagCompoundClazz.getConstructor();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IllegalStateException("Cannot initiate reflections for " + version, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the pages of the book to the components json equivalent
|
||||||
|
* @param meta the book meta to change
|
||||||
|
* @param components the pages of the book
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")//reflections = unchecked warnings
|
||||||
|
public static void setPages(BookMeta meta, BaseComponent[][] components) {
|
||||||
|
try {
|
||||||
|
List<Object> pages = (List<Object>) craftMetaBookField.get(meta);
|
||||||
|
pages.clear();
|
||||||
|
for(BaseComponent[] c : components) {
|
||||||
|
final String json = ComponentSerializer.toString(c);
|
||||||
|
//System.out.println("page:" + json); //Debug
|
||||||
|
pages.add(chatSerializerA.invoke(null, json));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new UnsupportedVersionException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append the pages of the book to the components json equivalent
|
||||||
|
* @param meta the book meta to change
|
||||||
|
* @param components the pages of the book
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")//reflections = unchecked warnings
|
||||||
|
public static void addPages(BookMeta meta, BaseComponent[][] components) {
|
||||||
|
try {
|
||||||
|
List<Object> pages = (List<Object>) craftMetaBookField.get(meta);
|
||||||
|
for(BaseComponent[] c : components) {
|
||||||
|
final String json = ComponentSerializer.toString(c);
|
||||||
|
//System.out.println("page:" + json); //Debug
|
||||||
|
pages.add(chatSerializerA.invoke(null, json));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new UnsupportedVersionException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the book to a player (the player needs to have the book in one of his hands)
|
||||||
|
* @param player the player
|
||||||
|
* @param book the book to open
|
||||||
|
* @param offHand false if the book is in the right hand, true otherwise
|
||||||
|
*/
|
||||||
|
public static void openBook(Player player, ItemStack book, boolean offHand) {
|
||||||
|
//nms(player).openBook(nms(player), nms(book), hand);
|
||||||
|
try {
|
||||||
|
//Older versions:
|
||||||
|
/*playerConnectionSendPacket.invoke(
|
||||||
|
entityHumanPlayerConnection.get(toNms(player)),
|
||||||
|
createBookOpenPacket()
|
||||||
|
);*/
|
||||||
|
if(doubleHands) {
|
||||||
|
entityPlayerOpenBook.invoke(
|
||||||
|
toNms(player),
|
||||||
|
nmsCopy(book),
|
||||||
|
hands[offHand ? 1 : 0]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
entityPlayerOpenBook.invoke(
|
||||||
|
toNms(player),
|
||||||
|
nmsCopy(book)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new UnsupportedVersionException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Older versions
|
||||||
|
/*public static Object createBookOpenPacket() {
|
||||||
|
//new PacketPlayOutCustomPayload("MC|BOpen", new PacketDataSerializer(Unpooled.buffer())));
|
||||||
|
try {
|
||||||
|
return packetPlayOutCustomPayloadConstructor.newInstance(
|
||||||
|
"MC|BOpen",
|
||||||
|
packetDataSerializerConstructor.newInstance(Unpooled.buffer())
|
||||||
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new UnsupportedVersionException(e);
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translates an ItemStack to his Chat-Component equivalent
|
||||||
|
* @param item the item to be converted
|
||||||
|
* @return a Chat-Component equivalent of the parameter
|
||||||
|
*/
|
||||||
|
public static BaseComponent[] itemToComponents(ItemStack item) {
|
||||||
|
return jsonToComponents(itemToJson(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translates a json string to his Chat-Component equivalent
|
||||||
|
* @param json the json string to be converted
|
||||||
|
* @return a Chat-Component equivalent of the parameter
|
||||||
|
*/
|
||||||
|
public static BaseComponent[] jsonToComponents(String json) {
|
||||||
|
return new BaseComponent[] { new TextComponent(json) };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translates an ItemStack to his json equivalent
|
||||||
|
* @param item the item to be converted
|
||||||
|
* @return a json equivalent of the parameter
|
||||||
|
*/
|
||||||
|
private static String itemToJson(ItemStack item) {
|
||||||
|
try {
|
||||||
|
//net.minecraft.server.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
|
||||||
|
Object nmsItemStack = nmsCopy(item);
|
||||||
|
|
||||||
|
//net.minecraft.server.NBTTagCompound compound = new NBTTagCompound();
|
||||||
|
//compound = nmsItemStack.save(compound);
|
||||||
|
Object emptyTag = nbtTagCompoundConstructor.newInstance();
|
||||||
|
Object json = nmsItemStackSave.invoke(nmsItemStack, emptyTag);
|
||||||
|
return json.toString();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new UnsupportedVersionException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An error thrown when this NMS-helper class doesn't support the running MC version
|
||||||
|
*/
|
||||||
|
public static class UnsupportedVersionException extends RuntimeException {
|
||||||
|
/**
|
||||||
|
* serialVersionUID
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 6835583513394319946L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current running version
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
private final String version = BookReflection.version;
|
||||||
|
|
||||||
|
public UnsupportedVersionException(Exception e) {
|
||||||
|
super("Error while executing reflections, submit to developers the following log (version: " + BookReflection.version + ")", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the EntityPlayer handled by the argument
|
||||||
|
* @param player the Player handler
|
||||||
|
* @return the handled class
|
||||||
|
* @throws InvocationTargetException when some problems are found with the reflection
|
||||||
|
* @throws IllegalAccessException when some problems are found with the reflection
|
||||||
|
*/
|
||||||
|
public static Object toNms(Player player) throws InvocationTargetException, IllegalAccessException {
|
||||||
|
return craftPlayerGetHandle.invoke(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a NMS copy of the parameter
|
||||||
|
* @param item the ItemStack to be nms-copied
|
||||||
|
* @return a NMS-ItemStack that is the equivalent of the one passed as argument
|
||||||
|
* @throws InvocationTargetException when some problems are found with the reflection
|
||||||
|
* @throws IllegalAccessException when some problems are found with the reflection
|
||||||
|
*/
|
||||||
|
public static Object nmsCopy(ItemStack item) throws InvocationTargetException, IllegalAccessException {
|
||||||
|
return craftItemStackAsNMSCopy.invoke(null, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Class<?> getNmsClass(String className, boolean log) {
|
||||||
|
try {
|
||||||
|
return Class.forName("net.minecraft.server." + version + "." + className);
|
||||||
|
} catch(ClassNotFoundException e) {
|
||||||
|
if(log)
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Class<?> getNmsClass(String className) {
|
||||||
|
return getNmsClass(className, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static Class<?> getCraftClass(String path) {
|
||||||
|
try {
|
||||||
|
return Class.forName("org.bukkit.craftbukkit." + version + "." + path);
|
||||||
|
} catch(ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
package me.skymc.taboolib.bookformatter.action;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sky
|
||||||
|
* @since 2018-03-08 22:38:04
|
||||||
|
*/
|
||||||
|
public interface ClickAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Chat-Component action
|
||||||
|
* @return the Chat-Component action
|
||||||
|
*/
|
||||||
|
ClickEvent.Action action();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The value paired to the action
|
||||||
|
* @return the value paired tot the action
|
||||||
|
*/
|
||||||
|
String value();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a command action: when the player clicks, the command passed as parameter gets executed with the clicker as sender
|
||||||
|
* @param command the command to be executed
|
||||||
|
* @return a new ClickAction
|
||||||
|
*/
|
||||||
|
static ClickAction runCommand(String command) {
|
||||||
|
return new SimpleClickAction(ClickEvent.Action.RUN_COMMAND, command);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a suggest_command action: when the player clicks, the book closes and the chat opens with the parameter written into it
|
||||||
|
* @param command the command to be suggested
|
||||||
|
* @return a new ClickAction
|
||||||
|
*/
|
||||||
|
static ClickAction suggestCommand(String command) {
|
||||||
|
return new SimpleClickAction(ClickEvent.Action.SUGGEST_COMMAND, command);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a open_utl action: when the player clicks the url passed as argument will open in the browser
|
||||||
|
* @param url the url to be opened
|
||||||
|
* @return a new ClickAction
|
||||||
|
*/
|
||||||
|
static ClickAction openUrl(String url) {
|
||||||
|
if(url.startsWith("http://") || url.startsWith("https://"))
|
||||||
|
return new SimpleClickAction(ClickEvent.Action.OPEN_URL, url);
|
||||||
|
else
|
||||||
|
throw new IllegalArgumentException("Invalid url: \"" + url + "\", it should start with http:// or https://");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a change_page action: when the player clicks the book page will be set at the value passed as argument
|
||||||
|
* @param page the new page
|
||||||
|
* @return a new ClickAction
|
||||||
|
*/
|
||||||
|
static ClickAction changePage(int page) {
|
||||||
|
return new SimpleClickAction(ClickEvent.Action.CHANGE_PAGE, Integer.toString(page));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Accessors(fluent = true)
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
class SimpleClickAction implements ClickAction {
|
||||||
|
private final ClickEvent.Action action;
|
||||||
|
private final String value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,143 @@
|
|||||||
|
package me.skymc.taboolib.bookformatter.action;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.Achievement;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import me.skymc.taboolib.bookformatter.BookAchievement;
|
||||||
|
import me.skymc.taboolib.bookformatter.BookReflection;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sky
|
||||||
|
* @since 2018-03-08 22:38:51
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public interface HoverAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Chat-Component action
|
||||||
|
* @return the Chat-Component action
|
||||||
|
*/
|
||||||
|
HoverEvent.Action action();
|
||||||
|
/**
|
||||||
|
* The value paired to the action
|
||||||
|
* @return the value paired tot the action
|
||||||
|
*/
|
||||||
|
BaseComponent[] value();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a show_text action: when the component is hovered the text used as parameter will be displayed
|
||||||
|
* @param text the text to display
|
||||||
|
* @return a new HoverAction instance
|
||||||
|
*/
|
||||||
|
static HoverAction showText(BaseComponent... text) {
|
||||||
|
return new SimpleHoverAction(HoverEvent.Action.SHOW_TEXT, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a show_text action: when the component is hovered the text used as parameter will be displayed
|
||||||
|
* @param text the text to display
|
||||||
|
* @return a new HoverAction instance
|
||||||
|
*/
|
||||||
|
static HoverAction showText(String text) {
|
||||||
|
return new SimpleHoverAction(HoverEvent.Action.SHOW_TEXT, new TextComponent(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a show_item action: when the component is hovered some item information will be displayed
|
||||||
|
* @param item a component array representing item to display
|
||||||
|
* @return a new HoverAction instance
|
||||||
|
*/
|
||||||
|
static HoverAction showItem(BaseComponent... item) {
|
||||||
|
return new SimpleHoverAction(HoverEvent.Action.SHOW_ITEM, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a show_item action: when the component is hovered some item information will be displayed
|
||||||
|
* @param item the item to display
|
||||||
|
* @return a new HoverAction instance
|
||||||
|
*/
|
||||||
|
static HoverAction showItem(ItemStack item) {
|
||||||
|
return new SimpleHoverAction(HoverEvent.Action.SHOW_ITEM, BookReflection.itemToComponents(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a show_entity action: when the component is hovered some entity information will be displayed
|
||||||
|
* @param entity a component array representing the item to display
|
||||||
|
* @return a new HoverAction instance
|
||||||
|
*/
|
||||||
|
static HoverAction showEntity(BaseComponent... entity) {
|
||||||
|
return new SimpleHoverAction(HoverEvent.Action.SHOW_ENTITY, entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a show_entity action: when the component is hovered some entity information will be displayed
|
||||||
|
* @param uuid the entity's UniqueId
|
||||||
|
* @param type the entity's type
|
||||||
|
* @param name the entity's name
|
||||||
|
* @return a new HoverAction instance
|
||||||
|
*/
|
||||||
|
static HoverAction showEntity(UUID uuid, String type, String name) {
|
||||||
|
return new SimpleHoverAction(HoverEvent.Action.SHOW_ENTITY,
|
||||||
|
BookReflection.jsonToComponents(
|
||||||
|
"{id:\"" + uuid + "\",type:\"" + type + "\"name:\"" + name + "\"}"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a show_entity action: when the component is hovered some entity information will be displayed
|
||||||
|
* @param entity the item to display
|
||||||
|
* @return a new HoverAction instance
|
||||||
|
*/
|
||||||
|
static HoverAction showEntity(Entity entity) {
|
||||||
|
return showEntity(entity.getUniqueId(), entity.getType().getName(), entity.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a show_achievement action: when the component is hovered the achievement information will be displayed
|
||||||
|
* @param achievementId the id of the achievement to display
|
||||||
|
* @return a new HoverAction instance
|
||||||
|
*/
|
||||||
|
static HoverAction showAchievement(String achievementId) {
|
||||||
|
return new SimpleHoverAction(HoverEvent.Action.SHOW_ACHIEVEMENT, new TextComponent("achievement." + achievementId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a show_achievement action: when the component is hovered the achievement information will be displayed
|
||||||
|
* @param achievement the achievement to display
|
||||||
|
* @return a new HoverAction instance
|
||||||
|
*/
|
||||||
|
static HoverAction showAchievement(Achievement achievement) {
|
||||||
|
return showAchievement(BookAchievement.toId(achievement));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a show_achievement action: when the component is hovered the statistic information will be displayed
|
||||||
|
* @param statisticId the id of the statistic to display
|
||||||
|
* @return a new HoverAction instance
|
||||||
|
*/
|
||||||
|
static HoverAction showStatistic(String statisticId) {
|
||||||
|
return new SimpleHoverAction(HoverEvent.Action.SHOW_ACHIEVEMENT, new TextComponent("statistic." + statisticId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Accessors(fluent = true)
|
||||||
|
class SimpleHoverAction implements HoverAction {
|
||||||
|
private final HoverEvent.Action action;
|
||||||
|
private final BaseComponent[] value;
|
||||||
|
|
||||||
|
public SimpleHoverAction(HoverEvent.Action action, BaseComponent... value) {
|
||||||
|
this.action = action;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,129 @@
|
|||||||
|
package me.skymc.taboolib.bookformatter.builder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
|
|
||||||
|
import me.skymc.taboolib.bookformatter.BookReflection;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sky
|
||||||
|
* @since 2018-03-08 22:36:14
|
||||||
|
*/
|
||||||
|
public class BookBuilder {
|
||||||
|
|
||||||
|
private final BookMeta meta;
|
||||||
|
private final ItemStack book;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of the BookBuilder from an ItemStack representing the book item
|
||||||
|
* @param book the book's ItemStack
|
||||||
|
*/
|
||||||
|
public BookBuilder(ItemStack book) {
|
||||||
|
this.book = book;
|
||||||
|
this.meta = (BookMeta)book.getItemMeta();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of the BookBuilder from an ItemStack representing the book item
|
||||||
|
* @param book the book's ItemStack
|
||||||
|
*/
|
||||||
|
public BookBuilder(ItemStack book, String title, String author) {
|
||||||
|
this.book = book;
|
||||||
|
this.meta = (BookMeta)book.getItemMeta();
|
||||||
|
this.meta.setTitle(title);
|
||||||
|
this.meta.setAuthor(author);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the title of the book
|
||||||
|
* @param title the title of the book
|
||||||
|
* @return the BookBuilder's calling instance
|
||||||
|
*/
|
||||||
|
public BookBuilder title(String title) {
|
||||||
|
meta.setTitle(title);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the author of the book
|
||||||
|
* @param author the author of the book
|
||||||
|
* @return the BookBuilder's calling instance
|
||||||
|
*/
|
||||||
|
public BookBuilder author(String author) {
|
||||||
|
meta.setAuthor(author);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the generation of the book
|
||||||
|
* Only works from MC 1.10
|
||||||
|
* @param generation the Book generation
|
||||||
|
* @return the BookBuilder calling instance
|
||||||
|
*/
|
||||||
|
public BookBuilder generation(BookMeta.Generation generation) {
|
||||||
|
meta.setGeneration(generation);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the pages of the book without worrying about json or interactivity
|
||||||
|
* @param pages text-based pages
|
||||||
|
* @return the BookBuilder's calling instance
|
||||||
|
*/
|
||||||
|
public BookBuilder pagesRaw(String... pages) {
|
||||||
|
meta.setPages(pages);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the pages of the book without worrying about json or interactivity
|
||||||
|
* @param pages text-based pages
|
||||||
|
* @return the BookBuilder's calling instance
|
||||||
|
*/
|
||||||
|
public BookBuilder pagesRaw(List<String> pages) {
|
||||||
|
meta.setPages(pages);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the pages of the book
|
||||||
|
* @param pages the pages of the book
|
||||||
|
* @return the BookBuilder's calling instance
|
||||||
|
*/
|
||||||
|
public BookBuilder pages(BaseComponent[]... pages) {
|
||||||
|
BookReflection.setPages(meta, pages);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the pages of the book
|
||||||
|
* @param pages the pages of the book
|
||||||
|
* @return the BookBuilder's calling instance
|
||||||
|
*/
|
||||||
|
public BookBuilder pages(List<BaseComponent[]> pages) {
|
||||||
|
BookReflection.setPages(meta, pages.toArray(new BaseComponent[0][]));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append the pages of the book
|
||||||
|
* @param pages the pages of the book
|
||||||
|
* @return the BookBuilder's calling instance
|
||||||
|
*/
|
||||||
|
public BookBuilder addPages(BaseComponent[]... pages) {
|
||||||
|
BookReflection.addPages(meta, pages);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the book
|
||||||
|
* @return the built book
|
||||||
|
*/
|
||||||
|
public ItemStack build() {
|
||||||
|
book.setItemMeta(meta);
|
||||||
|
return book;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,114 @@
|
|||||||
|
package me.skymc.taboolib.bookformatter.builder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sky
|
||||||
|
* @since 2018-03-08 22:36:58
|
||||||
|
*/
|
||||||
|
public class PageBuilder {
|
||||||
|
|
||||||
|
private List<BaseComponent> text = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a simple black-colored text to the page
|
||||||
|
* @param text the text to add
|
||||||
|
* @return the PageBuilder's calling instance
|
||||||
|
*/
|
||||||
|
public PageBuilder add(String text) {
|
||||||
|
this.text.add(TextBuilder.of(text).build());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a component to the page
|
||||||
|
* @param component the component to add
|
||||||
|
* @return the PageBuilder's calling instance
|
||||||
|
*/
|
||||||
|
public PageBuilder add(BaseComponent component) {
|
||||||
|
this.text.add(component);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds one or more components to the page
|
||||||
|
* @param components the components to add
|
||||||
|
* @return the PageBuilder's calling instance
|
||||||
|
*/
|
||||||
|
public PageBuilder add(BaseComponent... components) {
|
||||||
|
this.text.addAll(Arrays.asList(components));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds one or more components to the page
|
||||||
|
* @param components the components to add
|
||||||
|
* @return the PageBuilder's calling instance
|
||||||
|
*/
|
||||||
|
public PageBuilder add(Collection<BaseComponent> components) {
|
||||||
|
this.text.addAll(components);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a newline to the page (equivalent of adding \n to the previous component)
|
||||||
|
* @return the PageBuilder's calling instance
|
||||||
|
*/
|
||||||
|
public PageBuilder newLine() {
|
||||||
|
this.text.add(new TextComponent("\n"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Another way of newLine(), better resolution (equivalent of adding \n to the previous component)
|
||||||
|
* @return the PageBuilder's calling instance
|
||||||
|
*/
|
||||||
|
public PageBuilder endLine() {
|
||||||
|
return newLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the page
|
||||||
|
* @return an array of BaseComponents representing the page
|
||||||
|
*/
|
||||||
|
public BaseComponent[] build() {
|
||||||
|
return text.toArray(new BaseComponent[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new PageBuilder instance wih the parameter as the initial text
|
||||||
|
* @param text the initial text of the page
|
||||||
|
* @return a new PageBuilder with the parameter as the initial text
|
||||||
|
*/
|
||||||
|
public static PageBuilder of(String text) {
|
||||||
|
return new PageBuilder().add(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new PageBuilder instance wih the parameter as the initial component
|
||||||
|
* @param text the initial component of the page
|
||||||
|
* @return a new PageBuilder with the parameter as the initial component
|
||||||
|
*/
|
||||||
|
public static PageBuilder of(BaseComponent text) {
|
||||||
|
return new PageBuilder().add(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new PageBuilder instance wih the parameter as the initial components
|
||||||
|
* @param text the initial components of the page
|
||||||
|
* @return a new PageBuilder with the parameter as the initial components
|
||||||
|
*/
|
||||||
|
public static PageBuilder of(BaseComponent... text) {
|
||||||
|
PageBuilder res = new PageBuilder();
|
||||||
|
for(BaseComponent b : text)
|
||||||
|
res.add(b);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
package me.skymc.taboolib.bookformatter.builder;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import me.skymc.taboolib.bookformatter.action.ClickAction;
|
||||||
|
import me.skymc.taboolib.bookformatter.action.HoverAction;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sky
|
||||||
|
* @since 2018-03-08 22:37:27
|
||||||
|
*/
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
@Accessors(fluent = true, chain = true)
|
||||||
|
public class TextBuilder {
|
||||||
|
|
||||||
|
private String text = "";
|
||||||
|
private ClickAction onClick = null;
|
||||||
|
private HoverAction onHover = null;
|
||||||
|
|
||||||
|
public TextBuilder() {}
|
||||||
|
|
||||||
|
public TextBuilder(String text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the component representing the built text
|
||||||
|
* @return the component representing the built text
|
||||||
|
*/
|
||||||
|
public BaseComponent build() {
|
||||||
|
TextComponent res = new TextComponent(text);
|
||||||
|
if(onClick != null) {
|
||||||
|
res.setClickEvent(new ClickEvent(onClick.action(), onClick.value()));
|
||||||
|
}
|
||||||
|
if(onHover != null) {
|
||||||
|
res.setHoverEvent(new HoverEvent(onHover.action(), onHover.value()));
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new TextBuilder with the parameter as his initial text
|
||||||
|
* @param text initial text
|
||||||
|
* @return a new TextBuilder with the parameter as his initial text
|
||||||
|
*/
|
||||||
|
public static TextBuilder of(String text) {
|
||||||
|
return new TextBuilder().text(text);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
package me.skymc.taboolib.events;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The event called when a book is opened trough this Util
|
||||||
|
*/
|
||||||
|
public class CustomBookOpenEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private boolean cancelled;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The player
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
private final Player player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The hand used to open the book (the previous item will be restored after the opening)
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private Hand hand;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The actual book to be opened
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private ItemStack book;
|
||||||
|
|
||||||
|
public CustomBookOpenEvent(Player player, ItemStack book, boolean offHand) {
|
||||||
|
this.player = player;
|
||||||
|
this.book = book;
|
||||||
|
this.hand = offHand ? Hand.OFF_HAND : Hand.MAIN_HAND;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Hand {
|
||||||
|
MAIN_HAND, OFF_HAND
|
||||||
|
}
|
||||||
|
}
|
@ -295,7 +295,7 @@ public class JSONFormatter {
|
|||||||
Object entityplayer = NMSUtils.getHandle(player);
|
Object entityplayer = NMSUtils.getHandle(player);
|
||||||
Object ppco = ppc.get(entityplayer);
|
Object ppco = ppc.get(entityplayer);
|
||||||
sp.invoke(ppco, jf.getPacket());
|
sp.invoke(ppco, jf.getPacket());
|
||||||
}catch(Exception e){
|
} catch(Exception e){
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + player.getName() + " " + jf.toJSON());
|
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + player.getName() + " " + jf.toJSON());
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
@ -0,0 +1,139 @@
|
|||||||
|
package me.skymc.taboolib.string.language2;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import me.skymc.taboolib.string.language2.value.Language2Action;
|
||||||
|
import me.skymc.taboolib.string.language2.value.Language2Json;
|
||||||
|
import me.skymc.taboolib.string.language2.value.Language2Sound;
|
||||||
|
import me.skymc.taboolib.string.language2.value.Language2Text;
|
||||||
|
import me.skymc.taboolib.string.language2.value.Language2Title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sky
|
||||||
|
* @since 2018-03-08 22:45:56
|
||||||
|
*/
|
||||||
|
public class Language2Format implements Language2Line {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private Language2Value language2Value = null;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private List<Language2Line> language2Lines = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造方法
|
||||||
|
*
|
||||||
|
* @param value 父类
|
||||||
|
*/
|
||||||
|
public Language2Format(Player player, Language2Value value) {
|
||||||
|
language2Value = value;
|
||||||
|
// 语言类型
|
||||||
|
Language2Type type = Language2Type.TEXT;
|
||||||
|
// 递交数据
|
||||||
|
List<String> values = new LinkedList<>();
|
||||||
|
|
||||||
|
// 遍历内容
|
||||||
|
for (String line : value.getLanguageValue()) {
|
||||||
|
// 文本类型
|
||||||
|
if (line.contains("[text]")) {
|
||||||
|
// 递交数据
|
||||||
|
parseValue(player, values, type);
|
||||||
|
// 更改类型
|
||||||
|
type = Language2Type.TEXT;
|
||||||
|
}
|
||||||
|
// 大标题
|
||||||
|
else if (line.contains("[title]")) {
|
||||||
|
// 递交数据
|
||||||
|
parseValue(player, values, type);
|
||||||
|
// 更改类型
|
||||||
|
type = Language2Type.TITLE;
|
||||||
|
}
|
||||||
|
// 小标题
|
||||||
|
else if (line.contains("[action]")) {
|
||||||
|
// 递交数据
|
||||||
|
parseValue(player, values, type);
|
||||||
|
// 更改类型
|
||||||
|
type = Language2Type.ACTION;
|
||||||
|
}
|
||||||
|
// JSON
|
||||||
|
else if (line.contains("[json]")) {
|
||||||
|
// 递交数据
|
||||||
|
parseValue(player, values, type);
|
||||||
|
// 更改类型
|
||||||
|
type = Language2Type.JSON;
|
||||||
|
}
|
||||||
|
// 音效
|
||||||
|
else if (line.contains("[sound]")) {
|
||||||
|
// 递交数据
|
||||||
|
parseValue(player, values, type);
|
||||||
|
// 更改类型
|
||||||
|
type = Language2Type.SOUND;
|
||||||
|
}
|
||||||
|
else if (line.contains("[return]")) {
|
||||||
|
// 递交数据
|
||||||
|
parseValue(player, values, type);
|
||||||
|
}
|
||||||
|
// 默认
|
||||||
|
else {
|
||||||
|
// 追加内容
|
||||||
|
values.add(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 识别内容
|
||||||
|
*
|
||||||
|
* @param player 玩家
|
||||||
|
* @param list 数据
|
||||||
|
* @param type 类型
|
||||||
|
*/
|
||||||
|
private void parseValue(Player player, List<String> list, Language2Type type) {
|
||||||
|
if (list.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 大标题
|
||||||
|
if (type == Language2Type.TITLE) {
|
||||||
|
language2Lines.add(new Language2Title(this, list));
|
||||||
|
}
|
||||||
|
// 小标题
|
||||||
|
else if (type == Language2Type.ACTION) {
|
||||||
|
language2Lines.add(new Language2Action(this, list));
|
||||||
|
}
|
||||||
|
// JSON
|
||||||
|
else if (type == Language2Type.JSON) {
|
||||||
|
language2Lines.add(new Language2Json(this, list, player));
|
||||||
|
}
|
||||||
|
// 音效
|
||||||
|
else if (type == Language2Type.SOUND) {
|
||||||
|
language2Lines.add(new Language2Sound(this, list));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
language2Lines.add(new Language2Text(this, list));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清理数据
|
||||||
|
list.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void send(Player player) {
|
||||||
|
for (Language2Line line : language2Lines) {
|
||||||
|
line.send(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void console() {
|
||||||
|
for (Language2Line line : language2Lines) {
|
||||||
|
line.console();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package me.skymc.taboolib.string.language2;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sky
|
||||||
|
* @since 2018-03-08 23:36:22
|
||||||
|
*/
|
||||||
|
public abstract interface Language2Line {
|
||||||
|
|
||||||
|
abstract void send(Player player);
|
||||||
|
|
||||||
|
abstract void console();
|
||||||
|
|
||||||
|
}
|
@ -26,4 +26,8 @@ public enum Language2Type {
|
|||||||
*/
|
*/
|
||||||
ACTION,
|
ACTION,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ÒôЧ
|
||||||
|
*/
|
||||||
|
SOUND,
|
||||||
}
|
}
|
||||||
|
@ -2,22 +2,17 @@ package me.skymc.taboolib.string.language2;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.skymc.taboolib.string.language2.type.Language2Action;
|
import me.skymc.taboolib.string.language2.value.Language2Text;
|
||||||
import me.skymc.taboolib.string.language2.type.Language2Json;
|
|
||||||
import me.skymc.taboolib.string.language2.type.Language2Title;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author sky
|
* @author sky
|
||||||
@ -34,9 +29,6 @@ public class Language2Value extends Object {
|
|||||||
@Getter
|
@Getter
|
||||||
private List<String> languageValue;
|
private List<String> languageValue;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private Language2Type languageType;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private LinkedHashMap<String, String> placeholder = new LinkedHashMap<>();
|
private LinkedHashMap<String, String> placeholder = new LinkedHashMap<>();
|
||||||
|
|
||||||
@ -63,42 +55,16 @@ public class Language2Value extends Object {
|
|||||||
if (language.getConfiguration().get(languageKey) instanceof List) {
|
if (language.getConfiguration().get(languageKey) instanceof List) {
|
||||||
// 设置文本
|
// 设置文本
|
||||||
languageValue = asColored(language.getConfiguration().getStringList(languageKey));
|
languageValue = asColored(language.getConfiguration().getStringList(languageKey));
|
||||||
// 获取类型
|
// 追加结尾
|
||||||
String type = languageValue.get(0).toLowerCase();
|
languageValue.add("[return]");
|
||||||
|
|
||||||
// 是否有类型注释
|
|
||||||
boolean isType = true;
|
|
||||||
|
|
||||||
// 是否启用PAPI
|
// 是否启用PAPI
|
||||||
if (type.contains("[papi]")) {
|
if (languageValue.get(0).contains("[papi]")) {
|
||||||
enablePlaceholderAPI = true;
|
enablePlaceholderAPI = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断类型
|
|
||||||
if (type.contains("[json]")) {
|
|
||||||
languageType = Language2Type.JSON;
|
|
||||||
}
|
|
||||||
else if (type.contains("[title]")) {
|
|
||||||
languageType = Language2Type.TITLE;
|
|
||||||
}
|
|
||||||
else if (type.contains("[action]")) {
|
|
||||||
languageType = Language2Type.ACTION;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
languageType = Language2Type.TEXT;
|
|
||||||
isType = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 是否需要删除类型注释
|
|
||||||
if (isType) {
|
|
||||||
languageValue.remove(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// 设置文本
|
// 设置文本
|
||||||
languageValue = Arrays.asList(ChatColor.translateAlternateColorCodes('&', language.getConfiguration().getString(languageKey)));
|
languageValue = Arrays.asList(ChatColor.translateAlternateColorCodes('&', language.getConfiguration().getString(languageKey)), "[return]");
|
||||||
// 设置类型
|
|
||||||
languageType = Language2Type.TEXT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化变量
|
// 初始化变量
|
||||||
@ -112,33 +78,7 @@ public class Language2Value extends Object {
|
|||||||
* @param player
|
* @param player
|
||||||
*/
|
*/
|
||||||
public void send(Player player) {
|
public void send(Player player) {
|
||||||
// 标题类型
|
new Language2Format(player, this).send(player);
|
||||||
if (languageType == Language2Type.TITLE) {
|
|
||||||
// 发送文本
|
|
||||||
new Language2Title(this).send(player);
|
|
||||||
}
|
|
||||||
// 动作栏类型
|
|
||||||
else if (languageType == Language2Type.ACTION) {
|
|
||||||
// 发送文本
|
|
||||||
new Language2Action(this).send(player);
|
|
||||||
}
|
|
||||||
// JSON类型
|
|
||||||
else if (languageType == Language2Type.JSON) {
|
|
||||||
// 发送文本
|
|
||||||
new Language2Json(this, player).send(player);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// 遍历文本
|
|
||||||
for (String message : languageValue) {
|
|
||||||
// 发送信息
|
|
||||||
if (player != null) {
|
|
||||||
player.sendMessage(setPlaceholder(message, player));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Bukkit.getConsoleSender().sendMessage(setPlaceholder(message, player));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -147,42 +87,8 @@ public class Language2Value extends Object {
|
|||||||
* @param players 玩家
|
* @param players 玩家
|
||||||
*/
|
*/
|
||||||
public void send(List<Player> players) {
|
public void send(List<Player> players) {
|
||||||
// 标题类型
|
for (Player player : players) {
|
||||||
if (languageType == Language2Type.TITLE) {
|
send(player);
|
||||||
// 识别文本
|
|
||||||
Language2Title title = new Language2Title(this);
|
|
||||||
// 发送文本
|
|
||||||
players.forEach(x -> title.send(x));
|
|
||||||
}
|
|
||||||
// 动作栏类型
|
|
||||||
else if (languageType == Language2Type.ACTION) {
|
|
||||||
// 识别文本
|
|
||||||
Language2Action action = new Language2Action(this);
|
|
||||||
// 发送文本
|
|
||||||
players.forEach(x -> action.send(x));
|
|
||||||
}
|
|
||||||
// JSON类型
|
|
||||||
else if (languageType == Language2Type.JSON) {
|
|
||||||
for (Player player : players) {
|
|
||||||
// 识别文本
|
|
||||||
Language2Json json = new Language2Json(this, player);
|
|
||||||
// 发送文本
|
|
||||||
json.send(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for (Player player : players) {
|
|
||||||
// 遍历文本
|
|
||||||
for (String message : languageValue) {
|
|
||||||
// 发送信息
|
|
||||||
if (player != null) {
|
|
||||||
player.sendMessage(setPlaceholder(message, player));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Bukkit.getConsoleSender().sendMessage(setPlaceholder(message, player));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +102,7 @@ public class Language2Value extends Object {
|
|||||||
send((Player) sender);
|
send((Player) sender);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
send(Bukkit.getPlayerExact(""));
|
console();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,11 +110,14 @@ public class Language2Value extends Object {
|
|||||||
* 全服公告
|
* 全服公告
|
||||||
*/
|
*/
|
||||||
public void broadcast() {
|
public void broadcast() {
|
||||||
List<Player> players = new ArrayList<>();
|
send(new ArrayList<>(Bukkit.getOnlinePlayers()));
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
}
|
||||||
players.add(player);
|
|
||||||
}
|
/**
|
||||||
send(players);
|
* 发送到后台
|
||||||
|
*/
|
||||||
|
public void console() {
|
||||||
|
new Language2Format(null, this).console();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -217,23 +126,32 @@ public class Language2Value extends Object {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String asString() {
|
public String asString() {
|
||||||
// 标题类型
|
Language2Format format = new Language2Format(null, this);
|
||||||
if (languageType == Language2Type.TITLE) {
|
if (format.getLanguage2Lines().get(0) instanceof Language2Text) {
|
||||||
return new Language2Title(this).getTitle();
|
Language2Text text = (Language2Text) format.getLanguage2Lines().get(0);
|
||||||
}
|
return text.getText().get(0);
|
||||||
// 动作栏类型
|
|
||||||
else if (languageType == Language2Type.ACTION) {
|
|
||||||
return new Language2Action(this).getText();
|
|
||||||
}
|
|
||||||
// JSON类型
|
|
||||||
else if (languageType == Language2Type.JSON) {
|
|
||||||
return new Language2Json(this, null).getText().toString();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return languageValue.size() == 0 ? ChatColor.DARK_RED + "[<ERROR-1>]" : setPlaceholder(languageValue.get(0), null);
|
return languageValue.size() == 0 ? ChatColor.DARK_RED + "[<ERROR-1>]" : setPlaceholder(languageValue.get(0), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文本集合
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<String> asStringList() {
|
||||||
|
Language2Format format = new Language2Format(null, this);
|
||||||
|
if (format.getLanguage2Lines().get(0) instanceof Language2Text) {
|
||||||
|
Language2Text text = (Language2Text) format.getLanguage2Lines().get(0);
|
||||||
|
return text.getText();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return Arrays.asList(languageValue.size() == 0 ? ChatColor.DARK_RED + "[<ERROR-1>]" : setPlaceholder(languageValue.get(0), null));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 变量替换
|
* 变量替换
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package me.skymc.taboolib.string.language2.type;
|
package me.skymc.taboolib.string.language2.value;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -13,13 +14,15 @@ import me.skymc.taboolib.TabooLib;
|
|||||||
import me.skymc.taboolib.display.ActionUtils;
|
import me.skymc.taboolib.display.ActionUtils;
|
||||||
import me.skymc.taboolib.message.MsgUtils;
|
import me.skymc.taboolib.message.MsgUtils;
|
||||||
import me.skymc.taboolib.other.NumberUtils;
|
import me.skymc.taboolib.other.NumberUtils;
|
||||||
|
import me.skymc.taboolib.string.language2.Language2Format;
|
||||||
|
import me.skymc.taboolib.string.language2.Language2Line;
|
||||||
import me.skymc.taboolib.string.language2.Language2Value;
|
import me.skymc.taboolib.string.language2.Language2Value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author sky
|
* @author sky
|
||||||
* @since 2018年2月13日 下午3:58:07
|
* @since 2018年2月13日 下午3:58:07
|
||||||
*/
|
*/
|
||||||
public class Language2Action {
|
public class Language2Action implements Language2Line {
|
||||||
|
|
||||||
private static final String KEY_TEXT = " text: ";
|
private static final String KEY_TEXT = " text: ";
|
||||||
private static final String KEY_STAY = " repeat: ";
|
private static final String KEY_STAY = " repeat: ";
|
||||||
@ -33,12 +36,11 @@ public class Language2Action {
|
|||||||
@Getter
|
@Getter
|
||||||
private Language2Value value;
|
private Language2Value value;
|
||||||
|
|
||||||
public Language2Action(Language2Value value) {
|
public Language2Action(Language2Format format, List<String> list) {
|
||||||
// 变量初始化
|
// 变量初始化
|
||||||
this.value = value;
|
this.value = format.getLanguage2Value();
|
||||||
|
|
||||||
// 遍历文本
|
// 遍历文本
|
||||||
for (String message : value.getLanguageValue()) {
|
for (String message : list) {
|
||||||
try {
|
try {
|
||||||
// 动作栏提示
|
// 动作栏提示
|
||||||
if (message.startsWith(KEY_TEXT)) {
|
if (message.startsWith(KEY_TEXT)) {
|
||||||
@ -72,8 +74,7 @@ public class Language2Action {
|
|||||||
if (TabooLib.getVerint() < 10800) {
|
if (TabooLib.getVerint() < 10800) {
|
||||||
player.sendMessage(ChatColor.DARK_RED + "[<ERROR-30: " + value.getLanguageKey() + ">]");
|
player.sendMessage(ChatColor.DARK_RED + "[<ERROR-30: " + value.getLanguageKey() + ">]");
|
||||||
}
|
}
|
||||||
// 쇱꿴鯤소
|
else {
|
||||||
else if (player != null) {
|
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
int times = 0;
|
int times = 0;
|
||||||
|
|
||||||
@ -86,8 +87,10 @@ public class Language2Action {
|
|||||||
}
|
}
|
||||||
}.runTaskTimer(Main.getInst(), 0, 20);
|
}.runTaskTimer(Main.getInst(), 0, 20);
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
Bukkit.getConsoleSender().sendMessage(value.setPlaceholder(text, player));
|
|
||||||
}
|
@Override
|
||||||
|
public void console() {
|
||||||
|
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED + "[<ERROR-40: " + value.getLanguageKey() + ">]");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,7 @@
|
|||||||
package me.skymc.taboolib.string.language2.type;
|
package me.skymc.taboolib.string.language2.value;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -11,13 +14,15 @@ import me.skymc.taboolib.jsonformatter.click.RunCommandEvent;
|
|||||||
import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
|
import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
|
||||||
import me.skymc.taboolib.jsonformatter.hover.HoverEvent;
|
import me.skymc.taboolib.jsonformatter.hover.HoverEvent;
|
||||||
import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent;
|
import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent;
|
||||||
|
import me.skymc.taboolib.string.language2.Language2Format;
|
||||||
|
import me.skymc.taboolib.string.language2.Language2Line;
|
||||||
import me.skymc.taboolib.string.language2.Language2Value;
|
import me.skymc.taboolib.string.language2.Language2Value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author sky
|
* @author sky
|
||||||
* @since 2018年2月13日 下午4:11:33
|
* @since 2018年2月13日 下午4:11:33
|
||||||
*/
|
*/
|
||||||
public class Language2Json {
|
public class Language2Json implements Language2Line {
|
||||||
|
|
||||||
private static final String KEY_TEXT = " text: ";
|
private static final String KEY_TEXT = " text: ";
|
||||||
private static final String KEY_COMMAND = " command: ";
|
private static final String KEY_COMMAND = " command: ";
|
||||||
@ -35,24 +40,24 @@ public class Language2Json {
|
|||||||
@Getter
|
@Getter
|
||||||
private StringBuffer text = new StringBuffer();
|
private StringBuffer text = new StringBuffer();
|
||||||
|
|
||||||
public Language2Json(Language2Value value, Player player) {
|
public Language2Json(Language2Format format, List<String> list, Player player) {
|
||||||
// Îı¾³õʼ»¯
|
|
||||||
String current = ChatColor.DARK_RED + "[<ERROR-20: " + value.getLanguageKey() + ">]";
|
|
||||||
|
|
||||||
// 首次检测
|
// 首次检测
|
||||||
boolean isFirst = true;
|
boolean isFirst = true;
|
||||||
boolean isBreak = false;
|
boolean isBreak = false;
|
||||||
|
|
||||||
// 变量初始化
|
// 变量初始化
|
||||||
this.value = value;
|
this.value = format.getLanguage2Value();
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
|
||||||
// 动作初始化
|
// 动作初始化
|
||||||
ClickEvent clickEvent = null;
|
ClickEvent clickEvent = null;
|
||||||
HoverEvent hoverEvent = null;
|
HoverEvent hoverEvent = null;
|
||||||
|
|
||||||
|
// Îı¾³õʼ»¯
|
||||||
|
String current = ChatColor.DARK_RED + "[<ERROR-20: " + value.getLanguageKey() + ">]";
|
||||||
|
|
||||||
// 遍历文本
|
// 遍历文本
|
||||||
for (String message : value.getLanguageValue()) {
|
for (String message : list) {
|
||||||
try {
|
try {
|
||||||
// 如果是显示文本
|
// 如果是显示文本
|
||||||
if (message.startsWith(KEY_TEXT)) {
|
if (message.startsWith(KEY_TEXT)) {
|
||||||
@ -107,12 +112,12 @@ public class Language2Json {
|
|||||||
* @param player 玩家
|
* @param player 玩家
|
||||||
*/
|
*/
|
||||||
public void send(Player player) {
|
public void send(Player player) {
|
||||||
if (player != null) {
|
json.send(player);
|
||||||
json.send(player);
|
}
|
||||||
}
|
|
||||||
else {
|
@Override
|
||||||
Bukkit.getConsoleSender().sendMessage(text.toString());
|
public void console() {
|
||||||
}
|
Bukkit.getConsoleSender().sendMessage(text.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -0,0 +1,47 @@
|
|||||||
|
package me.skymc.taboolib.string.language2.value;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import me.skymc.taboolib.sound.SoundPack;
|
||||||
|
import me.skymc.taboolib.string.language2.Language2Format;
|
||||||
|
import me.skymc.taboolib.string.language2.Language2Line;
|
||||||
|
import me.skymc.taboolib.string.language2.Language2Value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sky
|
||||||
|
* @since 2018-03-08 22:43:27
|
||||||
|
*/
|
||||||
|
public class Language2Sound implements Language2Line {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private List<SoundPack> sounds = new ArrayList<>();
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private Language2Value value;
|
||||||
|
|
||||||
|
public Language2Sound(Language2Format format, List<String> list) {
|
||||||
|
this.value = format.getLanguage2Value();
|
||||||
|
// ±éÀúÎı¾
|
||||||
|
for (String line : list) {
|
||||||
|
sounds.add(new SoundPack(line));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void send(Player player) {
|
||||||
|
for (SoundPack sound : sounds) {
|
||||||
|
sound.play(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void console() {
|
||||||
|
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED + "[<ERROR-40: " + value.getLanguageKey() + ">]");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
package me.skymc.taboolib.string.language2.value;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import me.skymc.taboolib.sound.SoundPack;
|
||||||
|
import me.skymc.taboolib.string.language2.Language2Format;
|
||||||
|
import me.skymc.taboolib.string.language2.Language2Line;
|
||||||
|
import me.skymc.taboolib.string.language2.Language2Value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sky
|
||||||
|
* @since 2018-03-08 22:43:27
|
||||||
|
*/
|
||||||
|
public class Language2Text implements Language2Line {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private List<String> text = new ArrayList<>();
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private Language2Value value;
|
||||||
|
|
||||||
|
public Language2Text(Language2Format format, List<String> list) {
|
||||||
|
this.value = format.getLanguage2Value();
|
||||||
|
// ±éÀúÎı¾
|
||||||
|
for (String line : list) {
|
||||||
|
text.add(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void send(Player player) {
|
||||||
|
for (String line : text) {
|
||||||
|
player.sendMessage(value.setPlaceholder(line, player));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void console() {
|
||||||
|
for (String line : text) {
|
||||||
|
Bukkit.getConsoleSender().sendMessage(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package me.skymc.taboolib.string.language2.type;
|
package me.skymc.taboolib.string.language2.value;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -10,14 +10,15 @@ import org.bukkit.entity.Player;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.skymc.taboolib.TabooLib;
|
import me.skymc.taboolib.TabooLib;
|
||||||
import me.skymc.taboolib.display.TitleUtils;
|
import me.skymc.taboolib.display.TitleUtils;
|
||||||
import me.skymc.taboolib.message.MsgUtils;
|
import me.skymc.taboolib.string.language2.Language2Format;
|
||||||
|
import me.skymc.taboolib.string.language2.Language2Line;
|
||||||
import me.skymc.taboolib.string.language2.Language2Value;
|
import me.skymc.taboolib.string.language2.Language2Value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author sky
|
* @author sky
|
||||||
* @since 2018年2月13日 下午3:58:07
|
* @since 2018年2月13日 下午3:58:07
|
||||||
*/
|
*/
|
||||||
public class Language2Title {
|
public class Language2Title implements Language2Line {
|
||||||
|
|
||||||
private static final String KEY_TITLE = " title: ";
|
private static final String KEY_TITLE = " title: ";
|
||||||
private static final String KEY_SUBTITLE = " subtitle: ";
|
private static final String KEY_SUBTITLE = " subtitle: ";
|
||||||
@ -41,12 +42,11 @@ public class Language2Title {
|
|||||||
@Getter
|
@Getter
|
||||||
private Language2Value value;
|
private Language2Value value;
|
||||||
|
|
||||||
public Language2Title(Language2Value value) {
|
public Language2Title(Language2Format format, List<String> list) {
|
||||||
// 变量初始化
|
// 变量初始化
|
||||||
this.value = value;
|
this.value = format.getLanguage2Value();
|
||||||
|
|
||||||
// 遍历文本
|
// 遍历文本
|
||||||
for (String message : value.getLanguageValue()) {
|
for (String message : list) {
|
||||||
try {
|
try {
|
||||||
// 大标题
|
// 大标题
|
||||||
if (message.startsWith(KEY_TITLE)) {
|
if (message.startsWith(KEY_TITLE)) {
|
||||||
@ -72,22 +72,19 @@ public class Language2Title {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* 랙箇못鯤소
|
|
||||||
*
|
|
||||||
* @param player 鯤소
|
|
||||||
*/
|
|
||||||
public void send(Player player) {
|
public void send(Player player) {
|
||||||
// 检查版本
|
// 检查版本
|
||||||
if (TabooLib.getVerint() < 10800) {
|
if (TabooLib.getVerint() < 10800) {
|
||||||
player.sendMessage(ChatColor.DARK_RED + "[<ERROR-31: " + value.getLanguageKey() + ">]");
|
player.sendMessage(ChatColor.DARK_RED + "[<ERROR-31: " + value.getLanguageKey() + ">]");
|
||||||
}
|
}
|
||||||
// 쇱꿴鯤소
|
else {
|
||||||
else if (player != null) {
|
|
||||||
TitleUtils.sendTitle(player, value.setPlaceholder(title, player), value.setPlaceholder(subtitle, player), fade1, stay, fade2);
|
TitleUtils.sendTitle(player, value.setPlaceholder(title, player), value.setPlaceholder(subtitle, player), fade1, stay, fade2);
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
Bukkit.getConsoleSender().sendMessage(value.setPlaceholder(title, player) + ", " + value.setPlaceholder(subtitle, player));
|
|
||||||
}
|
@Override
|
||||||
|
public void console() {
|
||||||
|
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED + "[<ERROR-40: " + value.getLanguageKey() + ">]");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,12 +10,20 @@
|
|||||||
# 21: JSON 语言类型识别异常
|
# 21: JSON 语言类型识别异常
|
||||||
# 30: 大标题不兼容当前版本服务器
|
# 30: 大标题不兼容当前版本服务器
|
||||||
# 31: 动作栏不兼容当前版本服务器
|
# 31: 动作栏不兼容当前版本服务器
|
||||||
|
# 40: 语言文件类型异常
|
||||||
|
|
||||||
# 正常提示
|
# 正常提示
|
||||||
TEXT: '&f正常的提示'
|
TEXT: '&f正常的提示'
|
||||||
|
|
||||||
|
# 多行正常提示
|
||||||
|
# 类型 [text] 可以省略不写
|
||||||
|
TEXT-MULTI:
|
||||||
|
- '[text]'
|
||||||
|
- '&f正常的提示 - 1'
|
||||||
|
- '&f正常的提示 - 2'
|
||||||
|
|
||||||
# JSON提示 + 占位符
|
# JSON提示 + 占位符
|
||||||
# 占位符注释可以追加到任何类型之后
|
# 占位符注释需要追加到第一行类型末尾
|
||||||
PAPI-TEXT:
|
PAPI-TEXT:
|
||||||
- '[json][papi]'
|
- '[json][papi]'
|
||||||
- '&f变量提示, 玩家名称: %player_name%'
|
- '&f变量提示, 玩家名称: %player_name%'
|
||||||
@ -64,3 +72,21 @@ ACTION-TEXT:
|
|||||||
- '[action]'
|
- '[action]'
|
||||||
- ' text: 动作栏提示'
|
- ' text: 动作栏提示'
|
||||||
- ' repeat: 10'
|
- ' repeat: 10'
|
||||||
|
|
||||||
|
# 多类型混合
|
||||||
|
TITLE-ACTION-TEXT:
|
||||||
|
- '[title]'
|
||||||
|
- ' title: 大标题'
|
||||||
|
- ' subtitle: 小标题'
|
||||||
|
- ' stay: 10|40|10'
|
||||||
|
- '[action]'
|
||||||
|
- ' text: 动作栏提示'
|
||||||
|
- ' repeat: 10'
|
||||||
|
|
||||||
|
# 音效 + 文本提示
|
||||||
|
SOUND-TEXT:
|
||||||
|
- '[text]'
|
||||||
|
- '单行文本 - 1'
|
||||||
|
- '单行文本 - 2'
|
||||||
|
- '[sound]'
|
||||||
|
- 'BLOCK_ANVIL_USE-1-1'
|
@ -3,6 +3,7 @@ COMMAND-HELP:
|
|||||||
- ''
|
- ''
|
||||||
- '&b&l----- &3&lTaooLibraryModule Commands &b&l-----'
|
- '&b&l----- &3&lTaooLibraryModule Commands &b&l-----'
|
||||||
- ''
|
- ''
|
||||||
|
- '&f /tlm kit list &6- &e列出所有礼包'
|
||||||
- '&f /tlm kit reward &8[&7名称] &8<&7名称&8> &6- &e领取礼包'
|
- '&f /tlm kit reward &8[&7名称] &8<&7名称&8> &6- &e领取礼包'
|
||||||
- '&f /tlm kit reset &8[&7名称] &8<&7玩家&8> &6- &e刷新礼包'
|
- '&f /tlm kit reset &8[&7名称] &8<&7玩家&8> &6- &e刷新礼包'
|
||||||
- ''
|
- ''
|
||||||
@ -23,6 +24,9 @@ NOPERMISSION-LIST: '&8[&3&lTLM&8] &4你没有权限这么做'
|
|||||||
NOPERMISSION-RELOAD: '&8[&3&lTLM&8] &4你没有权限这么做'
|
NOPERMISSION-RELOAD: '&8[&3&lTLM&8] &4你没有权限这么做'
|
||||||
NOPERMISSION-KIT-REWARD: '&8[&3&lTLM&8] &4你没有权限这么做'
|
NOPERMISSION-KIT-REWARD: '&8[&3&lTLM&8] &4你没有权限这么做'
|
||||||
NOPERMISSION-KIT-RESET: '&8[&3&lTLM&8] &4你没有权限这么做'
|
NOPERMISSION-KIT-RESET: '&8[&3&lTLM&8] &4你没有权限这么做'
|
||||||
|
|
||||||
|
# 3.60 新增
|
||||||
|
NOPERMISSION-KIT-LIST: '&8[&3&lTLM&8] &4你没有权限这么做'
|
||||||
NOPERMISSION-INV: '&8[&3&lTLM&8] &4你没有权限这么做'
|
NOPERMISSION-INV: '&8[&3&lTLM&8] &4你没有权限这么做'
|
||||||
|
|
||||||
# 3.59 增加
|
# 3.59 增加
|
||||||
@ -45,6 +49,9 @@ KIT-PLACEHOLDER:
|
|||||||
4: '&4冷却中'
|
4: '&4冷却中'
|
||||||
5: '&4无权限'
|
5: '&4无权限'
|
||||||
|
|
||||||
|
# 3.60 新增
|
||||||
|
KIT-LIST: '&8[&3&lTLM&8] &7当前礼包: &f$kits'
|
||||||
|
|
||||||
# 3.60 增加
|
# 3.60 增加
|
||||||
INV-EMPTY: '&8[&3&lTLM&8] &4参数错误'
|
INV-EMPTY: '&8[&3&lTLM&8] &4参数错误'
|
||||||
INV-DISABLE: '&8[&3&lTLM&8] &4该模块尚未在配置文件中启用'
|
INV-DISABLE: '&8[&3&lTLM&8] &4该模块尚未在配置文件中启用'
|
||||||
|
Loading…
Reference in New Issue
Block a user