Merge pull request #15 from Bkm016/dev

+ update
This commit is contained in:
坏黑 2019-04-01 21:49:30 +08:00 committed by GitHub
commit e008b62b61
63 changed files with 2204 additions and 4592 deletions

View File

@ -4,9 +4,8 @@ plugins {
id 'idea' id 'idea'
id 'com.github.johnrengelman.shadow' version '4.0.4' id 'com.github.johnrengelman.shadow' version '4.0.4'
} }
group = 'me.skymc' group = 'me.skymc'
version = '4.73' version = '4.75'
sourceCompatibility = 1.8 sourceCompatibility = 1.8
targetCompatibility = 1.8 targetCompatibility = 1.8
@ -28,11 +27,11 @@ dependencies {
exclude(module: 'slf4j-log4j12') exclude(module: 'slf4j-log4j12')
exclude(module: 'log4j') exclude(module: 'log4j')
} }
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
shadow group: 'com.zaxxer', name: 'HikariCP', version: '3.1.0' shadow group: 'com.zaxxer', name: 'HikariCP', version: '3.1.0'
shadow group: 'org.javalite', name: 'activejdbc', version: '2.0' shadow group: 'org.javalite', name: 'activejdbc', version: '2.0'
compile group: 'org.ow2.asm', name: 'asm', version: '7.0-beta'
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
shadow group: 'com.h2database', name: 'h2', version: '1.4.197' shadow group: 'com.h2database', name: 'h2', version: '1.4.197'
compile group: 'org.ow2.asm', name: 'asm', version: '6.1.1'
shadow group: 'me.clip', name: 'placeholderapi', version: '2.8.4' shadow group: 'me.clip', name: 'placeholderapi', version: '2.8.4'
shadow group: 'net.objecthunter', name: 'exp4j', version: '0.4.8' shadow group: 'net.objecthunter', name: 'exp4j', version: '0.4.8'
shadow group: 'org.scala-lang', name: 'scala-library', version: '2.12.8' shadow group: 'org.scala-lang', name: 'scala-library', version: '2.12.8'
@ -43,3 +42,16 @@ shadowJar {
// MANIFEST.MF lib // MANIFEST.MF lib
taskActions.removeIf { it.actionClassName.contains 'configureShadowTask' } taskActions.removeIf { it.actionClassName.contains 'configureShadowTask' }
} }
processResources {
inputs.property "version", project.version
from(sourceSets.main.resources.srcDirs) {
include 'plugin.yml'
expand 'version': project.version
}
from(sourceSets.main.resources.srcDirs) {
exclude 'plugin.yml'
}
}

View File

@ -1,6 +1,6 @@
name: TabooLib name: TabooLib
main: me.skymc.taboolib.Main main: me.skymc.taboolib.Main
version: ${project.version} version: ${version}
authors: authors:
- 坏黑 - 坏黑

View File

@ -1,4 +1,5 @@
package com.ilummc.eagletdl; package com.ilummc.eagletdl;
public class AlreadyStartException extends RuntimeException { public class AlreadyStartException extends RuntimeException {
} }

View File

@ -12,7 +12,6 @@ import sun.reflect.Reflection;
import javax.annotation.concurrent.ThreadSafe; import javax.annotation.concurrent.ThreadSafe;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;

View File

@ -32,9 +32,9 @@ class RichPlayer(private val player: Player) extends RichOfflinePlayer(player) {
def displaySidebarUnranked(title: String, elements: String*): Unit = ScoreboardUtil.unrankedSidebarDisplay(player, elements: _*) def displaySidebarUnranked(title: String, elements: String*): Unit = ScoreboardUtil.unrankedSidebarDisplay(player, elements: _*)
@deprecated def openSign(block: Block): Unit = SignUtils.openSign(player, block) def openSign(block: Block): Unit = SignUtils.openSign(player, block)
@deprecated def openSign(lines: Array[String], id: String): Unit = SignUtils.openSign(player, lines, id) def openSign(lines: Array[String], id: String): Unit = SignUtils.openSign(player, lines, id)
//todo TagDataHandler //todo TagDataHandler
@ -42,11 +42,9 @@ class RichPlayer(private val player: Player) extends RichOfflinePlayer(player) {
def removePermission(perm: String): Unit = PermissionUtils.removePermission(player, perm) def removePermission(perm: String): Unit = PermissionUtils.removePermission(player, perm)
def sendTitle(title: String, subtitle: String, fadein: Int, stay: Int, fadeout: Int): Unit = def sendTitle(title: String, subtitle: String, fadein: Int, stay: Int, fadeout: Int): Unit = TitleUtils.sendTitle(player, title, subtitle, fadein, stay, fadeout)
TitleUtils.sendTitle(player, title, subtitle, fadein, stay, fadeout)
def sendTitle(p: Player, title: String, fadeint: Int, stayt: Int, fadeoutt: Int, subtitle: String, fadeinst: Int, stayst: Int, fadeoutst: Int): Unit = def sendTitle(p: Player, title: String, fadeint: Int, stayt: Int, fadeoutt: Int, subtitle: String, fadeinst: Int, stayst: Int, fadeoutst: Int): Unit = TitleUtils.sendTitle(p, title, fadeint, stayt, fadeoutt, subtitle, fadeinst, stayst, fadeoutst)
TitleUtils.sendTitle(p, title, fadeint, stayt, fadeoutt, subtitle, fadeinst, stayst, fadeoutst)
def openAnvil(): Unit = AnvilContainerAPI.openAnvil(player) def openAnvil(): Unit = AnvilContainerAPI.openAnvil(player)

View File

@ -17,7 +17,6 @@ import me.skymc.taboolib.playerdata.DataUtils;
import me.skymc.taboolib.socket.TabooLibClient; import me.skymc.taboolib.socket.TabooLibClient;
import me.skymc.taboolib.socket.TabooLibServer; import me.skymc.taboolib.socket.TabooLibServer;
import me.skymc.taboolib.string.language2.Language2; import me.skymc.taboolib.string.language2.Language2;
import me.skymc.taboolib.update.UpdateTask;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
@ -141,10 +140,6 @@ public class Main extends JavaPlugin {
started = true; started = true;
// 载入语言文件 // 载入语言文件
exampleLanguage2 = new Language2("Language2", this); exampleLanguage2 = new Language2("Language2", this);
// 更新检测
if (!TabooLib.isSilent()) {
new UpdateTask();
}
} }
@Override @Override

View File

@ -154,15 +154,18 @@ public class TabooLibLoader implements Listener {
static void setupDatabase() { static void setupDatabase() {
DataUtils.addPluginData("TabooLibrary", null); DataUtils.addPluginData("TabooLibrary", null);
Main.setStorageType(Main.getInst().getConfig().getBoolean("MYSQL.ENABLE") ? Main.StorageType.SQL : Main.StorageType.LOCAL); Main.setStorageType(Main.StorageType.LOCAL);
TabooLibDatabase.init(); // Main.setStorageType(Main.getInst().getConfig().getBoolean("MYSQL.ENABLE") ? Main.StorageType.SQL : Main.StorageType.LOCAL);
// TabooLibDatabase.init();
} }
static void setupAddons() { static void setupAddons() {
TabooLib.instance().saveResource("Addons/TabooLibDeprecated", true); TabooLib.instance().saveResource("Addons/TabooLibDeprecated", true);
// 傻逼 Gradle shadow 插件会将所有 jar 排除 // 傻逼 Gradle shadow 插件会将所有 jar 排除
// https://github.com/johnrengelman/shadow/issues/276 // https://github.com/johnrengelman/shadow/issues/276
new File(TabooLib.instance().getDataFolder(), "Addons/TabooLibDeprecated").renameTo(new File(TabooLib.instance().getDataFolder(), "Addons/TabooLibDeprecated.jar")); File from = new File(TabooLib.instance().getDataFolder(), "Addons/TabooLibDeprecated");
from.renameTo(new File(TabooLib.instance().getDataFolder(), "Addons/TabooLibDeprecated.jar"));
from.delete();
File file = new File(TabooLib.instance().getDataFolder(), "Addons"); File file = new File(TabooLib.instance().getDataFolder(), "Addons");
if (file.exists()) { if (file.exists()) {
Arrays.stream(file.listFiles()).forEach(listFile -> TDependencyLoader.addToPath(TabooLib.instance(), listFile)); Arrays.stream(file.listFiles()).forEach(listFile -> TDependencyLoader.addToPath(TabooLib.instance(), listFile));

View File

@ -1,58 +0,0 @@
package me.skymc.taboolib.client;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import java.awt.*;
import java.text.SimpleDateFormat;
@Deprecated
public class LogClient extends JFrame {
/**
* DEFAULT VERSION UID
*/
private static final long serialVersionUID = 1L;
private JTextArea textArea = new JTextArea();
private SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
public LogClient(String title) {
super(title);
// DEFAULT CLOSE OPERATION
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
// SETTINGS
final JScrollPane scrollPane = new JScrollPane();
scrollPane.setBorder(new BevelBorder(BevelBorder.RAISED));
scrollPane.setViewportView(textArea);
getContentPane().add(scrollPane, BorderLayout.CENTER);
setSize(700, 500);
setVisible(true);
// CON'T EDIT
textArea.setEditable(false);
textArea.setFont(new Font("黑体", 0, 18));
textArea.setBackground(Color.black);
textArea.setForeground(Color.LIGHT_GRAY);
addString(title);
addString("");
}
public void addString(String a) {
textArea.append(a + '\n');
textArea.setSelectionStart(textArea.getText().length());
}
public void info(String a) {
textArea.append("[" + sdf.format(System.currentTimeMillis()) + " INFO]: " + a + '\n');
textArea.setSelectionStart(textArea.getText().length());
}
public void warn(String a) {
textArea.append("[" + sdf.format(System.currentTimeMillis()) + " WARN]: " + a + '\n');
textArea.setSelectionStart(textArea.getText().length());
}
}

View File

@ -9,6 +9,7 @@ import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.cloud.expansion.Expansion; import me.skymc.taboolib.cloud.expansion.Expansion;
import me.skymc.taboolib.cloud.expansion.ExpansionType; import me.skymc.taboolib.cloud.expansion.ExpansionType;
import me.skymc.taboolib.common.function.TFunction; import me.skymc.taboolib.common.function.TFunction;
import me.skymc.taboolib.common.schedule.TSchedule;
import me.skymc.taboolib.fileutils.FileUtils; import me.skymc.taboolib.fileutils.FileUtils;
import me.skymc.taboolib.plugin.PluginUtils; import me.skymc.taboolib.plugin.PluginUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -41,6 +42,7 @@ public class TCloudLoader {
} }
} }
@TSchedule(async = true, period = 20 * 60 * 60)
public static void refresh() { public static void refresh() {
Bukkit.getScheduler().runTaskAsynchronously(TabooLib.instance(), () -> { Bukkit.getScheduler().runTaskAsynchronously(TabooLib.instance(), () -> {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();

View File

@ -1,37 +0,0 @@
package me.skymc.taboolib.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@Deprecated
public abstract class SubCommand {
public CommandSender sender;
public String[] args;
public boolean returnValue = false;
public SubCommand(CommandSender sender, String[] args) {
this.sender = sender;
this.args = args;
}
public boolean setReturn(boolean returnValue) {
return this.returnValue = returnValue;
}
public boolean isPlayer() {
return sender instanceof Player;
}
public boolean command() {
return returnValue;
}
public String getArgs(int size) {
return IntStream.range(size, args.length).mapToObj(i -> args[i] + " ").collect(Collectors.joining()).trim();
}
}

View File

@ -1,10 +0,0 @@
package me.skymc.taboolib.commands;
import org.bukkit.command.CommandSender;
@Deprecated
public interface SubCommandExecutor {
boolean command(CommandSender sender, String[] args);
}

View File

@ -116,6 +116,11 @@ public class TabooLibMainCommand extends BaseMainCommand {
@CommandRegister(priority = 3) @CommandRegister(priority = 3)
BaseSubCommand itemInfo = new BaseSubCommand() { BaseSubCommand itemInfo = new BaseSubCommand() {
@Override
public boolean hideInHelp() {
return true;
}
@Override @Override
public String getLabel() { public String getLabel() {
return "itemInfo"; return "itemInfo";

View File

@ -1,6 +1,7 @@
package me.skymc.taboolib.commands.builder; package me.skymc.taboolib.commands.builder;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import me.skymc.taboolib.commands.builder.type.CompleterCommand; import me.skymc.taboolib.commands.builder.type.CompleterCommand;
import me.skymc.taboolib.commands.builder.type.CompleterTab; import me.skymc.taboolib.commands.builder.type.CompleterTab;
import me.skymc.taboolib.commands.internal.TCommandHandler; import me.skymc.taboolib.commands.internal.TCommandHandler;
@ -119,8 +120,22 @@ public class SimpleCommandBuilder {
aliases, aliases,
permission, permission,
permissionMessage, permissionMessage,
(sender, command, s, args) -> completerCommand.execute(sender, args), (sender, command, s, args) -> {
(sender, command, s, args) -> completerTab.execute(sender, args), try {
return completerCommand.execute(sender, args);
} catch (Throwable t) {
t.printStackTrace();
}
return false;
},
(sender, command, s, args) -> {
try {
return completerTab.execute(sender, args);
} catch (Throwable t) {
t.printStackTrace();
}
return Lists.newArrayList();
},
silence); silence);
build = true; build = true;
return this; return this;

View File

@ -1,78 +0,0 @@
package me.skymc.taboolib.commands.language;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.commands.builder.SimpleCommandBuilder;
import me.skymc.taboolib.common.loader.Instantiable;
import me.skymc.taboolib.string.language2.Language2Value;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* @author sky
* @since 2018年2月13日 下午5:11:01
*/
@Instantiable("Language2Command")
public class Language2Command {
public Language2Command() {
SimpleCommandBuilder.create("language2", TabooLib.instance())
.aliases("lang2")
.permission("taboolib.admin")
.execute((sender, args) -> {
if (args.length == 0) {
TLocale.sendTo(sender, "COMMANDS.LANGUAGE2.HELP", "langauge2");
} else if ("reload".equalsIgnoreCase(args[0])) {
reload(sender);
} else if ("send".equalsIgnoreCase(args[0])) {
send(sender, args);
}
return true;
}).build();
}
private void send(CommandSender sender, String[] args) {
if (args.length < 3) {
TLocale.sendTo(sender, "COMMANDS.PARAMETER.UNKNOWN");
} else {
long time = System.currentTimeMillis();
Language2Value value = getLanguage2Value(args);
if ("ALL".equalsIgnoreCase(args[1])) {
value.broadcast();
} else {
Player player = Bukkit.getPlayerExact(args[1]);
if (player == null) {
TLocale.sendTo(sender, "COMMANDS.LANGUAGE2.INVALID-PLAYER", args[1]);
} else {
value.send(player);
}
}
if (sender instanceof Player && ((Player) sender).getItemInHand().getType().equals(Material.COMMAND)) {
TLocale.sendTo(sender, "COMMANDS.LANGUAGE2.SUCCESS-SEND", String.valueOf(System.currentTimeMillis() - time));
}
}
}
private Language2Value getLanguage2Value(String[] args) {
Language2Value value = Main.getExampleLanguage2().get(args[2]);
if (args.length > 3) {
int i = 0;
for (String variable : args[3].split("\\|")) {
value.addPlaceholder("$" + i++, variable);
}
}
return value;
}
private void reload(CommandSender sender) {
TLocale.sendTo(sender, "COMMANDS.RELOAD.LOADING");
long time = System.currentTimeMillis();
Main.getExampleLanguage2().reload();
TLocale.sendTo(sender, "COMMANDS.RELOAD.SUCCESS-ELAPSED-TIME", String.valueOf(System.currentTimeMillis() - time));
}
}

View File

@ -1,20 +0,0 @@
package me.skymc.taboolib.commands.taboolib;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.commands.SubCommand;
import org.bukkit.command.CommandSender;
import java.util.Arrays;
public class AttributesCommand extends SubCommand {
public AttributesCommand(CommandSender sender, String[] args) {
super(sender, args);
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.ATTRIBUTES.HEAD");
Arrays.stream(new String[]{"damage", "speed", "attackspeed", "health", "knockback", "armor", "luck"}).forEach(attribute -> TLocale.sendTo(sender, "COMMANDS.TABOOLIB.ATTRIBUTES.BODY", attribute));
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.ATTRIBUTES.FOOT");
}
}

View File

@ -1,22 +0,0 @@
package me.skymc.taboolib.commands.taboolib;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.commands.SubCommand;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import java.util.Arrays;
public class EnchantCommand extends SubCommand {
@SuppressWarnings("deprecation")
public EnchantCommand(CommandSender sender, String[] args) {
super(sender, args);
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.ENCHANTS.HEAD");
Arrays.stream(Enchantment.values()).forEach(enchant -> TLocale.sendTo(sender, "COMMANDS.TABOOLIB.ENCHANTS.BODY", String.valueOf(enchant.getId()), enchant.getName()));
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.ENCHANTS.FOOT");
}
}

View File

@ -1,21 +0,0 @@
package me.skymc.taboolib.commands.taboolib;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.commands.SubCommand;
import org.bukkit.command.CommandSender;
import org.bukkit.inventory.ItemFlag;
import java.util.Arrays;
public class FlagCommand extends SubCommand {
public FlagCommand(CommandSender sender, String[] args) {
super(sender, args);
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.FLAGS.HEAD");
Arrays.stream(ItemFlag.values()).forEach(itemFlag -> TLocale.sendTo(sender, "COMMANDS.TABOOLIB.ENCHANTS.BODY", itemFlag.name()));
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.FLAGS.FOOT");
}
}

View File

@ -1,50 +0,0 @@
package me.skymc.taboolib.commands.taboolib;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.Main.StorageType;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.fileutils.ConfigUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.util.Objects;
public class ImportCommand extends SubCommand {
public ImportCommand(CommandSender sender, String[] args) {
super(sender, args);
if (isPlayer()) {
TLocale.sendTo(sender, "COMMANDS.GLOBAL.ONLY-PLAYER");
return;
}
if (Main.getStorageType() == StorageType.LOCAL) {
TLocale.Logger.warn("COMMANDS.GLOBAL.ONLY-STORAGE-SQL");
return;
}
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.IMPORTDATA.CLEARING");
Main.getConnection().truncateTable(Main.getTablePrefix() + "_playerdata");
if (!Main.getPlayerDataFolder().exists()) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.IMPORTDATA.EMPTYDATA");
return;
}
int size = Objects.requireNonNull(Main.getPlayerDataFolder().listFiles()).length;
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.IMPORTDATA.IMPORTING-START", String.valueOf(size));
int loop = 1;
for (File file : Objects.requireNonNull(Main.getPlayerDataFolder().listFiles())) {
Main.getConnection().intoValue(Main.getTablePrefix() + "_playerdata", file.getName().replace(".yml", ""), ConfigUtils.encodeYAML(YamlConfiguration.loadConfiguration(file)));
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.IMPORTDATA.IMPORTING-PROGRESS", file.getName().replace(".yml", ""), String.valueOf(loop), String.valueOf(size));
loop++;
}
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.IMPORTDATA.SUCCESS");
}
}

View File

@ -1,31 +0,0 @@
package me.skymc.taboolib.commands.taboolib;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.itemnbtapi.NBTItem;
import me.skymc.taboolib.json.JSONReader;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class InfoCommand extends SubCommand {
@SuppressWarnings("deprecation")
public InfoCommand(CommandSender sender, String[] args) {
super(sender, args);
if (isPlayer()) {
Player player = (Player) sender;
if (player.getItemInHand().getType().equals(Material.AIR)) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.INFO.INVALID-ITEM");
} else {
NBTItem nbt = new NBTItem(player.getItemInHand());
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.INFO.ITEM-INFO",
player.getItemInHand().getType().name(),
ItemUtils.getCustomName(player.getItemInHand()),
player.getItemInHand().getTypeId() + ":" + player.getItemInHand().getDurability(),
JSONReader.formatJson(nbt.asNBTString()));
}
}
}
}

View File

@ -1,63 +0,0 @@
package me.skymc.taboolib.commands.taboolib;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.other.NumberUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
public class ItemCommand extends SubCommand {
public ItemCommand(CommandSender sender, String[] args) {
super(sender, args);
if (args.length < 2) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.ITEM.INVALID-NAME");
return;
}
if (ItemUtils.getCacheItem(args[1]) == null) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.ITEM.INVALID-ITEM", args[1]);
return;
}
Player player;
Integer amount = 1;
ItemStack item = ItemUtils.getCacheItem(args[1]).clone();
if (args.length > 2) {
player = Bukkit.getPlayerExact(args[2]);
if (player == null) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.ITEM.INVALID-PLAYER", args[2]);
return;
}
} else if (sender instanceof Player) {
player = (Player) sender;
} else {
TLocale.sendTo(sender, "COMMANDS.GLOBAL.ONLY-PLAYER");
return;
}
if (args.length > 3) {
amount = NumberUtils.getInteger(args[3]);
if (amount < 1) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.ITEM.INVALID-NUMBER");
return;
}
}
item.setAmount(amount);
HashMap<Integer, ItemStack> map = player.getInventory().addItem(item);
if (map.size() > 0) {
player.getWorld().dropItem(player.getLocation(), item);
}
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.ITEM.SUCCESS", player.getName());
setReturn(true);
}
}

View File

@ -1,25 +0,0 @@
package me.skymc.taboolib.commands.taboolib;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.commands.taboolib.listener.ListenerItemListCommand;
import me.skymc.taboolib.other.NumberUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* @author sky
* @since 2018年2月4日 下午8:08:22
*/
public class ItemListCommand extends SubCommand {
public ItemListCommand(CommandSender sender, String[] args) {
super(sender, args);
if (isPlayer()) {
if (args.length == 1) {
ListenerItemListCommand.openInventory((Player) sender, 1);
} else {
ListenerItemListCommand.openInventory((Player) sender, NumberUtils.getInteger(args[1]));
}
}
}
}

View File

@ -1,24 +0,0 @@
package me.skymc.taboolib.commands.taboolib;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.commands.SubCommand;
import org.bukkit.command.CommandSender;
import org.bukkit.potion.PotionEffectType;
public class PotionCommand extends SubCommand {
@SuppressWarnings("deprecation")
public PotionCommand(CommandSender sender, String[] args) {
super(sender, args);
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.POTIONS.HEAD");
for (PotionEffectType potionEffectType : PotionEffectType.values()) {
if (potionEffectType != null) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.POTIONS.BODY", String.valueOf(potionEffectType.getId()), potionEffectType.getName());
}
}
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.POTIONS.FOOT");
}
}

View File

@ -1,89 +0,0 @@
package me.skymc.taboolib.commands.taboolib;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.fileutils.ConfigUtils;
import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.message.ChatCatcher;
import me.skymc.taboolib.message.ChatCatcher.Catcher;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.playerdata.DataUtils;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
/**
* @author sky
*/
public class SaveCommand extends SubCommand {
public SaveCommand(CommandSender sender, String[] args) {
super(sender, args);
if (!(sender instanceof Player)) {
TLocale.sendTo(sender, "COMMANDS.GLOBAL.ONLY-PLAYER");
return;
}
if (args.length < 2) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.SAVE.INVALID-NAME");
return;
}
if (((Player) sender).getItemInHand().getType().equals(Material.AIR)) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.SAVE.INVALID-ITEM");
return;
}
if (ItemUtils.getItemCachesFinal().containsKey(args[1])) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.SAVE.INVALID-ITEM-FINAL-EXISTS");
return;
}
if (ItemUtils.getItemCaches().containsKey(args[1])) {
// 检查聊天引导
if (ChatCatcher.contains((Player) sender)) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.SAVE.GUIDE-EXISTS");
return;
}
ChatCatcher.call((Player) sender, new Catcher() {
@Override
public void cancel() {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.SAVE.GUIDE-QUIT");
}
@Override
public Catcher before() {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.SAVE.GUIDE-BEFORE", args[1]);
return this;
}
@SuppressWarnings("deprecation")
@Override
public boolean after(String message) {
if ("yes".equalsIgnoreCase(message)) {
saveItem(args[1], ((Player) sender).getItemInHand());
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.SAVE.SUCCESS", args[1]);
} else {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.SAVE.GUIDE-QUIT");
}
return false;
}
});
} else {
saveItem(args[1], ((Player) sender).getItemInHand());
MsgUtils.send(sender, "物品 &f" + args[1] + " &7已保存");
}
}
private void saveItem(String name, ItemStack item) {
FileConfiguration conf = ConfigUtils.load(Main.getInst(), ItemUtils.getItemCacheFile());
conf.set(name + ".bukkit", item);
DataUtils.saveConfiguration(conf, ItemUtils.getItemCacheFile());
ItemUtils.reloadItemCache();
}
}

View File

@ -1,20 +0,0 @@
package me.skymc.taboolib.commands.taboolib;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.commands.SubCommand;
import org.bukkit.command.CommandSender;
import java.util.Arrays;
public class SlotCommand extends SubCommand {
public SlotCommand(CommandSender sender, String[] args) {
super(sender, args);
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.SLOTS.HEAD");
Arrays.stream(new String[]{"mainhand", "offhand", "feet", "legs", "chest", "head", "all"}).forEach(slots -> TLocale.sendTo(sender, "COMMANDS.TABOOLIB.SLOTS.BODY", slots));
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.SLOTS.FOOT");
}
}

View File

@ -1,27 +0,0 @@
package me.skymc.taboolib.commands.taboolib;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.commands.taboolib.listener.ListenerSoundsCommand;
import me.skymc.taboolib.other.NumberUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* @author sky
* @since 2018-03-18 21:02:26
*/
public class SoundsCommand extends SubCommand {
public SoundsCommand(CommandSender sender, String[] args) {
super(sender, args);
if (isPlayer()) {
if (args.length == 1) {
ListenerSoundsCommand.openInventory((Player) sender, 1, null);
} else if (args.length == 2) {
ListenerSoundsCommand.openInventory((Player) sender, NumberUtils.getInteger(args[1]), null);
} else {
ListenerSoundsCommand.openInventory((Player) sender, NumberUtils.getInteger(args[1]), args[2]);
}
}
}
}

View File

@ -1,35 +0,0 @@
package me.skymc.taboolib.commands.taboolib;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.itagapi.TagDataHandler;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* @author sky
* @since 2018-03-19 23:13:35
*/
public class TagDeleteCommand extends SubCommand {
public TagDeleteCommand(CommandSender sender, String[] args) {
super(sender, args);
if (args.length < 2) {
TLocale.sendTo(sender, "COMMANDS.PARAMETER.UNKNOWN");
return;
}
Player player = Bukkit.getPlayerExact(args[1]);
if (player == null) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.PLAYERTAG.INVALID-PLAYER", args[1]);
return;
}
TagDataHandler.getHandler().reset(player);
if (sender instanceof Player) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.PLAYERTAG.SUCCESS-DELETE", args[1]);
}
}
}

View File

@ -1,37 +0,0 @@
package me.skymc.taboolib.commands.taboolib;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.itagapi.TagDataHandler;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* @author sky
* @since 2018-03-19 23:13:35
*/
public class TagDisplayCommand extends SubCommand {
public TagDisplayCommand(CommandSender sender, String[] args) {
super(sender, args);
if (args.length < 3) {
TLocale.sendTo(sender, "COMMANDS.PARAMETER.UNKNOWN");
return;
}
Player player = Bukkit.getPlayerExact(args[1]);
if (player == null) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.PLAYERTAG.INVALID-PLAYER", args[1]);
return;
}
String value = TLocale.Translate.setPlaceholders(player, getArgs(2));
TagDataHandler.getHandler().setDisplay(player, value);
if (sender instanceof Player) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.PLAYERTAG.SUCCESS-DISPLAY-SET", args[1], value);
}
}
}

View File

@ -1,37 +0,0 @@
package me.skymc.taboolib.commands.taboolib;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.itagapi.TagDataHandler;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* @author sky
* @since 2018-03-19 23:13:35
*/
public class TagPrefixCommand extends SubCommand {
public TagPrefixCommand(CommandSender sender, String[] args) {
super(sender, args);
if (args.length < 3) {
TLocale.sendTo(sender, "COMMANDS.PARAMETER.UNKNOWN");
return;
}
Player player = Bukkit.getPlayerExact(args[1]);
if (player == null) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.PLAYERTAG.INVALID-PLAYER", args[1]);
return;
}
String value = TLocale.Translate.setPlaceholders(player, getArgs(2));
TagDataHandler.getHandler().setPrefix(player, value);
if (sender instanceof Player) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.PLAYERTAG.SUCCESS-PREFIX-SET", args[1], value);
}
}
}

View File

@ -1,37 +0,0 @@
package me.skymc.taboolib.commands.taboolib;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.itagapi.TagDataHandler;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* @author sky
* @since 2018-03-19 23:13:35
*/
public class TagSuffixCommand extends SubCommand {
public TagSuffixCommand(CommandSender sender, String[] args) {
super(sender, args);
if (args.length < 3) {
TLocale.sendTo(sender, "COMMANDS.PARAMETER.UNKNOWN");
return;
}
Player player = Bukkit.getPlayerExact(args[1]);
if (player == null) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.PLAYERTAG.INVALID-PLAYER", args[1]);
return;
}
String value = TLocale.Translate.setPlaceholders(player, getArgs(2));
TagDataHandler.getHandler().setSuffix(player, value);
if (sender instanceof Player) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.PLAYERTAG.SUCCESS-SUFFIX-SET", args[1], value);
}
}
}

View File

@ -1,38 +0,0 @@
package me.skymc.taboolib.commands.taboolib;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.database.GlobalDataManager;
import org.bukkit.command.CommandSender;
/**
* @author sky
*/
public class VariableGetCommand extends SubCommand {
public VariableGetCommand(CommandSender sender, String[] args) {
super(sender, args);
if (args.length < 3) {
TLocale.sendTo(sender, "COMMANDS.PARAMETER.INSUFFICIENT");
return;
}
if (!("-a".equals(args[1]) || "-s".equals(args[1]))) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.VARIABLE.READ-ERROR-TYPE");
return;
}
Long time = System.currentTimeMillis();
String value = null;
if ("-s".equals(args[1])) {
value = GlobalDataManager.getVariable(args[2], null);
} else if ("-a".equals(args[1])) {
value = GlobalDataManager.getVariableAsynchronous(args[2], null);
}
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.VARIABLE.READ-SUCCESS", String.valueOf(System.currentTimeMillis() - time));
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.VARIABLE.READ-RESULT", value == null ? "null" : value);
}
}

View File

@ -1,35 +0,0 @@
package me.skymc.taboolib.commands.taboolib;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.database.GlobalDataManager;
import org.bukkit.command.CommandSender;
public class VariableSetCommand extends SubCommand {
public VariableSetCommand(CommandSender sender, String[] args) {
super(sender, args);
if (args.length < 4) {
TLocale.sendTo(sender, "COMMANDS.PARAMETER.INSUFFICIENT");
return;
}
if (!("-a".equals(args[1]) || "-s".equals(args[1]))) {
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.VARIABLE.WRITE-ERROR-TYPE");
return;
}
Long time = System.currentTimeMillis();
String value = getArgs(3);
if ("-s".equals(args[1])) {
GlobalDataManager.setVariable(args[2], value);
} else if ("-a".equals(args[1])) {
GlobalDataManager.setVariableAsynchronous(args[2], value);
}
TLocale.sendTo(sender, "COMMANDS.TABOOLIB.VARIABLE.WRITE-SUCCESS", String.valueOf(System.currentTimeMillis() - time));
setReturn(true);
}
}

View File

@ -1,107 +0,0 @@
package me.skymc.taboolib.commands.taboolib.listener;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.inventory.InventoryUtil;
import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.listener.TListener;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
/**
* @author sky
* @since 2018年2月4日 下午4:35:00
*/
@TListener
public class ListenerItemListCommand implements Listener {
/**
* 打开物品库界面
*
* @param player
* @param page
*/
public static void openInventory(Player player, int page) {
ItemLibraryHolder holder = new ItemLibraryHolder(page);
Inventory inventory = Bukkit.createInventory(holder, 54, TLocale.asString("COMMANDS.TABOOLIB.ITEMLIST.MENU.TITLE", String.valueOf(page)));
LinkedHashMap<String, ItemStack> map = new LinkedHashMap<>();
map.putAll(ItemUtils.getItemCachesFinal());
map.putAll(ItemUtils.getItemCaches());
int loop = 0;
for (String name : map.keySet()) {
if (loop >= (page - 1) * 28) {
if (loop < page * 28) {
int slot = InventoryUtil.SLOT_OF_CENTENTS.get(loop - ((page - 1) * 28));
ItemStack item = map.get(name).clone();
ItemMeta meta = item.getItemMeta();
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
lore.addAll(TLocale.asStringList("COMMANDS.TABOOLIB.ITEMLIST.MENU.LORE", name));
meta.setLore(lore);
item.setItemMeta(meta);
inventory.setItem(slot, item);
holder.ITEMS_DATA.put(slot, name);
} else {
break;
}
}
loop++;
}
if (page > 1) {
inventory.setItem(47, ItemUtils.setName(new ItemStack(Material.ARROW), TLocale.asString("COMMANDS.TABOOLIB.ITEMLIST.MENU.BACK")));
}
if (((int) Math.ceil(map.size() / 28D)) > page) {
inventory.setItem(51, ItemUtils.setName(new ItemStack(Material.ARROW), TLocale.asString("COMMANDS.TABOOLIB.ITEMLIST.MENU.NEXT")));
}
player.openInventory(inventory);
}
@EventHandler
public void inventoryClick(InventoryClickEvent e) {
if (e.getInventory().getHolder() instanceof ItemLibraryHolder) {
e.setCancelled(true);
if (e.getCurrentItem() == null || e.getCurrentItem().getType().equals(Material.AIR) || e.getRawSlot() >= e.getInventory().getSize()) {
return;
}
int i = e.getRawSlot();
if (i == 47) {
openInventory((Player) e.getWhoClicked(), ((ItemLibraryHolder) e.getInventory().getHolder()).PAGE - 1);
} else if (i == 51) {
openInventory((Player) e.getWhoClicked(), ((ItemLibraryHolder) e.getInventory().getHolder()).PAGE + 1);
} else {
e.getWhoClicked().getInventory().addItem(ItemUtils.getCacheItem(((ItemLibraryHolder) e.getInventory().getHolder()).ITEMS_DATA.get(e.getRawSlot())));
}
}
}
public static class ItemLibraryHolder implements InventoryHolder {
public final int PAGE;
public final HashMap<Integer, String> ITEMS_DATA = new HashMap<>();
public ItemLibraryHolder(int page) {
this.PAGE = page;
}
@Override
public Inventory getInventory() {
return null;
}
}
}

View File

@ -1,119 +0,0 @@
package me.skymc.taboolib.commands.taboolib.listener;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.inventory.InventoryUtil;
import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.listener.TListener;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author sky
* @since 2018年2月4日 下午4:35:00
*/
@TListener
public class ListenerSoundsCommand implements Listener {
public static void openInventory(Player player, int page, String search) {
if (page < 1) {
page = 1;
}
SoundLibraryHolder holder = new SoundLibraryHolder(page, search);
Inventory inventory = Bukkit.createInventory(holder, 54, TLocale.asString("COMMANDS.TABOOLIB.SOUNDS.MENU.TITLE", String.valueOf(page)));
List<Sound> soundFilter = Arrays.stream(Sound.values()).filter(sound -> search == null || sound.name().contains(search.toUpperCase())).collect(Collectors.toList());
List<String> soundLore = TLocale.asStringList("COMMANDS.TABOOLIB.SOUNDS.MENU.LORE");
int loop = 0;
for (Sound sound : soundFilter) {
if (loop >= (page - 1) * 28) {
if (loop < page * 28) {
int slot = InventoryUtil.SLOT_OF_CENTENTS.get(loop - ((page - 1) * 28));
ItemStack item = new ItemStack(Material.MAP);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§f§n" + sound);
meta.setLore(soundLore);
item.setItemMeta(meta);
inventory.setItem(slot, item);
holder.SOUNDS_DATA.put(slot, sound);
} else {
break;
}
}
loop++;
}
if (page > 1) {
inventory.setItem(47, ItemUtils.setName(new ItemStack(Material.ARROW), TLocale.asString("COMMANDS.TABOOLIB.SOUNDS.MENU.BACK")));
}
if (((int) Math.ceil(Sound.values().length / 28D)) > page) {
inventory.setItem(51, ItemUtils.setName(new ItemStack(Material.ARROW), TLocale.asString("COMMANDS.TABOOLIB.SOUNDS.MENU.NEXT")));
}
if (!(player.getOpenInventory().getTopInventory().getHolder() instanceof SoundLibraryHolder)) {
TLocale.sendTo(player, "COMMANDS.TABOOLIB.SOUNDS.RESULT.SEARCH", (search == null ? "*" : search), String.valueOf(soundFilter.size()));
}
player.openInventory(inventory);
}
@EventHandler
public void inventoryClick(InventoryClickEvent e) {
if (e.getInventory().getHolder() instanceof SoundLibraryHolder) {
e.setCancelled(true);
if (e.getCurrentItem() == null || e.getCurrentItem().getType().equals(Material.AIR) || e.getRawSlot() >= e.getInventory().getSize()) {
return;
}
SoundLibraryHolder soundLibraryHolder = ((SoundLibraryHolder) e.getInventory().getHolder());
int i = e.getRawSlot();
if (i == 47) {
openInventory((Player) e.getWhoClicked(), soundLibraryHolder.PAGE - 1, soundLibraryHolder.SEARCH);
} else if (i == 51) {
openInventory((Player) e.getWhoClicked(), soundLibraryHolder.PAGE + 1, soundLibraryHolder.SEARCH);
} else {
Sound sound = soundLibraryHolder.SOUNDS_DATA.get(e.getRawSlot());
if (e.getClick().isKeyboardClick()) {
((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), sound, 1f, 0f);
} else if (e.getClick().isLeftClick()) {
((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), sound, 1f, 1f);
} else if (e.getClick().isRightClick()) {
((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), sound, 1f, 2f);
} else if (e.getClick().isCreativeAction()) {
TLocale.sendTo(e.getWhoClicked(), "COMMANDS.TABOOLIB.SOUNDS.RESULT.COPY", sound.name());
}
}
}
}
public static class SoundLibraryHolder implements InventoryHolder {
public final int PAGE;
public final String SEARCH;
public final HashMap<Integer, Sound> SOUNDS_DATA = new HashMap<>();
public SoundLibraryHolder(int page, String search) {
this.PAGE = page;
this.SEARCH = search;
}
@Override
public Inventory getInventory() {
return null;
}
}
}

View File

@ -20,7 +20,7 @@ import java.util.Map;
*/ */
public class TInjectLoader implements TabooLibLoader.Loader { public class TInjectLoader implements TabooLibLoader.Loader {
private static Map<Class<?>, TInjectTask> injectTypes = Maps.newHashMap(); private static Map<Class<?>, TInjectTask> injectTypes = Maps.newLinkedHashMap();
static { static {
// Instance Inject // Instance Inject
@ -50,11 +50,7 @@ public class TInjectLoader implements TabooLibLoader.Loader {
// TConfiguration Inject // TConfiguration Inject
injectTypes.put(TConfiguration.class, (plugin, field, args, instance) -> { injectTypes.put(TConfiguration.class, (plugin, field, args, instance) -> {
try { try {
if (args.length == 0) { field.set(instance, TConfiguration.createInResource(plugin, args.length == 0 ? "config.yml" : args[0]));
TLogger.getGlobalLogger().error("Invalid inject arguments: " + field.getName() + " (" + field.getType().getName() + ")");
} else {
field.set(instance, TConfiguration.createInResource(plugin, args[0]));
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -1,7 +1,5 @@
package me.skymc.taboolib.common.nms; package me.skymc.taboolib.common.nms;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.commands.builder.SimpleCommandBuilder;
import me.skymc.taboolib.common.function.TFunction; import me.skymc.taboolib.common.function.TFunction;
import me.skymc.taboolib.common.versioncontrol.SimpleVersionControl; import me.skymc.taboolib.common.versioncontrol.SimpleVersionControl;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -21,11 +19,6 @@ public abstract class NMSHandler {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
SimpleCommandBuilder.create("title", TabooLib.instance())
.execute((sender, args) -> {
handler.sendTitle((Player) sender, "TabooLib", 10, 40, 10, "author Bkm016", 10, 40, 10);
return true;
}).build();
} }
abstract public void sendTitle(Player player, String title, int titleFadein, int titleStay, int titleFadeout, String subtitle, int subtitleFadein, int subtitleStay, int subtitleFadeout); abstract public void sendTitle(Player player, String title, int titleFadein, int titleStay, int titleFadeout, String subtitle, int subtitleFadein, int subtitleStay, int subtitleFadeout);

View File

@ -0,0 +1,20 @@
package me.skymc.taboolib.common.serialize;
/**
* @Author 坏黑
* @Since 2019-03-08 17:28
*/
public interface TSerializable {
void read(String fieldName, String value);
String write(String fieldName, Object value);
default void read(String value) {
TSerializer.read(this, value);
}
default String write() {
return TSerializer.write(this);
}
}

View File

@ -0,0 +1,149 @@
package me.skymc.taboolib.common.serialize;
import ch.njol.skript.classes.ConfigurationSerializer;
import com.google.gson.*;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
/**
* @Author 坏黑
* @Since 2019-03-08 17:31
*/
public class TSerializer {
public static <T extends ConfigurationSerializable> T read(String value, Class<T> type) {
return ConfigurationSerializer.deserializeCS(value, type);
}
public static TSerializable read(TSerializable serializable, String serializedString) {
try {
JsonObject jsonObject = (JsonObject) new JsonParser().parse(serializedString);
if (jsonObject.has("serializeObject")) {
JsonObject serializeObject = jsonObject.getAsJsonObject("serializeObject");
for (Map.Entry<String, JsonElement> jsonElementEntry : serializeObject.entrySet()) {
try {
Field declaredField = serializable.getClass().getDeclaredField(jsonElementEntry.getKey());
declaredField.setAccessible(true);
Optional<TSerializerElementGeneral> serializer = Arrays.stream(TSerializerElementGeneral.values()).filter(serializerElements -> serializerElements.getSerializer().matches(declaredField.getType())).findFirst();
if (serializer.isPresent()) {
declaredField.set(serializable, serializer.get().getSerializer().read(jsonElementEntry.getValue().getAsString()));
} else {
serializable.read(jsonElementEntry.getKey(), jsonElementEntry.getValue().getAsString());
}
} catch (Throwable t) {
t.printStackTrace();
}
}
}
} catch (Throwable t) {
t.printStackTrace();
}
return serializable;
}
public static String write(ConfigurationSerializable serializable) {
return ConfigurationSerializer.serializeCS(serializable);
}
public static String write(TSerializable serializable) {
JsonObject jsonObject = new JsonObject();
JsonObject serializeObject = new JsonObject();
for (Field declaredField : serializable.getClass().getDeclaredFields()) {
try {
if (!Modifier.isStatic(declaredField.getModifiers())) {
declaredField.setAccessible(true);
Optional<TSerializerElementGeneral> serializer = Arrays.stream(TSerializerElementGeneral.values()).filter(serializerElements -> serializerElements.getSerializer().matches(declaredField.getType())).findFirst();
Object o = declaredField.get(serializable);
if (o == null) {
continue;
}
if (serializer.isPresent()) {
serializeObject.addProperty(declaredField.getName(), serializer.get().getSerializer().write(o));
} else {
Optional.ofNullable(serializable.write(declaredField.getName(), o)).ifPresent(value -> serializeObject.addProperty(declaredField.getName(), value));
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}
jsonObject.add("serializeObject", serializeObject);
return jsonObject.toString();
}
public static void readMap(Map map, String serializedString, TSerializerElementGeneral elementKey, TSerializerElementGeneral elementValue) {
readMap(map, serializedString, elementKey.getSerializer(), elementValue.getSerializer());
}
public static void readMap(Map map, String serializedString, TSerializerElement elementKey, TSerializerElement elementValue) {
try {
JsonObject jsonObject = (JsonObject) new JsonParser().parse(serializedString);
for (Map.Entry<String, JsonElement> jsonElementEntry : jsonObject.entrySet()) {
try {
map.put(elementKey.read(jsonElementEntry.getKey()), elementValue.read(jsonElementEntry.getValue().getAsString()));
} catch (Throwable t) {
t.printStackTrace();
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}
public static String writeMap(Map<?, ?> map, TSerializerElementGeneral elementKey, TSerializerElementGeneral elementValue) {
return writeMap(map, elementKey.getSerializer(), elementValue.getSerializer());
}
public static String writeMap(Map<?, ?> map, TSerializerElement elementKey, TSerializerElement elementValue) {
JsonObject jsonObject = new JsonObject();
for (Map.Entry<?, ?> entry : map.entrySet()) {
try {
jsonObject.addProperty(elementKey.write(entry.getKey()), elementValue.write(entry.getValue()));
} catch (Throwable t) {
t.printStackTrace();
}
}
return jsonObject.toString();
}
public static void readCollection(Collection collection, String serializedString, TSerializerElementGeneral elementValue) {
readCollection(collection, serializedString, elementValue.getSerializer());
}
public static void readCollection(Collection collection, String serializedString, TSerializerElement elementValue) {
try {
JsonArray jsonArray = (JsonArray) new JsonParser().parse(serializedString);
for (JsonElement jsonElement : jsonArray) {
try {
collection.add(elementValue.read(jsonElement.getAsString()));
} catch (Throwable t) {
t.printStackTrace();
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}
public static String writeCollection(Collection collection, TSerializerElementGeneral elementValue) {
return writeCollection(collection, elementValue.getSerializer());
}
public static String writeCollection(Collection collection, TSerializerElement elementValue) {
JsonArray jsonArray = new JsonArray();
for (Object object : collection) {
try {
jsonArray.add(new JsonPrimitive(elementValue.write(object)));
} catch (Throwable t) {
t.printStackTrace();
}
}
return jsonArray.toString();
}
}

View File

@ -0,0 +1,15 @@
package me.skymc.taboolib.common.serialize;
/**
* @Author 坏黑
* @Since 2019-03-08 17:28
*/
public interface TSerializerElement<T> {
T read(String value);
String write(Object value);
boolean matches(Class objectClass);
}

View File

@ -0,0 +1,217 @@
package me.skymc.taboolib.common.serialize;
import ch.njol.skript.classes.ConfigurationSerializer;
import me.skymc.taboolib.other.NumberUtils;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
import java.util.Objects;
/**
* @Author 坏黑
* @Since 2019-03-10 18:49
*/
public enum TSerializerElementGeneral {
STRING(new TSerializerElement() {
@Override
public String read(String value) {
return String.valueOf(value);
}
@Override
public String write(Object value) {
return Objects.toString(value);
}
@Override
public boolean matches(Class objectClass) {
return String.class.equals(objectClass);
}
}),
INT(new TSerializerElement() {
@Override
public Integer read(String value) {
try {
return Integer.parseInt(value);
} catch (Throwable t) {
t.printStackTrace();
}
return 0;
}
@Override
public String write(Object value) {
return Objects.toString(value);
}
@Override
public boolean matches(Class objectClass) {
return Integer.class.equals(objectClass) || Integer.TYPE.equals(objectClass);
}
}),
LONG(new TSerializerElement() {
@Override
public Long read(String value) {
try {
return Long.parseLong(value);
} catch (Throwable t) {
t.printStackTrace();
}
return 0L;
}
@Override
public String write(Object value) {
return Objects.toString(value);
}
@Override
public boolean matches(Class objectClass) {
return Long.class.equals(objectClass) || Long.TYPE.equals(objectClass);
}
}),
SHORT(new TSerializerElement() {
@Override
public Short read(String value) {
try {
return Short.parseShort(value);
} catch (Throwable t) {
t.printStackTrace();
}
return (short) 0;
}
@Override
public String write(Object value) {
return Objects.toString(value);
}
@Override
public boolean matches(Class objectClass) {
return Short.class.equals(objectClass) || Short.TYPE.equals(objectClass);
}
}),
DOUBLE(new TSerializerElement() {
@Override
public Double read(String value) {
try {
return Double.parseDouble(value);
} catch (Throwable t) {
t.printStackTrace();
}
return 0D;
}
@Override
public String write(Object value) {
return Objects.toString(value);
}
@Override
public boolean matches(Class objectClass) {
return Double.class.equals(objectClass) || Boolean.TYPE.equals(objectClass);
}
}),
FLOAT(new TSerializerElement() {
@Override
public Float read(String value) {
try {
return Float.parseFloat(value);
} catch (Throwable t) {
t.printStackTrace();
}
return 0f;
}
@Override
public String write(Object value) {
return Objects.toString(value);
}
@Override
public boolean matches(Class objectClass) {
return Float.class.equals(objectClass) || Float.TYPE.equals(objectClass);
}
}),
BOOLEAN(new TSerializerElement() {
@Override
public Boolean read(String value) {
try {
return NumberUtils.getBooleanAbbreviation(value);
} catch (Throwable t) {
t.printStackTrace();
}
return false;
}
@Override
public String write(Object value) {
return Objects.toString(value);
}
@Override
public boolean matches(Class objectClass) {
return Boolean.class.equals(objectClass) || Boolean.TYPE.equals(objectClass);
}
}),
ITEM_STACK(new TSerializerElement() {
@Override
public ItemStack read(String value) {
return ConfigurationSerializer.deserializeCS(value, ItemStack.class);
}
@Override
public String write(Object value) {
return ConfigurationSerializer.serializeCS((ItemStack) value);
}
@Override
public boolean matches(Class objectClass) {
return ItemStack.class.equals(objectClass);
}
}),
LOCATION(new TSerializerElement() {
@Override
public Location read(String value) {
return ConfigurationSerializer.deserializeCS(value, Location.class);
}
@Override
public String write(Object value) {
return ConfigurationSerializer.serializeCS((Location) value);
}
@Override
public boolean matches(Class objectClass) {
return Location.class.equals(objectClass);
}
});
private TSerializerElement serializer;
TSerializerElementGeneral(TSerializerElement serializer) {
this.serializer = serializer;
}
public TSerializerElement getSerializer() {
return serializer;
}
}

View File

@ -0,0 +1,85 @@
package me.skymc.taboolib.common.serialize;
import com.google.common.collect.Lists;
import java.util.Collection;
import java.util.List;
/**
* @Author 坏黑
* @Since 2019-04-01 17:49
*/
public class TSerializerExample {
public static void main(String[] args) {
// 创建对象
SimpleData date = new SimpleData();
// 修改参数
date.number = 100;
// 序列化
String value = date.write();
// 打印
System.out.println(value);
// 创建新的对象
SimpleData dataCopy = new SimpleData();
// 反序列化
dataCopy.read(value);
// 打印
System.out.println(dataCopy);
}
/**
* 创建序列化类
* 实现 TSerializable 接口
*/
public static class SimpleData implements TSerializable {
/**
* 基本类型不需要手动进行序列化
* 包含: StringintshortlongdoublefloatbooleanItemStackLocation
*/
private String text;
private int number;
/**
* 特殊类型需要进行手动序列化
* 本工具提供了基本容器的序列化方法
*/
private List<Double> list = Lists.newArrayList();
/**
* 基本类型不会执行以下两个方法
* TSerializer 自动进行序列化和反序列化步骤
*/
@Override
public void read(String fieldName, String value) {
switch (fieldName) {
case "list": {
// List 类型可以直接通过 TSerializer 提供的预设方法进行反序列化
TSerializer.readCollection(list, value, TSerializerElementGeneral.DOUBLE);
break;
}
default:
}
}
@Override
public String write(String fieldName, Object value) {
switch (fieldName) {
case "list": {
// 序列化同理
return TSerializer.writeCollection((Collection) value, TSerializerElementGeneral.DOUBLE);
}
}
return null;
}
@Override
public String toString() {
return "SimpleData{" +
"text='" + text + '\'' +
", number=" + number +
", list=" + list +
'}';
}
}
}

View File

@ -1,44 +0,0 @@
package me.skymc.taboolib.damage;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
/**
* @author sky
*/
public class DamageUtils {
public static Player getAttackerInDamageEvent(EntityDamageByEntityEvent e) {
if (e.getDamager() instanceof Player) {
return (Player) e.getDamager();
} else if (e.getDamager() instanceof Projectile && ((Projectile) e.getDamager()).getShooter() instanceof Player) {
return (Player) ((Projectile) e.getDamager()).getShooter();
} else {
return null;
}
}
// *********************************
//
// Deprecated
//
// *********************************
@Deprecated
public static void damage(Player player, LivingEntity victim, double damage) {
dmg(player, victim, damage);
}
@Deprecated
public static void damage(Player player, Entity victim, double damage) {
dmg(player, (LivingEntity) victim, damage);
}
@Deprecated
public static void dmg(LivingEntity attacker, LivingEntity victim, double damage) {
attacker.damage(damage, victim);
}
}

View File

@ -1,114 +0,0 @@
package me.skymc.taboolib.fileutils;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
/**
* @author Unknown
*/
public class EncodeUtils {
/**
* 把指定文件或目录转换成指定的编码
*
* @param fileName 要转换的文件
* @param fromCharsetName 源文件的编码
* @param toCharsetName 要转换的编码
* @throws Exception
*/
public static void convert(String fileName, String fromCharsetName, String toCharsetName) throws Exception {
convert(new File(fileName), fromCharsetName, toCharsetName, null);
}
/**
* 把指定文件或目录转换成指定的编码
*
* @param file 要转换的文件或目录
* @param fromCharsetName 源文件的编码
* @param toCharsetName 要转换的编码
* @throws Exception
*/
public static void convert(File file, String fromCharsetName, String toCharsetName) throws Exception {
convert(file, fromCharsetName, toCharsetName, null);
}
/**
* 把指定文件或目录转换成指定的编码
*
* @param fromCharsetName 源文件的编码
* @param toCharsetName 转换的编码
* @param filter 文件名过滤器
* @throws Exception
*/
public static void convert(String fileName, String fromCharsetName, String toCharsetName, FilenameFilter filter) throws Exception {
convert(new File(fileName), fromCharsetName, toCharsetName, filter);
}
/**
* 把指定文件或目录转换成指定的编码
*
* @param file 要转换的文件或目录
* @param fromCharsetName 源文件的编码
* @param toCharsetName 要转换的编码
* @param filter 文件名过滤器
* @throws Exception
*/
public static void convert(File file, String fromCharsetName, String toCharsetName, FilenameFilter filter) throws Exception {
if (file.isDirectory()) {
File[] fileList;
if (filter == null) {
fileList = file.listFiles();
} else {
fileList = file.listFiles(filter);
}
for (File f : fileList) {
convert(f, fromCharsetName, toCharsetName, filter);
}
} else {
if (filter == null || filter.accept(file.getParentFile(), file.getName())) {
String fileContent = getFileContentFromCharset(file, fromCharsetName);
saveFile2Charset(file, toCharsetName, fileContent);
}
}
}
/**
* 以指定编码方式读取文件返回文件内容
*
* @param file 要转换的文件
* @param fromCharsetName 源文件的编码
* @return
* @throws Exception
*/
public static String getFileContentFromCharset(File file, String fromCharsetName) throws Exception {
if (!Charset.isSupported(fromCharsetName)) {
throw new UnsupportedCharsetException(fromCharsetName);
}
InputStream inputStream = new FileInputStream(file);
InputStreamReader reader = new InputStreamReader(inputStream, fromCharsetName);
char[] chs = new char[(int) file.length()];
reader.read(chs);
String str = new String(chs).trim();
reader.close();
return str;
}
/**
* 以指定编码方式写文本文件存在会覆盖
*
* @param file 要写入的文件
* @param toCharsetName 要转换的编码
* @param content 文件内容
* @throws Exception
*/
public static void saveFile2Charset(File file, String toCharsetName, String content) throws Exception {
if (!Charset.isSupported(toCharsetName)) {
throw new UnsupportedCharsetException(toCharsetName);
}
OutputStream outputStream = new FileOutputStream(file);
OutputStreamWriter outWrite = new OutputStreamWriter(outputStream, toCharsetName);
outWrite.write(content);
outWrite.close();
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,68 +1,94 @@
package me.skymc.taboolib.sound; package me.skymc.taboolib.sound;
import me.skymc.taboolib.TabooLib;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class SoundPack { public class SoundPack {
private Sound sound; private Sound sound;
private Float a; private float a;
private Float b; private float b;
private int delay;
/**
* ENTITY_VILLAGER_NO-0-0
*/
public SoundPack() { public SoundPack() {
this.sound = Sound.valueOf(SoundUtils.getModifiedSound("ENTITY_VILLAGER_NO")); this.sound = Sound.valueOf(SoundUtils.getModifiedSound("ENTITY_VILLAGER_NO"));
this.a = 1f; this.a = 1.0F;
this.b = 1f; this.b = 1.0F;
} }
public SoundPack(Sound sound, Float a, Float b) { public SoundPack(Sound sound, float a, float b) {
this(sound, a, b, 0);
}
public SoundPack(Sound sound, float a, float b, int delay) {
this.sound = sound; this.sound = sound;
this.a = a; this.a = a;
this.b = b; this.b = b;
this.delay = delay;
} }
public SoundPack(String s) { public SoundPack(String s) {
parse(s);
}
public void play(Player p) {
Bukkit.getScheduler().runTaskLater(TabooLib.instance(), () -> p.playSound(p.getLocation(), this.sound, this.a, this.b), delay);
}
public void play(Location l) {
Bukkit.getScheduler().runTaskLater(TabooLib.instance(), () -> l.getWorld().playSound(l, this.sound, this.a, this.b), delay);
}
public void parse(String s) {
try { try {
sound = Sound.valueOf(SoundUtils.getModifiedSound(s.split("-")[0])); String[] split = s.split("-");
a = Float.valueOf(s.split("-")[1]); this.sound = Sound.valueOf(SoundUtils.getModifiedSound(split[0]));
b = Float.valueOf(s.split("-")[2]); this.a = Float.parseFloat(split[1]);
} catch (Exception e) { this.b = Float.parseFloat(split[2]);
this.delay = split.length > 3 ? Integer.parseInt(split[3]) : 0;
} catch (Exception var3) {
this.sound = Sound.valueOf(SoundUtils.getModifiedSound("ENTITY_VILLAGER_NO")); this.sound = Sound.valueOf(SoundUtils.getModifiedSound("ENTITY_VILLAGER_NO"));
this.a = 1f; this.a = 1.0F;
this.b = 1f; this.b = 1.0F;
this.delay = 0;
} }
} }
// *********************************
//
// Getter and Setter
//
// *********************************
public Sound getSound() { public Sound getSound() {
return sound; return sound;
} }
public Float getA() { public float getA() {
return a; return a;
} }
public Float getB() { public float getB() {
return b; return b;
} }
public void play(Player p) { public int getDelay() {
p.playSound(p.getLocation(), sound, a, b); return delay;
}
public void parse(String s) {
try {
sound = Sound.valueOf(SoundUtils.getModifiedSound(s.split("-")[0]));
a = Float.valueOf(s.split("-")[1]);
b = Float.valueOf(s.split("-")[2]);
} catch (Exception e) {
this.sound = Sound.valueOf(SoundUtils.getModifiedSound("ENTITY_VILLAGER_NO"));
this.a = 1f;
this.b = 1f;
}
} }
@Override @Override
public String toString() { public String toString() {
return sound.name() + "-" + a + "-" + b; return "SoundPack{" +
"sound=" + sound +
", a=" + a +
", b=" + b +
", delay=" + delay +
'}';
} }
} }

View File

@ -1,126 +0,0 @@
package me.skymc.taboolib.string;
import com.google.common.base.Charsets;
import me.skymc.taboolib.message.MsgUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.List;
@Deprecated
public class Language {
private FileConfiguration conf = null;
private String langName;
private Plugin plugin;
public Language(Plugin plugin) {
this("zh_CN", plugin, false);
}
public Language(String name, Plugin plugin) {
this(name, plugin, false);
}
public Language(String name, Plugin plugin, boolean utf8) {
this.plugin = plugin;
this.langName = name;
File file = new File(getLanguageDir(), name + ".yml");
if (!file.exists()) {
plugin.saveResource("Language/" + name + ".yml", true);
}
if (utf8) {
reloadUTF8(this.langName);
} else {
reload(this.langName);
}
}
public FileConfiguration getConfiguration() {
return conf;
}
public void send(CommandSender sender, String key) {
sender.sendMessage(get(key));
}
public void send(Player player, String key) {
player.sendMessage(get(key));
}
public void sendList(CommandSender sender, String key) {
List<String> list = getList(key);
for (String msg : list) {
sender.sendMessage(msg);
}
}
public void sendList(Player player, String key) {
List<String> list = getList(key);
for (String msg : list) {
player.sendMessage(msg);
}
}
public String get(String key) {
if (conf == null || conf.getString(key) == null) {
return "§4[Language \"" + key + "\" Not Found]";
}
return conf.getString(key).replace("&", "§");
}
public List<String> getList(String key) {
if (conf == null || conf.getString(key) == null) {
return Collections.singletonList("§4[Language \"" + key + "\" Not Found]");
}
List<String> list = conf.getStringList(key);
for (int i = 0; i < list.size(); i++) {
list.set(i, list.get(i).replace("&", "§"));
}
return list;
}
public void reload() {
reload(langName);
}
public void reload(String name) {
File langFile = new File(getLanguageDir(), name + ".yml");
if (!langFile.exists()) {
MsgUtils.warn("语言文件 " + langName + " 不存在, 请更改配置文件");
return;
}
conf = YamlConfiguration.loadConfiguration(langFile);
}
public void reloadUTF8(String name) {
File langFile = new File(getLanguageDir(), name + ".yml");
if (!langFile.exists()) {
MsgUtils.warn("语言文件 " + langName + " 不存在, 请更改配置文件");
return;
}
try {
conf = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(langFile), Charsets.UTF_8));
} catch (FileNotFoundException e) {
conf = new YamlConfiguration();
}
}
private File getLanguageDir() {
File dir = new File(plugin.getDataFolder(), "Language");
if (!dir.exists()) {
dir.mkdirs();
}
return dir;
}
}

View File

@ -1,104 +0,0 @@
package me.skymc.taboolib.string;
import me.skymc.taboolib.message.MsgUtils;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@Deprecated
public class LanguagePack {
private File filedir;
private File file;
private FileConfiguration fileconf;
private String name;
private Plugin plugin;
private HashMap<String, List<String>> lang = new HashMap<>();
public LanguagePack(String name, Plugin plugin) {
this.plugin = plugin;
this.name = name;
filedir = new File(plugin.getDataFolder(), "Languages");
if (!filedir.exists()) {
filedir.mkdir();
}
file = new File(filedir, name + ".yml");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
MsgUtils.Console("&8[" + plugin.getName() + "]&4 载入语言文件出错");
}
}
fileconf = YamlConfiguration.loadConfiguration(file);
reloadLanguage();
MsgUtils.Console("&8[" + plugin.getName() + "]&7 载入语言文件&f: " + name + ".yml");
}
public File getLanguageFile() {
return file;
}
public File getLanguageDir() {
return filedir;
}
public FileConfiguration getLanguageConfiguration() {
return fileconf;
}
public HashMap<String, List<String>> getLanguage() {
return lang;
}
public String getLanguageName() {
return name;
}
public Plugin getLanguagePlugin() {
return plugin;
}
public void reloadLanguage(String name) {
file = new File(filedir, name + ".yml");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
fileconf = YamlConfiguration.loadConfiguration(file);
reloadLanguage();
}
public void reloadLanguage() {
lang.clear();
for (String key : fileconf.getConfigurationSection("").getKeys(false)) {
List<String> _lang = new ArrayList<>();
fileconf.getStringList(key).forEach(x -> _lang.add(x.replace("&", "§")
.replace("$plugin_name", plugin.getDescription().getName())
.replace("$plugin_authors", plugin.getDescription().getAuthors().toString())
.replace("$plugin_version", plugin.getDescription().getVersion())));
lang.put(key, _lang);
}
}
}

View File

@ -1,33 +0,0 @@
package me.skymc.taboolib.string;
import me.skymc.taboolib.message.MsgUtils;
import org.bukkit.plugin.Plugin;
import java.io.File;
import java.util.Collections;
import java.util.List;
@Deprecated
public class LanguageUtils {
public static String a(LanguagePack l, String key) {
if (l.getLanguage().containsKey(key)) {
return l.getLanguage().get(key).get(0);
}
return "";
}
public static List<String> b(LanguagePack l, String key) {
if (l.getLanguage().containsKey(key)) {
return l.getLanguage().get(key);
}
return Collections.singletonList("");
}
public static void saveLanguageFile(String name, Plugin plugin) {
if (!new File(new File(plugin.getDataFolder(), "Languages"), name + ".yml").exists()) {
plugin.saveResource("Languages/" + name + ".yml", true);
MsgUtils.Console("&8[" + plugin.getName() + "]&7 生成语言文件&f: " + name + ".yml");
}
}
}

View File

@ -1,23 +0,0 @@
package me.skymc.taboolib.string;
@Deprecated
public class PatternUtils {
@Deprecated
public static String doubleNumber = "((\\-|\\+)?\\d+(\\.\\d+)?)";
@Deprecated
public static String doubleNumber2 = "(\\d+(\\.\\d+)?)";
public static String doubleNumber3 = "((?:\\-|\\+)?\\d+(?:\\.\\d+)?)";
public static String consolidateStrings(final String[] args, final int start) {
StringBuilder ret = new StringBuilder(args[start]);
if (args.length > start + 1) {
for (int i = start + 1; i < args.length; ++i) {
ret.append(" ").append(args[i]);
}
}
return ret.toString();
}
}

View File

@ -1,102 +0,0 @@
package me.skymc.taboolib.string.language2;
import com.ilummc.tlib.resources.TLocale;
import me.clip.placeholderapi.PlaceholderAPI;
import me.skymc.taboolib.fileutils.ConfigUtils;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.io.File;
/**
* @author sky
* @since 2018年2月13日 下午2:37:07
*/
public class Language2 {
private FileConfiguration configuration;
private File languageFile;
private File languageFolder;
private Plugin plugin;
private String languageName;
public Language2(Plugin plugin) {
this("zh_CN", plugin);
}
public Language2(String languageName, Plugin plugin) {
this.languageName = languageName;
this.plugin = plugin;
reload(languageName);
}
public FileConfiguration getConfiguration() {
return configuration;
}
public File getLanguageFile() {
return languageFile;
}
public File getLanguageFolder() {
return languageFolder;
}
public Plugin getPlugin() {
return plugin;
}
public String getLanguageName() {
return languageName;
}
public Language2Value get(String key) {
return new Language2Value(this, key);
}
public Language2Value get(String key, String... placeholder) {
Language2Value value = new Language2Value(this, key);
for (int i = 0; i < placeholder.length; i++) {
value.addPlaceholder("$" + i, placeholder[i]);
}
return value;
}
public void reload() {
reload(this.languageName);
}
public void reload(String languageName) {
createFolder(plugin);
languageName = formatName(languageName);
languageFile = new File(languageFolder, languageName);
if (!languageFile.exists()) {
if (plugin.getResource("Language2/" + languageName) == null) {
TLocale.Logger.error("LANGUAGE2.FAIL-NOTFOUND-FILE", languageName);
} else {
plugin.saveResource("Language2/" + languageName, true);
}
}
configuration = ConfigUtils.load(plugin, languageFile);
}
public String setPlaceholderAPI(Player player, String string) {
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null && player != null) {
return PlaceholderAPI.setPlaceholders(player, string);
}
return string;
}
private String formatName(String name) {
return name.contains(".yml") ? name : name + ".yml";
}
private void createFolder(Plugin plugin) {
languageFolder = new File(plugin.getDataFolder(), "Language2");
if (!languageFolder.exists()) {
languageFolder.mkdir();
}
}
}

View File

@ -1,152 +0,0 @@
package me.skymc.taboolib.string.language2;
import me.skymc.taboolib.string.language2.value.*;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/**
* @author sky
* @since 2018-03-08 22:45:56
*/
public class Language2Format implements Language2Line {
private Language2Value language2Value;
private List<Language2Line> language2Lines = new ArrayList<>();
public Language2Format(Player player, Language2Value value) {
language2Value = value;
// 语言类型
Language2Type type = Language2Type.TEXT;
// 递交数据
List<String> values = new LinkedList<>();
// 遍历内容
for (String line : value.getLanguageValue()) {
// 文本类型
if (line.contains("[text]")) {
// 递交数据
parseValue(player, values, type);
// 更改类型
type = Language2Type.TEXT;
}
// 大标题
else if (line.contains("[title]")) {
// 递交数据
parseValue(player, values, type);
// 更改类型
type = Language2Type.TITLE;
}
// 小标题
else if (line.contains("[action]")) {
// 递交数据
parseValue(player, values, type);
// 更改类型
type = Language2Type.ACTION;
}
// JSON
else if (line.contains("[json]")) {
// 递交数据
parseValue(player, values, type);
// 更改类型
type = Language2Type.JSON;
}
// JSON2
else if (line.contains("[json2]")) {
// 递交数据
parseValue(player, values, type);
// 更改类型
type = Language2Type.JSON2;
}
// 音效
else if (line.contains("[sound]")) {
// 递交数据
parseValue(player, values, type);
// 更改类型
type = Language2Type.SOUND;
}
// 书本
else if (line.contains("[book]")) {
// 递交数据
parseValue(player, values, type);
// 更改类型
type = Language2Type.BOOK;
} else if (line.contains("[return]")) {
// 递交数据
parseValue(player, values, type);
}
// 默认
else {
// 追加内容
values.add(line);
}
}
}
public Language2Value getLanguage2Value() {
return language2Value;
}
public List<Language2Line> getLanguage2Lines() {
return language2Lines;
}
/**
* 识别内容
*
* @param player 玩家
* @param list 数据
* @param type 类型
*/
private void parseValue(Player player, List<String> list, Language2Type type) {
if (list.size() == 0) {
return;
}
// 变量转换
List<String> listPlaceholder = language2Value.setPlaceholder(list, player);
// 大标题
switch (type) {
case TITLE:
language2Lines.add(new Language2Title(this, listPlaceholder));
break;
// 小标题
case ACTION:
language2Lines.add(new Language2Action(this, listPlaceholder));
break;
// JSON
case JSON:
language2Lines.add(new Language2Json(this, listPlaceholder, player));
break;
// JSON2
case JSON2:
language2Lines.add(new Language2Json2(this, listPlaceholder, player));
break;
// 音效
case SOUND:
language2Lines.add(new Language2Sound(this, listPlaceholder));
break;
// 书本
case BOOK:
language2Lines.add(new Language2Book(this, listPlaceholder, player));
break;
default:
language2Lines.add(new Language2Text(this, listPlaceholder));
break;
}
// 清理数据
list.clear();
listPlaceholder.clear();
}
@Override
public void send(Player player) {
language2Lines.forEach(line -> line.send(player));
}
@Override
public void console() {
language2Lines.forEach(Language2Line::console);
}
}

View File

@ -1,15 +0,0 @@
package me.skymc.taboolib.string.language2;
import org.bukkit.entity.Player;
/**
* @author sky
* @since 2018-03-08 23:36:22
*/
public interface Language2Line {
void send(Player player);
void console();
}

View File

@ -1,43 +0,0 @@
package me.skymc.taboolib.string.language2;
/**
* @author sky
* @since 2018年2月13日 下午3:14:00
*/
public enum Language2Type {
/**
* 一般文本
*/
TEXT,
/**
* JSON 文本
*/
JSON,
/**
* JSON2 文本
*/
JSON2,
/**
* 大标题
*/
TITLE,
/**
* 小标题
*/
ACTION,
/**
* 音效
*/
SOUND,
/**
* 书本
*/
BOOK
}

View File

@ -1,216 +0,0 @@
package me.skymc.taboolib.string.language2;
import me.skymc.taboolib.string.language2.value.Language2Text;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.IntStream;
/**
* @author sky
* @since 2018年2月13日 下午3:05:15
*/
public class Language2Value {
private Language2 language;
private String languageKey;
private List<String> languageValue;
private LinkedHashMap<String, String> placeholder = new LinkedHashMap<>();
private boolean enablePlaceholderAPI = false;
/**
* 构造方法
*/
public Language2Value(Language2 language, String languageKey) {
// 如果语言文件不存在
if (language == null || languageKey == null) {
languageValue = Arrays.asList(ChatColor.DARK_RED + "[<ERROR-0>]", "[return]");
return;
}
// 如果语言文本不存在
if (!language.getConfiguration().contains(languageKey)) {
languageValue = Arrays.asList(ChatColor.DARK_RED + "[<ERROR-1: " + languageKey + ">]", "[return]");
return;
}
// 如果不是集合类型
if (language.getConfiguration().get(languageKey) instanceof List) {
// 设置文本
languageValue = asColored(language.getConfiguration().getStringList(languageKey));
// 追加结尾
languageValue.add("[return]");
// 是否启用PAPI
if (languageValue.get(0).contains("[papi]")) {
enablePlaceholderAPI = true;
}
} else {
// 设置文本
languageValue = Arrays.asList(ChatColor.translateAlternateColorCodes('&', language.getConfiguration().getString(languageKey)), "[return]");
}
// 初始化变量
this.language = language;
this.languageKey = languageKey;
}
public Language2 getLanguage() {
return language;
}
public String getLanguageKey() {
return languageKey;
}
public List<String> getLanguageValue() {
return languageValue;
}
public LinkedHashMap<String, String> getPlaceholder() {
return placeholder;
}
public boolean isEnablePlaceholderAPI() {
return enablePlaceholderAPI;
}
/**
* 向玩家发送信息
*
* @param player
*/
public void send(Player player) {
new Language2Format(player, this).send(player);
}
/**
* 向玩家发送信息
*
* @param players 玩家
*/
public void send(List<Player> players) {
players.forEach(this::send);
}
/**
* 向指令发送者发送信息
*
* @param sender
*/
public void send(CommandSender sender) {
if (sender instanceof Player) {
send((Player) sender);
} else {
console();
}
}
/**
* 全服公告
*/
public void broadcast() {
send(new ArrayList<>(Bukkit.getOnlinePlayers()));
}
/**
* 发送到后台
*/
public void console() {
new Language2Format(null, this).console();
}
/**
* 获取文本
*
* @return
*/
public String asString() {
Language2Format format = new Language2Format(null, this);
if (format.getLanguage2Lines().get(0) instanceof Language2Text) {
Language2Text text = (Language2Text) format.getLanguage2Lines().get(0);
return setPlaceholder(text.getText().get(0), null);
} else {
return languageValue.size() == 0 ? ChatColor.DARK_RED + "[<ERROR-1>]" : setPlaceholder(languageValue.get(0), null);
}
}
/**
* 获取文本集合
*
* @return
*/
public List<String> asStringList() {
Language2Format format = new Language2Format(null, this);
if (format.getLanguage2Lines().get(0) instanceof Language2Text) {
Language2Text text = (Language2Text) format.getLanguage2Lines().get(0);
return setPlaceholder(text.getText(), null);
} else {
return Collections.singletonList(languageValue.size() == 0 ? ChatColor.DARK_RED + "[<ERROR-1>]" : setPlaceholder(languageValue.get(0), null));
}
}
/**
* 变量替换
*
* @param value 替换文本
* @param player 检测玩家
* @return String
*/
public String setPlaceholder(String value, Player player) {
for (Entry<String, String> entry : placeholder.entrySet()) {
value = value.replace(entry.getKey(), entry.getValue());
}
return isEnablePlaceholderAPI() ? this.language.setPlaceholderAPI(player, value) : value;
}
/**
* 变量替换
*
* @param list 替换集合
* @param player 检测玩家
* @return {@link List}
*/
public List<String> setPlaceholder(List<String> list, Player player) {
List<String> _list = new ArrayList<>(list);
for (int i = 0; i < _list.size(); i++) {
_list.set(i, setPlaceholder(_list.get(i), player));
}
return _list;
}
/**
* 变量替换构造
*
* @param key
* @param value
* @return {@link Language2Value}
*/
public Language2Value addPlaceholder(String key, String value) {
this.placeholder.put(key, value);
return this;
}
/**
* 替换颜色
*
* @param list
* @return
*/
public List<String> asColored(List<String> list) {
IntStream.range(0, list.size()).forEach(i -> list.set(i, ChatColor.translateAlternateColorCodes('&', list.get(i))));
return list;
}
@Override
public String toString() {
return asString();
}
}

View File

@ -1,100 +0,0 @@
package me.skymc.taboolib.string.language2.value;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.display.ActionUtils;
import me.skymc.taboolib.other.NumberUtils;
import me.skymc.taboolib.string.language2.Language2Format;
import me.skymc.taboolib.string.language2.Language2Line;
import me.skymc.taboolib.string.language2.Language2Value;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.List;
/**
* @author sky
* @since 2018年2月13日 下午3:58:07
*/
public class Language2Action implements Language2Line {
private static final String KEY_TEXT = " text: ";
private static final String KEY_STAY = " repeat: ";
private String text = "";
private int repeat = 1;
private Language2Value value;
public Language2Action(Language2Format format, List<String> list) {
// 变量初始化
this.value = format.getLanguage2Value();
// 遍历文本
for (String message : list) {
try {
// 动作栏提示
if (message.startsWith(KEY_TEXT)) {
text = message.substring(KEY_TEXT.length());
}
// 持续时间
if (message.startsWith(KEY_STAY)) {
repeat = NumberUtils.getInteger(message.substring(KEY_STAY.length()));
}
} catch (Exception e) {
// 识别异常
text = ChatColor.DARK_RED + "[<ERROR-11: " + value.getLanguageKey() + ">]";
}
}
// 检查重复次数
if (repeat < 0) {
repeat = 1;
text = ChatColor.DARK_RED + "[<ERROR-12: " + value.getLanguageKey() + ">]";
}
}
public String getText() {
return text;
}
public int getRepeat() {
return repeat;
}
public Language2Value getValue() {
return value;
}
/**
* 发送给玩家
*
* @param player 玩家
*/
@Override
public void send(Player player) {
// 检查版本
if (TabooLib.getVerint() < 10800) {
player.sendMessage(ChatColor.DARK_RED + "[<ERROR-30: " + value.getLanguageKey() + ">]");
} else {
new BukkitRunnable() {
int times = 0;
@Override
public void run() {
ActionUtils.send(player, text);
if ((times += 1) >= repeat) {
cancel();
}
}
}.runTaskTimer(Main.getInst(), 0, 20);
}
}
@Override
public void console() {
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED + "[<ERROR-40: " + value.getLanguageKey() + ">]");
}
}

View File

@ -1,242 +0,0 @@
package me.skymc.taboolib.string.language2.value;
import com.ilummc.tlib.bungee.api.chat.BaseComponent;
import com.ilummc.tlib.bungee.api.chat.ClickEvent;
import com.ilummc.tlib.bungee.api.chat.HoverEvent;
import com.ilummc.tlib.bungee.api.chat.TextComponent;
import me.skymc.taboolib.bookformatter.BookFormatter;
import me.skymc.taboolib.bookformatter.action.ClickAction;
import me.skymc.taboolib.bookformatter.action.HoverAction;
import me.skymc.taboolib.bookformatter.builder.BookBuilder;
import me.skymc.taboolib.bookformatter.builder.PageBuilder;
import me.skymc.taboolib.bookformatter.builder.TextBuilder;
import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.other.NumberUtils;
import me.skymc.taboolib.string.VariableFormatter;
import me.skymc.taboolib.string.language2.Language2Format;
import me.skymc.taboolib.string.language2.Language2Line;
import me.skymc.taboolib.string.language2.Language2Value;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.regex.Pattern;
/**
* @author sky
* @since 2018-03-10 15:55:28
*/
public class Language2Book implements Language2Line {
private static final String KEY_TEXT = " text: ";
private static final String KEY_COMMAND = " command: ";
private static final String KEY_SUGGEST = " suggest: ";
private static final String KEY_URL = " url: ";
private static final String KEY_PAGE = " page: ";
private static final String KEY_SHOWTEXT = " showtext: ";
private static final String KEY_SHOWITEM = " showitem: ";
private static final String KEY_OPTION = "@option:";
private static final Pattern pattern = Pattern.compile("<@(\\S+)>");
private Player player;
private Language2Value value;
private HashMap<String, TextBuilder> options = new HashMap<>();
private BookBuilder book;
public Language2Book(Language2Format format, List<String> list, Player player) {
// 变量
this.player = player;
this.value = format.getLanguage2Value();
this.book = BookFormatter.writtenBook();
// 设置
formatOptions(list);
// 内容
PageBuilder page = new PageBuilder();
// 遍历内容
for (String line : list) {
// 翻页
if (line.equals("[page]")) {
book.addPages(page.build());
page = new PageBuilder();
}
// 设置
else if (line.startsWith("@option")) {
break;
} else {
for (VariableFormatter.Variable variable : new VariableFormatter(line, pattern).find().getVariableList()) {
if (variable.isVariable()) {
String node = variable.getText().substring(1);
if (!options.containsKey(node)) {
page.add("§4[<ERROR-50: " + format.getLanguage2Value().getLanguageKey() + ">]");
} else {
TextBuilder builder = options.get(node);
BaseComponent component = new TextComponent(builder.getText());
if (builder.getHover() != null) {
component.setHoverEvent(new HoverEvent(builder.getHover().action(), builder.getHover().value()));
}
if (builder.getClick() != null) {
component.setClickEvent(new ClickEvent(builder.getClick().action(), builder.getClick().value()));
}
page.add(component);
}
} else {
page.add(variable.getText());
}
}
page.newLine();
}
}
// 结尾
book.addPages(page.build());
}
@Override
public void send(Player player) {
BookFormatter.forceOpen(player, book.build());
}
@Override
public void console() {
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED + "[<ERROR-40: " + value.getLanguageKey() + ">]");
}
// *********************************
//
// Getter and Setter
//
// *********************************
public static Pattern getPattern() {
return pattern;
}
public Player getPlayer() {
return player;
}
public Language2Value getValue() {
return value;
}
public HashMap<String, TextBuilder> getOptions() {
return options;
}
public BookBuilder getBook() {
return book;
}
// *********************************
//
// Private Methods
//
// *********************************
private List<List<String>> getBookPages(List<String> source) {
List<List<String>> list = new ArrayList<>();
for (String line : removeOption(source)) {
if (line.equalsIgnoreCase("[page]")) {
list.add(new ArrayList<>());
} else {
getLatestList(list).add(line);
}
}
return list;
}
public List<String> getLatestList(List<List<String>> list) {
if (list.size() == 0) {
List<String> newList = new ArrayList<>();
list.add(newList);
return newList;
} else {
return list.get(list.size() - 1);
}
}
public List<String> removeOption(List<String> source) {
List<String> list = new ArrayList<>();
for (String line : source) {
if (!line.contains("@option")) {
list.add(line);
} else {
return list;
}
}
return list;
}
private void formatOptions(List<String> list) {
// 获取书本设置
HashMap<String, List<String>> _options = getOptions(list);
for (Entry<String, List<String>> entry : _options.entrySet()) {
TextBuilder builder = new TextBuilder();
// 遍历内容
for (String _option : entry.getValue()) {
if (_option.startsWith(KEY_TEXT)) {
builder.text(_option.substring(KEY_TEXT.length()));
} else if (_option.startsWith(KEY_COMMAND)) {
builder.onClick(ClickAction.runCommand(_option.substring(KEY_COMMAND.length())));
} else if (_option.startsWith(KEY_SUGGEST)) {
builder.onClick(ClickAction.suggestCommand(_option.substring(KEY_SUGGEST.length())));
} else if (_option.startsWith(KEY_URL)) {
try {
builder.onClick(ClickAction.openUrl(_option.substring(KEY_URL.length())));
} catch (Exception e) {
builder.text("§4[<ERROR-52: " + value.getLanguageKey() + ">]");
}
} else if (_option.startsWith(KEY_PAGE)) {
builder.onClick(ClickAction.changePage(NumberUtils.getInteger(_option.substring(KEY_PAGE.length()))));
} else if (_option.startsWith(KEY_SHOWTEXT)) {
builder.onHover(HoverAction.showText(_option.substring(KEY_SHOWTEXT.length())));
} else if (_option.startsWith(KEY_SHOWITEM)) {
ItemStack item = ItemUtils.getCacheItem(_option.substring(KEY_SHOWITEM.length()));
if (item == null) {
item = new ItemStack(Material.STONE);
}
builder.onHover(HoverAction.showItem(item));
}
}
options.put(entry.getKey(), builder);
}
}
private HashMap<String, List<String>> getOptions(List<String> list) {
HashMap<String, List<String>> options_source = new HashMap<>();
List<String> option = new ArrayList<>();
// 遍历
String optionName = null;
boolean start = false;
// 遍历所有代码
for (String line : list) {
if (line.startsWith(KEY_OPTION)) {
// 如果已经开始检测
if (start) {
// 返回源码
options_source.put(optionName, new ArrayList<>(option));
// 清除源码
option.clear();
}
// 标签
start = true;
// 当前设置名称
optionName = line.substring(KEY_OPTION.length());
} else if (start) {
option.add(line);
}
}
// 返回最后设置
options_source.put(optionName, option);
return options_source;
}
}

View File

@ -1,174 +0,0 @@
package me.skymc.taboolib.string.language2.value;
import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.jsonformatter.JSONFormatter;
import me.skymc.taboolib.jsonformatter.click.ClickEvent;
import me.skymc.taboolib.jsonformatter.click.OpenUrlEvent;
import me.skymc.taboolib.jsonformatter.click.RunCommandEvent;
import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
import me.skymc.taboolib.jsonformatter.hover.HoverEvent;
import me.skymc.taboolib.jsonformatter.hover.ShowItemEvent;
import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent;
import me.skymc.taboolib.string.language2.Language2Format;
import me.skymc.taboolib.string.language2.Language2Line;
import me.skymc.taboolib.string.language2.Language2Value;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.List;
/**
* @author sky
* @since 2018年2月13日 下午4:11:33
*/
public class Language2Json implements Language2Line {
private static final String KEY_TEXT = " text: ";
private static final String KEY_COMMAND = " command: ";
private static final String KEY_SUGGEST = " suggest: ";
private static final String KEY_URL = " url: ";
private static final String KEY_ITEM = " item: ";
private Player player;
private Language2Value value;
private JSONFormatter json = new JSONFormatter();
private StringBuffer text = new StringBuffer();
public Language2Json(Language2Format format, List<String> list, Player player) {
// 首次检测
boolean isFirst = true;
boolean isBreak = false;
// 变量初始化
this.value = format.getLanguage2Value();
this.player = player;
// 动作初始化
ClickEvent clickEvent = null;
HoverEvent hoverEvent = null;
// 文本初始化
String current = ChatColor.DARK_RED + "[<ERROR-20: " + value.getLanguageKey() + ">]";
// 遍历文本
for (String message : list) {
try {
// 如果是显示文本
if (message.startsWith(KEY_TEXT)) {
hoverEvent = new ShowTextEvent(message.replace("||", "\n").substring(KEY_TEXT.length()));
}
// 显示物品
else if (message.startsWith(KEY_ITEM)) {
ItemStack item = ItemUtils.getCacheItem(message.substring(KEY_ITEM.length()));
if (item == null) {
item = new ItemStack(Material.STONE);
}
hoverEvent = new ShowItemEvent(item);
}
// 执行指令
else if (message.startsWith(KEY_COMMAND)) {
clickEvent = new RunCommandEvent(message.substring(KEY_COMMAND.length()));
}
// 打印指令
else if (message.startsWith(KEY_SUGGEST)) {
clickEvent = new SuggestCommandEvent(message.substring(KEY_SUGGEST.length()));
}
// 打开连接
else if (message.startsWith(KEY_URL)) {
clickEvent = new OpenUrlEvent(message.substring(KEY_URL.length()));
}
// 换行
else if ("[break]".equals(message)) {
append(current, clickEvent, hoverEvent);
// 删除动作
clickEvent = null;
hoverEvent = null;
// 换行
json.newLine();
// 标记
isBreak = true;
}
// 新内容
else {
if (!isFirst && !isBreak) {
append(current, clickEvent, hoverEvent);
// 删除动作
clickEvent = null;
hoverEvent = null;
}
// 更新
current = message;
// 标记
isFirst = false;
isBreak = false;
}
} catch (Exception e) {
// 识别异常
json.append(ChatColor.DARK_RED + "[<ERROR-21: " + value.getLanguageKey() + ">]");
}
}
// 追加
append(current, clickEvent, hoverEvent);
}
public Player getPlayer() {
return player;
}
public Language2Value getValue() {
return value;
}
public JSONFormatter getJson() {
return json;
}
public StringBuffer getText() {
return text;
}
/**
* 发送给玩家
*
* @param player 玩家
*/
@Override
public void send(Player player) {
json.send(player);
}
@Override
public void console() {
Bukkit.getConsoleSender().sendMessage(text.toString());
}
/**
* 追加 JSON 内容
*
* @param current 文本
* @param hoverEvent 显示动作
*/
private void append(String current, ClickEvent clickEvent, HoverEvent hoverEvent) {
if (clickEvent == null && hoverEvent == null) {
// 纯文本
json.append(current);
} else if (clickEvent != null && hoverEvent == null) {
// 纯点击
json.appendClick(current, clickEvent);
} else if (clickEvent == null && hoverEvent != null) {
// 纯显示
json.appendHover(current, hoverEvent);
} else {
// 全部
json.appendHoverClick(current, hoverEvent, clickEvent);
}
// 追加显示文本
text.append(current);
}
}

View File

@ -1,214 +0,0 @@
package me.skymc.taboolib.string.language2.value;
import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.jsonformatter.JSONFormatter;
import me.skymc.taboolib.jsonformatter.click.ClickEvent;
import me.skymc.taboolib.jsonformatter.click.OpenUrlEvent;
import me.skymc.taboolib.jsonformatter.click.RunCommandEvent;
import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
import me.skymc.taboolib.jsonformatter.hover.HoverEvent;
import me.skymc.taboolib.jsonformatter.hover.ShowItemEvent;
import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent;
import me.skymc.taboolib.string.language2.Language2Format;
import me.skymc.taboolib.string.language2.Language2Line;
import me.skymc.taboolib.string.language2.Language2Value;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author sky
* @since 2018-03-10 15:55:28
*/
public class Language2Json2 implements Language2Line {
private static final String KEY_TEXT = " text: ";
private static final String KEY_COMMAND = " command: ";
private static final String KEY_SUGGEST = " suggest: ";
private static final String KEY_URL = " url: ";
private static final String KEY_SHOWTEXT = " showtext: ";
private static final String KEY_SHOWITEM = " showitem: ";
private static final String KEY_OPTION = "@option:";
private static final Pattern pattern = Pattern.compile("<@(\\S+)>");
private Player player;
private Language2Value value;
private HashMap<String, JSONFormatter> options = new HashMap<>();
private JSONFormatter json = new JSONFormatter();
public Language2Json2(Language2Format format, List<String> list, Player player) {
// 变量
this.player = player;
this.value = format.getLanguage2Value();
// 获取书本设置
formatOptions(list);
// 遍历内容
int lineNumber = 0;
int lineNumberEnd = getLineNumberEnd(list);
for (String line : list) {
if (line.startsWith("@option")) {
break;
} else {
Matcher matcher = pattern.matcher(line);
boolean find = false;
while (matcher.find()) {
find = true;
String optionName = matcher.group(1);
String optionFullName = "<@" + matcher.group(1) + ">";
// 判断设置是否存在
if (!options.containsKey(optionName)) {
json.append("§4[<ERROR-60: " + format.getLanguage2Value().getLanguageKey() + ">]");
} else {
String[] line_split = line.split(optionFullName);
try {
// 单独一行
if (line_split.length == 0) {
json.append(options.get(optionName));
} else {
// 前段
json.append(line_split[0]);
// 变量
json.append(options.get(optionName));
// 后段
if (line_split.length >= 2) {
// 获取文本
StringBuilder sb = new StringBuilder();
for (int i = 1; i < line_split.length; i++) {
sb.append(line_split[i]).append(optionFullName);
}
// 更改文本
line = sb.substring(0, sb.length() - optionFullName.length());
// 如果后段还有变量
if (!pattern.matcher(line).find()) {
json.append(line_split[1]);
}
}
}
} catch (Exception e) {
json.append("§4[<ERROR-61: " + format.getLanguage2Value().getLanguageKey() + ">]");
}
}
}
if (!find) {
json.append(line);
}
if (++lineNumber < lineNumberEnd) {
json.newLine();
}
}
}
}
public Player getPlayer() {
return player;
}
public Language2Value getValue() {
return value;
}
public HashMap<String, JSONFormatter> getOptions() {
return options;
}
public JSONFormatter getJson() {
return json;
}
private int getLineNumberEnd(List<String> list) {
int line = list.size();
for (int i = 0; i < list.size(); i++) {
if (list.get(i).startsWith("@option")) {
return i;
}
}
return line;
}
private void formatOptions(List<String> list) {
HashMap<String, List<String>> _options = getOptions(list);
for (Entry<String, List<String>> entry : _options.entrySet()) {
JSONFormatter jsonFormatter = new JSONFormatter();
String current = ChatColor.DARK_RED + "[<ERROR-20: " + value.getLanguageKey() + ">]";
ClickEvent clickEvent = null;
HoverEvent hoverEvent = null;
for (String _option : entry.getValue()) {
if (_option.startsWith(KEY_TEXT)) {
current = _option.substring(KEY_TEXT.length());
} else if (_option.startsWith(KEY_COMMAND)) {
clickEvent = new RunCommandEvent(_option.substring(KEY_COMMAND.length()));
} else if (_option.startsWith(KEY_SUGGEST)) {
clickEvent = new SuggestCommandEvent(_option.substring(KEY_SUGGEST.length()));
} else if (_option.startsWith(KEY_URL)) {
clickEvent = new OpenUrlEvent(_option.substring(KEY_URL.length()));
} else if (_option.startsWith(KEY_SHOWTEXT)) {
hoverEvent = new ShowTextEvent(_option.replace("||", "\n").substring(KEY_SHOWTEXT.length()));
} else if (_option.startsWith(KEY_SHOWITEM)) {
ItemStack item = ItemUtils.getCacheItem(_option.substring(KEY_SHOWITEM.length()));
if (item == null) {
item = new ItemStack(Material.STONE);
}
hoverEvent = new ShowItemEvent(item);
}
}
append(jsonFormatter, current, clickEvent, hoverEvent);
options.put(entry.getKey(), jsonFormatter);
}
}
private void append(JSONFormatter json, String current, ClickEvent clickEvent, HoverEvent hoverEvent) {
if (clickEvent == null && hoverEvent == null) {
json.append(current);
} else if (clickEvent != null && hoverEvent == null) {
json.appendClick(current, clickEvent);
} else if (clickEvent == null) {
json.appendHover(current, hoverEvent);
} else {
json.appendHoverClick(current, hoverEvent, clickEvent);
}
}
private HashMap<String, List<String>> getOptions(List<String> list) {
HashMap<String, List<String>> options_source = new HashMap<>();
List<String> option = new ArrayList<>();
String optionName = null;
boolean start = false;
for (String line : list) {
if (line.startsWith(KEY_OPTION)) {
if (start) {
options_source.put(optionName, new ArrayList<>(option));
option.clear();
}
start = true;
optionName = line.substring(KEY_OPTION.length());
} else if (start) {
option.add(line);
}
}
options_source.put(optionName, option);
return options_source;
}
@Override
public void send(Player player) {
json.send(player);
}
@Override
public void console() {
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED + "[<ERROR-40: " + value.getLanguageKey() + ">]");
}
}

View File

@ -1,46 +0,0 @@
package me.skymc.taboolib.string.language2.value;
import me.skymc.taboolib.sound.SoundPack;
import me.skymc.taboolib.string.language2.Language2Format;
import me.skymc.taboolib.string.language2.Language2Line;
import me.skymc.taboolib.string.language2.Language2Value;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
/**
* @author sky
* @since 2018-03-08 22:43:27
*/
public class Language2Sound implements Language2Line {
private List<SoundPack> sounds = new ArrayList<>();
private Language2Value value;
public Language2Sound(Language2Format format, List<String> list) {
this.value = format.getLanguage2Value();
list.forEach(line -> sounds.add(new SoundPack(line)));
}
public List<SoundPack> getSounds() {
return sounds;
}
public Language2Value getValue() {
return value;
}
@Override
public void send(Player player) {
sounds.forEach(sound -> sound.play(player));
}
@Override
public void console() {
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED + "[<ERROR-40: " + value.getLanguageKey() + ">]");
}
}

View File

@ -1,44 +0,0 @@
package me.skymc.taboolib.string.language2.value;
import me.skymc.taboolib.string.language2.Language2Format;
import me.skymc.taboolib.string.language2.Language2Line;
import me.skymc.taboolib.string.language2.Language2Value;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
/**
* @author sky
* @since 2018-03-08 22:43:27
*/
public class Language2Text implements Language2Line {
private List<String> text = new ArrayList<>();
private Language2Value value;
public List<String> getText() {
return text;
}
public Language2Value getValue() {
return value;
}
public Language2Text(Language2Format format, List<String> list) {
this.value = format.getLanguage2Value();
text.addAll(list);
}
@Override
public void send(Player player) {
text.forEach(player::sendMessage);
}
@Override
public void console() {
text.forEach(line -> Bukkit.getConsoleSender().sendMessage(line));
}
}

View File

@ -1,103 +0,0 @@
package me.skymc.taboolib.string.language2.value;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.display.TitleUtils;
import me.skymc.taboolib.string.language2.Language2Format;
import me.skymc.taboolib.string.language2.Language2Line;
import me.skymc.taboolib.string.language2.Language2Value;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.util.List;
/**
* @author sky
* @since 2018年2月13日 下午3:58:07
*/
public class Language2Title implements Language2Line {
private static final String KEY_TITLE = " title: ";
private static final String KEY_SUBTITLE = " subtitle: ";
private static final String KEY_STAYRULE = " stay: ";
private String title = "";
private String subtitle = "";
private int fade1 = 0;
private int fade2 = 0;
private int stay = 20;
private Language2Value value;
public Language2Title(Language2Format format, List<String> list) {
// 变量初始化
this.value = format.getLanguage2Value();
// 遍历文本
for (String message : list) {
try {
// 大标题
if (message.startsWith(KEY_TITLE)) {
title = message.substring(KEY_TITLE.length());
}
// 小标题
else if (message.startsWith(KEY_SUBTITLE)) {
subtitle = message.substring(KEY_SUBTITLE.length());
}
// 持续时间
else if (message.startsWith(KEY_STAYRULE)) {
String rule = message.substring(KEY_STAYRULE.length());
fade1 = Integer.valueOf(rule.split("\\|")[0]);
stay = Integer.valueOf(rule.split("\\|")[1]);
fade2 = Integer.valueOf(rule.split("\\|")[2]);
}
} catch (Exception e) {
// 识别异常
title = ChatColor.DARK_RED + "[<ERROR-10: " + value.getLanguageKey() + ">]";
subtitle = ChatColor.DARK_RED + "[<ERROR-10: " + value.getLanguageKey() + ">]";
}
}
}
public String getTitle() {
return title;
}
public String getSubtitle() {
return subtitle;
}
public int getFade1() {
return fade1;
}
public int getFade2() {
return fade2;
}
public int getStay() {
return stay;
}
public Language2Value getValue() {
return value;
}
@Override
public void send(Player player) {
// 检查版本
if (TabooLib.getVerint() < 10800) {
player.sendMessage(ChatColor.DARK_RED + "[<ERROR-31: " + value.getLanguageKey() + ">]");
} else {
TitleUtils.sendTitle(player, title, subtitle, fade1, stay, fade2);
}
}
@Override
public void console() {
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED + "[<ERROR-40: " + value.getLanguageKey() + ">]");
}
}

View File

@ -8,12 +8,9 @@ import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -21,6 +18,8 @@ import java.util.stream.Collectors;
*/ */
public class SupportWorldGuard { public class SupportWorldGuard {
public static final SupportWorldGuard INSTANCE = new SupportWorldGuard();
private WorldGuardPlugin worldGuard; private WorldGuardPlugin worldGuard;
public SupportWorldGuard() { public SupportWorldGuard() {

View File

@ -6,11 +6,11 @@ import com.google.gson.JsonParser;
import com.ilummc.tlib.resources.TLocale; import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.Main; import me.skymc.taboolib.Main;
import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.common.schedule.TSchedule;
import me.skymc.taboolib.fileutils.FileUtils; import me.skymc.taboolib.fileutils.FileUtils;
import me.skymc.taboolib.player.PlayerUtils; import me.skymc.taboolib.player.PlayerUtils;
import me.skymc.taboolib.plugin.PluginUtils; import me.skymc.taboolib.plugin.PluginUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable;
import java.io.*; import java.io.*;
@ -34,46 +34,41 @@ public class UpdateTask {
} }
}; };
public UpdateTask() { @TSchedule(async = true, delay = 100, period = 20 * 60 * 60 * 6)
new BukkitRunnable() { static void update() {
if (!Main.getInst().getConfig().getBoolean("UPDATE-CHECK", true)) {
@Override return;
public void run() { }
if (!Main.getInst().getConfig().getBoolean("UPDATE-CHECK", true)) { for (int i = 0; i < updateLocation.length; i++) {
return; String[] location = updateLocation[i];
} String value = FileUtils.getStringFromURL(location[0], null);
for (int i = 0; i < updateLocation.length; i++) { if (value == null) {
String[] location = updateLocation[i]; continue;
String value = FileUtils.getStringFromURL(location[0], null);
if (value == null) {
continue;
}
JsonElement json = new JsonParser().parse(value);
if (json.isJsonArray()) {
JsonObject releaseData = json.getAsJsonArray().get(0).getAsJsonObject();
updateLocationUsing = i;
newVersion = releaseData.get("tag_name").getAsDouble();
// 获取文件长度
for (JsonElement assetData : releaseData.getAsJsonArray("assets")) {
if (assetData instanceof JsonObject && ((JsonObject) assetData).get("name").getAsString().equals("TabooLib-" + newVersion + ".jar")) {
length = ((JsonObject) assetData).get("size").getAsInt();
}
}
if (TabooLib.getPluginVersion() >= newVersion) {
TLocale.Logger.info("UPDATETASK.VERSION-LATEST");
} else {
TLocale.Logger.info("UPDATETASK.VERSION-OUTDATED", String.valueOf(TabooLib.getPluginVersion()), String.valueOf(newVersion));
// 是否启用启动下载
if (Main.getInst().getConfig().getBoolean("UPDATE-DOWNLOAD", false)) {
Bukkit.getScheduler().runTask(TabooLib.instance(), () -> updatePlugin(true, false));
}
}
return;
}
}
TLocale.Logger.error("UPDATETASK.VERSION-FAIL");
} }
}.runTaskTimerAsynchronously(Main.getInst(), 100, 20 * 60 * 60 * 6); JsonElement json = new JsonParser().parse(value);
if (json.isJsonArray()) {
JsonObject releaseData = json.getAsJsonArray().get(0).getAsJsonObject();
updateLocationUsing = i;
newVersion = releaseData.get("tag_name").getAsDouble();
// 获取文件长度
for (JsonElement assetData : releaseData.getAsJsonArray("assets")) {
if (assetData instanceof JsonObject && ((JsonObject) assetData).get("name").getAsString().equals("TabooLib-" + newVersion + ".jar")) {
length = ((JsonObject) assetData).get("size").getAsInt();
}
}
if (TabooLib.getPluginVersion() >= newVersion) {
TLocale.Logger.info("UPDATETASK.VERSION-LATEST");
} else {
TLocale.Logger.info("UPDATETASK.VERSION-OUTDATED", String.valueOf(TabooLib.getPluginVersion()), String.valueOf(newVersion));
// 是否启用启动下载
if (Main.getInst().getConfig().getBoolean("UPDATE-DOWNLOAD", false)) {
Bukkit.getScheduler().runTask(TabooLib.instance(), () -> updatePlugin(true, false));
}
}
return;
}
}
TLocale.Logger.error("UPDATETASK.VERSION-FAIL");
} }
public static boolean isHaveUpdate() { public static boolean isHaveUpdate() {