Add some events for warp access

This commit is contained in:
Aria 2023-02-28 21:42:19 -07:00
parent 1542891f6d
commit 984cb45b02
4 changed files with 85 additions and 11 deletions

View file

@ -70,18 +70,29 @@ public class AccessControlList {
return ids;
}
public void add(ServerPlayer player)
/**
* Adds a ACL Entry for a name and ID
* @param name
* @param id
* @return null if the entry was already in the ACL
* @return Entry if the entry was successfully added to the ACL
*/
public ACLEntry addEntry(String name, UUID id)
{
ACLEntry entry = new ACLEntry(player.getName().getContents(), player.getUUID());
ACLEntry entry = new ACLEntry(name, id);
if(getIDs().contains(id)) return null;
entries.add(entry);
return entry;
}
public void addEntry(String name, UUID id)
{
entries.add(new ACLEntry(name, id));
}
public void removeByID(UUID ID)
/**
* Removes a ACLEntry by UUID
* @param ID
* @return null if no such entry
* @return Entry that was removed from the list
*/
public ACLEntry removeByID(UUID ID)
{
Iterator<ACLEntry> entr = entries.iterator();
while(entr.hasNext())
@ -90,9 +101,11 @@ public class AccessControlList {
if(entry.id==ID)
{
entr.remove();
return;
return entry;
}
}
return null;
}
/**

View file

@ -5,6 +5,8 @@ import java.util.List;
import java.util.UUID;
import dev.zontreck.essentials.commands.teleport.TeleportDestination;
import dev.zontreck.essentials.events.WarpAccessControlListUpdatedEvent;
import dev.zontreck.essentials.warps.AccessControlList.ACLEntry;
import dev.zontreck.libzontreck.exceptions.InvalidDeserialization;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntArrayTag;
@ -12,6 +14,7 @@ import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.nbt.Tag;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.common.MinecraftForge;
public class Warp {
public UUID owner;
@ -97,7 +100,8 @@ public class Warp {
{
if(!isPublic)
{
ACL.addEntry(name, ID);
ACLEntry entry = ACL.addEntry(name, ID);
MinecraftForge.EVENT_BUS.post(new WarpAccessControlListUpdatedEvent(this, entry, true));
}else return;
}
@ -117,7 +121,8 @@ public class Warp {
{
if(ACL.getIDs().contains(id))
{
ACL.removeByID(id);
ACLEntry entry = ACL.removeByID(id);
MinecraftForge.EVENT_BUS.post(new WarpAccessControlListUpdatedEvent(this, entry, false));
}
}