Framework adjustment
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package io.izzel.taboolib.module.locale;
|
||||
|
||||
import io.izzel.taboolib.TabooLib;
|
||||
import io.izzel.taboolib.module.logger.TLoggerManager;
|
||||
import io.izzel.taboolib.module.locale.logger.TLoggerManager;
|
||||
import io.izzel.taboolib.module.nms.NMSHandler;
|
||||
import io.izzel.taboolib.module.tellraw.TellrawCreator;
|
||||
import io.izzel.taboolib.util.Ref;
|
||||
|
||||
@@ -4,7 +4,7 @@ import io.izzel.taboolib.TabooLib;
|
||||
import io.izzel.taboolib.TabooLibAPI;
|
||||
import io.izzel.taboolib.module.locale.type.*;
|
||||
import io.izzel.taboolib.module.config.TConfigWatcher;
|
||||
import io.izzel.taboolib.module.logger.TLogger;
|
||||
import io.izzel.taboolib.module.locale.logger.TLogger;
|
||||
import io.izzel.taboolib.util.Files;
|
||||
import io.izzel.taboolib.util.IO;
|
||||
import io.izzel.taboolib.util.Strings;
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
package io.izzel.taboolib.module.locale.logger;
|
||||
|
||||
import io.izzel.taboolib.TabooLibAPI;
|
||||
import io.izzel.taboolib.module.locale.TLocale;
|
||||
import io.izzel.taboolib.util.Strings;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class TLogger {
|
||||
|
||||
public static final int VERBOSE = 0, FINEST = 1, FINE = 2, INFO = 3, WARN = 4, ERROR = 5, FATAL = 6;
|
||||
|
||||
private final String pattern;
|
||||
private final String name;
|
||||
private int level;
|
||||
|
||||
public TLogger(String pattern, Plugin plugin, int level) {
|
||||
this.pattern = pattern;
|
||||
this.name = plugin.getName();
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public TLogger(String pattern, String name, int level) {
|
||||
this.pattern = pattern;
|
||||
this.name = name;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public static TLogger getGlobalLogger() {
|
||||
return io.izzel.taboolib.TabooLib.getLogger();
|
||||
}
|
||||
|
||||
public static TLogger getUnformatted(Plugin plugin) {
|
||||
return new TLogger("§8[§3§l{0}§8][§r{1}§8] §f{2}", plugin, TLogger.FINE);
|
||||
}
|
||||
|
||||
public static TLogger getUnformatted(String name) {
|
||||
return new TLogger("§8[§3§l{0}§8][§r{1}§8] §f{2}", name, TLogger.FINE);
|
||||
}
|
||||
|
||||
public String getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public void verbose(String msg) {
|
||||
if (level <= VERBOSE) {
|
||||
if (TabooLibAPI.isBukkit()) {
|
||||
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§fVERBOSE", TLocale.Translate.setColored(msg)));
|
||||
} else {
|
||||
BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§fVERBOSE", TLocale.Translate.setColored(msg))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void finest(String msg) {
|
||||
if (level <= FINEST) {
|
||||
if (TabooLibAPI.isBukkit()) {
|
||||
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§eFINEST", TLocale.Translate.setColored(msg)));
|
||||
} else {
|
||||
BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§eFINEST", TLocale.Translate.setColored(msg))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void fine(String msg) {
|
||||
if (level <= FINE) {
|
||||
if (TabooLibAPI.isBukkit()) {
|
||||
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§aFINE", TLocale.Translate.setColored(msg)));
|
||||
} else {
|
||||
BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§aFINE", TLocale.Translate.setColored(msg))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void info(String msg) {
|
||||
if (level <= INFO) {
|
||||
if (TabooLibAPI.isBukkit()) {
|
||||
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§bINFO", TLocale.Translate.setColored(msg)));
|
||||
} else {
|
||||
BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§bINFO", TLocale.Translate.setColored(msg))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void warn(String msg) {
|
||||
if (level <= WARN) {
|
||||
if (TabooLibAPI.isBukkit()) {
|
||||
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§6WARN", "§6" + TLocale.Translate.setColored(msg)));
|
||||
} else {
|
||||
BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§6WARN", "§6" + TLocale.Translate.setColored(msg))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void error(String msg) {
|
||||
if (level <= ERROR) {
|
||||
if (TabooLibAPI.isBukkit()) {
|
||||
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§cERROR", "§c" + TLocale.Translate.setColored(msg)));
|
||||
} else {
|
||||
BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§cERROR", "§c" + TLocale.Translate.setColored(msg))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void fatal(String msg) {
|
||||
if (level <= FATAL) {
|
||||
if (TabooLibAPI.isBukkit()) {
|
||||
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, name, "§4FATAL", "§4" + TLocale.Translate.setColored(msg)));
|
||||
} else {
|
||||
BungeeCord.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(Strings.replaceWithOrder(pattern, name, "§4FATAL", "§4" + TLocale.Translate.setColored(msg))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.izzel.taboolib.module.locale.logger;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class TLoggerManager {
|
||||
|
||||
private static final Map<Plugin, TLogger> map = new HashMap<>();
|
||||
|
||||
public static void setDefaultLogger(Plugin plugin, TLogger logger) {
|
||||
map.put(plugin, logger);
|
||||
}
|
||||
|
||||
public static TLogger getLogger(Plugin plugin) {
|
||||
TLogger logger = map.get(plugin);
|
||||
if (logger == null) {
|
||||
logger = TLogger.getUnformatted(plugin);
|
||||
map.put(plugin, logger);
|
||||
}
|
||||
return logger;
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import io.izzel.taboolib.TabooLib;
|
||||
import io.izzel.taboolib.module.locale.TLocale;
|
||||
import io.izzel.taboolib.module.locale.TLocaleSerialize;
|
||||
import io.izzel.taboolib.module.tellraw.TellrawJson;
|
||||
import io.izzel.taboolib.origin.book.BookFormatter;
|
||||
import io.izzel.taboolib.origin.book.builder.BookBuilder;
|
||||
import io.izzel.taboolib.util.book.BookFormatter;
|
||||
import io.izzel.taboolib.util.book.builder.BookBuilder;
|
||||
import io.izzel.taboolib.util.Strings;
|
||||
import io.izzel.taboolib.util.chat.ComponentSerializer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@@ -2,7 +2,7 @@ package io.izzel.taboolib.module.locale.type;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import io.izzel.taboolib.module.locale.TLocaleSerialize;
|
||||
import io.izzel.taboolib.origin.lite.Sounds;
|
||||
import io.izzel.taboolib.util.lite.SoundPack;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -21,19 +21,19 @@ import java.util.stream.Collectors;
|
||||
@SerializableAs("ACTION")
|
||||
public class TLocaleSound extends TLocaleSerialize {
|
||||
|
||||
private final List<Sounds> soundPacks;
|
||||
private final List<SoundPack> soundPacks;
|
||||
|
||||
public TLocaleSound(List<Sounds> soundPacks) {
|
||||
public TLocaleSound(List<SoundPack> soundPacks) {
|
||||
this.soundPacks = soundPacks;
|
||||
}
|
||||
|
||||
public static TLocaleSound valueOf(Map<String, Object> map) {
|
||||
List<Sounds> soundPacks = new ArrayList<>();
|
||||
List<SoundPack> soundPacks = new ArrayList<>();
|
||||
Object sounds = map.containsKey("sounds") ? map.get("sounds") : map.getOrDefault("sound", "");
|
||||
if (sounds instanceof List) {
|
||||
soundPacks = ((List<String>) sounds).stream().map(Sounds::new).collect(Collectors.toList());
|
||||
soundPacks = ((List<String>) sounds).stream().map(SoundPack::new).collect(Collectors.toList());
|
||||
} else {
|
||||
soundPacks.add(new Sounds(sounds.toString()));
|
||||
soundPacks.add(new SoundPack(sounds.toString()));
|
||||
}
|
||||
return new TLocaleSound(soundPacks);
|
||||
}
|
||||
@@ -61,7 +61,7 @@ public class TLocaleSound extends TLocaleSerialize {
|
||||
if (soundPacks.size() == 1) {
|
||||
map.put("sounds", soundPacks.get(0).toString());
|
||||
} else if (soundPacks.size() > 1) {
|
||||
map.put("sounds", soundPacks.stream().map(Sounds::toString).collect(Collectors.toList()));
|
||||
map.put("sounds", soundPacks.stream().map(SoundPack::toString).collect(Collectors.toList()));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user