Skip to content
Browse files

Added a bunch of error checking, can set location now

  • Loading branch information...
1 parent 0bd5170 commit 05be8066bc83a6dbd5ea45866cde956cf9061b89 @FernFerret FernFerret committed Jul 21, 2011
View
2 .gitignore
@@ -24,7 +24,7 @@
/world
# Mac filesystem dust
-/.DS_Store
+*.DS_Store
# intellij
*.iml
View
4 src/main/java/com/onarandombox/MultiversePortals/MVPPlayerListener.java
@@ -46,8 +46,8 @@ public void onPlayerMove(PlayerMoveEvent event) {
Location l = null;
if(d.getType() == DestinationType.World) {
- if(this.plugin.core.isMVWorld(d.getName())) {
- MVWorld w = this.plugin.core.getMVWorld(d.getName());
+ if(this.plugin.getCore().isMVWorld(d.getName())) {
+ MVWorld w = this.plugin.getCore().getMVWorld(d.getName());
l = w.getCBWorld().getSpawnLocation();
} else if(this.plugin.getServer().getWorld(d.getName()) != null) {
l = this.plugin.getServer().getWorld(d.getName()).getSpawnLocation();
View
4 src/main/java/com/onarandombox/MultiversePortals/MVPPluginListener.java
@@ -19,7 +19,7 @@ public MVPPluginListener(MultiversePortals plugin) {
@Override
public void onPluginEnable(PluginEnableEvent event) {
if (event.getPlugin().getDescription().getName().equals("Multiverse-Core")) {
- this.plugin.core = ((MultiverseCore) this.plugin.getServer().getPluginManager().getPlugin("Multiverse-Core"));
+ this.plugin.setCore(((MultiverseCore) this.plugin.getServer().getPluginManager().getPlugin("Multiverse-Core")));
this.plugin.getServer().getPluginManager().enablePlugin(this.plugin);
} else if(event.getPlugin().getDescription().getName().equals("WorldEdit")) {
this.plugin.worldEditAPI = new WorldEditAPI((WorldEditPlugin)this.plugin.getServer().getPluginManager().getPlugin("WorldEdit"));
@@ -30,7 +30,7 @@ public void onPluginEnable(PluginEnableEvent event) {
@Override
public void onPluginDisable(PluginDisableEvent event) {
if (event.getPlugin().getDescription().getName().equals("Multiverse-Core")) {
- this.plugin.core = null;
+ this.plugin.setCore(null);
this.plugin.getServer().getPluginManager().disablePlugin(this.plugin);
}
}
View
8 src/main/java/com/onarandombox/MultiversePortals/MVPortal.java
@@ -98,7 +98,7 @@ public boolean setPortalLocation(String locationString, MVWorld world) {
public boolean setPortalLocation(PortalLocation location) {
this.location = location;
if (!this.location.isValidLocation()) {
- this.plugin.core.log(Level.WARNING, "Portal " + ChatColor.RED + this.name + ChatColor.WHITE + " has an invalid LOCATION!");
+ this.plugin.getCore().log(Level.WARNING, "Portal " + ChatColor.RED + this.name + ChatColor.WHITE + " has an invalid LOCATION!");
return false;
}
this.config.setProperty(this.portalConfigString + ".location", this.location.toString());
@@ -107,7 +107,7 @@ public boolean setPortalLocation(PortalLocation location) {
this.config.setProperty(this.portalConfigString + ".world", world.getName());
} else {
- this.plugin.core.log(Level.WARNING, "Portal " + ChatColor.RED + this.name + ChatColor.WHITE + " has an invalid WORLD");
+ this.plugin.getCore().log(Level.WARNING, "Portal " + ChatColor.RED + this.name + ChatColor.WHITE + " has an invalid WORLD");
return false;
}
this.config.save();
@@ -121,9 +121,9 @@ private void setOwner(String owner) {
}
public boolean setDestination(String destinationString) {
- this.destination = Destination.parseDestination(destinationString, this.plugin.core);
+ this.destination = Destination.parseDestination(destinationString, this.plugin.getCore());
if (this.destination.getType() == DestinationType.Invalid) {
- this.plugin.core.log(Level.WARNING, "Portal " + ChatColor.RED + this.name + ChatColor.WHITE + " has an invalid DESTINATION!");
+ this.plugin.getCore().log(Level.WARNING, "Portal " + ChatColor.RED + this.name + ChatColor.WHITE + " has an invalid DESTINATION!");
return false;
}
this.config.setProperty(this.portalConfigString + ".destination", this.destination.toString());
View
11 src/main/java/com/onarandombox/MultiversePortals/MultiversePortals.java
@@ -17,11 +17,12 @@
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.config.Configuration;
-import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiversePortals.commands.CreateCommand;
import com.onarandombox.MultiversePortals.commands.DebugCommand;
import com.onarandombox.MultiversePortals.commands.ListCommand;
+import com.onarandombox.MultiversePortals.commands.ModifyCommand;
+import com.onarandombox.MultiversePortals.commands.ModifySetCommand;
import com.onarandombox.MultiversePortals.commands.RemoveCommand;
import com.onarandombox.MultiversePortals.utils.PortalManager;
import com.onarandombox.utils.DebugLog;
@@ -33,7 +34,7 @@
public static final Logger log = Logger.getLogger("Minecraft");
public static final String logPrefix = "[MultiVerse-Portals] ";
protected static DebugLog debugLog;
- protected MultiverseCore core;
+ private MultiverseCore core;
protected Configuration MVPconfig;
@@ -112,6 +113,8 @@ private void registerCommands() {
this.commandHandler.registerCommand(new CreateCommand(this));
this.commandHandler.registerCommand(new DebugCommand(this));
this.commandHandler.registerCommand(new RemoveCommand(this));
+ this.commandHandler.registerCommand(new ModifySetCommand(this));
+ this.commandHandler.registerCommand(new ModifyCommand(this));
}
@Override
@@ -157,4 +160,8 @@ public PortalManager getPortalManager() {
public Configuration getMVPConfig() {
return this.MVPconfig;
}
+
+ public void setCore(MultiverseCore multiverseCore) {
+ this.core = multiverseCore;
+ }
}
View
23 src/main/java/com/onarandombox/MultiversePortals/PortalPlayerSession.java
@@ -4,6 +4,11 @@
import org.bukkit.Location;
import org.bukkit.entity.Player;
+import com.sk89q.worldedit.IncompleteRegionException;
+import com.sk89q.worldedit.LocalSession;
+import com.sk89q.worldedit.bukkit.WorldEditAPI;
+import com.sk89q.worldedit.regions.Region;
+
public class PortalPlayerSession {
private MultiversePortals plugin;
private Player player;
@@ -69,4 +74,22 @@ public void setStaleLocation(Location loc) {
}
}
+
+ public Region getSelectedRegion() {
+ WorldEditAPI api = this.plugin.getWEAPI();
+ if (api == null) {
+ this.player.sendMessage("Did not find the WorldEdit API...");
+ this.player.sendMessage("It is currently required to use Multiverse-Portals.");
+ return null;
+ }
+ LocalSession s = api.getSession(this.player);
+ Region r = null;
+ try {
+ r = s.getSelection(s.getSelectionWorld());
+ } catch (IncompleteRegionException e) {
+ this.player.sendMessage("You haven't finished your selection.");
+ return null;
+ }
+ return r;
+ }
}
View
17 src/main/java/com/onarandombox/MultiversePortals/commands/CreateCommand.java
@@ -11,6 +11,7 @@
import com.onarandombox.MultiversePortals.MVPortal;
import com.onarandombox.MultiversePortals.MultiversePortals;
import com.onarandombox.MultiversePortals.PortalLocation;
+import com.onarandombox.MultiversePortals.PortalPlayerSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.bukkit.WorldEditAPI;
@@ -44,18 +45,10 @@ public void runCommand(CommandSender sender, List<String> args) {
}
MVWorld world = this.plugin.getCore().getMVWorld(p.getWorld().getName());
- WorldEditAPI api = this.plugin.getWEAPI();
- if (api == null) {
- sender.sendMessage("Did not find the WorldEdit API...");
- sender.sendMessage("It is currently required to use Multiverse-Portals.");
- return;
- }
- LocalSession s = api.getSession(p);
- Region r = null;
- try {
- r = s.getSelection(s.getSelectionWorld());
- } catch (IncompleteRegionException e) {
- sender.sendMessage("You haven't finished your selection");
+ PortalPlayerSession ps = this.plugin.getPortalSession(p);
+
+ Region r = ps.getSelectedRegion();
+ if (r == null) {
return;
}
MVPortal portal = this.plugin.getPortalManager().getPortal(args.get(0));
View
9 src/main/java/com/onarandombox/MultiversePortals/commands/ModifyCommand.java
@@ -4,7 +4,6 @@
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
-import org.bukkit.permissions.PermissionDefault;
import com.onarandombox.MultiversePortals.MultiversePortals;
@@ -29,10 +28,10 @@ public ModifyCommand(MultiversePortals plugin) {
this.setCommandUsage("/mvp modify" + ChatColor.GREEN + " {set|add|remove|clear} ...");
// make it so no one can ever execute this.
this.setArgRange(1, 0);
- this.addKey("mvnp link");
- this.addKey("mvnpl");
- this.addKey("mvnplink");
- this.setPermission("multiverse.portals.modify", "Allows you to modify all existing portal.", PermissionDefault.OP);
+ this.addKey("mvnp modify");
+ this.addKey("mvnpm");
+ this.addKey("mvnpmodify");
+ // Don't need this perm, it'll get added automatically!
}
protected static boolean validateAction(Action action, String property) {
View
83 src/main/java/com/onarandombox/MultiversePortals/commands/ModifySetCommand.java
@@ -7,16 +7,19 @@
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionDefault;
+import com.onarandombox.MultiverseCore.MVWorld;
+import com.onarandombox.MultiversePortals.MVPortal;
import com.onarandombox.MultiversePortals.MultiversePortals;
+import com.onarandombox.MultiversePortals.PortalLocation;
import com.onarandombox.MultiversePortals.PortalPlayerSession;
-import com.pneumaticraft.commandhandler.CommandHandler;
+import com.sk89q.worldedit.regions.Region;
public class ModifySetCommand extends PortalCommand {
public ModifySetCommand(MultiversePortals plugin) {
super(plugin);
this.setName("Modify a Portal (Set a value)");
- this.setCommandUsage("/mvp modify" + ChatColor.GREEN + "set {PROPERTY}" + ChatColor.GOLD + " [VALUE] -p [PORTAL]");
+ this.setCommandUsage("/mvp modify" + ChatColor.GREEN + " set {PROPERTY}" + ChatColor.GOLD + " [VALUE] -p [PORTAL]");
this.setArgRange(1, 4);
this.addKey("mvp modify set");
this.addKey("mvpmodify set");
@@ -31,47 +34,85 @@ public void runCommand(CommandSender sender, List<String> args) {
sender.sendMessage("Sorry, right now this command is player only :(");
return;
}
-
-
-
+
Player player = (Player) sender;
if (!ModifyCommand.validateAction(Action.Set, args.get(0))) {
sender.sendMessage("Sorry, you cannot " + ChatColor.AQUA + "SET" + ChatColor.WHITE + " the property " +
ChatColor.DARK_AQUA + args.get(0) + ChatColor.WHITE + ".");
return;
}
-
- if(!validCommand(args, SetProperties.valueOf(args.get(0)))) {
- sender.sendMessage("Looks like you forgot your -p or [PORTAL],");
- sender.sendMessage("or you did not specify the value you wanted to set!");
- sender.sendMessage("or you did not specify the value you wanted to set!");
-
+
+ if (!validCommand(args, SetProperties.valueOf(args.get(0)))) {
+ sender.sendMessage("Looks like you forgot or added an extra parameter.");
+ sender.sendMessage("Please try again, or see our Wiki for help!");
return;
}
String portalName = extractPortalName(args);
-
-
-
- //TODO: Resume work here!
- if (portalName == null && !userHasPortalSelected(player)) {
- sender.sendMessage("You need to select a portal using" + ChatColor.AQUA + "/mvp select {NAME}");
+ MVPortal selectedPortal = null;
+ // If they provided -p PORTALNAME, try to retrieve it
+ if (portalName != null) {
+ selectedPortal = this.plugin.getPortalManager().getPortal(portalName);
+ if (selectedPortal == null) {
+ sender.sendMessage("Sorry, the portal " + ChatColor.RED + portalName + ChatColor.WHITE + " did not exist!");
+ return;
+ }
+ }
+ // If they didn't provide -p, then try to use their selected portal
+ if (selectedPortal == null) {
+ selectedPortal = this.getUserSelectedPortal(player);
+ }
+
+ if (selectedPortal == null) {
+ sender.sendMessage("You need to select a portal using " + ChatColor.AQUA + "/mvp select {NAME}");
sender.sendMessage("or append " + ChatColor.DARK_AQUA + "-p {PORTAL}" + ChatColor.WHITE + " to this command.");
return;
}
+
+ if (portalName != null) {
+ if(SetProperties.valueOf(args.get(0)) == SetProperties.location) {
+ this.setLocation(selectedPortal, player);
+ }
+ this.setProperty(selectedPortal, args.get(0), args.get(1));
+ }
+ }
+
+ private void setProperty(MVPortal selectedPortal, String property, String value) {
+ // TODO Auto-generated method stub
+
}
- private boolean userHasPortalSelected(Player player) {
+ private void setLocation(MVPortal selectedPortal, Player player) {
PortalPlayerSession ps = this.plugin.getPortalSession(player);
- return ps.getSelectedPortal() != null;
+ Region r = ps.getSelectedRegion();
+ if(r != null) {
+ MVWorld world = this.plugin.getCore().getMVWorld(player.getWorld().getName());
+ PortalLocation location = new PortalLocation(r.getMinimumPoint(), r.getMaximumPoint(), world);
+ selectedPortal.setPortalLocation(location);
+ player.sendMessage("Portal location is not set to your selection!");
+ }
+ }
+
+ private MVPortal getUserSelectedPortal(Player player) {
+ PortalPlayerSession ps = this.plugin.getPortalSession(player);
+ return ps.getSelectedPortal();
}
private boolean validCommand(List<String> args, SetProperties property) {
// This means that they did not specify the -p or forgot the [PORTAL]
- return !(args.size() == 3 && property == SetProperties.location);
+
+ if (property == SetProperties.location && args.size() % 2 == 0) {
+ System.out.print("Invalid params!" + args);
+ return false;
+ } else if (property != SetProperties.location && args.size() % 2 != 0) {
+ System.out.print("Invalid params!" + args);
+ return false;
+ }
+ System.out.print("VALID params!" + args);
+ return true;
}
private String extractPortalName(List<String> args) {
- if (args.contains("-p")) {
+ if (!args.contains("-p")) {
return null;
}
int index = args.indexOf("-p");

0 comments on commit 05be806

Please sign in to comment.
Something went wrong with that request. Please try again.