Update v5.19 & Optimization

This commit is contained in:
sky 2020-03-08 16:31:34 +08:00
parent 0152bb05c7
commit 1d66c4ed8f
14 changed files with 131 additions and 36 deletions

View File

@ -6,7 +6,7 @@ plugins {
} }
group = 'me.skymc' group = 'me.skymc'
version = '5.18' version = '5.19'
sourceCompatibility = 1.8 sourceCompatibility = 1.8
targetCompatibility = 1.8 targetCompatibility = 1.8
@ -19,28 +19,42 @@ tasks.withType(ScalaCompile) {
} }
repositories { repositories {
mavenCentral() maven { url "http://ptms.ink:8081/repository/codemc-nms/" }
maven { url "http://ptms.ink:8081/repository/maven-releases/" }
maven { url "http://repo.extendedclip.com/content/repositories/placeholderapi/" } maven { url "http://repo.extendedclip.com/content/repositories/placeholderapi/" }
mavenCentral()
} }
dependencies { dependencies {
shadow(group: 'org.apache.cassandra', name: 'cassandra-all', version: '0.8.1') { shadow('org.apache.cassandra:cassandra-all:0.8.1') {
exclude(module: 'slf4j-log4j12') exclude(module: 'slf4j-log4j12')
exclude(module: 'log4j') exclude(module: 'log4j')
} }
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8' compile 'ink.ptms.core:v11200:11200:all'
compile group: 'org.ow2.asm', name: 'asm', version: '7.0-beta' compile 'ink.ptms.core:v11500:11500:all'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6' compile 'ink.ptms.core:v11400:11400:all'
compile subprojects compile 'ink.ptms.core:v11300:11300:all'
shadow group: 'com.zaxxer', name: 'HikariCP', version: '3.1.0' compile 'ink.ptms.core:v10800:10800:all'
shadow group: 'org.scala-lang', name: 'scala-library', version: '2.12.8' compile 'net.md_5.bungee:BungeeCord:1:all'
shadow group: 'me.clip', name: 'placeholderapi', version: '2.10.4' compile 'org.apache.commons:commons-lang3:3.8'
shadow group: 'com.google.inject', name: 'guice', version: '4.2.2' compile 'com.google.code.gson:gson:2.8.6'
compile 'org.ow2.asm:asm:7.0-beta'
shadow 'com.zaxxer:HikariCP:3.1.0'
shadow 'com.google.inject:guice:4.2.2'
shadow 'org.scala-lang:scala-library:2.12.8'
shadow 'pw.yumc.Yum:Yum:1:all'
shadow 'me.clip:placeholderapi:2.10.4'
shadow 'net.milkbowl.vault:Vault:1:all'
shadow 'me.skymc.taboolib:TabooLib:4.9:all'
shadow 'us.myles.ViaVersion:ViaVersion:1:all'
shadow 'protocolsupport:ProtocolSupport:1:all'
shadow 'com.sk89q.worldedit:WorldEdit:7:all'
shadow 'com.sk89q.worldguard:WorldGuard:7:all'
shadow 'org.inventivetalent.bossbar:BossBar:1:all'
shadow fileTree(dir: 'libs', includes: ['*.jar']) shadow fileTree(dir: 'libs', includes: ['*.jar'])
} }
shadowJar { shadowJar {
// MANIFEST.MF lib // MANIFEST.MF lib
taskActions.removeIf { it.actionClassName.contains 'configureShadowTask' } taskActions.removeIf { it.actionClassName.contains 'configureShadowTask' }
@ -48,7 +62,6 @@ shadowJar {
it.include it.dependency('org.apache.commons:.*') it.include it.dependency('org.apache.commons:.*')
it.include it.dependency('org.ow2.asm:.*') it.include it.dependency('org.ow2.asm:.*')
it.include it.dependency('com.google.code.gson:.*') it.include it.dependency('com.google.code.gson:.*')
it.include it.dependency('me.skymc:.*')
} }
relocate 'org.apache.commons', 'io.izzel.taboolib.internal.apache' relocate 'org.apache.commons', 'io.izzel.taboolib.internal.apache'
@ -57,8 +70,6 @@ shadowJar {
} }
processResources { processResources {
inputs.property "version", project.version
from(sourceSets.main.resources.srcDirs) { from(sourceSets.main.resources.srcDirs) {
include '__resources__/version' include '__resources__/version'
include 'plugin.yml' include 'plugin.yml'

View File

@ -1,4 +1,3 @@
rootProject.name = 'TabooLib' rootProject.name = 'TabooLib'
include 'injector' include 'injector'
include 'module-ipc' include 'module-ipc'

View File

@ -1,6 +1,7 @@
package io.izzel.taboolib; package io.izzel.taboolib;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import io.izzel.taboolib.module.command.TCommandHandler; import io.izzel.taboolib.module.command.TCommandHandler;
import io.izzel.taboolib.module.config.TConfig; import io.izzel.taboolib.module.config.TConfig;
@ -27,6 +28,7 @@ public abstract class PluginLoader {
private static List<PluginLoader> registerLoader = Lists.newArrayList(); private static List<PluginLoader> registerLoader = Lists.newArrayList();
private static Set<String> plugins = Sets.newHashSet(); private static Set<String> plugins = Sets.newHashSet();
private static Map<String, Object> redefine = Maps.newHashMap();
static { static {
registerLoader.add(new PluginLoader() { registerLoader.add(new PluginLoader() {
@ -65,8 +67,6 @@ public abstract class PluginLoader {
@Override @Override
public void onStopping(Plugin plugin) { public void onStopping(Plugin plugin) {
// 卸载语言文件
TLocaleLoader.unload(plugin);
// 保存数据 // 保存数据
Local.saveFiles(plugin.getName()); Local.saveFiles(plugin.getName());
Local.clearFiles(plugin.getName()); Local.clearFiles(plugin.getName());
@ -80,6 +80,8 @@ public abstract class PluginLoader {
DBSource.getDataSource().entrySet().stream().filter(dataEntry -> dataEntry.getKey().getPlugin().equals(plugin)).map(Map.Entry::getKey).forEach(DBSource::closeDataSource); DBSource.getDataSource().entrySet().stream().filter(dataEntry -> dataEntry.getKey().getPlugin().equals(plugin)).map(Map.Entry::getKey).forEach(DBSource::closeDataSource);
// 注销调度器 // 注销调度器
Bukkit.getScheduler().cancelTasks(plugin); Bukkit.getScheduler().cancelTasks(plugin);
// 卸载语言文件
TLocaleLoader.unload(plugin);
} }
}); });
} }
@ -140,4 +142,12 @@ public abstract class PluginLoader {
public static boolean isPlugin(Plugin plugin) { public static boolean isPlugin(Plugin plugin) {
return plugins.contains(plugin.getName()); return plugins.contains(plugin.getName());
} }
public static void redefine(Plugin origin, Object instance) {
redefine.put(origin.getName(), instance);
}
public static Object get(Plugin plugin) {
return redefine.getOrDefault(plugin.getName(), plugin);
}
} }

View File

@ -1,8 +1,11 @@
package io.izzel.taboolib.common.listener; package io.izzel.taboolib.common.listener;
import com.google.common.collect.Lists;
import io.izzel.taboolib.TabooLibAPI; import io.izzel.taboolib.TabooLibAPI;
import io.izzel.taboolib.module.db.local.Local; import io.izzel.taboolib.module.db.local.Local;
import io.izzel.taboolib.module.db.local.LocalPlayer; import io.izzel.taboolib.module.db.local.LocalPlayer;
import io.izzel.taboolib.module.hologram.Hologram;
import io.izzel.taboolib.module.hologram.THologram;
import io.izzel.taboolib.module.inject.TListener; import io.izzel.taboolib.module.inject.TListener;
import io.izzel.taboolib.module.locale.TLocale; import io.izzel.taboolib.module.locale.TLocale;
import io.izzel.taboolib.module.locale.logger.TLogger; import io.izzel.taboolib.module.locale.logger.TLogger;
@ -11,6 +14,7 @@ import io.izzel.taboolib.util.Files;
import io.izzel.taboolib.util.item.Items; import io.izzel.taboolib.util.item.Items;
import io.izzel.taboolib.util.lite.Signs; import io.izzel.taboolib.util.lite.Signs;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -46,6 +50,30 @@ public class ListenerCommand implements Listener {
e.getPlayer().sendMessage("§8[§3§lTabooLib§8] §7FakeSign Lines: §f" + Arrays.toString(lines)); e.getPlayer().sendMessage("§8[§3§lTabooLib§8] §7FakeSign Lines: §f" + Arrays.toString(lines));
}); });
} }
if (e.getMessage().equalsIgnoreCase("/hologramTest") && e.getPlayer().hasPermission("*")) {
e.setCancelled(true);
e.getPlayer().sendMessage("§8[§3§lTabooLib§8] §7Hologram Test.");
Location location = e.getPlayer().getEyeLocation().add(e.getPlayer().getLocation().getDirection());
Hologram hologram = THologram.create(location, "TabooLib", e.getPlayer())
.flash(Lists.newArrayList(
"§bT§fabooLib",
"§bTa§fbooLib",
"§bTab§fooLib",
"§bTabo§foLib",
"§bTaboo§fLib",
"§bTabooL§fib",
"§bTabooLi§fb",
"§bTabooLib",
"§bTabooLi§fb",
"§bTabooL§fib",
"§bTaboo§fLib",
"§bTabo§foLib",
"§bTab§fooLib",
"§bTa§fbooLib",
"§bT§fabooLib",
"§fTabooLib"
), 1).deleteOn(30);
}
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)

View File

@ -9,8 +9,7 @@ import java.util.Arrays;
public class TDependency { public class TDependency {
// 阿里 http://maven.aliyun.com/nexus/content/groups/public public static final String MAVEN_REPO = "https://maven.aliyun.com/repository/central";
public static final String MAVEN_REPO = "http://repo1.maven.org/maven2";
/** /**
* 请求一个插件作为依赖这个插件将会在所有已经添加的 Jenkins 仓库Maven 仓库寻找 * 请求一个插件作为依赖这个插件将会在所有已经添加的 Jenkins 仓库Maven 仓库寻找

View File

@ -1,13 +1,16 @@
package io.izzel.taboolib.module.hologram; package io.izzel.taboolib.module.hologram;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import io.izzel.taboolib.TabooLib;
import io.izzel.taboolib.module.nms.NMS; import io.izzel.taboolib.module.nms.NMS;
import io.izzel.taboolib.module.packet.TPacketHandler; import io.izzel.taboolib.module.packet.TPacketHandler;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.function.Consumer;
/** /**
* @Author sky * @Author sky
@ -22,6 +25,7 @@ public class Hologram {
private boolean deleted = false; private boolean deleted = false;
private boolean autoDelete = false; private boolean autoDelete = false;
private int viewDistance = 50; private int viewDistance = 50;
private Consumer<Player> event;
Hologram(Location location, String text, Player... viewers) { Hologram(Location location, String text, Player... viewers) {
THologram.getHolograms().add(this); THologram.getHolograms().add(this);
@ -42,6 +46,11 @@ public class Hologram {
return this; return this;
} }
// public Hologram onClick(Consumer<Player> event) {
// this.event = event;
// return this;
// }
public Hologram refresh() { public Hologram refresh() {
if (deleted) { if (deleted) {
return this; return this;
@ -75,6 +84,14 @@ public class Hologram {
return this; return this;
} }
public Hologram flash(List<String> text, int period) {
for (int i = 0; i < text.size(); i++) {
String line = text.get(i);
Bukkit.getScheduler().runTaskLater(TabooLib.getPlugin(), () -> flash(line), period * i);
}
return this;
}
public Hologram flash(String text) { public Hologram flash(String text) {
if (deleted) { if (deleted) {
return this; return this;
@ -99,6 +116,11 @@ public class Hologram {
return this; return this;
} }
public Hologram deleteOn(int delay) {
Bukkit.getScheduler().runTaskLater(TabooLib.getPlugin(), this::delete, delay);
return this;
}
public Hologram destroy() { public Hologram destroy() {
if (deleted) { if (deleted) {
return this; return this;
@ -181,6 +203,10 @@ public class Hologram {
return viewDistance; return viewDistance;
} }
public Consumer<Player> getEvent() {
return event;
}
public void setText(String text) { public void setText(String text) {
this.text = text; this.text = text;
} }

View File

@ -44,6 +44,15 @@ class THologramHandler implements Listener {
learned = true; learned = true;
Bukkit.getScheduler().runTask(TabooLib.getPlugin(), () -> learn(player)); Bukkit.getScheduler().runTask(TabooLib.getPlugin(), () -> learn(player));
} }
if (packet.is("PacketPlayInUseEntity")) {
int id = packet.read("a", Integer.TYPE);
for (Hologram hologram : THologram.getHolograms()) {
HologramViewer viewer = hologram.getViewer(player);
if (viewer != null && viewer.getId() == id) {
hologram.getEvent().accept(player);
}
}
}
return true; return true;
} }
@ -134,7 +143,6 @@ class THologramHandler implements Listener {
public static void learn(Player player) { public static void learn(Player player) {
player.getWorld().spawn(player.getLocation(), ArmorStand.class, c -> { player.getWorld().spawn(player.getLocation(), ArmorStand.class, c -> {
learnTarget = c; learnTarget = c;
learnTarget.setSmall(true);
learnTarget.setMarker(true); learnTarget.setMarker(true);
learnTarget.setVisible(false); learnTarget.setVisible(false);
learnTarget.setCustomName(" "); learnTarget.setCustomName(" ");

View File

@ -1,6 +1,7 @@
package io.izzel.taboolib.module.inject; package io.izzel.taboolib.module.inject;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.izzel.taboolib.PluginLoader;
import io.izzel.taboolib.compat.kotlin.CompatKotlin; import io.izzel.taboolib.compat.kotlin.CompatKotlin;
import io.izzel.taboolib.module.locale.logger.TLogger; import io.izzel.taboolib.module.locale.logger.TLogger;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -43,13 +44,17 @@ public class TInjectHelper {
// No Static // No Static
else if (!Modifier.isStatic(field.getModifiers())) { else if (!Modifier.isStatic(field.getModifiers())) {
// Main // Main
if (pluginClass.equals(plugin.getClass())) { if (pluginClass.equals(PluginLoader.get(plugin).getClass())) {
instance.add(plugin); instance.add(PluginLoader.get(plugin));
} }
// TInject // TInject
else if (TInjectCreator.getInstanceMap().entrySet().stream().anyMatch(e -> e.getKey().getType().equals(pluginClass))) { else if (TInjectCreator.getInstanceMap().entrySet().stream().anyMatch(e -> e.getKey().getType().equals(pluginClass))) {
TInjectCreator.getInstanceMap().entrySet().stream().filter(e -> e.getKey().getType().equals(pluginClass)).forEach(i -> instance.add(i.getValue().getInstance())); TInjectCreator.getInstanceMap().entrySet().stream().filter(e -> e.getKey().getType().equals(pluginClass)).forEach(i -> instance.add(i.getValue().getInstance()));
} }
// TListener
else {
instance.addAll(TListenerHandler.getInstance(plugin, pluginClass));
}
} }
// Nothing // Nothing
if (instance.isEmpty()) { if (instance.isEmpty()) {

View File

@ -14,6 +14,7 @@ import org.bukkit.plugin.Plugin;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* @Author sky * @Author sky
@ -39,8 +40,6 @@ public class TListenerHandler {
/** /**
* 初始化插件的所有监听器 * 初始化插件的所有监听器
* 该操作会执行无参构造方法 * 该操作会执行无参构造方法
*
* @param plugin 插件
*/ */
public static void setupListener(Plugin plugin) { public static void setupListener(Plugin plugin) {
for (Class<?> pluginClass : TabooLibLoader.getPluginClassSafely(plugin)) { for (Class<?> pluginClass : TabooLibLoader.getPluginClassSafely(plugin)) {
@ -89,8 +88,6 @@ public class TListenerHandler {
/** /**
* 注册插件的所有监听器 * 注册插件的所有监听器
* 该操作会执行 TListener 注解中的 register() 对应方法 * 该操作会执行 TListener 注解中的 register() 对应方法
*
* @param plugin 插件
*/ */
public static void registerListener(Plugin plugin) { public static void registerListener(Plugin plugin) {
Optional.ofNullable(listeners.get(plugin.getName())).ifPresent(listeners -> { Optional.ofNullable(listeners.get(plugin.getName())).ifPresent(listeners -> {
@ -141,8 +138,6 @@ public class TListenerHandler {
/** /**
* 注销插件的所有监听器 * 注销插件的所有监听器
* 该操作会执行 TListener 注解中的 cancel() 对应方法 * 该操作会执行 TListener 注解中的 cancel() 对应方法
*
* @param plugin 插件
*/ */
public static void cancelListener(Plugin plugin) { public static void cancelListener(Plugin plugin) {
Optional.ofNullable(listeners.remove(plugin.getName())).ifPresent(listeners -> { Optional.ofNullable(listeners.remove(plugin.getName())).ifPresent(listeners -> {
@ -162,6 +157,11 @@ public class TListenerHandler {
}); });
} }
public static List<Listener> getInstance(Plugin plugin, Class pluginClass) {
List<Listener> list = TListenerHandler.listeners.get(plugin.getName());
return list == null ? Collections.emptyList() : list.stream().filter(listener -> pluginClass.equals(listener.getClass())).collect(Collectors.toList());
}
public static HashMap<String, List<Listener>> getListeners() { public static HashMap<String, List<Listener>> getListeners() {
return listeners; return listeners;
} }

View File

@ -254,7 +254,7 @@ public class NMSImpl extends NMS {
} else { } else {
attr = ((net.minecraft.server.v1_8_R3.ItemStack) nmsItem).getItem().i(); attr = ((net.minecraft.server.v1_8_R3.ItemStack) nmsItem).getItem().i();
} }
((Multimap) attr).forEach((k, v) -> { ((Multimap) attr).asMap().forEach((k, v) -> {
Object nbt = net.minecraft.server.v1_12_R1.GenericAttributes.a((net.minecraft.server.v1_12_R1.AttributeModifier) v); Object nbt = net.minecraft.server.v1_12_R1.GenericAttributes.a((net.minecraft.server.v1_12_R1.AttributeModifier) v);
list.add(new NBTAttribute( list.add(new NBTAttribute(
new UUID(((NBTTagCompound) nbt).getLong("UUIDMost"), ((NBTTagCompound) nbt).getLong("UUIDLeast")), new UUID(((NBTTagCompound) nbt).getLong("UUIDMost"), ((NBTTagCompound) nbt).getLong("UUIDLeast")),

View File

@ -70,7 +70,7 @@ public class NBTCompound extends NBTBase implements Map<String, NBTBase> {
if (element instanceof JsonObject) { if (element instanceof JsonObject) {
JsonObject json = (JsonObject) element; JsonObject json = (JsonObject) element;
// base // base
if (json.has("type") && json.has("data") && json.size() == 2) { if (json.has("type") && json.has("data") && json.entrySet().size() == 2) {
switch (NBTType.parse(json.get("type").getAsString())) { switch (NBTType.parse(json.get("type").getAsString())) {
case BYTE: case BYTE:
return new NBTBase(json.get("data").getAsByte()); return new NBTBase(json.get("data").getAsByte());

View File

@ -11,6 +11,7 @@ import io.izzel.taboolib.module.nms.nbt.Attribute;
import io.izzel.taboolib.module.nms.nbt.NBTBase; import io.izzel.taboolib.module.nms.nbt.NBTBase;
import io.izzel.taboolib.module.nms.nbt.NBTCompound; import io.izzel.taboolib.module.nms.nbt.NBTCompound;
import io.izzel.taboolib.module.nms.nbt.NBTList; import io.izzel.taboolib.module.nms.nbt.NBTList;
import io.izzel.taboolib.util.Reflection;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -75,7 +76,11 @@ public class Items {
public static Material asMaterial(String args) { public static Material asMaterial(String args) {
try { try {
Material material = Material.getMaterial(args.toUpperCase()); Material material = Material.getMaterial(args.toUpperCase());
return material != null ? material : Material.getMaterial(Integer.valueOf(args)); if (material != null) {
return material;
}
Object getById = Reflection.invokeMethod(Material.class, "getMaterial", NumberConversions.toInt(args));
return getById != null ? (Material) getById : null;
} catch (Exception e) { } catch (Exception e) {
return Material.STONE; return Material.STONE;
} }
@ -101,7 +106,11 @@ public class Items {
public static Enchantment asEnchantment(String enchant) { public static Enchantment asEnchantment(String enchant) {
try { try {
Enchantment enchantment = Enchantment.getByName(enchant); Enchantment enchantment = Enchantment.getByName(enchant);
return enchantment != null ? enchantment : Enchantment.getById(Integer.valueOf(enchant)); if (enchantment != null) {
return enchantment;
}
Object getById = Reflection.invokeMethod(Enchantment.class, "getById", NumberConversions.toInt(enchant));
return getById != null ? (Enchantment) getById : null;
} catch (Exception e) { } catch (Exception e) {
return null; return null;
} }