mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-22 10:36:17 +01:00
Removed unused exeption
This commit is contained in:
parent
d7890a7d07
commit
55bb31c470
@ -57,7 +57,10 @@ 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.
|
||||
desti.error.noname=No name for the portal has been given.
|
||||
desti.error.takenname=The name given for the portal is already taken.
|
||||
|
||||
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
|
||||
|
||||
|
@ -185,7 +185,7 @@ public class AdvancedPortalsCore {
|
||||
return instance.portalManager;
|
||||
}
|
||||
|
||||
public static DestinationManager getDestiManager() {
|
||||
public static DestinationManager getDestinationManager() {
|
||||
return instance.destiManager;
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,10 @@ public class Destination {
|
||||
this.args.put(argName, argValue);
|
||||
}
|
||||
|
||||
public void setArg(DataTag portalTag) {
|
||||
this.setArg(portalTag.NAME, portalTag.VALUE);
|
||||
}
|
||||
|
||||
public void removeArg(String arg) {
|
||||
this.args.remove(arg);
|
||||
}
|
||||
|
@ -4,7 +4,8 @@ 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.api.portal.PortalException;
|
||||
import com.sekwah.advancedportals.core.api.warphandler.TagHandler;
|
||||
import com.sekwah.advancedportals.core.data.PlayerLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
@ -27,9 +28,29 @@ public class DestinationManager {
|
||||
this.portalsCore = portalsCore;
|
||||
}
|
||||
|
||||
public void createDesti(PlayerContainer player, PlayerLocation playerLocation, ArrayList<DataTag> dataTags) throws DestinationException {
|
||||
|
||||
public void createDesti(String name, PlayerContainer player, PlayerLocation playerLocation, ArrayList<DataTag> tags) throws PortalException {
|
||||
Destination destination = new Destination(playerLocation);
|
||||
if(name == null || name.equals("")) {
|
||||
throw new PortalException("desti.error.noname");
|
||||
}
|
||||
else if(this.destiHashMap.containsKey(name)) {
|
||||
throw new PortalException("desti.error.takenname");
|
||||
}
|
||||
|
||||
Destination desti = new Destination(playerLocation);
|
||||
for(DataTag portalTag : tags) {
|
||||
desti.setArg(portalTag);
|
||||
}
|
||||
for(DataTag destiTag : tags) {
|
||||
TagHandler.Creation<Destination> creation = AdvancedPortalsCore.getDestinationTagRegistry().getCreationHandler(destiTag.NAME);
|
||||
if(creation != null) {
|
||||
creation.created(desti, player, destiTag.VALUE);
|
||||
}
|
||||
}
|
||||
this.destiHashMap.put(name, desti);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void loadDestinations() {
|
||||
Type type = new TypeToken<HashMap<String, Destination>>() {
|
||||
|
@ -143,22 +143,28 @@ public class PortalManager {
|
||||
PortalLocation maxLoc = new PortalLocation(loc1.worldName, maxX, maxY, maxZ);
|
||||
PortalLocation minLoc = new PortalLocation(loc1.worldName, minX, minY, minZ);
|
||||
|
||||
if(name == null || name.equals("")) {
|
||||
throw new PortalException("portal.error.noname");
|
||||
}
|
||||
else if(this.portalHashMap.containsKey(name)) {
|
||||
throw new PortalException("portal.error.takenname");
|
||||
}
|
||||
|
||||
AdvancedPortal portal = new AdvancedPortal(maxLoc, minLoc);
|
||||
for(DataTag portalTag : tags) {
|
||||
if(portalTag.NAME.equalsIgnoreCase("triggerblock")) {
|
||||
portal.setTriggerBlocks(portalTag.VALUE.split(","));
|
||||
}
|
||||
else {
|
||||
portal.setArg(portalTag);
|
||||
}
|
||||
}
|
||||
for(DataTag portalTag : tags) {
|
||||
TagHandler.Creation<AdvancedPortal> creation = AdvancedPortalsCore.getPortalTagRegistry().getCreationHandler(portalTag.NAME);
|
||||
if(creation != null) {
|
||||
creation.created(portal, player, portalTag.VALUE);
|
||||
}
|
||||
}
|
||||
if(name == null || name.equals("")) {
|
||||
throw new PortalException("portal.error.noname");
|
||||
}
|
||||
else if(this.portalHashMap.containsKey(name)) {
|
||||
throw new PortalException("portal.error.takenname");
|
||||
}
|
||||
this.portalHashMap.put(name, portal);
|
||||
this.updatePortalArray();
|
||||
}
|
||||
@ -172,7 +178,7 @@ public class PortalManager {
|
||||
String portal = this.selectedPortal.get(player.getUUID().toString());
|
||||
if(portal != null) {
|
||||
try {
|
||||
this.removePortal(player, portal);
|
||||
this.removePortal(portal, player);
|
||||
}
|
||||
catch(PortalException e) {
|
||||
if(e.getMessage().equals("command.remove.noname")) {
|
||||
@ -188,11 +194,11 @@ public class PortalManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player null if a player didnt send it
|
||||
* @param portalName name of portal
|
||||
* @param player null if a player didnt send it
|
||||
* @throws PortalException
|
||||
*/
|
||||
public void removePortal(PlayerContainer player, String portalName) throws PortalException {
|
||||
public void removePortal(String portalName, PlayerContainer player) throws PortalException {
|
||||
AdvancedPortal portal = this.getPortal(portalName);
|
||||
if(portal == null) {
|
||||
throw new PortalException("command.remove.noname");
|
||||
|
@ -109,4 +109,8 @@ public class AdvancedPortal {
|
||||
}
|
||||
return tagList;
|
||||
}
|
||||
|
||||
public void setTriggerBlocks(String[] triggerBlocks) {
|
||||
this.triggerBlocks = triggerBlocks;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.sekwah.advancedportals.core.commands.subcommands.desti;
|
||||
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||
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;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CreateSubCommand implements SubCommand {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
if(args.length > 2) {
|
||||
PlayerContainer player = sender.getPlayerContainer();
|
||||
if(player == null) {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.create.console"));
|
||||
return;
|
||||
}
|
||||
ArrayList<DataTag> portalTags = new ArrayList<>();
|
||||
boolean partingValueWithSpaces = false;
|
||||
String argBeingParsed = "";
|
||||
String currentParsedValue = "";
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
if(partingValueWithSpaces) {
|
||||
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.toLowerCase(), currentParsedValue));
|
||||
}
|
||||
else {
|
||||
currentParsedValue += " " + args[i];
|
||||
}
|
||||
}
|
||||
else {
|
||||
String detectedTag = this.getTag(args[i].toLowerCase());
|
||||
if(detectedTag != null) {
|
||||
String arg = args[i].substring(detectedTag.length());
|
||||
if(arg.length() > 0 && arg.charAt(0) == '"') {
|
||||
argBeingParsed = detectedTag;
|
||||
currentParsedValue = arg;
|
||||
}
|
||||
else {
|
||||
portalTags.add(new DataTag(detectedTag.toLowerCase(), arg));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
AdvancedPortalsCore.getDestinationManager().createDesti(args[1], player, player.getLoc(), portalTags);
|
||||
} catch (PortalException portalTagExeption) {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.create.error") + " "
|
||||
+ Lang.translate(portalTagExeption.getMessage()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Lang.translate("command.error.noname"));
|
||||
}
|
||||
}
|
||||
|
||||
private String getTag(String arg) {
|
||||
ArrayList<String> tags = AdvancedPortalsCore.getPortalTagRegistry().getTags();
|
||||
for(String tag : tags) {
|
||||
if(arg.startsWith(tag + ":")) {
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSenderContainer sender) {
|
||||
return sender.isOp() || sender.hasPermission("advancedportals.createportal");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBasicHelpText() {
|
||||
return Lang.translate("command.create.help");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDetailedHelpText() {
|
||||
return Lang.translate("command.create.detailedhelp");
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ public class ReloadSubCommand implements SubCommand {
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
portalsCore.loadPortalConfig();
|
||||
portalsCore.getPortalManager().loadPortals();
|
||||
portalsCore.getDestiManager().loadDestinations();
|
||||
portalsCore.getDestinationManager().loadDestinations();
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.reload.reloaded"));
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ public class RemoveSubCommand implements SubCommand {
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
if(args.length > 1) {
|
||||
try {
|
||||
AdvancedPortalsCore.getPortalManager().removePortal(sender.getPlayerContainer(), args[1]);
|
||||
AdvancedPortalsCore.getPortalManager().removePortal(args[1], sender.getPlayerContainer());
|
||||
} catch (PortalException portalTagExeption) {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.negative")
|
||||
+ Lang.translateColor("command.remove.error") + " " + Lang.translate(portalTagExeption.getMessage()));
|
||||
|
Loading…
Reference in New Issue
Block a user