From c3f466720d66666fbd6777e3814d943f446fd909 Mon Sep 17 00:00:00 2001 From: Alastair Date: Sun, 31 Jul 2016 02:22:43 +0000 Subject: [PATCH] Started creating the tag handlers --- src/com/sekwah/advancedportals/Listeners.java | 4 +- .../api/registry/TagRegistry.java | 24 ++++++ .../api/warphandler/ActivationData.java | 67 +++++++++++++++ .../api/warphandler/TagHandler.java | 85 +++++++++++++++++++ 4 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 src/com/sekwah/advancedportals/api/warphandler/ActivationData.java create mode 100644 src/com/sekwah/advancedportals/api/warphandler/TagHandler.java diff --git a/src/com/sekwah/advancedportals/Listeners.java b/src/com/sekwah/advancedportals/Listeners.java index b75e993..bfb366a 100644 --- a/src/com/sekwah/advancedportals/Listeners.java +++ b/src/com/sekwah/advancedportals/Listeners.java @@ -1,6 +1,6 @@ package com.sekwah.advancedportals; -import com.sekwah.advancedportals.events.WarpEvent; +import com.sekwah.advancedportals.api.events.WarpEvent; import com.sekwah.advancedportals.portals.AdvancedPortal; import com.sekwah.advancedportals.portals.Portal; import org.bukkit.Bukkit; @@ -86,7 +86,7 @@ public class Listeners implements Listener { Player player = event.getPlayer(); - Location fromloc = event.getFrom(); + //Location fromloc = event.getFrom(); Location loc = event.getTo(); // Potentially fixes that stupid error cauzed by a bukkit update. // Would save event.getTo() as eyeLoc and change the Y position but that seemed to teleport players. diff --git a/src/com/sekwah/advancedportals/api/registry/TagRegistry.java b/src/com/sekwah/advancedportals/api/registry/TagRegistry.java index 3db0849..ee89b15 100644 --- a/src/com/sekwah/advancedportals/api/registry/TagRegistry.java +++ b/src/com/sekwah/advancedportals/api/registry/TagRegistry.java @@ -1,5 +1,7 @@ package com.sekwah.advancedportals.api.registry; +import com.sekwah.advancedportals.api.warphandler.TagHandler; + import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -15,11 +17,33 @@ public class TagRegistry { private Map tagDesc = new HashMap(); + // TODO the event can be used for general data detection and management, but use a TagHandler to make it so they can register + // the individual class to handle. + public TagRegistry(){ } + /** + * + * @return if the tag has been registered or if it already exists. + */ + public boolean registerTag(String tag, TagHandler tagHandler){ + tagDesc. + if(tagHandler == null){ + + } + else{ + if(!(tagHandler instanceof TagHandler.Activation) && !(tagHandler instanceof TagHandler.TagStatus) && + !(tagHandler instanceof TagHandler.Creation)){ + + } + } + return true; + } + + } diff --git a/src/com/sekwah/advancedportals/api/warphandler/ActivationData.java b/src/com/sekwah/advancedportals/api/warphandler/ActivationData.java new file mode 100644 index 0000000..bb8fa11 --- /dev/null +++ b/src/com/sekwah/advancedportals/api/warphandler/ActivationData.java @@ -0,0 +1,67 @@ +package com.sekwah.advancedportals.api.warphandler; + +import com.sekwah.advancedportals.portals.Portal; + +/** + * Created by on 30/07/2016. + * + * @author sekwah41 + */ +public class ActivationData { + + private boolean warpAllowed = true; + + private WarpedStatus warpStatus = WarpedStatus.INACTIVE; + + private Portal activePortal; + + public ActivationData(Portal portal){ + this.activePortal = portal; + } + + public WarpedStatus getWarped(){ + return this.warpStatus; + } + + public void setWarpStatus(WarpedStatus warped){ + if(this.warpStatus == WarpedStatus.WARPED){ + return; + } + else if(this.warpStatus == WarpedStatus.INACTIVE){ + return; + } + this.warpStatus = warped; + } + + /** + * In case you need to set the status back down a step for whatever reason. However it is not recommended. + * @param warped + */ + public void setWarpStatusAbsolute(WarpedStatus warped){ + this.warpStatus = warped; + } + + public boolean getAllowed(){ + return this.warpAllowed; + } + + public void setAllowed(boolean allowed){ + this.warpAllowed = allowed; + } + + public enum WarpedStatus{ + /** + * Player has moved or something major has happened. (only one of these should activate) + */ + WARPED, + /** + * Shows that the portal has been activated even if a major function is not performed. + */ + ACTIVATED, + /** + * Nothing has activated on the portal. + */ + INACTIVE; + } + +} diff --git a/src/com/sekwah/advancedportals/api/warphandler/TagHandler.java b/src/com/sekwah/advancedportals/api/warphandler/TagHandler.java new file mode 100644 index 0000000..f61cb52 --- /dev/null +++ b/src/com/sekwah/advancedportals/api/warphandler/TagHandler.java @@ -0,0 +1,85 @@ +package com.sekwah.advancedportals.api.warphandler; + +import com.sekwah.advancedportals.portals.Portal; +import org.bukkit.entity.Player; + +/** + * Created by on 30/07/2016. + * + * @author sekwah41 + */ +public class TagHandler { + + public interface Creation{ + + /** + * Example if the player does not have access to use a tag on the portal. + * @param player + * @param activeData + * @param argData + * @return if the portal can be created. + */ + boolean portalCreated(Player player, ActivationData activeData, String argData); + + /** + * Example if the player does not have access to remove the portal. + * @param player + * @param activeData + * @param argData + * @return if the portal can be destroyed. + */ + boolean portalDestroyed(Player player, ActivationData activeData, String argData); + + } + + public interface Activation{ + + /** + * Activates before the main part of portal activation. + * @param player + * @param activeData + * @param argData + */ + void portalPreActivated(Player player, ActivationData activeData, String argData); + + /** + * Activates after portal activation + * @param player + * @param activeData + * @param argData + */ + void portalPostActivated(Player player, ActivationData activeData, String argData); + + /** + * Activates if the portal is allowed from pre + * @param player + * @param activeData + * @param argData + */ + void portalActivated(Player player, ActivationData activeData, String argData); + + } + + public interface TagStatus{ + + /** + * If the user has access to add the tag + * @param player + * @param activeData + * @param argData + * @return if the tag will be added. + */ + boolean tagAdded(Player player, ActivationData activeData, String argData); + + /** + * If the user has access to remove the tag + * @param player + * @param activeData + * @param argData + * @return if the tag will be removed. + */ + boolean ragRemoved(Player player, ActivationData activeData, String argData); + + } + +}