diff --git a/src/main/java/dev/zontreck/essentials/Messages.java b/src/main/java/dev/zontreck/essentials/Messages.java index 82c3673..3000093 100644 --- a/src/main/java/dev/zontreck/essentials/Messages.java +++ b/src/main/java/dev/zontreck/essentials/Messages.java @@ -17,6 +17,8 @@ public class Messages { public static final String WARP_STANDARD; public static final String WARP_ACCESS_FORMAT; + public static final String PUBLIC; + public static final String PRIVATE; static{ ESSENTIALS_PREFIX = "!Gray![!Dark_Green!AE!Gray!] "; @@ -33,6 +35,8 @@ public class Messages { WARP_OWNER = "!Dark_Purple!The warp's owner is [0][1]"; COUNT = ESSENTIALS_PREFIX + "!Dark_Purple!There are [0] [1](s) available"; - WARP_ACCESS_FORMAT = "This warp is [0]"; + WARP_ACCESS_FORMAT = "!Dark_Purple!This warp is [0]"; + PUBLIC = "!Dark_Green!Public"; + PRIVATE = "!Dark_Red!Private"; } } diff --git a/src/main/java/dev/zontreck/essentials/commands/warps/WarpsCommand.java b/src/main/java/dev/zontreck/essentials/commands/warps/WarpsCommand.java index 99589b7..dfe52ae 100644 --- a/src/main/java/dev/zontreck/essentials/commands/warps/WarpsCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/warps/WarpsCommand.java @@ -79,7 +79,9 @@ public class WarpsCommand { HoverEvent h2 = HoverTip.get( ChatHelpers.macroize(Messages.WARP_HOVER_FORMAT, ChatHelpers.macroize(Messages.WARP_OWNER, prof.name_color, prof.nickname), - ChatHelpers.macroize(Messages.WARP_ACCESS_FORMAT, ) + ChatHelpers.macroize(Messages.WARP_ACCESS_FORMAT, + (warp.isPublic ? ChatHelpers.macroize(Messages.PUBLIC) : ChatHelpers.macroize(Messages.PRIVATE)) + ) ) ); diff --git a/src/main/java/dev/zontreck/essentials/warps/Warp.java b/src/main/java/dev/zontreck/essentials/warps/Warp.java index 7bcd896..a447b1d 100644 --- a/src/main/java/dev/zontreck/essentials/warps/Warp.java +++ b/src/main/java/dev/zontreck/essentials/warps/Warp.java @@ -1,10 +1,17 @@ package dev.zontreck.essentials.warps; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import dev.zontreck.essentials.commands.teleport.TeleportDestination; import dev.zontreck.libzontreck.exceptions.InvalidDeserialization; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.IntArrayTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.NbtUtils; +import net.minecraft.nbt.Tag; +import net.minecraft.server.level.ServerPlayer; public class Warp { public UUID owner; @@ -12,6 +19,7 @@ public class Warp { public boolean RTP; public boolean isPublic; public TeleportDestination destination; + private List ACL; public Warp(UUID owner, String name, boolean rtp, boolean publicWarp, TeleportDestination destination) { @@ -20,11 +28,29 @@ public class Warp { RTP=rtp; isPublic=publicWarp; this.destination=destination; + this.ACL = new ArrayList<>(); } public static Warp deserialize(CompoundTag tag) throws InvalidDeserialization { - return new Warp(tag.getUUID("owner"), tag.getString("name"), tag.getBoolean("rtp"), tag.getBoolean("public"), new TeleportDestination(tag.getCompound("destination"))); + Warp warp = new Warp(tag.getUUID("owner"), tag.getString("name"), tag.getBoolean("rtp"), tag.getBoolean("public"), new TeleportDestination(tag.getCompound("destination"))); + List acl = new ArrayList<>(); + + if(!warp.isPublic) + { + + ListTag lst = tag.getList("acl", Tag.TAG_INT_ARRAY); + if(lst!=null){ + + for (Tag tag2 : lst) { + IntArrayTag tag3 = (IntArrayTag)tag2; + acl.add(NbtUtils.loadUUID(tag3)); + } + warp.ACL=acl; + } + } + + return warp; } public CompoundTag serialize() @@ -35,7 +61,88 @@ public class Warp { tag.putBoolean("rtp", RTP); tag.putBoolean("public", isPublic); tag.put("destination", destination.serialize()); + if(!isPublic) + { + + ListTag lst = new ListTag(); + for(UUID id : ACL) + { + lst.add(NbtUtils.createUUID(id)); + } + tag.put("acl", lst); + } return tag; } + + /** + * Checks if a player has access to a warp + * @param player + * @return + */ + public boolean hasAccess(ServerPlayer player) + { + return hasAccess(player.getUUID()); + } + + /** + * Checks if an ID has access to the warp + * @param ID + * @return + */ + public boolean hasAccess(UUID ID) + { + if(isPublic)return true; + return ACL.contains(ID); + } + + /** + * Alias for Warp#giveAccess(UUID) + * @param player + */ + protected void giveAccess(ServerPlayer player) + { + giveAccess(player.getUUID()); + } + + /** + * If the warp is not public, it gives an ID access to the warp + * @param ID + */ + protected void giveAccess(UUID ID) + { + if(!isPublic) + { + ACL.add(ID); + }else return; + } + + /** + * Takes away access to the warp + * @param player + */ + protected void removeAccess(ServerPlayer player) + { + removeAccess(player.getUUID()); + } + /** + * Takes away access to the warp + * @param id + */ + protected void removeAccess(UUID id) + { + if(ACL.contains(id)) + { + ACL.remove(id); + } + } + + /** + * Returns a copy of the ACL List as it was when the request was made. + * @return + */ + protected List getWarpACL() + { + return new ArrayList(ACL); + } }