From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Ivan Pekov Date: Wed, 9 Sep 2020 16:14:00 +0300 Subject: [PATCH] ProxyForwardDataEvent diff --git a/src/main/java/net/yatopia/api/event/ProxyForwardDataEvent.java b/src/main/java/net/yatopia/api/event/ProxyForwardDataEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..22775d2d03ccd4c7decebc3e26b453efd44d865b --- /dev/null +++ b/src/main/java/net/yatopia/api/event/ProxyForwardDataEvent.java @@ -0,0 +1,114 @@ +package net.yatopia.api.event; + +import com.google.common.collect.ImmutableList; +import com.mojang.authlib.properties.Property; +import java.util.List; +import java.util.UUID; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +/** + * Called when a proxy such as BungeeCord or Velocity forwards player data to the server. + */ +public class ProxyForwardDataEvent extends Event { + + private final UUID uuid; + private final String name; + private List properties; + + public ProxyForwardDataEvent(boolean async, UUID uuid, String name, List properties) { + super(async); + this.uuid = uuid; + this.name = name; + this.properties = properties; + } + + /** + * Returns the unique id of the profile forwarded. + * + * @return unique id + */ + public UUID getUuid() { + return uuid; + } + + /** + * Returns the name of the profile forwarded. + * + * @return name + */ + public String getName() { + return name; + } + + /** + * Returns an immutable copy of the forwarded properties. + * + * @return properties + */ + public List getProperties() { + return ImmutableList.copyOf(properties); + } + + /** + * Adds a property to this game profile. If the property already exists, it overrides it. + * + * @param property property + */ + public void addProperty(Property property) { + if (hasProperty(property.getName())) { + removeProperty(property.getName()); + } + properties.add(property); + } + + /** + * Returns the property with the specified name. + * + * @param property the property's name you want to get + * @return property if present + */ + public Property getProperty(String property) { + for (Property prop : properties) { + if (prop.getName().toLowerCase().equalsIgnoreCase(property.toLowerCase())) { + return prop; + } + } + return null; + } + + /** + * Returns whether or not there's a property with the specified name. + * + * @param property the name of the property you want to check if exists + * @return boolean value + */ + public boolean hasProperty(String property) { + return getProperty(property) != null; + } + + /** + * Removes the specified property if present + * + * @param property the property's name you want to remove + */ + public void removeProperty(String property) { + properties.removeIf(prop -> prop.getName().toLowerCase().equalsIgnoreCase(property.toLowerCase())); + } + + /** + * Removes the specified property if present + * + * @param property the property you want to remove + */ + public void removeProperty(Property property) { + properties.remove(property); + } + + // + private static final HandlerList handlers = new HandlerList(); + @NotNull @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + // +}