引入沙雕值
This commit is contained in:
@@ -17,9 +17,43 @@ public class PlayerMap {
|
||||
protected HashMap<UUID, PlayerData> playerList = new HashMap<>();
|
||||
protected static final CoordinateRecorder plugin = CoordinateRecorder.getCurrent();
|
||||
protected static final PlayerMap current = new PlayerMap();
|
||||
//奖励得分间隔
|
||||
protected final static int REWARD_INTERVAL = 60 * 5;
|
||||
|
||||
private PlayerMap() {
|
||||
Bukkit.getScheduler().runTaskTimer(CoordinateRecorder.getCurrent(), this::flashTime, 0L, 200L);
|
||||
Bukkit.getScheduler().runTaskTimer(CoordinateRecorder.getCurrent(), this::awardFraction, 0L,
|
||||
20 * REWARD_INTERVAL);
|
||||
}
|
||||
|
||||
/// 广播玩家分数
|
||||
private void broadcastScore(PlayerData data) {
|
||||
for (Map.Entry<UUID, PlayerData> enter : playerList.entrySet()) {
|
||||
enter.getValue().updatePlayerFraction(data);
|
||||
}
|
||||
}
|
||||
|
||||
/// 提供玩家分数
|
||||
private void initScore(PlayerData data) {
|
||||
for (Map.Entry<UUID, PlayerData> enter : playerList.entrySet()) {
|
||||
data.updatePlayerFraction(enter.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
//扣除玩家沙雕值
|
||||
private void awardFraction() {
|
||||
for (Map.Entry<UUID, PlayerData> enter : playerList.entrySet()) {
|
||||
try {
|
||||
// 跳过加入时间不足的玩家
|
||||
if (enter.getValue().getFractionTime() > System.currentTimeMillis() - REWARD_INTERVAL * 800)
|
||||
continue;
|
||||
if (enter.getValue().addFraction(-1)) {
|
||||
broadcastScore(enter.getValue());
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
CoordinateRecorder.getCurrent().getLogger().severe("给予分数出错:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void flashTime() {
|
||||
@@ -45,7 +79,10 @@ public class PlayerMap {
|
||||
try {
|
||||
if (!playerList.containsKey(player.getUniqueId())) {
|
||||
plugin.getLogger().info("玩家[" + player.getName() + "]登录服务器,已添加到管理列表");
|
||||
playerList.put(player.getUniqueId(), new PlayerData(player));
|
||||
PlayerData data = new PlayerData(player);
|
||||
playerList.put(player.getUniqueId(), data);
|
||||
initScore(data);
|
||||
broadcastScore(data);
|
||||
} else {
|
||||
plugin.getLogger().warning("玩家[" + player.getName() + "]已经在管理列表中");
|
||||
}
|
||||
|
||||
@@ -84,6 +84,8 @@ public class Database {
|
||||
if (ctx.meta().getTables("PlayerSettings").isEmpty()) {
|
||||
ctx.createTable("PlayerSettings")
|
||||
.column("UID", SQLDataType.VARCHAR(64).nullable(false))
|
||||
//玩家分数
|
||||
.column("fraction", SQLDataType.BIGINT.nullable(false).default_(0L))
|
||||
//控制是否在玩家屏幕右侧通过计分板显示插件信息
|
||||
.column("displaySwitch", SQLDataType.BOOLEAN.nullable(false).default_(true))
|
||||
//控制是否在计分板上显示当前时间刻对应的时间
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Result;
|
||||
import org.jooq.impl.DSL;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.SQLException;
|
||||
@@ -36,16 +37,27 @@ public class PlayerData {
|
||||
protected Block tombstoneBlock;
|
||||
//上次死亡位置
|
||||
protected Location deathLocation;
|
||||
//上次计分时间
|
||||
protected long fractionTime;
|
||||
|
||||
|
||||
public PlayerData(Player player) throws SQLException {
|
||||
this.player = player;
|
||||
this.fractionTime = System.currentTimeMillis();
|
||||
loadPlayerSettings();
|
||||
ui = new ScoreboardUI(this);
|
||||
ui.createScoreboard();
|
||||
locationListUpdate();
|
||||
}
|
||||
|
||||
public long getFractionTime() {
|
||||
return fractionTime;
|
||||
}
|
||||
|
||||
public void setFractionTime(long fractionTime) {
|
||||
this.fractionTime = fractionTime;
|
||||
}
|
||||
|
||||
public void setTombstoneBlock(Block tombstone) {
|
||||
this.tombstoneBlock = tombstone;
|
||||
}
|
||||
@@ -177,6 +189,24 @@ public class PlayerData {
|
||||
ui.closeUI();
|
||||
}
|
||||
|
||||
public void updatePlayerFraction(PlayerData data) {
|
||||
ui.updateFractionScoreboard(data);
|
||||
}
|
||||
|
||||
/// 添加玩家分数
|
||||
public boolean addFraction(int fraction) throws SQLException {
|
||||
if (fraction < 0 && settings.getFraction() == 0) {
|
||||
return false;
|
||||
}
|
||||
var ctx = CoordinateRecorder.getDatabase().getDSL();
|
||||
int rows = ctx.update(PLAYERSETTINGS).set(
|
||||
PLAYERSETTINGS.FRACTION,
|
||||
DSL.greatest(PLAYERSETTINGS.FRACTION.plus(fraction), DSL.val(0)))
|
||||
.where(PLAYERSETTINGS.UID.eq(player.getUniqueId().toString())).execute();
|
||||
loadPlayerSettings();
|
||||
return rows == 1;
|
||||
}
|
||||
|
||||
/// 删除一个地标
|
||||
public boolean removeLocation(String name) throws SQLException {
|
||||
var ctx = CoordinateRecorder.getDatabase().getDSL();
|
||||
|
||||
@@ -15,10 +15,11 @@ public class ScoreboardUI {
|
||||
protected final Player player;
|
||||
protected final PlayerData playerData;
|
||||
protected Scoreboard scoreboard;
|
||||
protected Objective objective;
|
||||
protected Objective locationObjective;
|
||||
protected Location location;
|
||||
protected Score meLocation;
|
||||
protected Score time;
|
||||
protected Objective fraction;
|
||||
protected List<String> locals = new ArrayList<>();
|
||||
|
||||
protected ScoreboardUI(PlayerData data) {
|
||||
@@ -37,32 +38,46 @@ public class ScoreboardUI {
|
||||
//player.setScoreboard(this.scoreboard);
|
||||
return;
|
||||
}
|
||||
this.objective = scoreboard.registerNewObjective("坐标", Criteria.DUMMY,
|
||||
ChatColor.GOLD.toString() + ChatColor.BOLD + "坐标管理器");
|
||||
this.objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
meLocation = this.objective.getScore(getLocationString());
|
||||
this.locationObjective = scoreboard.registerNewObjective("坐标", Criteria.DUMMY,
|
||||
ChatColor.GOLD.toString() + ChatColor.BOLD + "坐标管理器");
|
||||
this.locationObjective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
meLocation = this.locationObjective.getScore(getLocationString());
|
||||
meLocation.setScore(999);
|
||||
|
||||
if (playerData.settings.getShowtime()) {
|
||||
var world = location.getWorld();
|
||||
|
||||
time = this.objective.getScore(world == null ? "Error" : getFormatTime(world.getTime()));
|
||||
time = this.locationObjective.getScore(world == null ? "Error" : getFormatTime(world.getTime()));
|
||||
time.setScore(998);
|
||||
}
|
||||
|
||||
Score line = objective.getScore("");
|
||||
Score line = locationObjective.getScore("");
|
||||
line.setScore(997);
|
||||
|
||||
createFractionScoreboard(scoreboard);
|
||||
player.setScoreboard(this.scoreboard);
|
||||
flashLocations();
|
||||
}
|
||||
|
||||
/// 设置玩家沙雕值计分板
|
||||
protected void createFractionScoreboard(Scoreboard scoreboard) {
|
||||
fraction = scoreboard.registerNewObjective("Fraction", Criteria.DUMMY, "沙雕值");
|
||||
fraction.setDisplaySlot(DisplaySlot.BELOW_NAME);
|
||||
}
|
||||
|
||||
/// 刷新玩家沙雕值计分板
|
||||
protected void updateFractionScoreboard(PlayerData data) {
|
||||
Score score = fraction.getScore(data.player.getName());
|
||||
score.setScore((int) (long) data.settings.getFraction());
|
||||
//fraction.setScore((int) (long) playerData.settings.getFraction());
|
||||
}
|
||||
|
||||
protected void flashTime() {
|
||||
var world = location.getWorld();
|
||||
if (world == null)
|
||||
return;
|
||||
this.scoreboard.resetScores(time.getEntry());
|
||||
time = objective.getScore(getFormatTime(world.getTime()));
|
||||
time = locationObjective.getScore(getFormatTime(world.getTime()));
|
||||
time.setScore(998);
|
||||
}
|
||||
|
||||
@@ -119,7 +134,7 @@ public class ScoreboardUI {
|
||||
}
|
||||
this.scoreboard.resetScores(this.meLocation.getEntry());
|
||||
this.location = local;
|
||||
meLocation = this.objective.getScore(getLocationString());
|
||||
meLocation = this.locationObjective.getScore(getLocationString());
|
||||
meLocation.setScore(999);
|
||||
}
|
||||
|
||||
@@ -146,7 +161,7 @@ public class ScoreboardUI {
|
||||
for (LocationnotepadPO po : list) {
|
||||
String item = po.getName() + " X " + po.getX() + " Y " + po.getY() + " Z " + po.getZ();
|
||||
locals.add(item);
|
||||
Score score = objective.getScore(item);
|
||||
Score score = locationObjective.getScore(item);
|
||||
score.setScore(locals.size());
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,11 @@ public class PlayersettingsTB extends TableImpl<PlayersettingsPO> {
|
||||
*/
|
||||
public final TableField<PlayersettingsPO, String> UID = createField(DSL.name("UID"), SQLDataType.VARCHAR(64).nullable(false), this, "");
|
||||
|
||||
/**
|
||||
* The column <code>PlayerSettings.fraction</code>.
|
||||
*/
|
||||
public final TableField<PlayersettingsPO, Long> FRACTION = createField(DSL.name("fraction"), SQLDataType.BIGINT.nullable(false).defaultValue(DSL.field(DSL.raw("0"), SQLDataType.BIGINT)), this, "");
|
||||
|
||||
/**
|
||||
* The column <code>PlayerSettings.displaySwitch</code>.
|
||||
*/
|
||||
|
||||
@@ -16,6 +16,7 @@ public class PlayersettingsBO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String uid;
|
||||
private Long fraction;
|
||||
private Boolean displayswitch;
|
||||
private Boolean showtime;
|
||||
private Boolean tpme;
|
||||
@@ -25,6 +26,7 @@ public class PlayersettingsBO implements Serializable {
|
||||
|
||||
public PlayersettingsBO(PlayersettingsBO value) {
|
||||
this.uid = value.uid;
|
||||
this.fraction = value.fraction;
|
||||
this.displayswitch = value.displayswitch;
|
||||
this.showtime = value.showtime;
|
||||
this.tpme = value.tpme;
|
||||
@@ -33,12 +35,14 @@ public class PlayersettingsBO implements Serializable {
|
||||
|
||||
public PlayersettingsBO(
|
||||
String uid,
|
||||
Long fraction,
|
||||
Boolean displayswitch,
|
||||
Boolean showtime,
|
||||
Boolean tpme,
|
||||
String settingsrejecttpmessage
|
||||
) {
|
||||
this.uid = uid;
|
||||
this.fraction = fraction;
|
||||
this.displayswitch = displayswitch;
|
||||
this.showtime = showtime;
|
||||
this.tpme = tpme;
|
||||
@@ -59,6 +63,20 @@ public class PlayersettingsBO implements Serializable {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>PlayerSettings.fraction</code>.
|
||||
*/
|
||||
public Long getFraction() {
|
||||
return this.fraction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>PlayerSettings.fraction</code>.
|
||||
*/
|
||||
public void setFraction(Long fraction) {
|
||||
this.fraction = fraction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>PlayerSettings.displaySwitch</code>.
|
||||
*/
|
||||
@@ -130,6 +148,12 @@ public class PlayersettingsBO implements Serializable {
|
||||
}
|
||||
else if (!this.uid.equals(other.uid))
|
||||
return false;
|
||||
if (this.fraction == null) {
|
||||
if (other.fraction != null)
|
||||
return false;
|
||||
}
|
||||
else if (!this.fraction.equals(other.fraction))
|
||||
return false;
|
||||
if (this.displayswitch == null) {
|
||||
if (other.displayswitch != null)
|
||||
return false;
|
||||
@@ -162,6 +186,7 @@ public class PlayersettingsBO implements Serializable {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((this.uid == null) ? 0 : this.uid.hashCode());
|
||||
result = prime * result + ((this.fraction == null) ? 0 : this.fraction.hashCode());
|
||||
result = prime * result + ((this.displayswitch == null) ? 0 : this.displayswitch.hashCode());
|
||||
result = prime * result + ((this.showtime == null) ? 0 : this.showtime.hashCode());
|
||||
result = prime * result + ((this.tpme == null) ? 0 : this.tpme.hashCode());
|
||||
@@ -174,6 +199,7 @@ public class PlayersettingsBO implements Serializable {
|
||||
StringBuilder sb = new StringBuilder("PlayersettingsBO (");
|
||||
|
||||
sb.append(uid);
|
||||
sb.append(", ").append(fraction);
|
||||
sb.append(", ").append(displayswitch);
|
||||
sb.append(", ").append(showtime);
|
||||
sb.append(", ").append(tpme);
|
||||
|
||||
@@ -33,60 +33,74 @@ public class PlayersettingsPO extends UpdatableRecordImpl<PlayersettingsPO> {
|
||||
return (String) get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>PlayerSettings.fraction</code>.
|
||||
*/
|
||||
public void setFraction(Long value) {
|
||||
set(1, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>PlayerSettings.fraction</code>.
|
||||
*/
|
||||
public Long getFraction() {
|
||||
return (Long) get(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>PlayerSettings.displaySwitch</code>.
|
||||
*/
|
||||
public void setDisplayswitch(Boolean value) {
|
||||
set(1, value);
|
||||
set(2, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>PlayerSettings.displaySwitch</code>.
|
||||
*/
|
||||
public Boolean getDisplayswitch() {
|
||||
return (Boolean) get(1);
|
||||
return (Boolean) get(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>PlayerSettings.showTime</code>.
|
||||
*/
|
||||
public void setShowtime(Boolean value) {
|
||||
set(2, value);
|
||||
set(3, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>PlayerSettings.showTime</code>.
|
||||
*/
|
||||
public Boolean getShowtime() {
|
||||
return (Boolean) get(2);
|
||||
return (Boolean) get(3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>PlayerSettings.tpMe</code>.
|
||||
*/
|
||||
public void setTpme(Boolean value) {
|
||||
set(3, value);
|
||||
set(4, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>PlayerSettings.tpMe</code>.
|
||||
*/
|
||||
public Boolean getTpme() {
|
||||
return (Boolean) get(3);
|
||||
return (Boolean) get(4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>PlayerSettings.settingsRejectTpMessage</code>.
|
||||
*/
|
||||
public void setSettingsrejecttpmessage(String value) {
|
||||
set(4, value);
|
||||
set(5, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>PlayerSettings.settingsRejectTpMessage</code>.
|
||||
*/
|
||||
public String getSettingsrejecttpmessage() {
|
||||
return (String) get(4);
|
||||
return (String) get(5);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -112,10 +126,11 @@ public class PlayersettingsPO extends UpdatableRecordImpl<PlayersettingsPO> {
|
||||
/**
|
||||
* Create a detached, initialised PlayersettingsPO
|
||||
*/
|
||||
public PlayersettingsPO(String uid, Boolean displayswitch, Boolean showtime, Boolean tpme, String settingsrejecttpmessage) {
|
||||
public PlayersettingsPO(String uid, Long fraction, Boolean displayswitch, Boolean showtime, Boolean tpme, String settingsrejecttpmessage) {
|
||||
super(PlayersettingsTB.PLAYERSETTINGS);
|
||||
|
||||
setUid(uid);
|
||||
setFraction(fraction);
|
||||
setDisplayswitch(displayswitch);
|
||||
setShowtime(showtime);
|
||||
setTpme(tpme);
|
||||
@@ -131,6 +146,7 @@ public class PlayersettingsPO extends UpdatableRecordImpl<PlayersettingsPO> {
|
||||
|
||||
if (value != null) {
|
||||
setUid(value.getUid());
|
||||
setFraction(value.getFraction());
|
||||
setDisplayswitch(value.getDisplayswitch());
|
||||
setShowtime(value.getShowtime());
|
||||
setTpme(value.getTpme());
|
||||
|
||||
Reference in New Issue
Block a user