Cleaned imports and changed warp data

This commit is contained in:
sekwah 2018-02-21 15:38:08 +00:00 committed by Sekwah
parent a08b60c64f
commit d7890a7d07
10 changed files with 110 additions and 50 deletions

View File

@ -189,11 +189,11 @@ public class AdvancedPortalsCore {
return instance.destiManager;
}
public static TagRegistry getPortalTagRegistry() {
public static TagRegistry<AdvancedPortal> getPortalTagRegistry() {
return instance.portalTagRegistry;
}
public static TagRegistry getDestinationTagRegistry() {
public static TagRegistry<Destination> getDestinationTagRegistry() {
return instance.destiTagRegistry;
}
}

View File

@ -1,9 +1,18 @@
package com.sekwah.advancedportals.core.api.destination;
import com.google.gson.annotations.SerializedName;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.portal.DataTag;
import com.sekwah.advancedportals.core.api.portal.PortalException;
import com.sekwah.advancedportals.core.api.registry.TagRegistry;
import com.sekwah.advancedportals.core.api.warphandler.ActivationData;
import com.sekwah.advancedportals.core.api.warphandler.TagHandler;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* Possibly look at adding the ability to add some tags to destinations such as permissions. Would make it easier
@ -22,10 +31,16 @@ public class Destination {
@SerializedName("a")
private HashMap<String, String> args = new HashMap<>();
private transient Set<String> argsCol;
public Destination(PlayerLocation loc) {
this.loc = loc;
}
public String getArg(String argName) {
return this.args.get(argName);
}
public void setArg(String argName, String argValue) {
this.args.put(argName, argValue);
}
@ -33,4 +48,53 @@ public class Destination {
public void removeArg(String arg) {
this.args.remove(arg);
}
public boolean activate(PlayerContainer player) {
ActivationData data = new ActivationData();
try {
this.portalActivate(player, data);
} catch (PortalException e) {
// TODO add portal error message
e.printStackTrace();
}
this.postActivate(player, data);
return true;
}
public boolean portalActivate(PlayerContainer player, ActivationData data) throws PortalException {
TagRegistry<Destination> tagRegistry = AdvancedPortalsCore.getDestinationTagRegistry();
DataTag[] destiTags = new DataTag[args.size()];
int i = 0;
for(Map.Entry<String, String> entry : args.entrySet()) {
destiTags[i++] = new DataTag(entry.getKey(), entry.getValue());
}
for(DataTag destiTag : destiTags) {
TagHandler.Activation<Destination> activationHandler = tagRegistry.getActivationHandler(destiTag.NAME);
if(activationHandler != null) {
activationHandler.preActivated(this, player, data, this.getArg(destiTag.NAME));
}
}
for(DataTag destiTag : destiTags) {
TagHandler.Activation<Destination> activationHandler = tagRegistry.getActivationHandler(destiTag.NAME);
if(activationHandler != null) {
activationHandler.activated(this, player, data, this.getArg(destiTag.NAME));
}
}
return true;
}
public void postActivate(PlayerContainer player, ActivationData data) {
TagRegistry<Destination> tagRegistry = AdvancedPortalsCore.getDestinationTagRegistry();
DataTag[] destiTags = new DataTag[args.size()];
int i = 0;
for(Map.Entry<String, String> entry : args.entrySet()) {
destiTags[i++] = new DataTag(entry.getKey(), entry.getValue());
}
for(DataTag destiTag : destiTags) {
TagHandler.Activation<Destination> activationHandler = tagRegistry.getActivationHandler(destiTag.NAME);
if(activationHandler != null) {
activationHandler.postActivated(this, player, data, this.getArg(destiTag.NAME));
}
}
}
}

View File

@ -7,15 +7,9 @@ import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
/**
* @author sekwah41
*/
public class TestEffect implements WarpEffect {
public class TestEffect extends WarpEffect {
@Override
public void onWarp(PlayerContainer player, PortalLocation loc, Action action, AdvancedPortal portal) {
void onWarp(PlayerContainer player, PortalLocation loc, Action action, Type type, AdvancedPortal portal) {
}
@Override
public Type getType() {
return null;
}
}

View File

@ -13,18 +13,16 @@ import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
*
* @author sekwah41
*/
public interface WarpEffect {
public abstract class WarpEffect {
void onWarp(PlayerContainer player, PortalLocation loc, Action action, AdvancedPortal portal);
abstract void onWarp(PlayerContainer player, PortalLocation loc, Action action, Type type, AdvancedPortal portal);
Type getType();
enum Action {
public enum Action {
ENTER,
EXIT;
}
enum Type {
public enum Type {
SOUND,
VISUAL;
}

View File

@ -6,7 +6,6 @@ import com.sekwah.advancedportals.core.api.destination.Destination;
import com.sekwah.advancedportals.core.api.portal.DataTag;
import com.sekwah.advancedportals.core.api.portal.DestinationException;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
import java.lang.reflect.Type;

View File

@ -149,7 +149,9 @@ public class PortalManager {
}
for(DataTag portalTag : tags) {
TagHandler.Creation<AdvancedPortal> creation = AdvancedPortalsCore.getPortalTagRegistry().getCreationHandler(portalTag.NAME);
creation.created(portal, player, portalTag.VALUE);
if(creation != null) {
creation.created(portal, player, portalTag.VALUE);
}
}
if(name == null || name.equals("")) {
throw new PortalException("portal.error.noname");

View File

@ -11,7 +11,6 @@ import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* @author sekwah41
@ -25,13 +24,11 @@ public class AdvancedPortal {
private PortalLocation minLoc;
@SerializedName("t")
private String triggerBlock;
private String[] triggerBlocks = {"PORTAL"};
@SerializedName("a")
private HashMap<String, String> args = new HashMap<>();
private transient Set<String> argsCol;
public AdvancedPortal(PortalLocation maxLoc, PortalLocation minLoc) {
this.maxLoc = maxLoc;
this.minLoc = minLoc;
@ -51,42 +48,52 @@ public class AdvancedPortal {
public void setArg(String argName, String argValue) {
this.args.put(argName, argValue);
this.updateArgsCol();
}
private void updateArgsCol() {
this.argsCol = this.args.keySet();
}
public void removeArg(String arg) {
this.args.remove(arg);
this.updateArgsCol();
}
public boolean activatePortal(PlayerContainer player) {
TagRegistry tagRegistry = AdvancedPortalsCore.getPortalTagRegistry();
public boolean hasTriggerBlock(String blockMaterial) {
for(String triggerBlock : triggerBlocks) {
if(blockMaterial.equals(triggerBlock)) {
return true;
}
}
return false;
}
public boolean activate(PlayerContainer player) {
TagRegistry<AdvancedPortal> tagRegistry = AdvancedPortalsCore.getPortalTagRegistry();
ActivationData data = new ActivationData();
DataTag[] portalTags = new DataTag[argsCol.size()];
String[] argNames = argsCol.toArray(new String[argsCol.size()]);
for (int i = 0; i < argNames.length; i++) {
portalTags[i] = new DataTag(argNames[i], this.getArg(argNames[i]));
DataTag[] portalTags = new DataTag[args.size()];
int i = 0;
for(Map.Entry<String, String> entry : args.entrySet()) {
portalTags[i++] = new DataTag(entry.getKey(), entry.getValue());
}
try {
for(DataTag portalTag : portalTags) {
TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
activationHandler.preActivated(this, player, data, this.getArg(portalTag.NAME));
TagHandler.Activation<AdvancedPortal> activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
if(activationHandler != null) {
activationHandler.preActivated(this, player, data, this.getArg(portalTag.NAME));
}
}
for(DataTag portalTag : portalTags) {
TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
activationHandler.activated(this, player, data, this.getArg(portalTag.NAME));
TagHandler.Activation<AdvancedPortal> activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
if(activationHandler != null) {
activationHandler.activated(this, player, data, this.getArg(portalTag.NAME));
}
}
}
catch(PortalException e) {
// TODO add portal error message
e.printStackTrace();
}
for(DataTag portalTag : portalTags) {
TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
activationHandler.postActivated(this, player, data, this.getArg(portalTag.NAME));
TagHandler.Activation<AdvancedPortal> activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
if(activationHandler != null) {
activationHandler.postActivated(this, player, data, this.getArg(portalTag.NAME));
}
}
return true;
}
@ -100,6 +107,6 @@ public class AdvancedPortal {
for(Map.Entry<String, String> entry : this.args.entrySet()){
tagList.add(new DataTag(entry.getKey(), entry.getValue()));
}
return tagList ;
return tagList;
}
}

View File

@ -23,12 +23,12 @@ public class WarpEffectRegistry {
* @param effect
* @return if the effect was registered
*/
public boolean registerEffect(String name, WarpEffect effect) {
public boolean registerEffect(String name, WarpEffect effect, WarpEffect.Type type) {
if(name == null){
return false;
}
Map<String, WarpEffect> list = null;
switch (effect.getType()){
switch (type){
case SOUND:
list = this.soundEffects;
break;
@ -36,7 +36,7 @@ public class WarpEffectRegistry {
list = this.visualEffects;
break;
default:
AdvancedPortalsCore.getInfoLogger().logWarning(effect.getType().toString()
AdvancedPortalsCore.getInfoLogger().logWarning(type.toString()
+ " effect type not recognised");
return false;
}

View File

@ -12,10 +12,6 @@ public class ActivationData {
private PlayerLocation wantedLocation;
/*public ActivationData(Portal portal){
this.activePortal = portal;
}
*/
public WarpedStatus getWarped() {
return this.warpStatus;
}

View File

@ -30,7 +30,7 @@ public class CreateSubCommand implements SubCommand {
if(args[i].charAt(args[i].length() - 1) == '"') {
args[i] = args[i].substring(0, args[i].length() - 1);
partingValueWithSpaces = false;
portalTags.add(new DataTag(argBeingParsed, currentParsedValue));
portalTags.add(new DataTag(argBeingParsed.toLowerCase(), currentParsedValue));
}
else {
currentParsedValue += " " + args[i];
@ -45,7 +45,7 @@ public class CreateSubCommand implements SubCommand {
currentParsedValue = arg;
}
else {
portalTags.add(new DataTag(detectedTag, arg));
portalTags.add(new DataTag(detectedTag.toLowerCase(), arg));
}
}
}