Skip to content

Commit

Permalink
Support 1.17+
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Jun 14, 2022
1 parent 033f0f7 commit 7a5abd3
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 234 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>codes.wasabi</groupId>
<artifactId>xclaim</artifactId>
<version>1.3.1</version>
<version>1.4.0</version>
<packaging>jar</packaging>

<name>XClaim</name>
Expand Down Expand Up @@ -76,7 +76,7 @@
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.19-R0.1-SNAPSHOT</version>
<version>1.17-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/codes/wasabi/xclaim/api/Claim.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public class Claim {
}
players.put(uuid, set);
}
return new Claim(name, chunks, new XCPlayer(owner), global, players);
return new Claim(name, chunks, XCPlayer.of(owner), global, players);
}

private String name;
Expand Down Expand Up @@ -390,7 +390,7 @@ public boolean hasPermission(@NotNull OfflinePlayer player, @NotNull Permission

public void serialize(@NotNull ConfigurationSection section) {
section.set("name", name);
section.set("owner", owner.getOfflinePlayer().getUniqueId().toString());
section.set("owner", owner.getUniqueId().toString());
section.set("world", "");
ConfigurationSection sec;
sec = section.getConfigurationSection("chunks");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/codes/wasabi/xclaim/api/MovementRoutine.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void onMove(@NotNull PlayerMoveEvent event) {
Player ply = event.getPlayer();
if (toSet) {
if (!toClaim.equals(fromClaim)) {
OfflinePlayer claimOwner = toClaim.getOwner();
XCPlayer claimOwner = toClaim.getOwner();
Player online = claimOwner.getPlayer();
Component name;
if (online != null) {
Expand Down
226 changes: 15 additions & 211 deletions src/main/java/codes/wasabi/xclaim/api/XCPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
import codes.wasabi.xclaim.XClaim;
import org.bukkit.*;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.profile.PlayerProfile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.stream.Stream;

public class XCPlayer implements OfflinePlayer {
public class XCPlayer {

public static @NotNull XCPlayer of(@NotNull OfflinePlayer ply) {
if (ply instanceof XCPlayer xcp) return xcp;
Expand All @@ -22,14 +20,21 @@ public class XCPlayer implements OfflinePlayer {
private final String uuidString;
private final OfflinePlayer op;

XCPlayer(@NotNull UUID uuid) {
protected XCPlayer(@NotNull UUID uuid) {
uuidString = uuid.toString();
op = Bukkit.getOfflinePlayer(uuid);
}

XCPlayer(@NotNull OfflinePlayer ply) {
uuidString = ply.getUniqueId().toString();
op = ply;
protected XCPlayer(@NotNull OfflinePlayer ply) {
this(ply.getUniqueId());
}

public @NotNull OfflinePlayer getOfflinePlayer() {
return op;
}

public @Nullable Player getPlayer() {
return op.getPlayer();
}

public boolean trustPlayer(@NotNull OfflinePlayer player) {
Expand Down Expand Up @@ -60,10 +65,6 @@ public boolean playerTrusted(@NotNull OfflinePlayer player) {
return false;
}

public @NotNull OfflinePlayer getOfflinePlayer() {
return op;
}

private @NotNull List<OfflinePlayer> getCurrentTrustedPlayers() {
List<?> entries = XClaim.trustConfig.getList(uuidString, new ArrayList<String>());
List<OfflinePlayer> ret = new ArrayList<>();
Expand Down Expand Up @@ -182,7 +183,7 @@ public boolean remove(Object o) {

@Override
public boolean containsAll(@NotNull Collection<?> c) {
return getCurrentTrustedPlayers().containsAll(c);
return new HashSet<>(getCurrentTrustedPlayers()).containsAll(c);
}

@Override
Expand Down Expand Up @@ -308,209 +309,12 @@ public String toString() {
return "XCPlayer[uuid=" + op.getUniqueId() + "]";
}

@Override
public boolean isOnline() {
return op.isOnline();
}

@Override
public @Nullable String getName() {
return op.getName();
}

@Override
public @NotNull UUID getUniqueId() {
return op.getUniqueId();
}

@Override
public @NotNull PlayerProfile getPlayerProfile() {
return op.getPlayerProfile();
}

@Override
public boolean isBanned() {
return op.isBanned();
}

@Override
public boolean isWhitelisted() {
return op.isWhitelisted();
}

@Override
public void setWhitelisted(boolean value) {
op.setWhitelisted(value);
}

@Override
public @Nullable Player getPlayer() {
return op.getPlayer();
}

@Override
public long getFirstPlayed() {
return op.getFirstPlayed();
}

@Override
public long getLastPlayed() {
return op.getLastPlayed();
}

@Override
public boolean hasPlayedBefore() {
return op.hasPlayedBefore();
}

@Override
public @Nullable Location getBedSpawnLocation() {
return op.getBedSpawnLocation();
}

@Override
public long getLastLogin() {
return op.getLastLogin();
}

@Override
public long getLastSeen() {
return op.getLastSeen();
}

@Override
public void incrementStatistic(@NotNull Statistic statistic) throws IllegalArgumentException {
op.incrementStatistic(statistic);
}

@Override
public void decrementStatistic(@NotNull Statistic statistic) throws IllegalArgumentException {
op.decrementStatistic(statistic);
}

@Override
public void incrementStatistic(@NotNull Statistic statistic, int amount) throws IllegalArgumentException {
op.incrementStatistic(statistic, amount);
}

@Override
public void decrementStatistic(@NotNull Statistic statistic, int amount) throws IllegalArgumentException {
op.decrementStatistic(statistic, amount);
}

@Override
public void setStatistic(@NotNull Statistic statistic, int newValue) throws IllegalArgumentException {
op.setStatistic(statistic, newValue);
}

@Override
public int getStatistic(@NotNull Statistic statistic) throws IllegalArgumentException {
return op.getStatistic(statistic);
}

@Override
public void incrementStatistic(@NotNull Statistic statistic, @NotNull Material material) throws IllegalArgumentException {
op.incrementStatistic(statistic, material);
}

@Override
public void decrementStatistic(@NotNull Statistic statistic, @NotNull Material material) throws IllegalArgumentException {
op.decrementStatistic(statistic, material);
}

@Override
public int getStatistic(@NotNull Statistic statistic, @NotNull Material material) throws IllegalArgumentException {
return op.getStatistic(statistic, material);
}

@Override
public void incrementStatistic(@NotNull Statistic statistic, @NotNull Material material, int amount) throws IllegalArgumentException {
op.incrementStatistic(statistic, material, amount);
}

@Override
public void decrementStatistic(@NotNull Statistic statistic, @NotNull Material material, int amount) throws IllegalArgumentException {
op.decrementStatistic(statistic, material, amount);
}

@Override
public void setStatistic(@NotNull Statistic statistic, @NotNull Material material, int newValue) throws IllegalArgumentException {
op.setStatistic(statistic, material, newValue);
}

@Override
public void incrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType) throws IllegalArgumentException {
op.incrementStatistic(statistic, entityType);
}

@Override
public void decrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType) throws IllegalArgumentException {
op.decrementStatistic(statistic, entityType);
}

@Override
public int getStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType) throws IllegalArgumentException {
return op.getStatistic(statistic, entityType);
}

@Override
public void incrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int amount) throws IllegalArgumentException {
op.incrementStatistic(statistic, entityType, amount);
}

@Override
public void decrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int amount) {
op.decrementStatistic(statistic, entityType, amount);
}

@Override
public void setStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int newValue) {
op.setStatistic(statistic, entityType, newValue);
}

@Override
public @Nullable Location getLastDeathLocation() {
return op.getLastDeathLocation();
}

@Override
public @NotNull Map<String, Object> serialize() {
return op.serialize();
}

@Override
public boolean isOp() {
return op.isOp();
}

@Override
public void setOp(boolean value) {
op.setOp(value);
}

@Override
public @NotNull BanEntry banPlayer(@Nullable String reason) {
return op.banPlayer(reason);
}

@Override
public @NotNull BanEntry banPlayer(@Nullable String reason, @Nullable String source) {
return op.banPlayer(reason, source);
}

@Override
public @NotNull BanEntry banPlayer(@Nullable String reason, @Nullable Date expires) {
return op.banPlayer(reason, expires);
}

@Override
public @NotNull BanEntry banPlayer(@Nullable String reason, @Nullable Date expires, @Nullable String source) {
return op.banPlayer(reason, expires, source);
}

@Override
public @NotNull BanEntry banPlayer(@Nullable String reason, @Nullable Date expires, @Nullable String source, boolean kickIfOnline) {
return op.banPlayer(reason, expires, source, kickIfOnline);
public @Nullable String getName() {
return op.getName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import codes.wasabi.xclaim.XClaim;
import codes.wasabi.xclaim.api.Claim;
import codes.wasabi.xclaim.api.XCPlayer;
import codes.wasabi.xclaim.api.dynmap.outline.ChunkBitmap;
import codes.wasabi.xclaim.api.dynmap.outline.Point;
import codes.wasabi.xclaim.util.ColorUtil;
import codes.wasabi.xclaim.util.hull.ConvexHull;
import org.bukkit.Chunk;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.dynmap.bukkit.DynmapPlugin;
Expand Down Expand Up @@ -36,8 +36,8 @@ public String getVersion() {

private final Map<UUID, Color> colorMap = new HashMap<>();
public @NotNull Color getClaimColor(@NotNull Claim claim) {
OfflinePlayer op = claim.getOwner();
UUID uuid = op.getUniqueId();
XCPlayer ply = claim.getOwner();
UUID uuid = ply.getUniqueId();
Color color = colorMap.get(uuid);
if (color == null) {
color = ColorUtil.uuidToColor(uuid);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package codes.wasabi.xclaim.command.sub;

import codes.wasabi.xclaim.api.Claim;
import codes.wasabi.xclaim.api.XCPlayer;
import codes.wasabi.xclaim.command.Command;
import codes.wasabi.xclaim.command.argument.Argument;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -56,7 +56,7 @@ public void execute(@NotNull CommandSender sender, @NotNull Object @NotNull ...
return;
}
Component ownerName;
OfflinePlayer owner = claim.getOwner();
XCPlayer owner = claim.getOwner();
Player player = owner.getPlayer();
if (player != null) {
ownerName = player.displayName();
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/codes/wasabi/xclaim/gui/ChunkEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void onLeave(@NotNull PlayerQuitEvent event) {

@EventHandler(priority = EventPriority.HIGHEST)
public void onDeath(@NotNull PlayerDeathEvent event) {
Player ply = event.getPlayer();
Player ply = event.getEntity();
if (stopEditing(ply)) {
boolean keepInventory = false;
Boolean value = ply.getWorld().getGameRuleValue(GameRule.KEEP_INVENTORY);
Expand Down Expand Up @@ -263,9 +263,9 @@ public void onMove(@NotNull PlayerMoveEvent event) {
} else {
Claim cl = Claim.getByChunk(toChunk);
if (cl != null) {
OfflinePlayer op = cl.getOwner().getOfflinePlayer();
ownerName = Objects.requireNonNullElse(op.getName(), "Unknown");
ownState = (op.getUniqueId().equals(ply.getUniqueId()) ? 2 : 3);
XCPlayer xcp = cl.getOwner();
ownerName = Objects.requireNonNullElse(xcp.getName(), "Unknown");
ownState = (xcp.getUniqueId().equals(ply.getUniqueId()) ? 2 : 3);
}
}
Color color = Color.GRAY;
Expand Down Expand Up @@ -343,7 +343,7 @@ public static void initialize() {
Claim ret = null;
if (!editingMap.containsKey(uuid)) {
PersistentDataContainer pdc = ply.getPersistentDataContainer();
if (pdc.has(KEY_FLAG)) {
if (pdc.has(KEY_FLAG, PersistentDataType.BYTE)) {
boolean flag = pdc.getOrDefault(KEY_FLAG, PersistentDataType.BYTE, (byte) 0) != ((byte) 0);
if (flag) {
String name = pdc.get(KEY_NAME, PersistentDataType.STRING);
Expand Down
Loading

0 comments on commit 7a5abd3

Please sign in to comment.