This commit is contained in:
Izzel_Aliz
2018-07-06 20:31:41 +08:00
34 changed files with 759 additions and 183 deletions

View File

@@ -102,7 +102,9 @@ public class TLib {
} catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException ignored) {
TLocale.Logger.fatal("TLIB.INJECTION-FAILED");
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
if (plugin != Main.getInst()) TDependencyInjector.inject(plugin, plugin);
if (plugin != Main.getInst()) {
TDependencyInjector.inject(plugin, plugin);
}
}
}
}

View File

@@ -37,8 +37,9 @@ public class TPluginManager implements PluginManager {
private List<Plugin> delayedDisable = new ArrayList<>();
public static void delayDisable(Plugin plugin) {
if (!singleton.delayedDisable.contains(plugin))
if (!singleton.delayedDisable.contains(plugin)) {
singleton.delayedDisable.add(plugin);
}
}
public TPluginManager() {

View File

@@ -2,10 +2,9 @@ package com.ilummc.tlib.resources.type;
import com.google.common.collect.Maps;
import com.ilummc.tlib.compat.PlaceholderHook;
import com.ilummc.tlib.nms.ActionBar;
import com.ilummc.tlib.resources.TLocaleSerialize;
import com.ilummc.tlib.util.Strings;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.display.ActionUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.SerializableAs;
@@ -34,7 +33,7 @@ public class TLocaleActionBar extends TLocaleSerialize {
@Override
public void sendTo(CommandSender sender, String... args) {
if (sender instanceof Player) {
ActionBar.sendActionBar(((Player) sender), replace(sender, text, args));
ActionUtils.send(((Player) sender), replace(sender, text, args));
}
}

View File

@@ -71,7 +71,7 @@ public class TLocaleBook extends TLocaleSerialize {
@Override
public void run() {
BookBuilder bookBuilder = BookFormatter.writtenBook();
pages.stream().map(jsonPage -> papi ? TLocale.Translate.setPlaceholders(sender, Strings.replaceWithOrder(jsonPage.toRawMessage(), args)) : TLocale.Translate.setColored(Strings.replaceWithOrder(jsonPage.toRawMessage(), args))).map(ComponentSerializer::parse).forEach(bookBuilder::addPages);
pages.stream().map(jsonPage -> format(jsonPage, sender, args)).map(ComponentSerializer::parse).forEach(bookBuilder::addPages);
new BukkitRunnable() {
@Override
public void run() {
@@ -82,6 +82,10 @@ public class TLocaleBook extends TLocaleSerialize {
}.runTaskAsynchronously(Main.getInst());
}
private String format(TellrawJson jsonPage, CommandSender sender, String[] args) {
return papi ? TLocale.Translate.setPlaceholders(sender, Strings.replaceWithOrder(jsonPage.toRawMessage(), args)) : Strings.replaceWithOrder(jsonPage.toRawMessage(), args);
}
public static TLocaleBook valueOf(Map<String, Object> map) {
Map<String, Object> pages = map.containsKey("pages") ? (Map<String, Object>) map.get("pages") : new HashMap<>();
Map<String, Object> section = map.containsKey("args") ? (Map<String, Object>) map.get("args") : new HashMap<>();

View File

@@ -171,7 +171,7 @@ public class TLocaleJson extends TLocaleSerialize {
// 遍历本页文本
for (int i = 0; i < textList.size(); i++) {
// 捕捉变量
for (VariableFormatter.Variable variable : new VariableFormatter(textList.get(i), pattern).find().getVariableList()) {
for (VariableFormatter.Variable variable : new VariableFormatter(TLocale.Translate.setColored(textList.get(i)), pattern).find().getVariableList()) {
// 如果是变量
if (variable.isVariable()) {
String[] split = variable.getText().split("@");

View File

@@ -42,13 +42,7 @@ public class TLocaleTitle extends TLocaleSerialize {
public static TLocaleTitle valueOf(Map<String, Object> map) {
TLocaleTitle title;
try {
title = new TLocaleTitle(
getStringOrDefault(map, "title", ""),
getStringOrDefault(map, "subtitle", ""),
getIntegerOrDefault(map, "fadein", 10),
getIntegerOrDefault(map, "fadeout", 10),
getIntegerOrDefault(map, "stay", 10),
isPlaceholderEnabled(map));
title = new TLocaleTitle(getStringOrDefault(map, "title", ""), getStringOrDefault(map, "subtitle", ""), getIntegerOrDefault(map, "fadein", 10), getIntegerOrDefault(map, "fadeout", 10), getIntegerOrDefault(map, "stay", 10), isPlaceholderEnabled(map));
} catch (Exception e) {
title = new TLocaleTitle("Empty Title message.", e.getMessage(), 10, 20, 10, false);
}
@@ -58,7 +52,7 @@ public class TLocaleTitle extends TLocaleSerialize {
@Override
public void sendTo(CommandSender sender, String... args) {
if (sender instanceof Player) {
TitleUtils.sendTitle((Player) sender, replaceText(sender, title), replaceText(sender, subtitle), fadein, stay, fadeout);
TitleUtils.sendTitle((Player) sender, replaceText(sender, Strings.replaceWithOrder(title, args)), replaceText(sender, Strings.replaceWithOrder(subtitle, args)), fadein, stay, fadeout);
} else {
TLocale.Logger.error("LOCALE.TITLE-SEND-TO-NON-PLAYER", asString(args));
}
@@ -86,7 +80,7 @@ public class TLocaleTitle extends TLocaleSerialize {
return map;
}
private String replaceText(CommandSender sender, String args) {
return usePlaceholder ? TLocale.Translate.setPlaceholders(sender, args) : TLocale.Translate.setColored(args);
private String replaceText(CommandSender sender, String text, String... args) {
return usePlaceholder ? TLocale.Translate.setPlaceholders(sender, text) : TLocale.Translate.setColored(text);
}
}