版本更新至 4.13

+ TellrawJoin 新增 append 方法用于拼接其他 json 信息
o 修复 1.12 版本载入报错的问题
o 修复 json 信息发送方式错误的问题
This commit is contained in:
坏黑 2018-07-07 22:43:58 +08:00
parent a8c6aafbce
commit 655e3c2619
5 changed files with 33 additions and 22 deletions

View File

@ -6,7 +6,7 @@
<groupId>me.skymc</groupId>
<artifactId>TabooLib</artifactId>
<version>4.12</version>
<version>4.13</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -140,6 +140,8 @@ public class TLocale {
public static class Tellraw extends TLocale {
private static final Class<?> chatSerializer = NMSUtils.getNMSClassSilent("ChatSerializer", "IChatBaseComponent");
private static final Method chatSerializerA = NMSUtils.getMethodSilent(chatSerializer, "a", String.class);
private static final Field playerConnection = NMSUtils.getFieldSilent(NMSUtil19.class_EntityPlayer, "playerConnection");
private static final Method sendPacket = NMSUtils.getMethodSilent(NMSUtil19.class_PlayerConnection, "sendPacket", NMSUtil19.class_Packet);
private static final Constructor<?> PacketPlayOutChat = NMSUtils.getConstructorSilent(NMSUtil19.class_PacketPlayOutChat, NMSUtil19.class_IChatBaseComponent);
@ -147,7 +149,7 @@ public class TLocale {
public static void send(CommandSender sender, String rawMessage) {
if (sender instanceof Player) {
try {
sendPacket.invoke(playerConnection.get(NMSUtils.getHandle(sender)), PacketPlayOutChat.newInstance(rawMessage));
sendPacket.invoke(playerConnection.get(NMSUtils.getHandle(sender)), PacketPlayOutChat.newInstance(chatSerializerA.invoke(null, rawMessage)));
} catch (Exception e) {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName() + " " + rawMessage);
}

View File

@ -254,7 +254,7 @@ public class Main extends JavaPlugin implements Listener {
}
// 提示信息
TLocale.Logger.error("NOTIFY.SUCCESS-DISABLE");
TLocale.Logger.info("NOTIFY.SUCCESS-DISABLE");
// 结束连接
if (connection != null && connection.isConnection()) {

View File

@ -13,6 +13,7 @@ import me.skymc.taboolib.string.VariableFormatter;
import org.bukkit.command.CommandSender;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
@ -55,6 +56,14 @@ public class TellrawJson {
return this;
}
public TellrawJson append(TellrawJson json) {
BaseComponent[] newArray = new BaseComponent[components.length + json.components.length];
System.arraycopy(components, 0, newArray, 0, components.length);
System.arraycopy(json.components, 0, newArray, components.length, json.components.length);
components = newArray;
return this;
}
public TellrawJson hoverText(String text) {
getLatestComponent().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(text).create()));
return this;

View File

@ -539,7 +539,7 @@ public class NMSUtil19 {
class_NBTTagList_getDoubleMethod = class_NBTTagList.getMethod("e", Integer.TYPE);
}
} catch (Throwable ex) {
Bukkit.getLogger().log(Level.WARNING, "An error occurred while registering NBTTagList.getDouble, loading entities from schematics will not work", ex);
Bukkit.getLogger().log(Level.WARNING, "An error occurred while registering NBTTagList.getDouble, loading entities from schematics will not work");
class_NBTTagList_getDoubleMethod = null;
}
@ -577,7 +577,7 @@ public class NMSUtil19 {
}
}
} catch (Throwable ex) {
Bukkit.getLogger().log(Level.WARNING, "An error occurred while registering entity movement accessors, vehicle control will not work", ex);
Bukkit.getLogger().log(Level.WARNING, "An error occurred while registering entity movement accessors, vehicle control will not work");
class_Entity_jumpingField = null;
class_Entity_moveStrafingField = null;
class_Entity_moveForwardField = null;
@ -589,7 +589,7 @@ public class NMSUtil19 {
Class<?> craftMagicNumbers = fixBukkitClass("org.bukkit.craftbukkit.util.CraftMagicNumbers");
class_CraftMagicNumbers_getBlockMethod = craftMagicNumbers.getMethod("getBlock", Material.class);
} catch (Throwable ex) {
Bukkit.getLogger().log(Level.WARNING, "An error occurred while registering block durability accessor, durability-based block checks will not work", ex);
Bukkit.getLogger().log(Level.WARNING, "An error occurred while registering block durability accessor, durability-based block checks will not work");
class_Block_durabilityField = null;
class_CraftMagicNumbers_getBlockMethod = null;
}
@ -614,7 +614,7 @@ public class NMSUtil19 {
class_PacketPlayOutChat_constructor = class_PacketPlayOutChat.getConstructor(class_IChatBaseComponent, Byte.TYPE);
}
} catch (Throwable ex) {
Bukkit.getLogger().log(Level.WARNING, "An error occurred while registering action bar methods, action bar messages will not work", ex);
Bukkit.getLogger().log(Level.WARNING, "An error occurred while registering action bar methods, action bar messages will not work");
class_PacketPlayOutChat = null;
}
@ -631,7 +631,7 @@ public class NMSUtil19 {
class_CraftWorld_spawnMethod = class_CraftWorld.getMethod("spawn", Location.class, Class.class, CreatureSpawnEvent.SpawnReason.class);
}
} catch (Throwable ex) {
Bukkit.getLogger().log(Level.WARNING, "An error occurred while registering custom spawn method, spawn reasons will not work", ex);
Bukkit.getLogger().log(Level.WARNING, "An error occurred while registering custom spawn method, spawn reasons will not work");
class_CraftWorld_spawnMethod = null;
class_Consumer = null;
}
@ -642,7 +642,7 @@ public class NMSUtil19 {
class_TileEntity_updateMethod = class_TileEntity.getMethod("update");
class_TileEntity_saveMethod = class_TileEntity.getMethod("save", class_NBTTagCompound);
} catch (Throwable ex) {
Bukkit.getLogger().log(Level.WARNING, "An error occurred, handling of tile entities may not work well", ex);
Bukkit.getLogger().log(Level.WARNING, "An error occurred, handling of tile entities may not work well");
class_TileEntity_loadMethod = null;
class_TileEntity_updateMethod = null;
class_TileEntity_saveMethod = null;
@ -651,7 +651,7 @@ public class NMSUtil19 {
try {
class_NBTCompressedStreamTools_loadFileMethod = class_NBTCompressedStreamTools.getMethod("a", InputStream.class);
} catch (Throwable ex) {
Bukkit.getLogger().log(Level.WARNING, "An error occurred, schematics will not load", ex);
Bukkit.getLogger().log(Level.WARNING, "An error occurred, schematics will not load");
}
try {
@ -659,7 +659,7 @@ public class NMSUtil19 {
class_DamageSource_getMagicSourceMethod = class_DamageSource.getMethod("b", class_Entity, class_Entity);
class_DamageSource_MagicField = class_DamageSource.getField("MAGIC");
} catch (Throwable ex) {
Bukkit.getLogger().log(Level.WARNING, "An error occurred, magic damage will not work, using normal damage instead", ex);
Bukkit.getLogger().log(Level.WARNING, "An error occurred, magic damage will not work, using normal damage instead");
class_EntityLiving_damageEntityMethod = null;
class_DamageSource_getMagicSourceMethod = null;
class_DamageSource_MagicField = null;
@ -699,7 +699,7 @@ public class NMSUtil19 {
}
}
} catch (Throwable ex) {
Bukkit.getLogger().log(Level.WARNING, "An error occurred, armor stand slots cannot be locked", ex);
Bukkit.getLogger().log(Level.WARNING, "An error occurred, armor stand slots cannot be locked");
class_EntityArmorStand_disabledSlotsField = null;
}
if (class_EntityArmorStand_disabledSlotsField != null) {
@ -730,7 +730,7 @@ public class NMSUtil19 {
}
}
} catch (Throwable ex) {
Bukkit.getLogger().log(Level.WARNING, "An error occurred, chest locking and unlocking will not work", ex);
Bukkit.getLogger().log(Level.WARNING, "An error occurred, chest locking and unlocking will not work");
class_TileEntityContainer_setLock = null;
class_TileEntityContainer_getLock = null;
}
@ -750,7 +750,7 @@ public class NMSUtil19 {
class_PlayerConnection_floatCountField.setAccessible(true);
}
} catch (Throwable ex) {
Bukkit.getLogger().log(Level.WARNING, "An error occurred, player flight exemption will not work", ex);
Bukkit.getLogger().log(Level.WARNING, "An error occurred, player flight exemption will not work");
class_PlayerConnection_floatCountField = null;
}
@ -769,7 +769,7 @@ public class NMSUtil19 {
}
}
} catch (Throwable ex) {
Bukkit.getLogger().log(Level.WARNING, "An error occurred, setting arrow lifespan will not work", ex);
Bukkit.getLogger().log(Level.WARNING, "An error occurred, setting arrow lifespan will not work");
class_EntityArrow_lifeField = null;
}
if (class_EntityArrow_lifeField != null) {
@ -780,7 +780,7 @@ public class NMSUtil19 {
// 1.9 and up
class_EntityDamageSource_setThornsMethod = class_EntityDamageSource.getMethod("w");
} catch (Throwable ex) {
Bukkit.getLogger().log(Level.WARNING, "An error occurred, thorn damage override to hurt ender dragon will not work", ex);
Bukkit.getLogger().log(Level.WARNING, "An error occurred, thorn damage override to hurt ender dragon will not work");
class_EntityDamageSource_setThornsMethod = null;
}
@ -801,7 +801,7 @@ public class NMSUtil19 {
class_Entity_saveMethod = class_Entity.getMethod("e", class_NBTTagCompound);
}
} catch (Throwable ex) {
Bukkit.getLogger().log(Level.WARNING, "An error occurred, saving entities to spawn eggs will not work", ex);
Bukkit.getLogger().log(Level.WARNING, "An error occurred, saving entities to spawn eggs will not work");
class_Entity_getTypeMethod = null;
class_Entity_saveMethod = null;
}
@ -819,7 +819,7 @@ public class NMSUtil19 {
class_ItemStack_createStackMethod = class_ItemStack.getMethod("createStack", class_NBTTagCompound);
}
} catch (Throwable ex) {
Bukkit.getLogger().log(Level.WARNING, "An error occurred, restoring inventories from schematics will not work", ex);
Bukkit.getLogger().log(Level.WARNING, "An error occurred, restoring inventories from schematics will not work");
class_ItemStack_createStackMethod = null;
}
@ -827,7 +827,7 @@ public class NMSUtil19 {
class_EntityArrow_damageField = class_EntityArrow.getDeclaredField("damage");
class_EntityArrow_damageField.setAccessible(true);
} catch (Throwable ex) {
Bukkit.getLogger().log(Level.WARNING, "An error occurred, setting arrow damage will not work", ex);
Bukkit.getLogger().log(Level.WARNING, "An error occurred, setting arrow damage will not work");
class_EntityArrow_damageField = null;
}
@ -844,7 +844,7 @@ public class NMSUtil19 {
class_Entity_isSilentMethod = class_Entity.getDeclaredMethod("ad");
}
} catch (Throwable ex) {
Bukkit.getLogger().log(Level.WARNING, "An error occurred, silent entities will not work", ex);
Bukkit.getLogger().log(Level.WARNING, "An error occurred, silent entities will not work");
class_Entity_setSilentMethod = null;
class_Entity_isSilentMethod = null;
}
@ -861,7 +861,7 @@ public class NMSUtil19 {
class_ArmorStand_setGravity = class_EntityArmorStand.getDeclaredMethod("setGravity", Boolean.TYPE);
}
} catch (Throwable ex) {
Bukkit.getLogger().log(Level.WARNING, "An error occurred, hacky no-gravity armor stands won't work", ex);
Bukkit.getLogger().log(Level.WARNING, "An error occurred, hacky no-gravity armor stands won't work");
class_Entity_setNoGravity = null;
class_ArmorStand_setGravity = null;
}
@ -876,7 +876,7 @@ public class NMSUtil19 {
}
} catch (Throwable ex) {
failed = true;
Bukkit.getLogger().log(Level.SEVERE, "An unexpected error occurred initializing Magic", ex);
Bukkit.getLogger().log(Level.SEVERE, "An unexpected error occurred initializing Magic");
}
}