created the tag handler registry

This commit is contained in:
Alastair 2016-07-31 02:32:27 +00:00
parent c3f466720d
commit 75419c00bc
2 changed files with 30 additions and 24 deletions

View File

@ -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;
}
}

View File

@ -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<String> tags = new ArrayList<String>();
private Map<String, TagInfo> tagDesc = new HashMap<String, TagInfo>();
private Map<String, TagHandler.Activation> tagActivation = new HashMap<String, TagHandler.Activation>();
private Map<String, TagHandler.Creation> tagCreation = new HashMap<String, TagHandler.Creation>();
private Map<String, TagHandler.TagStatus> tagStatus = new HashMap<String, TagHandler.TagStatus>();
// 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;