与PlayerExpSystem集成
This commit is contained in:
parent
67362ee1d2
commit
a29f0473af
@ -5,9 +5,9 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
public class PlayerJoinListener implements Listener {
|
public class PlayerJoinListener implements Listener {
|
||||||
private final Foundation plugin;
|
private final StatusFoundation plugin;
|
||||||
|
|
||||||
public PlayerJoinListener(Foundation plugin) {
|
public PlayerJoinListener(StatusFoundation plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,9 +8,16 @@ import org.bukkit.plugin.RegisteredServiceProvider;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.bukkit.scoreboard.*;
|
import org.bukkit.scoreboard.*;
|
||||||
|
import com.mmlsystem.PlayerExpSystem.Foundation;
|
||||||
|
import com.mmlsystem.PlayerExpSystem.ExpAPI;
|
||||||
|
|
||||||
public class Foundation extends JavaPlugin {
|
import java.time.Duration;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class StatusFoundation extends JavaPlugin {
|
||||||
public static Economy econ;
|
public static Economy econ;
|
||||||
|
public static ExpAPI api;
|
||||||
|
public int totalTime;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@ -23,6 +30,8 @@ public class Foundation extends JavaPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
getServer().getPluginManager().registerEvents(new PlayerJoinListener(this), this);
|
getServer().getPluginManager().registerEvents(new PlayerJoinListener(this), this);
|
||||||
|
Foundation foundation = (Foundation) Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("PlayerExpSystem"));
|
||||||
|
api = new ExpAPI(foundation);
|
||||||
getLogger().info("插件启用成功。");
|
getLogger().info("插件启用成功。");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,11 +59,15 @@ public class Foundation extends JavaPlugin {
|
|||||||
Objective objective = board.registerNewObjective("info", "dummy", ChatColor.GOLD + "✦ 统计数据 ✦");
|
Objective objective = board.registerNewObjective("info", "dummy", ChatColor.GOLD + "✦ 统计数据 ✦");
|
||||||
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||||
|
|
||||||
objective.getScore(ChatColor.AQUA + "金币").setScore(7);
|
objective.getScore(ChatColor.AQUA + "金币").setScore(10);
|
||||||
objective.getScore(ChatColor.RED + " " + econ.getBalance(player) ).setScore(6);
|
objective.getScore(ChatColor.RED + " " + econ.getBalance(player) ).setScore(9);
|
||||||
|
objective.getScore(" ").setScore(8);
|
||||||
|
objective.getScore(ChatColor.AQUA + "当前在线人数").setScore(7);
|
||||||
|
objective.getScore(ChatColor.GREEN + " " + Bukkit.getOnlinePlayers().size()).setScore(6);
|
||||||
objective.getScore(" ").setScore(5);
|
objective.getScore(" ").setScore(5);
|
||||||
objective.getScore(ChatColor.AQUA + "当前在线人数").setScore(4);
|
getTime(player);
|
||||||
objective.getScore(ChatColor.GREEN + " " + Bukkit.getOnlinePlayers().size()).setScore(3);
|
objective.getScore(ChatColor.AQUA + "在线时长").setScore(4);
|
||||||
|
objective.getScore(ChatColor.GREEN + " " + getTimeString()).setScore(3);
|
||||||
objective.getScore("").setScore(2);
|
objective.getScore("").setScore(2);
|
||||||
objective.getScore(ChatColor.GRAY + "mymc.life").setScore(1);
|
objective.getScore(ChatColor.GRAY + "mymc.life").setScore(1);
|
||||||
|
|
||||||
@ -72,9 +85,31 @@ public class Foundation extends JavaPlugin {
|
|||||||
board.resetScores(entry);
|
board.resetScores(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
objective.getScore(ChatColor.RED + " " + econ.getBalance(player) ).setScore(6);
|
objective.getScore(ChatColor.RED + " " + econ.getBalance(player) ).setScore(9);
|
||||||
objective.getScore(ChatColor.GREEN + " " + Bukkit.getOnlinePlayers().size()).setScore(3);
|
objective.getScore(ChatColor.GREEN + " " + Bukkit.getOnlinePlayers().size()).setScore(6);
|
||||||
|
getTime(player);
|
||||||
|
objective.getScore(ChatColor.GREEN + " " + getTimeString()).setScore(3);
|
||||||
}
|
}
|
||||||
}.runTaskTimer(this, 0L, 100L);
|
}.runTaskTimer(this, 0L, 100L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTime(int time) {
|
||||||
|
this.totalTime = time / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getTime(Player player) {
|
||||||
|
api.getPlayerOnlineTime(player, this::setTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTimeString() {
|
||||||
|
if (totalTime == -1) {
|
||||||
|
return "未知错误";
|
||||||
|
}
|
||||||
|
long hour;
|
||||||
|
long minute;
|
||||||
|
Duration duration = Duration.ofSeconds(totalTime);
|
||||||
|
hour = duration.toHours();
|
||||||
|
minute = duration.toMinutesPart();
|
||||||
|
return String.format("%d:%02d", hour, minute);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user