1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-11-22 01:48:50 +00:00

fix: 修复代码问题

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-09-19 16:32:34 +08:00
parent b559c6f756
commit 271bbed5da
4 changed files with 15 additions and 15 deletions

View File

@ -15,7 +15,7 @@ import pw.yumc.YumCore.bukkit.Log;
/** /**
* 物品序列化类 * 物品序列化类
* *
* @since 2016年9月9日 下午3:47:17 * @since 2016年9月9日 下午3:47:17
* @author * @author
*/ */
@ -52,14 +52,14 @@ public abstract class ItemSerialize {
final Class<?> nmsItemStack = asNMSCopyMethod.getReturnType(); final Class<?> nmsItemStack = asNMSCopyMethod.getReturnType();
for (final Method method : nmsItemStack.getMethods()) { for (final Method method : nmsItemStack.getMethods()) {
final Class<?> rt = method.getReturnType(); final Class<?> rt = method.getReturnType();
if (method.getParameterTypes().length == 0 && rt.getSimpleName().equals("NBTTagCompound")) { if (method.getParameterTypes().length == 0 && "NBTTagCompound".equals(rt.getSimpleName())) {
nmsNBTTagCompound = rt; nmsNBTTagCompound = rt;
} }
} }
for (final Method method : nmsItemStack.getMethods()) { for (final Method method : nmsItemStack.getMethods()) {
final Class<?>[] paras = method.getParameterTypes(); final Class<?>[] paras = method.getParameterTypes();
final Class<?> rt = method.getReturnType(); final Class<?> rt = method.getReturnType();
if (paras.length == 1 && paras[0].getSimpleName().equals("NBTTagCompound") && rt.getSimpleName().equals("NBTTagCompound")) { if (paras.length == 1 && "NBTTagCompound".equals(paras[0].getSimpleName()) && "NBTTagCompound".equals(rt.getSimpleName())) {
nmsSaveNBTMethod = method; nmsSaveNBTMethod = method;
} }
} }
@ -70,7 +70,7 @@ public abstract class ItemSerialize {
return "Automatic"; return "Automatic";
} }
public Class<?> getOBCClass(final String cname) throws ClassNotFoundException { public Class getOBCClass(final String cname) throws ClassNotFoundException {
return Class.forName("org.bukkit.craftbukkit." + ver + "." + cname); return Class.forName("org.bukkit.craftbukkit." + ver + "." + cname);
} }
@ -105,7 +105,7 @@ public abstract class ItemSerialize {
* @return 获取显示序列化 * @return 获取显示序列化
*/ */
private String getDisplay(final ItemMeta im) { private String getDisplay(final ItemMeta im) {
final StringBuffer display = new StringBuffer(); final StringBuilder display = new StringBuilder();
display.append("{"); display.append("{");
if (im.hasDisplayName()) { if (im.hasDisplayName()) {
display.append(String.format("Name:\"%s\",", im.getDisplayName())); display.append(String.format("Name:\"%s\",", im.getDisplayName()));
@ -133,7 +133,7 @@ public abstract class ItemSerialize {
* @return 获得附魔序列化 * @return 获得附魔序列化
*/ */
private String getEnch(final Set<Entry<Enchantment, Integer>> set) { private String getEnch(final Set<Entry<Enchantment, Integer>> set) {
final StringBuffer enchs = new StringBuffer(); final StringBuilder enchs = new StringBuilder();
for (final Map.Entry<Enchantment, Integer> ench : set) { for (final Map.Entry<Enchantment, Integer> ench : set) {
enchs.append(String.format("{id:%s,lvl:%s},", ench.getKey().getId(), ench.getValue())); enchs.append(String.format("{id:%s,lvl:%s},", ench.getKey().getId(), ench.getValue()));
} }
@ -149,7 +149,7 @@ public abstract class ItemSerialize {
* @return 获得属性序列化 * @return 获得属性序列化
*/ */
private String getTag(final ItemMeta im) { private String getTag(final ItemMeta im) {
final StringBuffer meta = new StringBuffer("{"); final StringBuilder meta = new StringBuilder("{");
if (im.hasEnchants()) { if (im.hasEnchants()) {
meta.append(String.format("ench:[%s],", getEnch(im.getEnchants().entrySet()))); meta.append(String.format("ench:[%s],", getEnch(im.getEnchants().entrySet())));
} }
@ -169,7 +169,7 @@ public abstract class ItemSerialize {
* @return 物品字符串 * @return 物品字符串
*/ */
private String serialize(final ItemStack item) { private String serialize(final ItemStack item) {
final StringBuffer json = new StringBuffer("{"); final StringBuilder json = new StringBuilder("{");
json.append(String.format("id:\"%s\",Damage:\"%s\"", item.getTypeId(), item.getDurability())); json.append(String.format("id:\"%s\",Damage:\"%s\"", item.getTypeId(), item.getDurability()));
if (item.getAmount() > 1) { if (item.getAmount() > 1) {
json.append(String.format(",Count:%s", item.getAmount())); json.append(String.format(",Count:%s", item.getAmount()));

View File

@ -2,7 +2,7 @@ package pw.yumc.YumCore.tellraw;
/** /**
* Json构建 * Json构建
* *
* @since 2016年9月14日 上午11:55:36 * @since 2016年9月14日 上午11:55:36
* @author * @author
*/ */
@ -21,10 +21,10 @@ public class JsonBuilder {
REPLACEMENT_CHARS['\r'] = "\\r"; REPLACEMENT_CHARS['\r'] = "\\r";
REPLACEMENT_CHARS['\f'] = "\\f"; REPLACEMENT_CHARS['\f'] = "\\f";
} }
StringBuffer json; StringBuilder json;
public JsonBuilder() { public JsonBuilder() {
json = new StringBuffer(); json = new StringBuilder();
} }
public JsonBuilder(final String string) { public JsonBuilder(final String string) {

View File

@ -57,7 +57,7 @@ public class MessagePart {
* @param str * @param str
* 流对象 * 流对象
*/ */
public void writeJson(final StringBuffer str) { public void writeJson(final StringBuilder str) {
str.append("{"); str.append("{");
str.append(String.format(TEXT_FORMAT, new JsonBuilder(text))); str.append(String.format(TEXT_FORMAT, new JsonBuilder(text)));
if (clickActionName != null) { if (clickActionName != null) {

View File

@ -232,10 +232,10 @@ public class Tellraw {
* @return {@link Tellraw} * @return {@link Tellraw}
*/ */
public Tellraw tip(final List<String> texts) { public Tellraw tip(final List<String> texts) {
if (texts.size() == 0) { if (texts.isEmpty()) {
return this; return this;
} }
final StringBuffer text = new StringBuffer(); final StringBuilder text = new StringBuilder();
for (final String t : texts) { for (final String t : texts) {
text.append(t).append("\n"); text.append(t).append("\n");
} }
@ -270,7 +270,7 @@ public class Tellraw {
* @return Json串 * @return Json串
*/ */
public String toJsonString() { public String toJsonString() {
final StringBuffer msg = new StringBuffer(); final StringBuilder msg = new StringBuilder();
msg.append("[\"\""); msg.append("[\"\"");
for (final MessagePart messagePart : messageParts) { for (final MessagePart messagePart : messageParts) {
msg.append(","); msg.append(",");