Skip to content

Commit 72c1d69

Browse files
committed
📝 fixs
1 parent c816fec commit 72c1d69

7 files changed

Lines changed: 51 additions & 24 deletions

File tree

src/main/java/fr/maxlego08/koth/KothListener.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.bukkit.event.inventory.InventoryCloseEvent;
1919
import org.bukkit.event.player.PlayerInteractEvent;
2020
import org.bukkit.event.player.PlayerMoveEvent;
21+
import org.bukkit.event.player.PlayerQuitEvent;
2122
import org.bukkit.inventory.EquipmentSlot;
2223
import org.bukkit.inventory.Inventory;
2324
import org.bukkit.inventory.ItemStack;
@@ -30,6 +31,8 @@
3031

3132
public class KothListener extends ListenerAdapter {
3233

34+
private static final long SHULKER_REMOVE_DELAY_TICKS = 20L * 60L; // 1 minute in ticks
35+
3336
private final KothPlugin plugin;
3437
private final KothManager manager;
3538
private final Board board = NmsVersion.nmsVersion.isHexVersion() ? new ColorBoard() : new EmptyBoard();
@@ -77,7 +80,7 @@ protected void onInteract(PlayerInteractEvent event, Player player) {
7780

7881
entity = shulker;
7982

80-
Bukkit.getScheduler().runTaskLater(this.plugin, shulker::remove, 20 * 60);
83+
Bukkit.getScheduler().runTaskLater(this.plugin, shulker::remove, SHULKER_REMOVE_DELAY_TICKS);
8184
}
8285

8386
selection.action(action, location, entity);
@@ -105,6 +108,14 @@ protected void onMove(PlayerMoveEvent event, Player player) {
105108
}
106109
}
107110

111+
@Override
112+
protected void onQuit(PlayerQuitEvent event, Player player) {
113+
// Clean up player selection data
114+
this.manager.removeSelection(player.getUniqueId());
115+
// Clean up player scoreboard
116+
this.plugin.getScoreBoardManager().delete(player);
117+
}
118+
108119
@Override
109120
protected void onInventoryClose(InventoryCloseEvent event, Player player) {
110121
Inventory inventory = event.getInventory();

src/main/java/fr/maxlego08/koth/KothManager.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,21 @@ public void createSelection(UUID uniqueId, Selection selection) {
102102
this.selections.put(uniqueId, selection);
103103
}
104104

105+
public void removeSelection(UUID uniqueId) {
106+
Selection selection = this.selections.remove(uniqueId);
107+
if (selection != null) {
108+
selection.clear();
109+
}
110+
}
111+
105112
public void saveKoth(Koth koth) {
106113

107114
File file = new File(this.folder, koth.getFileName() + ".yml");
108115
if (!file.exists()) {
109116
try {
110117
file.createNewFile();
111118
} catch (IOException exception) {
112-
exception.printStackTrace();
119+
Logger.info("Failed to create koth file " + file.getName() + ": " + exception.getMessage(), Logger.LogType.ERROR);
113120
}
114121
}
115122

@@ -118,7 +125,7 @@ public void saveKoth(Koth koth) {
118125
try {
119126
configuration.save(file);
120127
} catch (IOException exception) {
121-
exception.printStackTrace();
128+
Logger.info("Failed to save koth file " + file.getName() + ": " + exception.getMessage(), Logger.LogType.ERROR);
122129
}
123130
}
124131

@@ -132,8 +139,9 @@ public void createKoth(Player player, String name, Location minLocation, Locatio
132139
return;
133140
}
134141

135-
int distance = Math.abs(minLocation.getBlockX() - maxLocation.getBlockY());
136-
if (distance <= 0) {
142+
int distanceX = Math.abs(minLocation.getBlockX() - maxLocation.getBlockX());
143+
int distanceZ = Math.abs(minLocation.getBlockZ() - maxLocation.getBlockZ());
144+
if (distanceX <= 0 || distanceZ <= 0) {
137145
message(player, Message.KOTH_SIZE);
138146
return;
139147
}

src/main/java/fr/maxlego08/koth/KothPlugin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void onEnable() {
7474
Object implementation = clazz.getConstructor(fr.maxlego08.koth.api.KothPlugin.class).newInstance(this);
7575
clazz.getMethod("register").invoke(implementation);
7676
} catch (Exception exception) {
77-
exception.printStackTrace();
77+
Logger.info("Failed to register zScheduler: " + exception.getMessage(), Logger.LogType.ERROR);
7878
}
7979
}
8080

@@ -84,7 +84,7 @@ public void onEnable() {
8484
Class<?> clazz = Class.forName("fr.maxlego08.koth.hologram.DecentHologram");
8585
this.kothHologram = (KothHologram) clazz.getConstructor().newInstance();
8686
} catch (Exception exception) {
87-
exception.printStackTrace();
87+
Logger.info("Failed to register DecentHologram: " + exception.getMessage(), Logger.LogType.ERROR);
8888
}
8989
}
9090

@@ -94,7 +94,7 @@ public void onEnable() {
9494
Class<?> clazz = Class.forName("fr.maxlego08.koth.hologram.FancyHologram");
9595
this.kothHologram = (KothHologram) clazz.getConstructor().newInstance();
9696
} catch (Exception exception) {
97-
exception.printStackTrace();
97+
Logger.info("Failed to register FancyHologram: " + exception.getMessage(), Logger.LogType.ERROR);
9898
}
9999
}
100100

src/main/java/fr/maxlego08/koth/ZKoth.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@
4646
import java.util.ArrayList;
4747
import java.util.Collections;
4848
import java.util.Comparator;
49-
import java.util.HashMap;
5049
import java.util.List;
5150
import java.util.Map;
5251
import java.util.Random;
5352
import java.util.Timer;
5453
import java.util.TimerTask;
5554
import java.util.UUID;
55+
import java.util.concurrent.ConcurrentHashMap;
5656
import java.util.concurrent.atomic.AtomicInteger;
5757
import java.util.stream.Collectors;
5858

@@ -67,7 +67,7 @@ public class ZKoth extends ZUtils implements Koth {
6767
private final int stopAfterSeconds;
6868
private final int randomItemStacks;
6969
private final int scoreboardRadius;
70-
private final Map<UUID, Integer> playersValues = new HashMap<>();
70+
private final Map<UUID, Integer> playersValues = new ConcurrentHashMap<>();
7171
private final boolean enableStartCapMessage;
7272
private final boolean enableLooseCapMessage;
7373
private final boolean enableEverySecondsCapMessage;
@@ -92,6 +92,7 @@ public class ZKoth extends ZUtils implements Koth {
9292
private AtomicInteger remainingSeconds;
9393
private TimerTask timerTask;
9494
private TimerTask timerTaskStop;
95+
private Timer stopTimer;
9596
private List<PlayerResult> playerResults = new ArrayList<>();
9697

9798
public ZKoth(KothPlugin plugin, String fileName, KothType kothType, String name, int captureSeconds, Location minLocation, Location maxLocation, List<String> startCommands, List<String> endCommands, ScoreboardConfiguration cooldownScoreboard, ScoreboardConfiguration startScoreboard, int cooldownStart, int stopAfterSeconds, boolean enableStartCapMessage, boolean enableLooseCapMessage, boolean enableEverySecondsCapMessage, boolean enableEverySecondsCooldownMessage, HologramConfig hologramConfig, List<ItemStack> itemStacks, KothLootType kothLootType, DiscordWebhookConfig discordWebhookConfig, int randomItemStacks, List<String> blacklistTeamId, ProgressBar progressBar, List<RandomCommand> randomCommands, int maxRandomCommands) {
@@ -304,6 +305,10 @@ public void stop() {
304305
this.plugin.getScoreBoardManager().clearBoard();
305306
// this.resetBlocks();
306307
if (this.timerTaskStop != null) this.timerTaskStop.cancel();
308+
if (this.stopTimer != null) {
309+
this.stopTimer.cancel();
310+
this.stopTimer = null;
311+
}
307312

308313
this.plugin.getKothHologram().end(this);
309314
}
@@ -415,15 +420,15 @@ private void spawnNow() {
415420
}*/
416421

417422
Koth koth = this;
418-
Timer timer = new Timer();
423+
this.stopTimer = new Timer();
419424
this.timerTaskStop = new TimerTask() {
420425
@Override
421426
public void run() {
422427
plugin.getKothHologram().end(koth);
423428
Bukkit.getScheduler().runTask(plugin, () -> stop(Bukkit.getConsoleSender()));
424429
}
425430
};
426-
timer.schedule(this.timerTaskStop, this.stopAfterSeconds * 1000L);
431+
this.stopTimer.schedule(this.timerTaskStop, this.stopAfterSeconds * 1000L);
427432

428433
this.plugin.getKothHologram().start(this);
429434

src/main/java/fr/maxlego08/koth/hologram/EmptyHologram.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,29 @@
33
import fr.maxlego08.koth.api.Koth;
44
import fr.maxlego08.koth.api.KothHologram;
55

6+
/**
7+
* No-op implementation of KothHologram used when no hologram plugin is available.
8+
*/
69
public class EmptyHologram implements KothHologram {
710

811
@Override
912
public void start(Koth koth) {
10-
// TODO Auto-generated method stub
11-
13+
// No hologram plugin available - do nothing
1214
}
1315

1416
@Override
1517
public void end(Koth koth) {
16-
// TODO Auto-generated method stub
17-
18+
// No hologram plugin available - do nothing
1819
}
1920

2021
@Override
2122
public void update(Koth koth) {
22-
// TODO Auto-generated method stub
23-
23+
// No hologram plugin available - do nothing
2424
}
2525

2626
@Override
2727
public void onDisable() {
28-
// TODO Auto-generated method stub
29-
28+
// No hologram plugin available - do nothing
3029
}
3130

3231
}

src/main/java/fr/maxlego08/koth/hook/ScoreboardPlugin.java

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

33
import fr.maxlego08.koth.api.KothPlugin;
44
import fr.maxlego08.koth.api.KothScoreboard;
5+
import fr.maxlego08.koth.hook.scoreboard.DefaultHook;
6+
import fr.maxlego08.koth.zcore.logger.Logger;
57
import org.bukkit.Bukkit;
68
import org.bukkit.plugin.Plugin;
79

@@ -36,8 +38,8 @@ public KothScoreboard init(KothPlugin plugin) {
3638
Class<?> clazz = Class.forName(this.className);
3739
return (KothScoreboard) clazz.getConstructor(KothPlugin.class).newInstance(plugin);
3840
} catch (Exception exception) {
39-
exception.printStackTrace();
41+
Logger.info("Failed to initialize " + this.pluginName + " scoreboard hook: " + exception.getMessage(), Logger.LogType.ERROR);
4042
}
41-
return null;
43+
return new DefaultHook();
4244
}
4345
}

src/main/java/fr/maxlego08/koth/hook/TeamPlugin.java

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

33
import fr.maxlego08.koth.api.KothPlugin;
44
import fr.maxlego08.koth.api.KothTeam;
5+
import fr.maxlego08.koth.hook.teams.NoneHook;
6+
import fr.maxlego08.koth.zcore.logger.Logger;
57
import org.bukkit.Bukkit;
68
import org.bukkit.plugin.Plugin;
79

@@ -41,8 +43,8 @@ public KothTeam init(KothPlugin plugin) {
4143
Class<?> clazz = Class.forName(this.className);
4244
return (KothTeam) clazz.getConstructor(KothPlugin.class).newInstance(plugin);
4345
} catch (Exception exception) {
44-
exception.printStackTrace();
46+
Logger.info("Failed to initialize " + this.pluginName + " team hook: " + exception.getMessage(), Logger.LogType.ERROR);
4547
}
46-
return null;
48+
return new NoneHook();
4749
}
4850
}

0 commit comments

Comments
 (0)