版本更新至:3.81
新增:TagManager 工具,用于更改玩家头顶称号,并兼容其他计分板插件。 修复:Language2 工具的 [json] 类型 ”url“ 参数失效。
This commit is contained in:
		@@ -6,7 +6,7 @@ website: http://www.15imc.com/index.html
 | 
			
		||||
 | 
			
		||||
main: me.skymc.taboolib.Main
 | 
			
		||||
 | 
			
		||||
version: 3.8
 | 
			
		||||
version: 3.81
 | 
			
		||||
 | 
			
		||||
commands:
 | 
			
		||||
  taboolib:
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,15 @@
 | 
			
		||||
package me.skymc.taboolib.listener;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.event.EventHandler;
 | 
			
		||||
import org.bukkit.event.Listener;
 | 
			
		||||
import org.bukkit.event.server.PluginDisableEvent;
 | 
			
		||||
import org.bukkit.scheduler.BukkitRunnable;
 | 
			
		||||
 | 
			
		||||
import me.skymc.taboolib.Main;
 | 
			
		||||
import me.skymc.taboolib.message.MsgUtils;
 | 
			
		||||
import me.skymc.taboolib.mysql.MysqlUtils;
 | 
			
		||||
import me.skymc.taboolib.mysql.protect.MySQLConnection;
 | 
			
		||||
@@ -13,20 +19,42 @@ public class ListenerPluginDisable implements Listener {
 | 
			
		||||
	
 | 
			
		||||
	@EventHandler
 | 
			
		||||
	public void disable(PluginDisableEvent e) {
 | 
			
		||||
		int i = 0;
 | 
			
		||||
		for (MySQLConnection conn : MysqlUtils.CONNECTIONS) {
 | 
			
		||||
			if (conn.getPlugin().equals(e.getPlugin())) {
 | 
			
		||||
				MysqlUtils.CONNECTIONS.remove(conn);
 | 
			
		||||
				conn.closeConnection();
 | 
			
		||||
				i++;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		if (i > 0) {
 | 
			
		||||
			MsgUtils.send("已停止插件 &f" + e.getPlugin().getName() + "&7 的 &f" + i + "&7 条数据库连接");
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// 注销时间周期
 | 
			
		||||
		TimeCycleManager.cancel(e.getPlugin());
 | 
			
		||||
		
 | 
			
		||||
		// 获取连接
 | 
			
		||||
		List<MySQLConnection> conns = new ArrayList<>();
 | 
			
		||||
		for (MySQLConnection conn : MysqlUtils.CONNECTIONS) {
 | 
			
		||||
			if (conn.getPlugin().equals(e.getPlugin())) {
 | 
			
		||||
				conns.add(conn);
 | 
			
		||||
				MysqlUtils.CONNECTIONS.remove(conn);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// 异步注销
 | 
			
		||||
		BukkitRunnable runnable = new BukkitRunnable() {
 | 
			
		||||
			
 | 
			
		||||
			@Override
 | 
			
		||||
			public void run() {
 | 
			
		||||
				int i = 0;
 | 
			
		||||
				for (MySQLConnection conn : conns) {
 | 
			
		||||
					conn.setFallReconnection(false);
 | 
			
		||||
					conn.closeConnection();
 | 
			
		||||
					i++;
 | 
			
		||||
				}
 | 
			
		||||
				if (i > 0) {
 | 
			
		||||
					MsgUtils.send("已停止插件 &f" + e.getPlugin().getName() + "&7 的 &f" + i + "&7 条数据库连接");
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		};
 | 
			
		||||
		
 | 
			
		||||
		// 如果插件关闭
 | 
			
		||||
		try {
 | 
			
		||||
			runnable.runTaskLater(Main.getInst(), 40);
 | 
			
		||||
		}
 | 
			
		||||
		catch (Exception err) {
 | 
			
		||||
			MsgUtils.warn("异步任务失败, 执行方式改为同步执行");
 | 
			
		||||
			runnable.run();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@ import ch.njol.skript.lang.Expression;
 | 
			
		||||
import ch.njol.skript.lang.SkriptParser.ParseResult;
 | 
			
		||||
import ch.njol.skript.lang.util.SimpleExpression;
 | 
			
		||||
import ch.njol.util.Kleenean;
 | 
			
		||||
import me.skymc.taboocode.TabooCodeItem;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author sky
 | 
			
		||||
@@ -17,8 +18,6 @@ import ch.njol.util.Kleenean;
 | 
			
		||||
public class ExpressionTabooCodeItem extends SimpleExpression<ItemStack> {
 | 
			
		||||
	
 | 
			
		||||
	private Expression<String> name;
 | 
			
		||||
	private Class<?> tabooCodeItem;
 | 
			
		||||
	private Method getItem;
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public Class<? extends ItemStack> getReturnType() {
 | 
			
		||||
@@ -34,13 +33,6 @@ public class ExpressionTabooCodeItem extends SimpleExpression<ItemStack> {
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean init(Expression<?>[] args, int arg1, Kleenean arg2, ParseResult arg3) {
 | 
			
		||||
		name = (Expression<String>) args[0];
 | 
			
		||||
		try {
 | 
			
		||||
			tabooCodeItem = Class.forName("me.skymc.taboocode.TabooCodeItem");
 | 
			
		||||
			getItem = tabooCodeItem.getMethod("getItem", String.class, Boolean.class);
 | 
			
		||||
		}
 | 
			
		||||
		catch (Exception e) {
 | 
			
		||||
			//
 | 
			
		||||
		}
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -52,7 +44,7 @@ public class ExpressionTabooCodeItem extends SimpleExpression<ItemStack> {
 | 
			
		||||
	@Override
 | 
			
		||||
	protected ItemStack[] get(Event e) {
 | 
			
		||||
		try {
 | 
			
		||||
			ItemStack item = (ItemStack) getItem.invoke(null, name.getSingle(e), false);
 | 
			
		||||
			ItemStack item = TabooCodeItem.getItem(name.getSingle(e), false);
 | 
			
		||||
			return new ItemStack[] { item == null ? null : item.clone() };
 | 
			
		||||
		}
 | 
			
		||||
		catch (Exception err) {
 | 
			
		||||
 
 | 
			
		||||
@@ -88,7 +88,7 @@ public class Language2Json implements Language2Line {
 | 
			
		||||
				}
 | 
			
		||||
				// 打开连接
 | 
			
		||||
				else if (message.startsWith(KEY_URL)) {
 | 
			
		||||
					clickEvent = new OpenUrlEvent(message.substring(KEY_SUGGEST.length()));
 | 
			
		||||
					clickEvent = new OpenUrlEvent(message.substring(KEY_URL.length()));
 | 
			
		||||
				}
 | 
			
		||||
				// 换行
 | 
			
		||||
				else if (message.equals("[break]")) {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										187
									
								
								src/main/java/me/skymc/taboolib/team/TagManager.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										187
									
								
								src/main/java/me/skymc/taboolib/team/TagManager.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,187 @@
 | 
			
		||||
package me.skymc.taboolib.team;
 | 
			
		||||
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.event.EventHandler;
 | 
			
		||||
import org.bukkit.event.Listener;
 | 
			
		||||
import org.bukkit.event.player.PlayerJoinEvent;
 | 
			
		||||
import org.bukkit.event.player.PlayerQuitEvent;
 | 
			
		||||
import org.bukkit.scoreboard.Scoreboard;
 | 
			
		||||
import org.bukkit.scoreboard.Team;
 | 
			
		||||
 | 
			
		||||
import lombok.Getter;
 | 
			
		||||
import lombok.Setter;
 | 
			
		||||
import me.skymc.taboolib.Main;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author sky
 | 
			
		||||
 * @since 2018-03-17 21:43:49
 | 
			
		||||
 */
 | 
			
		||||
public class TagManager implements Listener {
 | 
			
		||||
	
 | 
			
		||||
	private static TagManager inst;
 | 
			
		||||
	
 | 
			
		||||
	@Getter
 | 
			
		||||
	private HashMap<String, PlayerData> playerdata = new HashMap<>();
 | 
			
		||||
	
 | 
			
		||||
	private TagManager() {
 | 
			
		||||
		Bukkit.getPluginManager().registerEvents(this, Main.getInst());
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public static TagManager getInst() {
 | 
			
		||||
		synchronized (TagManager.class) {
 | 
			
		||||
			if (inst == null) {
 | 
			
		||||
				inst = new TagManager();
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return inst;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * 设置玩家前缀
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param player 名称
 | 
			
		||||
	 * @param prefix 前缀
 | 
			
		||||
	 */
 | 
			
		||||
	public void setPrefix(Player player, String prefix) {
 | 
			
		||||
		getPlayerData(player).setPrefix(prefix);
 | 
			
		||||
		uploadData(player);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * 设置玩家后缀
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param player 玩家
 | 
			
		||||
	 * @param suffix 后缀
 | 
			
		||||
	 */
 | 
			
		||||
	public void setSuffix(Player player, String suffix) {
 | 
			
		||||
		getPlayerData(player).setSuffix(suffix);
 | 
			
		||||
		uploadData(player);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * 获取玩家前缀
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param player 玩家
 | 
			
		||||
	 * @return String
 | 
			
		||||
	 */
 | 
			
		||||
	public String getPrefix(Player player) {
 | 
			
		||||
		return getPlayerData(player).getPrefix();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * 获取玩家后缀
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param player 玩家
 | 
			
		||||
	 * @return String
 | 
			
		||||
	 */
 | 
			
		||||
	public String getSuffix(Player player) {
 | 
			
		||||
		return getPlayerData(player).getSuffix();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * 获取玩家数据
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param player 玩家
 | 
			
		||||
	 * @return {@link PlayerData}
 | 
			
		||||
	 */
 | 
			
		||||
	private PlayerData getPlayerData(Player player) {
 | 
			
		||||
		PlayerData data = playerdata.get(player.getName());
 | 
			
		||||
		if (data == null) {
 | 
			
		||||
			data = new PlayerData(player.getName());
 | 
			
		||||
			playerdata.put(player.getName(), data);
 | 
			
		||||
		}
 | 
			
		||||
		return data;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * 将该玩家的数据向服务器所有玩家更新
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param player 玩家
 | 
			
		||||
	 */
 | 
			
		||||
	public void uploadData(Player player) {
 | 
			
		||||
		PlayerData data = getPlayerData(player);
 | 
			
		||||
		String prefix = data.getPrefix().length() > 16 ? data.getPrefix().substring(0, 16) : data.getPrefix();
 | 
			
		||||
		String suffix = data.getSuffix().length() > 16 ? data.getSuffix().substring(0, 16) : data.getSuffix();
 | 
			
		||||
		// 如果没有称号数据
 | 
			
		||||
		if (prefix.isEmpty() && suffix.isEmpty()) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		for (Player _player : Bukkit.getOnlinePlayers()) {
 | 
			
		||||
			Scoreboard scoreboard = _player.getScoreboard();
 | 
			
		||||
			if (scoreboard == null) {
 | 
			
		||||
				_player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
 | 
			
		||||
			}
 | 
			
		||||
			Team team = scoreboard.getTeam(player.getName());
 | 
			
		||||
			if (team == null) {
 | 
			
		||||
				team = scoreboard.registerNewTeam(player.getName());
 | 
			
		||||
				team.addEntry(player.getName());
 | 
			
		||||
			}
 | 
			
		||||
			team.setPrefix(prefix);
 | 
			
		||||
			team.setSuffix(suffix);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * 下载服务器内的称号数据到该玩家
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param player 玩家
 | 
			
		||||
	 */
 | 
			
		||||
	public void downloadData(Player player) {
 | 
			
		||||
		Scoreboard scoreboard = player.getScoreboard();
 | 
			
		||||
		if (scoreboard == null) {
 | 
			
		||||
			player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		for (Player _player : Bukkit.getOnlinePlayers()) {
 | 
			
		||||
			PlayerData data = getPlayerData(_player);
 | 
			
		||||
			String prefix = data.getPrefix().length() > 16 ? data.getPrefix().substring(0, 16) : data.getPrefix();
 | 
			
		||||
			String suffix = data.getSuffix().length() > 16 ? data.getSuffix().substring(0, 16) : data.getSuffix();
 | 
			
		||||
			// 如果没有称号数据
 | 
			
		||||
			if (prefix.isEmpty() && suffix.isEmpty()) {
 | 
			
		||||
				continue;
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			Team team = scoreboard.getTeam(_player.getName());
 | 
			
		||||
			if (team == null) {
 | 
			
		||||
				team = scoreboard.registerNewTeam(_player.getName());
 | 
			
		||||
				team.addEntry(_player.getName());
 | 
			
		||||
			}
 | 
			
		||||
			team.setPrefix(prefix);
 | 
			
		||||
			team.setSuffix(suffix);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@EventHandler
 | 
			
		||||
	public void onJoin(PlayerJoinEvent e) {
 | 
			
		||||
		downloadData(e.getPlayer());
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@EventHandler
 | 
			
		||||
	public void onQuit(PlayerQuitEvent e) {
 | 
			
		||||
		playerdata.remove(e.getPlayer().getName());
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	static class PlayerData {
 | 
			
		||||
		
 | 
			
		||||
		@Getter
 | 
			
		||||
		private String name;
 | 
			
		||||
		
 | 
			
		||||
		@Getter
 | 
			
		||||
		@Setter
 | 
			
		||||
		private String prefix;
 | 
			
		||||
		
 | 
			
		||||
		@Getter
 | 
			
		||||
		@Setter
 | 
			
		||||
		private String suffix;
 | 
			
		||||
		
 | 
			
		||||
		public PlayerData(String name) {
 | 
			
		||||
			this.name = name;
 | 
			
		||||
			this.prefix = "";
 | 
			
		||||
			this.suffix = "";
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -9,90 +9,127 @@ import org.bukkit.scoreboard.Team;
 | 
			
		||||
import me.skymc.taboolib.message.MsgUtils;
 | 
			
		||||
import me.skymc.taboolib.methods.MethodsUtils;
 | 
			
		||||
 | 
			
		||||
@Deprecated
 | 
			
		||||
/**
 | 
			
		||||
 * @author sky
 | 
			
		||||
 * @since 2018-03-17 21:36:52
 | 
			
		||||
 */
 | 
			
		||||
public class TagUtils {
 | 
			
		||||
	
 | 
			
		||||
	public static void setTag(Player p, String prefix, String suffix) throws Exception {
 | 
			
		||||
	/**
 | 
			
		||||
	 * 设置玩家前后缀
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param p 玩家
 | 
			
		||||
	 * @param prefix 前缀
 | 
			
		||||
	 * @param suffix 后缀
 | 
			
		||||
	 */
 | 
			
		||||
	public static void setTag(Player p, String prefix, String suffix) {
 | 
			
		||||
		// 判断长度
 | 
			
		||||
		if (prefix.length() > 16) {
 | 
			
		||||
			prefix = prefix.substring(0, 16);
 | 
			
		||||
		} 
 | 
			
		||||
		if (suffix.length() > 16) {
 | 
			
		||||
			suffix = suffix.substring(0, 16);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// 获取计分板
 | 
			
		||||
		Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
 | 
			
		||||
		Team t = board.getTeam(p.getName());
 | 
			
		||||
		if (t == null)
 | 
			
		||||
		{
 | 
			
		||||
		if (t == null) {
 | 
			
		||||
			t = board.registerNewTeam(p.getName());
 | 
			
		||||
			t.setPrefix(prefix);
 | 
			
		||||
			t.setSuffix(suffix);
 | 
			
		||||
			t.addPlayer(p);
 | 
			
		||||
			
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			t = board.getTeam(p.getName());
 | 
			
		||||
			t.setPrefix(prefix);
 | 
			
		||||
			t.setSuffix(suffix);
 | 
			
		||||
			t.addPlayer(p);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// 更新称号
 | 
			
		||||
		t.setPrefix(prefix);
 | 
			
		||||
		t.setSuffix(suffix);
 | 
			
		||||
		t.addEntry(p.getName());
 | 
			
		||||
		
 | 
			
		||||
		// 更新玩家
 | 
			
		||||
		for (Player o : Bukkit.getOnlinePlayers()) {
 | 
			
		||||
			o.setScoreboard(board);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
  
 | 
			
		||||
	public static void unregisterTag(Player p) throws Exception 
 | 
			
		||||
	{
 | 
			
		||||
		Bukkit.getScoreboardManager().getMainScoreboard().getPlayerTeam(p).unregister();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public static void delete() {
 | 
			
		||||
		try {
 | 
			
		||||
			for (Team t : Bukkit.getScoreboardManager().getMainScoreboard().getTeams()) {
 | 
			
		||||
				t.unregister();
 | 
			
		||||
			if (!board.equals(o.getScoreboard())) {
 | 
			
		||||
				o.setScoreboard(board);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		catch (Exception e) {
 | 
			
		||||
			// TODO: handle exception
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
  
 | 
			
		||||
	public static void unregisterAll() throws Exception
 | 
			
		||||
	{
 | 
			
		||||
	/**
 | 
			
		||||
	 * 注销玩家前后缀
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param p 玩家
 | 
			
		||||
	 */
 | 
			
		||||
	public static void unregisterTag(Player p) {
 | 
			
		||||
		Team team = Bukkit.getScoreboardManager().getMainScoreboard().getTeam(p.getName());
 | 
			
		||||
		if (team != null) {
 | 
			
		||||
			team.unregister();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * 注销所有在线玩家前后缀
 | 
			
		||||
	 */
 | 
			
		||||
	public static void unregisterAll() {
 | 
			
		||||
		for (Player o : Bukkit.getOnlinePlayers()) {
 | 
			
		||||
			unregisterTag(o);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
  
 | 
			
		||||
	public static void registerAll(String prefix, String suffix) throws Exception
 | 
			
		||||
	{
 | 
			
		||||
		for (Player o : Bukkit.getOnlinePlayers()) {
 | 
			
		||||
			setTag(o, prefix, " " + suffix);
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * 删除所有前后缀
 | 
			
		||||
	 */
 | 
			
		||||
	public static void delete() {
 | 
			
		||||
		for (Team t : Bukkit.getScoreboardManager().getMainScoreboard().getTeams()) {
 | 
			
		||||
			t.unregister();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
  
 | 
			
		||||
	public static void refresh()
 | 
			
		||||
	{
 | 
			
		||||
	/**
 | 
			
		||||
	 * 设置全服玩家前后缀
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param prefix 前缀
 | 
			
		||||
	 * @param suffix 后缀
 | 
			
		||||
	 */
 | 
			
		||||
	public static void registerAll(String prefix, String suffix) {
 | 
			
		||||
		for (Player o : Bukkit.getOnlinePlayers()) {
 | 
			
		||||
			setTag(o, prefix, suffix);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
  
 | 
			
		||||
	/**
 | 
			
		||||
	 * 刷新计分板数据
 | 
			
		||||
	 */
 | 
			
		||||
	public static void refresh() {
 | 
			
		||||
		Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
 | 
			
		||||
		for (Player o : Bukkit.getOnlinePlayers()) {
 | 
			
		||||
			o.setScoreboard(board);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
  
 | 
			
		||||
	public static String getPrefix(Player p) throws Exception
 | 
			
		||||
	{
 | 
			
		||||
	/**
 | 
			
		||||
	 * 获取玩家前缀
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param p 玩家
 | 
			
		||||
	 * @return String
 | 
			
		||||
	 */
 | 
			
		||||
	public static String getPrefix(Player p) {
 | 
			
		||||
		Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
 | 
			
		||||
		Team t = board.getTeam(p.getName());
 | 
			
		||||
		if ((t != null) && (board.getPlayerTeam(p).getPrefix() != null) && (!board.getPlayerTeam(p).getPrefix().isEmpty())) {
 | 
			
		||||
			return board.getPlayerTeam(p).getPrefix();
 | 
			
		||||
		if (t != null) {
 | 
			
		||||
			return t.getPrefix();
 | 
			
		||||
		}
 | 
			
		||||
		return "";
 | 
			
		||||
		return null;
 | 
			
		||||
	}
 | 
			
		||||
  
 | 
			
		||||
	public static String getSuffix(Player p) throws Exception
 | 
			
		||||
	{
 | 
			
		||||
	/**
 | 
			
		||||
	 * 获取玩玩家后缀
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param p 玩家
 | 
			
		||||
	 * @return String
 | 
			
		||||
	 */
 | 
			
		||||
	public static String getSuffix(Player p) {
 | 
			
		||||
		Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
 | 
			
		||||
		Team t = board.getTeam(p.getName());
 | 
			
		||||
		if ((t != null) && (board.getPlayerTeam(p).getSuffix() != null) && (!board.getPlayerTeam(p).getSuffix().isEmpty())) {
 | 
			
		||||
			return board.getPlayerTeam(p).getSuffix();
 | 
			
		||||
		if (t != null) {
 | 
			
		||||
			return t.getSuffix();
 | 
			
		||||
		}
 | 
			
		||||
		return "";
 | 
			
		||||
		return null;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user