Yes. Cannons. In Multiverse2. What now.

This commit is contained in:
Eric Stokes 2011-08-08 22:02:56 -06:00
parent 04779cb8ba
commit c629fe72e4
11 changed files with 211 additions and 24 deletions

@ -1 +1 @@
Subproject commit 978a713857aa777db45eba9e312679f49d96db6c
Subproject commit ac9d8c94e483589ccfb9e85bb34b7129b83a6881

View File

@ -63,6 +63,7 @@ import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
import com.onarandombox.MultiverseCore.listeners.MVPluginListener;
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
import com.onarandombox.utils.CannonDestination;
import com.onarandombox.utils.DebugLog;
import com.onarandombox.utils.DestinationFactory;
import com.onarandombox.utils.ExactDestination;
@ -175,6 +176,7 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
this.destFactory.registerDestinationType(WorldDestination.class, "w");
this.destFactory.registerDestinationType(ExactDestination.class, "e");
this.destFactory.registerDestinationType(PlayerDestination.class, "pl");
this.destFactory.registerDestinationType(CannonDestination.class, "ca");
}
/**

View File

@ -48,7 +48,7 @@ public class CoordCommand extends MultiverseCommand {
p.sendMessage(ChatColor.AQUA + "Alias: " + mvworld.getColoredWorldString());
p.sendMessage(ChatColor.AQUA + "World Scale: " + ChatColor.WHITE + mvworld.getScaling());
p.sendMessage(ChatColor.AQUA + "Coordinates: " + ChatColor.WHITE + this.locMan.strCoords(p.getLocation()));
p.sendMessage(ChatColor.AQUA + "Direction: " + ChatColor.WHITE + this.locMan.getDirection(p.getLocation()));
p.sendMessage(ChatColor.AQUA + "Direction: " + ChatColor.WHITE + LocationManipulation.getDirection(p.getLocation()));
p.sendMessage(ChatColor.AQUA + "Block: " + ChatColor.WHITE + Material.getMaterial(world.getBlockTypeIdAt(p.getLocation())));
} else {
sender.sendMessage("This command needs to be used from a Player.");

View File

@ -111,6 +111,8 @@ public class TeleportCommand extends MultiverseCommand {
}
String message = ChatColor.GREEN + "Multiverse" + ChatColor.WHITE + " did not teleport " + ChatColor.AQUA + player + ChatColor.WHITE + " to " + ChatColor.DARK_AQUA + d.getName() + ChatColor.WHITE + " because it was unsafe.";
this.plugin.getCommandHandler().queueCommand(sender, "mvteleport", "teleportPlayer", items, paramTypes, message, "Would you like to try anyway?", "", "", 15);
} else {
teleportee.setVelocity(d.getVelocity());
}
}
}

View File

@ -0,0 +1,167 @@
package com.onarandombox.utils;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import com.onarandombox.MultiverseCore.MultiverseCore;
public class CannonDestination implements MVDestination {
private final String coordRegex = "(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*)";
private boolean isValid;
private Location location;
private double speed;
public Vector getVelocity() {
double x = Math.cos(location.getPitch()) * speed;
//double y = Math.sin(location.getPitch()) * speed;
double y = 0;
double z = Math.sin(location.getYaw()) * speed;
return new Vector(x,y,z);
}
@Override
public String getIdentifer() {
return "ca";
}
@Override
public boolean isThisType(JavaPlugin plugin, String destination) {
if (!(plugin instanceof MultiverseCore)) {
return false;
}
List<String> parsed = Arrays.asList(destination.split(":"));
// NEED ca:world:x,y,z:pitch:yaw:speed
// so basically 6
if (parsed.size() != 6) {
return false;
}
// If it's not an Cannon type
if (!parsed.get(0).equalsIgnoreCase("ca")) {
return false;
}
// If it's not a MV world
if (!((MultiverseCore) plugin).isMVWorld(parsed.get(1))) {
return false;
}
// Verify X,Y,Z are numbers
if (!parsed.get(2).matches(coordRegex)) {
return false;
}
try {
Float.parseFloat(parsed.get(3));
Float.parseFloat(parsed.get(4));
Float.parseFloat(parsed.get(5));
} catch (NumberFormatException e) {
return false;
}
return true;
}
@Override
public Location getLocation(Entity e) {
return this.location;
}
@Override
public boolean isValid() {
return this.isValid;
}
@Override
public void setDestination(JavaPlugin plugin, String dest) {
if (!(plugin instanceof MultiverseCore)) {
return;
}
List<String> parsed = Arrays.asList(dest.split(":"));
System.out.print(parsed);
// Need at least: e:world:x,y,z
// OR e:world:x,y,z:pitch:yaw
// so basically 3 or 5
if (parsed.size() != 6) {
this.isValid = false;
return;
}
if (!parsed.get(0).equalsIgnoreCase(this.getIdentifer())) {
this.isValid = false;
return;
}
if (!((MultiverseCore) plugin).isMVWorld(parsed.get(1))) {
this.isValid = false;
return;
}
this.location = new Location(((MultiverseCore) plugin).getMVWorld(parsed.get(1)).getCBWorld(), 0, 0, 0);
if (!parsed.get(2).matches(this.coordRegex)) {
this.isValid = false;
return;
}
double[] coords = new double[3];
String[] coordString = parsed.get(2).split(",");
for (int i = 0; i < 3; i++) {
try {
coords[i] = Double.parseDouble(coordString[i]);
} catch (NumberFormatException e) {
this.isValid = false;
return;
}
}
this.location.setX(coords[0]);
this.location.setY(coords[1]);
this.location.setZ(coords[2]);
try {
this.location.setPitch(Float.parseFloat(parsed.get(3)));
this.location.setYaw(Float.parseFloat(parsed.get(4)));
this.speed = Math.abs(Float.parseFloat(parsed.get(5)));
} catch (NumberFormatException e) {
this.isValid = false;
return;
}
this.isValid = true;
}
@Override
public String getType() {
return "Cannon!";
}
@Override
public String getName() {
return "Cannon (" + this.location.getX() + ", " + this.location.getY() + ", " + this.location.getZ() + ":" +
this.location.getPitch() + ":" + this.location.getYaw() + ":" + this.speed + ")";
}
public void setDestination(Location location, double speed) {
if (location != null) {
this.location = location;
this.speed = Math.abs(speed);
this.isValid = true;
}
this.isValid = false;
}
@Override
public String toString() {
if (isValid) {
return "ca:" + location.getWorld().getName() + ":" + location.getX() + "," + location.getY() + "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw() + ":" + this.speed;
}
return "i:Invalid Destination";
}
@Override
public String getRequiredPermission() {
return "multiverse.access." + this.location.getWorld().getName();
}
}

View File

@ -6,6 +6,7 @@ import java.util.List;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import com.onarandombox.MultiverseCore.MultiverseCore;
@ -19,6 +20,10 @@ public class ExactDestination implements MVDestination {
return "e";
}
public Vector getVelocity() {
return new Vector(0,0,0);
}
@Override
public boolean isThisType(JavaPlugin plugin, String destination) {
if (!(plugin instanceof MultiverseCore)) {
@ -55,12 +60,6 @@ public class ExactDestination implements MVDestination {
} catch (NumberFormatException e) {
return false;
}
try {
} catch (NumberFormatException e) {
return false;
}
return true;
}
@ -140,21 +139,21 @@ public class ExactDestination implements MVDestination {
@Override
public String getName() {
return "Exact (" + this.location.getX() + ", " + this.location.getY() + ", " + this.location.getZ() + ")";
return "Exact (" + this.location.getX() + ", " + this.location.getY() + ", " + this.location.getZ() + ":" + location.getPitch() + ":" + location.getYaw() + ")";
}
public void setDestination(Location location) {
if (location != null) {
this.location = location;
this.isValid = false;
}
this.isValid = true;
}
this.isValid = false;
}
@Override
public String toString() {
if (isValid) {
return "e:" + location.getWorld().getName() + ":" + location.getX() + "," + location.getY() + "," + location.getZ() + ": " + location.getX() + ":" + location.getX();
return "e:" + location.getWorld().getName() + ":" + location.getX() + "," + location.getY() + "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw();
}
return "i:Invalid Destination";
}

View File

@ -4,6 +4,7 @@ import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
public class InvalidDestination implements MVDestination {
@ -51,5 +52,8 @@ public class InvalidDestination implements MVDestination {
public String getRequiredPermission() {
return null;
}
public Vector getVelocity() {
return new Vector(0,0,0);
}
}

View File

@ -79,35 +79,38 @@ public class LocationManipulation {
* @param location
* @return
*/
public String getDirection(Location location) {
public static String getDirection(Location location) {
double r = (location.getYaw() % 360) + 180;
// Remember, these numbers are every 45 degrees with a 22.5 offset, to detect boundaries.
String dir;
if (r < 22.5)
dir = "N";
dir = "n";
else if (r < 67.5)
dir = "NE";
dir = "ne";
else if (r < 112.5)
dir = "E";
dir = "e";
else if (r < 157.5)
dir = "SE";
dir = "se";
else if (r < 202.5)
dir = "S";
dir = "s";
else if (r < 247.5)
dir = "SW";
dir = "sw";
else if (r < 292.5)
dir = "W";
dir = "w";
else if (r < 337.5)
dir = "NW";
dir = "nw";
else
dir = "N";
dir = "n";
return dir;
}
public static float getYaw(String orientation) {
if (orientationInts.containsKey(orientation)) {
return orientationInts.get(orientation);
if (orientation == null) {
return 0;
}
if (orientationInts.containsKey(orientation.toLowerCase())) {
return orientationInts.get(orientation.toLowerCase());
}
return 0;
}

View File

@ -3,6 +3,7 @@ package com.onarandombox.utils;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
public interface MVDestination {
public String getIdentifer();
@ -14,4 +15,5 @@ public interface MVDestination {
public String getName();
public String toString();
public String getRequiredPermission();
public Vector getVelocity();
}

View File

@ -4,6 +4,7 @@ import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
public class PlayerDestination implements MVDestination {
String player;
@ -81,5 +82,8 @@ public class PlayerDestination implements MVDestination {
public String getRequiredPermission() {
return "";
}
public Vector getVelocity() {
return new Vector(0,0,0);
}
}

View File

@ -3,6 +3,7 @@ package com.onarandombox.utils;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
@ -104,5 +105,8 @@ public class WorldDestination implements MVDestination {
public String getRequiredPermission() {
return "multiverse.access."+this.world.getName();
}
public Vector getVelocity() {
return new Vector(0,0,0);
}
}