Added more info for desti

This commit is contained in:
sekwah41 2018-02-03 20:31:50 +00:00 committed by Sekwah
parent cd0fc209a0
commit 188d4c1db6
15 changed files with 143 additions and 54 deletions

View File

@ -52,10 +52,12 @@ command.selector= You have been given a portal selector.
command.selector.help=Gives you a portal region selector
command.selector.detailedhelp=Gives you a portal selector to select the regions for making portals.
portal.invalidselection=You must have both pos1 and pos2 selected to create a portal.
portal.noname=No name for the portal has been given.
portal.takenname=The name given for the portal is already taken.
portal.selection.differentworlds=Both the selected points need to be in the same world.
portal.error.invalidselection=You must have both pos1 and pos2 selected to create a portal.
portal.error.noname=No name for the portal has been given.
portal.error.takenname=The name given for the portal is already taken.
portal.error.selection.differentworlds=Both the selected points need to be in the same world.
=error.notplayer=Only players can do that.
portal.selector.poschange=\u00A7eYou have selected pos%1$s X:%2$s Y:%3$s Z:%4$s

View File

@ -112,6 +112,8 @@ public class AdvancedPortalsCore {
this.portalManager.loadPortals();
this.destiManager.loadDestinations();
this.infoLogger.log(Lang.translate("logger.pluginenable"));
}

View File

@ -1,6 +1,5 @@
package com.sekwah.advancedportals.core;
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import com.sekwah.advancedportals.core.data.PortalLocation;
import com.sekwah.advancedportals.core.util.Lang;

View File

@ -1,5 +1,10 @@
package com.sekwah.advancedportals.core.api.destination;
import com.google.gson.annotations.SerializedName;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import java.util.HashMap;
/**
* Possibly look at adding the ability to add some tags to destinations such as permissions. Would make it easier
* to add permissions to block access to certain areas and such. Could be a different permission system or just
@ -10,4 +15,22 @@ package com.sekwah.advancedportals.core.api.destination;
* @author sekwah41
*/
public class Destination {
@SerializedName("l")
private PlayerLocation loc;
@SerializedName("a")
private HashMap<String, String> args = new HashMap<>();
public Destination(PlayerLocation loc) {
this.loc = loc;
}
public void setArg(String argName, String argValue) {
this.args.put(argName, argValue);
}
public void removeArg(String arg) {
this.args.remove(arg);
}
}

View File

@ -1,8 +1,16 @@
package com.sekwah.advancedportals.core.api.managers;
import com.google.gson.reflect.TypeToken;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
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;
import java.util.ArrayList;
import java.util.HashMap;
/**
@ -19,4 +27,22 @@ public class DestinationManager {
public DestinationManager(AdvancedPortalsCore portalsCore) {
this.portalsCore = portalsCore;
}
public void createDesti(PlayerContainer player, PlayerLocation playerLocation, ArrayList<DataTag> dataTags) throws DestinationException {
if(player == null) {
throw new DestinationException(Lang.translate("error.notplayer"));
}
}
public void loadDestinations() {
Type type = new TypeToken<HashMap<String, Destination>>() {
}.getType();
this.destiHashMap = this.portalsCore.getDataStorage().loadJson(type, "destinations.json");
if (this.destiHashMap == null) {
this.destiHashMap = new HashMap<>();
}
this.portalsCore.getDataStorage().storeJson(this.destiHashMap, "destinations.json");
}
}

View File

@ -3,7 +3,7 @@ package com.sekwah.advancedportals.core.api.managers;
import com.google.gson.reflect.TypeToken;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.api.portal.PortalTag;
import com.sekwah.advancedportals.core.api.portal.DataTag;
import com.sekwah.advancedportals.core.api.portal.PortalException;
import com.sekwah.advancedportals.core.api.warphandler.TagHandler;
import com.sekwah.advancedportals.core.data.PlayerLocation;
@ -94,7 +94,7 @@ public class PortalManager {
return false;
}
public void createPortal(PlayerContainer player, ArrayList<PortalTag> tags) throws PortalException {
public void createPortal(PlayerContainer player, ArrayList<DataTag> tags) throws PortalException {
if (this.portalSelectorLeftClick.containsKey(player.getUUID().toString())
&& this.portalSelectorRightClick.containsKey(player.getUUID().toString())) {
this.createPortal(player, this.portalSelectorLeftClick.get(player.getUUID().toString()),
@ -112,8 +112,8 @@ public class PortalManager {
* @return
* @throws PortalException
*/
public boolean createPortal(PortalLocation loc1, PortalLocation loc2, ArrayList<PortalTag> tags) throws PortalException {
return createPortal(null, loc1, loc2, tags);
public void createPortal(PortalLocation loc1, PortalLocation loc2, ArrayList<DataTag> tags) throws PortalException {
createPortal(null, loc1, loc2, tags);
}
@ -125,10 +125,13 @@ public class PortalManager {
* @param loc1
* @param loc2
* @param tags
* @return
* @throws PortalException
*/
public boolean createPortal(PlayerContainer player, PortalLocation loc1, PortalLocation loc2, ArrayList<PortalTag> tags) throws PortalException {
public void createPortal(PlayerContainer player, PortalLocation loc1, PortalLocation loc2, ArrayList<DataTag> tags) throws PortalException {
if(player == null) {
throw new PortalException(Lang.translate("error.notplayer"));
}
int maxX = Math.max(loc1.posX, loc2.posX);
int maxY = Math.max(loc1.posY, loc2.posY);
int maxZ = Math.max(loc1.posZ, loc2.posZ);
@ -137,31 +140,30 @@ public class PortalManager {
int minZ = Math.min(loc1.posZ, loc2.posZ);
if(!loc1.worldName.equalsIgnoreCase(loc2.worldName)) {
throw new PortalException(Lang.translate("portal.selection.differentworlds"));
throw new PortalException(Lang.translate("portal.error.selection.differentworlds"));
}
PortalLocation maxLoc = new PortalLocation(loc1.worldName, maxX, maxY, maxZ);
PortalLocation minLoc = new PortalLocation(loc1.worldName, minX, minY, minZ);
AdvancedPortal portal = new AdvancedPortal(maxLoc, minLoc);
for(PortalTag portalTag : tags) {
for(DataTag portalTag : tags) {
portal.setArg(portalTag);
}
for(PortalTag portalTag : tags) {
for(DataTag portalTag : tags) {
TagHandler.Creation creation = AdvancedPortalsCore.getTagRegistry().getCreationHandler(portalTag.NAME);
creation.portalCreated(portal, player, portalTag.VALUE);
}
String portalName = portal.getArg("name");
if(portalName == null || portalName.equals("")) {
throw new PortalException(Lang.translate("portal.noname"));
throw new PortalException(Lang.translate("portal.error.noname"));
}
else if(this.portalHashMap.containsKey(portalName)) {
throw new PortalException(Lang.translate("portal.takenname"));
throw new PortalException(Lang.translate("portal.error.takenname"));
}
portal.removeArg("name");
this.portalHashMap.put(portalName, portal);
this.updatePortalArray();
return true;
}
private void updatePortalArray() {
@ -199,6 +201,11 @@ public class PortalManager {
throw new PortalException(Lang.translate("command.remove.noname"));
}
for(DataTag portalTag : portal.getArgs()) {
TagHandler.Creation creation = AdvancedPortalsCore.getTagRegistry().getCreationHandler(portalTag.NAME);
creation.portalCreated(portal, player, portalTag.VALUE);
}
}
private AdvancedPortal getPortal(String portalName) {

View File

@ -8,7 +8,7 @@ import com.sekwah.advancedportals.core.api.warphandler.TagHandler;
import com.sekwah.advancedportals.core.data.PortalLocation;
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
import java.util.Collection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@ -65,27 +65,35 @@ public class AdvancedPortal {
public boolean activatePortal(PlayerContainer player) {
TagRegistry tagRegistry = AdvancedPortalsCore.getTagRegistry();
ActivationData data = new ActivationData();
PortalTag[] portalTags = new PortalTag[argsCol.size()];
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 PortalTag(argNames[i], this.getArg(argNames[i]));
portalTags[i] = new DataTag(argNames[i], this.getArg(argNames[i]));
}
for(PortalTag portalTag : portalTags) {
for(DataTag portalTag : portalTags) {
TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
activationHandler.portalPreActivated(this, player, data, this.getArg(portalTag.NAME));
activationHandler.preActivated(this, player, data, this.getArg(portalTag.NAME));
}
for(PortalTag portalTag : portalTags) {
for(DataTag portalTag : portalTags) {
TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
activationHandler.portalActivated(this, player, data, this.getArg(portalTag.NAME));
activationHandler.activated(this, player, data, this.getArg(portalTag.NAME));
}
for(PortalTag portalTag : portalTags) {
for(DataTag portalTag : portalTags) {
TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
activationHandler.portalPostActivated(this, player, data, this.getArg(portalTag.NAME));
activationHandler.postActivated(this, player, data, this.getArg(portalTag.NAME));
}
return true;
}
public void setArg(PortalTag portalTag) {
public void setArg(DataTag portalTag) {
this.setArg(portalTag.NAME, portalTag.VALUE);
}
public ArrayList<DataTag> getArgs() {
ArrayList<DataTag> tagList = new ArrayList<>();
for(Map.Entry<String, String> entry : this.args.entrySet()){
tagList.add(new DataTag(entry.getKey(), entry.getValue()));
}
return tagList ;
}
}

View File

@ -1,11 +1,11 @@
package com.sekwah.advancedportals.core.api.portal;
public class PortalTag {
public class DataTag {
public final String NAME;
public final String VALUE;
public PortalTag(String argName, String value) {
public DataTag(String argName, String value) {
this.NAME = argName;
this.VALUE = value;
}

View File

@ -0,0 +1,10 @@
package com.sekwah.advancedportals.core.api.portal;
/**
* Returns a message saying what went wrong with the portal tag.
*/
public class DestinationException extends Exception {
public DestinationException(String reason) {
super(reason);
}
}

View File

@ -1,7 +1,7 @@
package com.sekwah.advancedportals.core.api.registry;
import com.sekwah.advancedportals.core.api.warphandler.TagHandler;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.warphandler.TagHandler;
import java.util.ArrayList;
import java.util.Collections;

View File

@ -4,20 +4,10 @@ import org.bukkit.entity.Player;
public class TagHandler {
/**
* When the user wants to activate the tag, not all will support this of course. its just a _ before or after the tag
* to specify
*/
public enum ActivatePref{
BEFORE,
AFTER,
DEFAULT;
}
/**
* The events for portal creation and destroying
*/
public interface Creation {
public interface Creation<T> {
/**
* Example if the player does not have access to use a tag on the portal.
@ -27,7 +17,7 @@ public class TagHandler {
* @return if the portal can be created.
* @throws PortalException message given is the reason the portal cant be made
*/
void portalCreated(AdvancedPortal portal, PlayerContainer player, String argData) throws PortalException;
void portalCreated(T target, PlayerContainer player, String argData) throws PortalException;
/**
* Example if the player does not have access to remove the portal.
@ -37,11 +27,11 @@ public class TagHandler {
* @return if the portal can be destroyed.
* @throws PortalException message given is the reason the portal cant be removed
*/
void portalDestroyed(AdvancedPortal portal, PlayerContainer player, String argData) throws PortalException;
void portalDestroyed(T target, PlayerContainer player, String argData) throws PortalException;
}
public interface Activation {
public interface Activation<T> {
/**
* Activates before the main part of portal activation.
@ -50,7 +40,7 @@ public class TagHandler {
* @param activeData
* @param argData
*/
void portalPreActivated(AdvancedPortal portal, PlayerContainer player, ActivationData activeData, String argData);
void preActivated(T target, PlayerContainer player, ActivationData activeData, String argData);
/**
* Activates after portal activation
@ -59,7 +49,7 @@ public class TagHandler {
* @param activeData
* @param argData
*/
void portalPostActivated(AdvancedPortal portal, PlayerContainer player, ActivationData activeData, String argData);
void postActivated(T target, PlayerContainer player, ActivationData activeData, String argData);
/**
* Activates if the portal is allowed from pre
@ -68,11 +58,11 @@ public class TagHandler {
* @param activeData
* @param argData
*/
void portalActivated(AdvancedPortal portal, PlayerContainer player, ActivationData activeData, String argData);
void activated(T target, PlayerContainer player, ActivationData activeData, String argData);
}
public interface TagStatus {
public interface TagStatus<T> {
/**
* If the user has access to add the tag (this does not include being added on creation)
@ -81,7 +71,7 @@ public class TagHandler {
* @param argData
* @return if the tag will be added.
*/
boolean tagAdded(AdvancedPortal portal, PlayerContainer player, String argData);
boolean tagAdded(T target, PlayerContainer player, String argData);
/**
* If the user has access to remove the tag (this does not include being added on destruction)

View File

@ -2,7 +2,7 @@ package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.commands.SubCommand;
import com.sekwah.advancedportals.core.api.portal.PortalTag;
import com.sekwah.advancedportals.core.api.portal.DataTag;
import com.sekwah.advancedportals.core.api.portal.PortalException;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
@ -21,7 +21,7 @@ public class CreateSubCommand implements SubCommand {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.create.console"));
return;
}
ArrayList<PortalTag> portalTags = new ArrayList<>();
ArrayList<DataTag> portalTags = new ArrayList<>();
boolean partingValueWithSpaces = false;
String argBeingParsed = "";
String currentParsedValue = "";
@ -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 PortalTag(argBeingParsed, currentParsedValue));
portalTags.add(new DataTag(argBeingParsed, currentParsedValue));
}
else {
currentParsedValue += " " + args[i];
@ -45,7 +45,7 @@ public class CreateSubCommand implements SubCommand {
currentParsedValue = arg;
}
else {
portalTags.add(new PortalTag(detectedTag, arg));
portalTags.add(new DataTag(detectedTag, arg));
}
}
}

View File

@ -2,7 +2,6 @@ package com.sekwah.advancedportals.core.commands.subcommands.portal;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.commands.SubCommand;
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
@ -20,6 +19,7 @@ public class ReloadSubCommand implements SubCommand {
public void onCommand(CommandSenderContainer sender, String[] args) {
portalsCore.loadPortalConfig();
portalsCore.getPortalManager().loadPortals();
portalsCore.getDestiManager().loadDestinations();
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.reload.reloaded"));
}

View File

@ -1,16 +1,37 @@
package com.sekwah.advancedportals.core.data;
import com.google.gson.annotations.SerializedName;
public class PlayerLocation {
@SerializedName("x")
public final double posX;
@SerializedName("y")
public final double posY;
@SerializedName("z")
public final double posZ;
@SerializedName("w")
public final String worldName;
@SerializedName("yaw")
public final float yaw;
@SerializedName("p")
public final float pitch;
public PlayerLocation(String worldName, double posX, double posY, double posZ) {
this.worldName = worldName;
this.posX = posX;
this.posY = posY;
this.posZ = posZ;
this.yaw = 0;
this.pitch = 0;
}
public PlayerLocation(String worldName, double posX, double posY, double posZ, float yaw, float pitch) {
this.worldName = worldName;
this.posX = posX;
this.posY = posY;
this.posZ = posZ;
this.yaw = yaw;
this.pitch = pitch;
}
}

View File

@ -1,6 +1,7 @@
package com.sekwah.advancedportals.core.util;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;