Skip to content

Commit a9bafa5

Browse files
committed
常時更新するとtneがバグるのでイベントが発生した際に更新するように
1 parent eb70b12 commit a9bafa5

File tree

9 files changed

+70
-93
lines changed

9 files changed

+70
-93
lines changed

src/main/java/com/github/elic0de/thejpspit/TheJpsPit.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ public void onDisable() {
219219
Bukkit.getOnlinePlayers().forEach(player -> {
220220
final PitPlayer pitPlayer = PitPlayerManager.getPitPlayer(player);
221221
game.leave(pitPlayer);
222-
if (pitPlayer.getBoard() != null) {
223-
pitPlayer.getBoard().delete();
224-
}
222+
pitPlayer.getBoard().destoryScoreboard();
225223
});
226224
Bukkit.getScheduler().cancelTasks(this);
227225
}

src/main/java/com/github/elic0de/thejpspit/config/Settings.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,6 @@ public class Settings {
6363
Database.Table.PIT_DATA.name().toLowerCase(), Database.Table.PIT_DATA.getDefaultName()
6464
);
6565

66-
@YamlKey("scoreboard")
67-
private List<String> scoreboard = Arrays.asList(
68-
"",
69-
"レベル: [%level%]",
70-
"JP: [%coins%]",
71-
"",
72-
"K/Dレート: &c%rating%",
73-
"最高レート: &b%bestRating%",
74-
"",
75-
"次のレベルまで:&a%neededXp%",
76-
"",
77-
"連続キル数: &a%streaks%",
78-
"最高連続キル数: &a%bestStreaks%",
79-
"",
80-
"&ejapanpvpserver.net"
81-
);
82-
8366
@YamlKey("level")
8467
private List<String> level = Arrays.asList(
8568
"1,15,15," + ChatColor.GRAY.name(),
@@ -150,10 +133,6 @@ public String getTableName(Database.Table tableName) {
150133
return Optional.ofNullable(tableNames.get(tableName.name().toLowerCase())).orElse(tableName.getDefaultName());
151134
}
152135

153-
public List<String> getScoreboard() {
154-
return scoreboard;
155-
}
156-
157136
public List<String> getLevel() {
158137
return level;
159138
}

src/main/java/com/github/elic0de/thejpspit/game/Game.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.github.elic0de.thejpspit.TheJpsPit;
44
import com.github.elic0de.thejpspit.player.PitPlayer;
5-
import com.github.elic0de.thejpspit.scoreboard.GameScoreboard;
65
import com.github.elic0de.thejpspit.task.GameTask;
76
import java.math.BigDecimal;
87
import java.util.HashSet;
@@ -14,18 +13,15 @@ public class Game {
1413

1514
private final TheJpsPit pit = TheJpsPit.getInstance();
1615
private final Set<PitPlayer> pitPlayers = new HashSet<>();
17-
private final GameScoreboard scoreboard;
1816
private final GameTask task;
1917

2018
public Game() {
21-
this.scoreboard = new GameScoreboard();
2219
this.task = new GameTask();
2320
}
2421

2522
public void join(PitPlayer player) {
2623
pitPlayers.add(player);
2724
player.addItem();
28-
player.getBoard().updateLines();
2925
player.updateDisplayName();
3026
player.setLastDamager(null);
3127
}
@@ -121,10 +117,6 @@ public Set<PitPlayer> getPitPlayers() {
121117
return pitPlayers;
122118
}
123119

124-
public GameScoreboard getScoreboard() {
125-
return scoreboard;
126-
}
127-
128120
public GameTask getTask() {
129121
return task;
130122
}

src/main/java/com/github/elic0de/thejpspit/hook/TneEconomyHook.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ public boolean hasMoney(PitPlayer player, BigDecimal amount) {
3434
@Override
3535
public void takeMoney(PitPlayer player, BigDecimal amount) {
3636
tneAPI.getAccount(player.getUniqueId()).removeHoldings(amount);
37+
player.getBoard().updateCoins();
3738
}
3839

3940
@Override
4041
public void giveMoney(PitPlayer player, BigDecimal amount) {
4142
tneAPI.getAccount(player.getUniqueId()).addHoldings(amount);
43+
player.getBoard().updateCoins();
4244
}
4345

4446
@Override

src/main/java/com/github/elic0de/thejpspit/listener/EventListener.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ public void onQuit(PlayerQuitEvent event) {
7575

7676
PitPlayerManager.unregisterUser(player);
7777
plugin.getGame().leave(player);
78-
if (player.getBoard() != null) {
79-
player.getBoard().delete();
80-
}
78+
player.getBoard().destoryScoreboard();
8179
}
8280

8381
@EventHandler

src/main/java/com/github/elic0de/thejpspit/player/PitPlayer.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.github.elic0de.thejpspit.database.Database;
55
import com.github.elic0de.thejpspit.hook.EconomyHook;
66
import com.github.elic0de.thejpspit.leveler.Levels;
7+
import com.github.elic0de.thejpspit.scoreboard.PitPlayerScoreboard;
78
import com.github.elic0de.thejpspit.util.ShowHealth;
89
import de.themoep.minedown.MineDown;
910
import fr.mrmicky.fastboard.FastBoard;
@@ -45,7 +46,7 @@ public class PitPlayer {
4546
private double rating;
4647
private double bestRating;
4748
private double xp;
48-
private final FastBoard board;
49+
private final PitPlayerScoreboard board;
4950
private PitPlayer lastDamager;
5051

5152
private Optional<Preferences> preferences;
@@ -61,8 +62,7 @@ public PitPlayer(Player player) {
6162
this.rating = 0;
6263
this.bestRating = 0;
6364
this.xp = 0;
64-
this.board = new FastBoard(player);
65-
this.board.updateTitle(ChatColor.translateAlternateColorCodes('&', "&eTHE JPS PIT"));
65+
this.board = new PitPlayerScoreboard(this);
6666
this.level = Levels.getPlayerLevel(this);
6767
this.preferences = Optional.of(Preferences.getDefaults());
6868
}
@@ -78,8 +78,7 @@ public PitPlayer(Player player, long kills, long streaks, long bestStreaks, long
7878
this.rating = rating;
7979
this.bestRating = bestRating;
8080
this.xp = xp;
81-
this.board = new FastBoard(player);
82-
this.board.updateTitle(ChatColor.translateAlternateColorCodes('&', "&eTHE JPS PIT"));
81+
this.board = new PitPlayerScoreboard(this);
8382
this.level = Levels.getPlayerLevel(this);
8483
this.preferences = preferences;
8584
}
@@ -235,14 +234,16 @@ public void setRating(double rating) {
235234
this.rating = rating;
236235
if (bestRating < rating) {
237236
this.bestRating = rating;
237+
getBoard().updateBestRating();
238238
}
239+
getBoard().updateRating();
239240
}
240241

241242
public double getXp() {
242243
return xp;
243244
}
244245

245-
public FastBoard getBoard() {
246+
public PitPlayerScoreboard getBoard() {
246247
return board;
247248
}
248249

@@ -265,6 +266,8 @@ public void increaseStreaks() {
265266
if (bestStreaks < streaks) {
266267
this.bestStreaks = streaks;
267268
}
269+
getBoard().updateKillStreaks();
270+
getBoard().updateBestKillStreaks();
268271
}
269272
public void increaseDeaths() {
270273
this.deaths++;
@@ -275,6 +278,7 @@ public void increaseXP() {
275278
// レベルアップ
276279
if (Levels.getPlayerNeededXP(level, (int) xp) == 0) levelUp();
277280
updateXpBar();
281+
getBoard().updateNeededXp();
278282
}
279283

280284
public void setLastDamager(PitPlayer player) {
@@ -283,6 +287,8 @@ public void setLastDamager(PitPlayer player) {
283287

284288
public void resetStreaks() {
285289
streaks = 0;
290+
getBoard().updateKillStreaks();
291+
getBoard().updateBestKillStreaks();
286292
}
287293

288294
public void levelUp() {
@@ -292,5 +298,6 @@ public void levelUp() {
292298
player.sendTitle("§b§lLEVEL UP!", previousLevel + " → " + nextLevel, 20,40, 20);
293299
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1f, 1f);
294300
updateDisplayName();
301+
getBoard().updateLevel();
295302
}
296303
}

src/main/java/com/github/elic0de/thejpspit/scoreboard/GameScoreboard.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/main/java/com/github/elic0de/thejpspit/scoreboard/PitPlayerScoreboard.java

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,74 @@
44
import com.github.elic0de.thejpspit.leveler.Levels;
55
import com.github.elic0de.thejpspit.player.PitPlayer;
66
import fr.mrmicky.fastboard.FastBoard;
7+
import java.math.BigDecimal;
78
import java.util.List;
89
import java.util.stream.Collectors;
10+
import java.util.stream.Stream;
911
import me.clip.placeholderapi.PlaceholderAPI;
1012
import org.bukkit.ChatColor;
1113

1214
public class PitPlayerScoreboard {
1315

14-
private FastBoard board;
15-
private PitPlayer player;
16-
16+
private final FastBoard board;
17+
private final PitPlayer player;
1718
public PitPlayerScoreboard(PitPlayer player) {
1819
this.player = player;
1920
this.board = new FastBoard(player.getPlayer());
20-
board.updateLines(
21-
boardLines(player).stream().map(s -> ChatColor.translateAlternateColorCodes('&', s))
21+
this.board.updateTitle(ChatColor.translateAlternateColorCodes('&', "&eTHE JPS PIT"));
22+
this.board.updateLines(
23+
init(player).stream().map(s -> ChatColor.translateAlternateColorCodes('&', s))
2224
.collect(Collectors.toList()));
2325
}
2426

25-
public void updateKill() {
26-
//board.updateLine();
27+
public void destoryScoreboard() {
28+
if (board != null) board.delete();
29+
}
30+
public void updateLevel() {
31+
board.updateLine(0, "レベル: [%level%]".replaceAll("%level%", Levels.getPlayerLevelColor(player.getLevel()) + "" + player.getLevel() + ChatColor.RESET));
32+
}
33+
34+
public void updateCoins() {
35+
TheJpsPit.getInstance().getEconomyHook().ifPresent(economyHook -> board.updateLine(1, "JP: [%coins%]".replaceAll("%coins%", economyHook.getBalance(player).toPlainString())));
36+
}
37+
38+
public void updateRating() {
39+
board.updateLine(3, "K/Dレート: &c%rating%".replaceAll("%rating%", player.getRating() + ""));
40+
}
41+
42+
public void updateBestRating() {
43+
board.updateLine(4, "最高レート: &b%bestRating%".replaceAll("%bestRating%", player.getBestRating() + ""));
44+
}
45+
46+
public void updateNeededXp() {
47+
board.updateLine(6, "次のレベルまで:&a%neededXp%".replaceAll("%neededXp%", Levels.getPlayerNeededXP(player.getLevel(),
48+
(int) player.getXp()) + ""));
49+
}
50+
51+
public void updateKillStreaks() {
52+
board.updateLine(9, "連続キル数: &a%streaks%".replaceAll("%streaks%", player.getStreaks() + ""));
53+
}
54+
55+
public void updateBestKillStreaks() {
56+
board.updateLine(10, "最高連続キル数: &a%bestStreaks%".replaceAll("%bestStreaks%", player.getBestStreaks() + ""));
2757
}
2858

29-
private List<String> boardLines(PitPlayer player) {
30-
return TheJpsPit.getInstance().getSettings().getScoreboard().stream().map(s -> PlaceholderAPI.setPlaceholders(player.getPlayer(), s)).map(s ->
59+
private List<String> init(PitPlayer player) {
60+
return Stream.of(
61+
"",
62+
"レベル: [%level%]",
63+
"JP: [%coins%]",
64+
"",
65+
"K/Dレート: &c%rating%",
66+
"最高レート: &b%bestRating%",
67+
"",
68+
"次のレベルまで:&a%neededXp%",
69+
"",
70+
"連続キル数: &a%streaks%",
71+
"最高連続キル数: &a%bestStreaks%",
72+
"",
73+
"&ejapanpvpserver.net"
74+
).map(s -> PlaceholderAPI.setPlaceholders(player.getPlayer(), s)).map(s ->
3175
s.replaceAll("%level%", Levels.getPlayerLevelColor(player.getLevel()) + "" + player.getLevel() + ChatColor.RESET)
3276
.replaceAll("%neededXp%", Levels.getPlayerNeededXP(player.getLevel(),
3377
(int) player.getXp()) + "")

src/main/java/com/github/elic0de/thejpspit/task/GameTask.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public GameTask() {
2525
bukkitTask = new BukkitRunnable() {
2626
@Override
2727
public void run() {
28-
pit.getGame().getScoreboard().update();
2928

3029
/*repeats.getAndIncrement();
3130
if (repeats.get() >= 5) {

0 commit comments

Comments
 (0)