-
Notifications
You must be signed in to change notification settings - Fork 0
/
mian.class
123 lines (84 loc) · 4.55 KB
/
mian.class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package yanwang.yanwang.yanwang;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scoreboard.*;
import java.util.Arrays;
import java.util.List;
import java.util.OptionalDouble;
public final class YanWang extends JavaPlugin {
@Override
public void onEnable() {
// Plugin startup logic
getConfig().options().copyDefaults();
saveDefaultConfig();
System.out.println("插件已启动");
//getServer().getPluginManager().registerEvents(new newPlayer(),this);
new BukkitRunnable() {
@Override
public void run() {
Plugin config = YanWang.getPlugin(YanWang.class);
Bukkit.getOnlinePlayers().forEach(p ->{
Scoreboard scoreboard = p.getScoreboard();
String playerName = p.getName();
int playerping = p.getPing();
double[] servertps = Bukkit.getServer().getTPS();
String tps = String.valueOf(Arrays.stream(servertps).findFirst()).replace("OptionalDouble","").replace("[","").replace("]","").substring(0,5);
String serverip = getServer().getIp();
//Bukkit.getServer().broadcastMessage(tps);
//scoreboard = getServer().getScoreboardManager().getNewScoreboard();
if (scoreboard == null || scoreboard.equals(getServer().getScoreboardManager().getMainScoreboard())) {
scoreboard = getServer().getScoreboardManager().getNewScoreboard();
}
List<String> moneyName = config.getConfig().getStringList("money-Name");
List<String> moneyMoney = config.getConfig().getStringList("money-Money");
if (moneyName.contains(playerName)){
//Bukkit.getServer().broadcastMessage("true");
}else{
moneyName.add(playerName);
moneyMoney.add(String.valueOf(0));
config.getConfig().set("money-Name",moneyName);
config.getConfig().set("money-Money",moneyMoney);
//Bukkit.getServer().broadcastMessage("false");
config.saveConfig();
config.reloadConfig();
}
Objective objective =scoreboard.getObjective("个人信息");
if (objective == null) objective = scoreboard.registerNewObjective("个人信息","dummy");
Score huanying = objective.getScore("欢迎 " + playerName + " 来游玩");
huanying.setScore(0);
/*
Score score_playerping = objective.getScore(String.valueOf(playerping));
score_playerping.setScore(-5);
Score score_servertps = objective.getScore(String.valueOf(servertps));
score_servertps.setScore(-6);
*/
for (int i = -5;i>-7;i--){
Team team = scoreboard.registerNewTeam(Integer.toString(i));
if (team == null ) team = scoreboard.registerNewTeam(Integer.toString(i));
Score s = objective.getScore(ChatColor.translateAlternateColorCodes('&', "&" + Math.abs(i)));
s.setScore(i);
team.addEntry(ChatColor.translateAlternateColorCodes('&', "&" + Math.abs(i)));
}
int x = p.getLocation().getBlockX();
Team team = scoreboard.getTeam("-5");
team.setPrefix(ChatColor.translateAlternateColorCodes('&',"&b服务器延迟:"));
team.setSuffix(ChatColor.translateAlternateColorCodes('&',"&e" + playerping));
team = scoreboard.getTeam("-6");
team.setPrefix(ChatColor.translateAlternateColorCodes('&',"&b服务器TPS:"));
team.setSuffix(ChatColor.translateAlternateColorCodes('&',"&e" + x));
//因为测试所以tps不是显示tps而是x坐标
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
p.setScoreboard(scoreboard);
});
}
}.runTaskTimer(this,0L,10L);
}
@Override
public void onDisable() {
// Plugin shutdown logic
System.out.println("插件已关闭");
}
}