兼容 PlugMan

This commit is contained in:
坏黑 2018-04-25 22:58:58 +08:00
parent dbb9eadde7
commit 4f16196170
6 changed files with 137 additions and 10 deletions

View File

@ -12,8 +12,8 @@ import com.ilummc.tlib.filter.TLoggerFilter;
import com.ilummc.tlib.inject.TConfigWatcher;
import com.ilummc.tlib.inject.TDependencyInjector;
import com.ilummc.tlib.inject.TPluginManager;
import com.ilummc.tlib.logger.TLogger;
import com.ilummc.tlib.resources.TLocaleLoader;
import com.ilummc.tlib.util.TLogger;
import lombok.Getter;
import me.skymc.taboolib.Main;

View File

@ -5,7 +5,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.ilummc.tlib.util.TLogger;
import com.ilummc.tlib.logger.TLogger;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)

View File

@ -14,9 +14,9 @@ import com.ilummc.tlib.annotations.Dependency;
import com.ilummc.tlib.annotations.Logger;
import com.ilummc.tlib.annotations.PluginInstance;
import com.ilummc.tlib.dependency.TDependency;
import com.ilummc.tlib.logger.TLogger;
import com.ilummc.tlib.resources.TLocaleLoader;
import com.ilummc.tlib.util.Ref;
import com.ilummc.tlib.util.TLogger;
public class TDependencyInjector {

View File

@ -1,9 +1,18 @@
package com.ilummc.tlib.inject;
import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.event.Event;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -17,16 +26,57 @@ import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.UnknownDependencyException;
import com.ilummc.tlib.TLib;
import me.skymc.taboolib.Main;
@SuppressWarnings("unused")
public class TPluginManager implements PluginManager {
private final PluginManager instance;
private final Main main = (Main) Main.getInst();
private static File updateDirectory = null;
private Server server;
private Map<Pattern, PluginLoader> fileAssociations = new HashMap<>();
private List<Plugin> plugins = new ArrayList<>();
private Map<String, Plugin> lookupNames = new HashMap<>();
private SimpleCommandMap commandMap;
private Map<String, Permission> permissions = new HashMap<>();
private Map<Boolean, Set<Permission>> defaultPerms = new LinkedHashMap<>();
private Map<String, Map<Permissible, Boolean>> permSubs = new HashMap<>();
private Map<Boolean, Map<Permissible, Boolean>> defSubs = new HashMap<>();
private boolean useTimings = false;
public TPluginManager() {
instance = Bukkit.getPluginManager();
// clone all Field in SimplePluginManager
cloneField("updateDirectory");
cloneField("server");
cloneField("fileAssociations");
cloneField("plugins");
cloneField("lookupNames");
cloneField("commandMap");
cloneField("permissions");
cloneField("defaultPerms");
cloneField("permSubs");
cloneField("defSubs");
cloneField("useTimings");
}
private void cloneField(String bukkitName) {
try {
Field bukkitField = instance.getClass().getDeclaredField(bukkitName);
Field thisFiled = this.getClass().getDeclaredField(bukkitName);
if (bukkitField == null || thisFiled == null) {
TLib.getTLib().getLogger().warn("拷贝 " + bukkitName + " 对象失败");
return;
}
bukkitField.setAccessible(true);
thisFiled.setAccessible(true);
thisFiled.set(this, bukkitField.get(instance));
} catch (Exception ignored) {
TLib.getTLib().getLogger().error("拷贝 " + bukkitName + " 对象出错");
}
}
@Override

View File

@ -0,0 +1,67 @@
package com.ilummc.tlib.logger;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.Plugin;
import com.ilummc.tlib.util.Strings;
import lombok.Getter;
import lombok.Setter;
import me.skymc.taboolib.Main;
public class TLogger {
public static final int VERBOSE = 0, FINEST = 1, FINE = 2, INFO = 3, WARN = 4, ERROR = 5, FATAL = 6;
@Getter
private static TLogger globalLogger = new TLogger("§8[§3§lTabooLib§8][§r{1}§8] §f{2}", Main.getInst(), TLogger.FINE);
@Getter
private final String pattern;
@Getter
private Plugin plugin;
@Getter
@Setter
private int level;
public TLogger(String pattern, Plugin plugin, int level) {
this.pattern = pattern;
this.plugin = plugin;
this.level = level;
}
public void verbose(String msg) {
if (level <= VERBOSE)
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§f全部", ChatColor.translateAlternateColorCodes('&', msg)));
}
public void finest(String msg) {
if (level <= FINEST)
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§e良好", ChatColor.translateAlternateColorCodes('&', msg)));
}
public void fine(String msg) {
if (level <= FINE)
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§a正常", ChatColor.translateAlternateColorCodes('&', msg)));
}
public void info(String msg) {
if (level <= INFO)
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§b信息", ChatColor.translateAlternateColorCodes('&', msg)));
}
public void warn(String msg) {
if (level <= WARN)
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§6警告", "§6" + ChatColor.translateAlternateColorCodes('&', msg)));
}
public void error(String msg) {
if (level <= ERROR)
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§c错误", "§c" + ChatColor.translateAlternateColorCodes('&', msg)));
}
public void fatal(String msg) {
if (level <= FATAL)
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§4致命错误", "§4" + ChatColor.translateAlternateColorCodes('&', msg)));
}
}

View File

@ -5,24 +5,26 @@ import java.util.Map;
import javax.annotation.concurrent.Immutable;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
import org.bukkit.entity.Player;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.ilummc.tlib.TLib;
import com.ilummc.tlib.compat.PlaceholderHook;
import com.ilummc.tlib.resources.TLocaleSendable;
import com.ilummc.tlib.util.Strings;
import lombok.Data;
import lombok.Getter;
import net.minecraft.server.v1_11_R1.EntityEvoker.e;
import me.skymc.taboolib.display.TitleUtils;
/**
* @author Bkm016
* @since 2018-04-22
*/
@Immutable
@SerializableAs("TITLE")
public class TLocaleTitle implements TLocaleSendable, ConfigurationSerializable {
@ -45,11 +47,16 @@ public class TLocaleTitle implements TLocaleSendable, ConfigurationSerializable
@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);
} else {
TLib.getTLib().getLogger().error("该语言类型只能发送给玩家");
}
}
@Override
public String asString(String... args) {
return null;
return Strings.replaceWithOrder(title, args);
}
@Override
@ -80,4 +87,7 @@ public class TLocaleTitle implements TLocaleSendable, ConfigurationSerializable
return title;
}
private String replaceText(CommandSender sender, String s) {
return ChatColor.translateAlternateColorCodes('&', usePlaceholder ? PlaceholderHook.replace(sender, s) : s);
}
}