mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-26 12:36:11 +01:00
Updated tag registry
This commit is contained in:
parent
a8ce8e7d42
commit
7c8228558f
@ -3,6 +3,8 @@ package com.sekwah.advancedportals.core;
|
||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.api.managers.DestinationManager;
|
||||
import com.sekwah.advancedportals.core.api.managers.PortalManager;
|
||||
import com.sekwah.advancedportals.core.api.registry.TagRegistry;
|
||||
import com.sekwah.advancedportals.core.api.registry.WarpEffectRegistry;
|
||||
import com.sekwah.advancedportals.core.commands.CommandWithSubCommands;
|
||||
import com.sekwah.advancedportals.core.commands.subcommands.portal.ReloadSubCommand;
|
||||
import com.sekwah.advancedportals.core.commands.subcommands.portal.TransUpdateSubCommand;
|
||||
@ -20,7 +22,10 @@ public class AdvancedPortalsCore {
|
||||
private final DataStorage dataStorage;
|
||||
private final InfoLogger infoLogger;
|
||||
|
||||
private final CoreListeners coreListeners;
|
||||
private WarpEffectRegistry warpEffectRegistry;
|
||||
private TagRegistry tagRegistry;
|
||||
|
||||
private CoreListeners coreListeners;
|
||||
|
||||
private Config config;
|
||||
|
||||
@ -38,9 +43,6 @@ public class AdvancedPortalsCore {
|
||||
this.infoLogger = infoLogger;
|
||||
this.instance = this;
|
||||
this.commandRegister = commandRegister;
|
||||
this.coreListeners = new CoreListeners(this);
|
||||
this.portalManager = new PortalManager(this);
|
||||
this.destiManager = new DestinationManager(this);
|
||||
this.onEnable();
|
||||
}
|
||||
|
||||
@ -49,6 +51,12 @@ public class AdvancedPortalsCore {
|
||||
}
|
||||
|
||||
private void onEnable() {
|
||||
this.coreListeners = new CoreListeners(this);
|
||||
this.portalManager = new PortalManager(this);
|
||||
this.destiManager = new DestinationManager(this);
|
||||
this.warpEffectRegistry = new WarpEffectRegistry();
|
||||
this.tagRegistry = new TagRegistry();
|
||||
|
||||
this.dataStorage.copyDefaultFile("lang/en_GB.lang", false);
|
||||
|
||||
this.loadPortalConfig();
|
||||
|
@ -16,10 +16,6 @@ import java.util.Map;
|
||||
*/
|
||||
public class TagRegistry {
|
||||
|
||||
// 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.
|
||||
private static TagRegistry instance = new TagRegistry();
|
||||
|
||||
/**
|
||||
* List of tag names which should be in order alphabetically
|
||||
*/
|
||||
@ -39,9 +35,9 @@ public class TagRegistry {
|
||||
* @param tagHandler
|
||||
* @return if the tag was registered
|
||||
*/
|
||||
public static boolean registerTag(String tag, String desc, TagHandler tagHandler) {
|
||||
public boolean registerTag(String tag, String desc, TagHandler tagHandler) {
|
||||
if (registerTag(tag, tagHandler)) {
|
||||
instance.tagDesc.put(tag, desc);
|
||||
this.tagDesc.put(tag, desc);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -54,19 +50,19 @@ public class TagRegistry {
|
||||
* @param tag
|
||||
* @return if the tag was registered
|
||||
*/
|
||||
public static boolean registerTag(String tag) {
|
||||
public boolean registerTag(String tag) {
|
||||
if (tag.contains(" ")) {
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning("The tag '"
|
||||
+ tag + "' is invalid as it contains spaces.");
|
||||
return false;
|
||||
}
|
||||
if (instance.tags.contains(tag)) {
|
||||
if (this.tags.contains(tag)) {
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning("The tag "
|
||||
+ tag + " has already been registered.");
|
||||
return false;
|
||||
}
|
||||
instance.tags.add(tag);
|
||||
Collections.sort(instance.tags);
|
||||
this.tags.add(tag);
|
||||
Collections.sort(this.tags);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -77,29 +73,29 @@ public class TagRegistry {
|
||||
* @param desc
|
||||
* @return if the tag was registered
|
||||
*/
|
||||
public static boolean registerTag(String tag, String desc) {
|
||||
public boolean registerTag(String tag, String desc) {
|
||||
if (registerTag(tag)) {
|
||||
instance.tagDesc.put(tag, desc);
|
||||
this.tagDesc.put(tag, desc);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isTagRegistered(String tag){
|
||||
return instance.tagDesc.containsKey(tag);
|
||||
public boolean isTagRegistered(String tag){
|
||||
return this.tagDesc.containsKey(tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the tag has been registered or if it already exists.
|
||||
*/
|
||||
public static boolean registerTag(String tag, TagHandler tagHandler) {
|
||||
public boolean registerTag(String tag, TagHandler tagHandler) {
|
||||
|
||||
if (tag == null) {
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning("A tag cannot be null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!registerTag(tag)) {
|
||||
if (!this.registerTag(tag)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -107,13 +103,13 @@ public class TagRegistry {
|
||||
!(tagHandler instanceof TagHandler.Creation)) {
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning("Error with tag: " + tag + ". A tag handler must implement one of the handlers. Not just extend.");
|
||||
if (tagHandler instanceof TagHandler.Activation) {
|
||||
instance.activationHandlers.put(tag, (TagHandler.Activation) tagHandler);
|
||||
this.activationHandlers.put(tag, (TagHandler.Activation) tagHandler);
|
||||
}
|
||||
if (tagHandler instanceof TagHandler.TagStatus) {
|
||||
instance.statusHandlers.put(tag, (TagHandler.TagStatus) tagHandler);
|
||||
this.statusHandlers.put(tag, (TagHandler.TagStatus) tagHandler);
|
||||
}
|
||||
if (tagHandler instanceof TagHandler.Creation) {
|
||||
instance.creationHandlers.put(tag, (TagHandler.Creation) tagHandler);
|
||||
this.creationHandlers.put(tag, (TagHandler.Creation) tagHandler);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -16,8 +16,6 @@ public class WarpEffectRegistry {
|
||||
|
||||
private Map<String, WarpEffect> soundEffects = new HashMap();
|
||||
|
||||
private static final WarpEffectRegistry instance = new WarpEffectRegistry();
|
||||
|
||||
/**
|
||||
* Register a new warp effect.
|
||||
*
|
||||
@ -25,17 +23,17 @@ public class WarpEffectRegistry {
|
||||
* @param effect
|
||||
* @return if the effect was registered
|
||||
*/
|
||||
public static boolean registerEffect(String name, WarpEffect effect) {
|
||||
public boolean registerEffect(String name, WarpEffect effect) {
|
||||
if(name == null){
|
||||
return false;
|
||||
}
|
||||
Map<String, WarpEffect> list = null;
|
||||
switch (effect.getType()){
|
||||
case SOUND:
|
||||
list = instance.soundEffects;
|
||||
list = this.soundEffects;
|
||||
break;
|
||||
case VISUAL:
|
||||
list = instance.visualEffects;
|
||||
list = this.visualEffects;
|
||||
break;
|
||||
default:
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning(effect.getType().toString()
|
||||
@ -49,14 +47,14 @@ public class WarpEffectRegistry {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static WarpEffect getEffect(String name, WarpEffect.Type type){
|
||||
public WarpEffect getEffect(String name, WarpEffect.Type type){
|
||||
Map<String, WarpEffect> list = null;
|
||||
switch (type){
|
||||
case SOUND:
|
||||
list = instance.soundEffects;
|
||||
list = this.soundEffects;
|
||||
break;
|
||||
case VISUAL:
|
||||
list = instance.visualEffects;
|
||||
list = this.visualEffects;
|
||||
break;
|
||||
default:
|
||||
AdvancedPortalsCore.getInfoLogger().logWarning(type.toString()
|
||||
|
@ -18,4 +18,8 @@ public class CommandSenderContainer {
|
||||
public boolean isOp() {
|
||||
return sender.isOp();
|
||||
}
|
||||
|
||||
public boolean hasPermission(String permission) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -30,4 +30,8 @@ public class PlayerContainer {
|
||||
public PlayerLocation getLoc() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasPermission(String permission) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user