Started updating how portals are made

This commit is contained in:
sekwah41 2018-02-20 16:46:29 +00:00
parent dcee3c210a
commit 32a21873be
4 changed files with 13 additions and 20 deletions

View File

@ -38,7 +38,7 @@ command.create.help=Creates portals
command.create.noargs= You need to actually list args for portal creation. command.create.noargs= You need to actually list args for portal creation.
command.create.error= There was an error making the portal: command.create.error= There was an error making the portal:
command.create.console= You cannot create a portal using the console. command.create.console= You cannot create a portal using the console.
command.create.detailedhelp=List tags after create in the format tag:value, if your value needs spaces use the format tag:"value with spaces" command.create.detailedhelp=Format is /portal create (name) [tag:tagvalue] List tags after create in the format tag:value, if your value needs spaces use the format tag:"value with spaces"
command.playeronly= Sorry but that command can only be run by a player. command.playeronly= Sorry but that command can only be run by a player.

View File

@ -94,10 +94,10 @@ public class PortalManager {
return false; return false;
} }
public void createPortal(PlayerContainer player, ArrayList<DataTag> tags) throws PortalException { public void createPortal(String name, PlayerContainer player, ArrayList<DataTag> tags) throws PortalException {
if (this.portalSelectorLeftClick.containsKey(player.getUUID().toString()) if (this.portalSelectorLeftClick.containsKey(player.getUUID().toString())
&& this.portalSelectorRightClick.containsKey(player.getUUID().toString())) { && this.portalSelectorRightClick.containsKey(player.getUUID().toString())) {
this.createPortal(player, this.portalSelectorLeftClick.get(player.getUUID().toString()), this.createPortal(name, player, this.portalSelectorLeftClick.get(player.getUUID().toString()),
this.portalSelectorRightClick.get(player.getUUID().toString()), tags); this.portalSelectorRightClick.get(player.getUUID().toString()), tags);
} else { } else {
throw new PortalException(Lang.translate("portal.invalidselection")); throw new PortalException(Lang.translate("portal.invalidselection"));
@ -112,8 +112,8 @@ public class PortalManager {
* @return * @return
* @throws PortalException * @throws PortalException
*/ */
public void createPortal(PortalLocation loc1, PortalLocation loc2, ArrayList<DataTag> tags) throws PortalException { public void createPortal(String name, PortalLocation loc1, PortalLocation loc2, ArrayList<DataTag> tags) throws PortalException {
createPortal(null, loc1, loc2, tags); createPortal(name, null, loc1, loc2, tags);
} }
@ -127,10 +127,7 @@ public class PortalManager {
* @param tags * @param tags
* @throws PortalException * @throws PortalException
*/ */
public void createPortal(PlayerContainer player, PortalLocation loc1, PortalLocation loc2, ArrayList<DataTag> tags) throws PortalException { public void createPortal(String name, 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 maxX = Math.max(loc1.posX, loc2.posX);
int maxY = Math.max(loc1.posY, loc2.posY); int maxY = Math.max(loc1.posY, loc2.posY);
@ -154,15 +151,13 @@ public class PortalManager {
TagHandler.Creation creation = AdvancedPortalsCore.getTagRegistry().getCreationHandler(portalTag.NAME); TagHandler.Creation creation = AdvancedPortalsCore.getTagRegistry().getCreationHandler(portalTag.NAME);
creation.portalCreated(portal, player, portalTag.VALUE); creation.portalCreated(portal, player, portalTag.VALUE);
} }
String portalName = portal.getArg("name"); if(name == null || name.equals("")) {
if(portalName == null || portalName.equals("")) {
throw new PortalException(Lang.translate("portal.error.noname")); throw new PortalException(Lang.translate("portal.error.noname"));
} }
else if(this.portalHashMap.containsKey(portalName)) { else if(this.portalHashMap.containsKey(name)) {
throw new PortalException(Lang.translate("portal.error.takenname")); throw new PortalException(Lang.translate("portal.error.takenname"));
} }
portal.removeArg("name"); this.portalHashMap.put(name, portal);
this.portalHashMap.put(portalName, portal);
this.updatePortalArray(); this.updatePortalArray();
} }

View File

@ -21,7 +21,6 @@ public class TagHandler {
* *
* @param player if null the portal has been created by the server or a plugin * @param player if null the portal has been created by the server or a plugin
* @param argData * @param argData
* @return if the portal can be created.
* @throws PortalException message given is the reason the portal cant be made * @throws PortalException message given is the reason the portal cant be made
*/ */
void portalCreated(T target, PlayerContainer player, String argData) throws PortalException; void portalCreated(T target, PlayerContainer player, String argData) throws PortalException;
@ -31,7 +30,6 @@ public class TagHandler {
* *
* @param player if null the portal has been destroyed by the server or a plugin * @param player if null the portal has been destroyed by the server or a plugin
* @param argData * @param argData
* @return if the portal can be destroyed.
* @throws PortalException message given is the reason the portal cant be removed * @throws PortalException message given is the reason the portal cant be removed
*/ */
void portalDestroyed(T target, PlayerContainer player, String argData) throws PortalException; void portalDestroyed(T target, PlayerContainer player, String argData) throws PortalException;

View File

@ -15,7 +15,7 @@ public class CreateSubCommand implements SubCommand {
@Override @Override
public void onCommand(CommandSenderContainer sender, String[] args) { public void onCommand(CommandSenderContainer sender, String[] args) {
if(args.length > 1) { if(args.length > 2) {
PlayerContainer player = sender.getPlayerContainer(); PlayerContainer player = sender.getPlayerContainer();
if(player == null) { if(player == null) {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.create.console")); sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.create.console"));
@ -25,7 +25,7 @@ public class CreateSubCommand implements SubCommand {
boolean partingValueWithSpaces = false; boolean partingValueWithSpaces = false;
String argBeingParsed = ""; String argBeingParsed = "";
String currentParsedValue = ""; String currentParsedValue = "";
for (int i = 1; i < args.length; i++) { for (int i = 2; i < args.length; i++) {
if(partingValueWithSpaces) { if(partingValueWithSpaces) {
if(args[i].charAt(args[i].length() - 1) == '"') { if(args[i].charAt(args[i].length() - 1) == '"') {
args[i] = args[i].substring(0, args[i].length() - 1); args[i] = args[i].substring(0, args[i].length() - 1);
@ -51,14 +51,14 @@ public class CreateSubCommand implements SubCommand {
} }
} }
try { try {
AdvancedPortalsCore.getPortalManager().createPortal(player, portalTags); AdvancedPortalsCore.getPortalManager().createPortal(args[1], player, portalTags);
} catch (PortalException portalTagExeption) { } catch (PortalException portalTagExeption) {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.create.error") + " " sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.create.error") + " "
+ portalTagExeption.getMessage()); + portalTagExeption.getMessage());
} }
} }
else { else {
sender.sendMessage(Lang.translate("command.create.noargs")); sender.sendMessage(Lang.translate("command.error.noname"));
} }
} }