From 5183684f2ff2c2ef67d666a7003c63a2c2759c6c Mon Sep 17 00:00:00 2001 From: Alastair Date: Sun, 31 Jul 2016 02:32:27 +0000 Subject: [PATCH] created the tag handler registry --- .../advancedportals/api/registry/TagInfo.java | 16 -------- .../api/registry/TagRegistry.java | 38 +++++++++++++++---- 2 files changed, 30 insertions(+), 24 deletions(-) delete mode 100644 src/com/sekwah/advancedportals/api/registry/TagInfo.java diff --git a/src/com/sekwah/advancedportals/api/registry/TagInfo.java b/src/com/sekwah/advancedportals/api/registry/TagInfo.java deleted file mode 100644 index 4eaf9bf7..00000000 --- a/src/com/sekwah/advancedportals/api/registry/TagInfo.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.sekwah.advancedportals.api.registry; - -/** - * Created by on 25/07/2016. - * - * @author sekwah41 - */ -public class TagInfo { - - private final String dataType; - - public TagInfo(String tag, String dataType){ - this.dataType = dataType; - } - -} diff --git a/src/com/sekwah/advancedportals/api/registry/TagRegistry.java b/src/com/sekwah/advancedportals/api/registry/TagRegistry.java index ee89b153..d0916db8 100644 --- a/src/com/sekwah/advancedportals/api/registry/TagRegistry.java +++ b/src/com/sekwah/advancedportals/api/registry/TagRegistry.java @@ -1,5 +1,6 @@ package com.sekwah.advancedportals.api.registry; +import com.sekwah.advancedportals.AdvancedPortalsPlugin; import com.sekwah.advancedportals.api.warphandler.TagHandler; import java.util.ArrayList; @@ -13,15 +14,21 @@ import java.util.Map; */ public class TagRegistry { + private final AdvancedPortalsPlugin plugin; + private ArrayList tags = new ArrayList(); - private Map tagDesc = new HashMap(); + private Map tagActivation = new HashMap(); + + private Map tagCreation = new HashMap(); + + private Map tagStatus = 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(){ - + public TagRegistry(AdvancedPortalsPlugin plugin){ + this.plugin = plugin; } @@ -30,14 +37,29 @@ public class TagRegistry { * @return if the tag has been registered or if it already exists. */ public boolean registerTag(String tag, TagHandler tagHandler){ - tagDesc. - if(tagHandler == null){ + if(tag == null){ + plugin.getLogger().warning("A tag can not be null."); + return false; } - else{ - if(!(tagHandler instanceof TagHandler.Activation) && !(tagHandler instanceof TagHandler.TagStatus) && - !(tagHandler instanceof TagHandler.Creation)){ + if(tags.contains(tag)){ + return false; + } + + tags.add(tag); + + if(tagHandler != null && !(tagHandler instanceof TagHandler.Activation) && !(tagHandler instanceof TagHandler.TagStatus) && + !(tagHandler instanceof TagHandler.Creation)){ + plugin.getLogger().warning("Error with tag: " + tag + ". A tag handler must implement one of the handlers. Not just extend."); + if(tagHandler instanceof TagHandler.Activation){ + tagActivation.put(tag, (TagHandler.Activation) tagHandler); + } + if(tagHandler instanceof TagHandler.TagStatus){ + tagStatus.put(tag, (TagHandler.TagStatus) tagHandler); + } + if(tagHandler instanceof TagHandler.Creation){ + tagCreation.put(tag, (TagHandler.Creation) tagHandler); } } return true;