-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
PlayerMovementHandler.java
64 lines (59 loc) · 2.32 KB
/
PlayerMovementHandler.java
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
package com.cjburkey.claimchunk.event;
import java.util.UUID;
import java.util.regex.Pattern;
import org.bukkit.Chunk;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import com.cjburkey.claimchunk.ClaimChunk;
import com.cjburkey.claimchunk.Config;
import com.cjburkey.claimchunk.Utils;
import com.cjburkey.claimchunk.chunk.AutoClaimHandler;
import com.cjburkey.claimchunk.chunk.ChunkHandler;
import com.cjburkey.claimchunk.cmd.MainHandler;
import com.cjburkey.claimchunk.player.PlayerHandler;
public class PlayerMovementHandler implements Listener {
@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
if (e != null && e.getPlayer() != null && !e.isCancelled()) {
Chunk prev = e.getFrom().getChunk();
Chunk to = e.getTo().getChunk();
if (prev != to) {
if (AutoClaimHandler.inList(e.getPlayer())) {
MainHandler.claimChunk(e.getPlayer(), to);
}
ChunkHandler ch = ClaimChunk.getInstance().getChunkHandler();
boolean lastClaimed = ch.isClaimed(prev.getWorld(), prev.getX(), prev.getZ());
if (ch.isClaimed(to.getWorld(), to.getX(), to.getZ())) {
if (lastClaimed) {
UUID prevOwner = ch.getOwner(prev.getWorld(), prev.getX(), prev.getZ());
UUID newOwner = ch.getOwner(to.getWorld(), to.getX(), to.getZ());
if (!prevOwner.equals(newOwner)) {
showTitle(e.getPlayer(), to);
}
} else {
showTitle(e.getPlayer(), to);
}
} else {
if (lastClaimed) {
Utils.toPlayer(e.getPlayer(), Config.getColor("infoColor"), Utils.getMsg("chunkLeave"));
}
}
}
}
}
private void showTitle(Player player, Chunk newChunk) {
UUID newOwner = ClaimChunk.getInstance().getChunkHandler().getOwner(newChunk.getWorld(), newChunk.getX(), newChunk.getZ());
if (!newOwner.equals(player.getUniqueId())) {
PlayerHandler nh = ClaimChunk.getInstance().getPlayerHandler();
String newName = (nh.hasChunkName(newOwner)) ? nh.getChunkName(newOwner) : nh.getChunkName(newOwner);
if (newName != null) {
String text = Utils.getMsg("chunkOwner").replaceAll(Pattern.quote("%%PLAYER%%"), newName);
Utils.toPlayer(player, Config.getColor("infoColor"), text);
}
} else {
Utils.toPlayer(player, Config.getColor("infoColor"), Utils.getMsg("chunkSelf"));
}
}
}