Advanced-Portals/core/src/main/java/com/sekwah/advancedportals/core/registry/WarpEffectRegistry.java

79 lines
2.1 KiB
Java
Raw Normal View History

package com.sekwah.advancedportals.core.registry;
2018-06-06 23:29:02 +02:00
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.effect.WarpEffect;
import java.util.HashMap;
import java.util.Map;
/**
* @author sekwah41
*/
public class WarpEffectRegistry {
private Map<String, WarpEffect> visualEffects = new HashMap();
private Map<String, WarpEffect> soundEffects = new HashMap();
2018-06-06 23:29:02 +02:00
@Inject
private AdvancedPortalsCore portalsCore;
/**
* Register a new warp effect.
*
* @param name
* @param effect
* @return if the effect was registered
*/
2018-02-21 16:38:08 +01:00
public boolean registerEffect(String name, WarpEffect effect, WarpEffect.Type type) {
if(name == null){
return false;
}
Map<String, WarpEffect> list = null;
2018-02-21 16:38:08 +01:00
switch (type){
case SOUND:
2018-01-26 02:15:35 +01:00
list = this.soundEffects;
break;
case VISUAL:
2018-01-26 02:15:35 +01:00
list = this.visualEffects;
break;
default:
2018-06-06 23:29:02 +02:00
this.portalsCore.getInfoLogger().logWarning(type.toString()
+ " effect type not recognised");
return false;
}
if(list.containsKey(name)){
return false;
}
list.put(name, effect);
return true;
}
2018-01-26 02:15:35 +01:00
public WarpEffect getEffect(String name, WarpEffect.Type type){
Map<String, WarpEffect> list = null;
switch (type){
case SOUND:
2018-01-26 02:15:35 +01:00
list = this.soundEffects;
break;
case VISUAL:
2018-01-26 02:15:35 +01:00
list = this.visualEffects;
break;
default:
2018-06-06 23:29:02 +02:00
this.portalsCore.getInfoLogger().logWarning(type.toString()
+ " effect type not recognised");
return null;
}
if(list.containsKey(name)) {
return list.get(name);
}
else{
2018-06-06 23:29:02 +02:00
this.portalsCore.getInfoLogger().logWarning("No effect of type:"
+ type.toString() + " was registered with the name: " + name);
return null;
}
}
}