mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-25 20:16:06 +01:00
Fix pitch/yaw switched for mvss on reload
This commit is contained in:
parent
15ce10671e
commit
f6e49bd8eb
@ -23,7 +23,7 @@ public class LocationConfigProperty implements MVConfigProperty<Location> {
|
|||||||
this.configNode = name;
|
this.configNode = name;
|
||||||
this.section = section;
|
this.section = section;
|
||||||
this.help = help;
|
this.help = help;
|
||||||
this.setValue(this.getLocationFromConfig(this.configNode, defaultValue));
|
this.setValue(this.getLocationFromConfig(defaultValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocationConfigProperty(ConfigurationSection section, String name, Location defaultValue, String configNode, String help) {
|
public LocationConfigProperty(ConfigurationSection section, String name, Location defaultValue, String configNode, String help) {
|
||||||
@ -31,7 +31,7 @@ public class LocationConfigProperty implements MVConfigProperty<Location> {
|
|||||||
this.configNode = configNode;
|
this.configNode = configNode;
|
||||||
this.section = section;
|
this.section = section;
|
||||||
this.help = help;
|
this.help = help;
|
||||||
this.setValue(this.getLocationFromConfig(this.configNode, defaultValue));
|
this.setValue(this.getLocationFromConfig(defaultValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -46,7 +46,7 @@ public class LocationConfigProperty implements MVConfigProperty<Location> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean parseValue(String value) {
|
public boolean parseValue(String value) {
|
||||||
Location parsed = LocationManipulation.getLocationFromString(value);
|
Location parsed = LocationManipulation.stringToLocation(value);
|
||||||
return this.setValue(parsed);
|
return this.setValue(parsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,14 +80,14 @@ public class LocationConfigProperty implements MVConfigProperty<Location> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Location getLocationFromConfig(String node, Location defaultValue) {
|
private Location getLocationFromConfig(Location defaultValue) {
|
||||||
double x = this.section.getDouble(configNode + ".x", defaultValue.getX());
|
double x = this.section.getDouble(this.configNode + ".x", defaultValue.getX());
|
||||||
double y = this.section.getDouble(configNode + ".y", defaultValue.getY());
|
double y = this.section.getDouble(this.configNode + ".y", defaultValue.getY());
|
||||||
double z = this.section.getDouble(configNode + ".z", defaultValue.getZ());
|
double z = this.section.getDouble(this.configNode + ".z", defaultValue.getZ());
|
||||||
double p = this.section.getDouble(configNode + ".pitch", defaultValue.getPitch());
|
double pitch = this.section.getDouble(this.configNode + ".pitch", defaultValue.getPitch());
|
||||||
double yaw = this.section.getDouble(configNode + ".yaw", defaultValue.getYaw());
|
double yaw = this.section.getDouble(this.configNode + ".yaw", defaultValue.getYaw());
|
||||||
String w = this.section.getString(configNode + ".world", defaultValue.getWorld().getName());
|
String w = this.section.getString(this.configNode + ".world", defaultValue.getWorld().getName());
|
||||||
Location found = LocationManipulation.getLocationFromString(w + ":" + x + "," + y + "," + z + ":" + p + ":" + yaw);
|
Location found = LocationManipulation.stringToLocation(w + ":" + x + "," + y + "," + z + ":" + yaw + ":" + pitch);
|
||||||
if (found != null) {
|
if (found != null) {
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ public class AnchorManager {
|
|||||||
Set<String> anchorKeys = anchors.getKeys(false);
|
Set<String> anchorKeys = anchors.getKeys(false);
|
||||||
for (String key : anchorKeys) {
|
for (String key : anchorKeys) {
|
||||||
//world:x,y,z:pitch:yaw
|
//world:x,y,z:pitch:yaw
|
||||||
Location anchorLocation = LocationManipulation.getLocationFromString(anchors.getString(key, ""));
|
Location anchorLocation = LocationManipulation.stringToLocation(anchors.getString(key, ""));
|
||||||
if (anchorLocation != null) {
|
if (anchorLocation != null) {
|
||||||
MultiverseCore.staticLog(Level.INFO, "Loading anchor: '" + key + "'...");
|
MultiverseCore.staticLog(Level.INFO, "Loading anchor: '" + key + "'...");
|
||||||
this.anchors.put(key, anchorLocation);
|
this.anchors.put(key, anchorLocation);
|
||||||
@ -77,7 +77,7 @@ public class AnchorManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean saveAnchorLocation(String anchor, String location) {
|
public boolean saveAnchorLocation(String anchor, String location) {
|
||||||
Location parsed = LocationManipulation.getLocationFromString(location);
|
Location parsed = LocationManipulation.stringToLocation(location);
|
||||||
return parsed != null && this.saveAnchorLocation(anchor, parsed);
|
return parsed != null && this.saveAnchorLocation(anchor, parsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ import org.bukkit.entity.Vehicle;
|
|||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
import java.util.Formatter;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -35,44 +36,73 @@ public class LocationManipulation {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a Location into a Colon separated string to allow us to store it in text.
|
* Convert a Location into a Colon separated string to allow us to store it in text.
|
||||||
* world:x,y,z:pitch:yaw
|
* <p/>
|
||||||
|
* WORLD:X,Y,Z:yaw:pitch
|
||||||
|
* <p/>
|
||||||
|
* The corresponding String2Loc function is {@link #stringToLocation }
|
||||||
*
|
*
|
||||||
* @param location
|
* @param location The Location to save.
|
||||||
* @return
|
* @return The location as a string in this format: WORLD:x,y,z:yaw:pitch
|
||||||
*/
|
*/
|
||||||
public static String locationToString(Location location) {
|
public static String locationToString(Location location) {
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
StringBuilder l = new StringBuilder();
|
StringBuilder l = new StringBuilder();
|
||||||
l.append(location.getWorld().getName() + ":");
|
Formatter formatter = new Formatter(l);
|
||||||
l.append(location.getBlockX() + ",");
|
formatter.format("%s:%.2f,%.2f,%.2f:%.2f:%.2f", location.getWorld().getName(), location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
||||||
l.append(location.getBlockY() + ",");
|
return formatter.toString();
|
||||||
l.append(location.getBlockZ() + ":");
|
|
||||||
l.append(location.getYaw() + ":");
|
|
||||||
l.append(location.getPitch());
|
|
||||||
return l.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a String to a Location.
|
* Returns a new location from a given string. The format is as follows:
|
||||||
|
* <p/>
|
||||||
|
* WORLD:X,Y,Z:yaw:pitch
|
||||||
|
* <p/>
|
||||||
|
* The corresponding Location2String function is {@link #stringToLocation }
|
||||||
*
|
*
|
||||||
* @param world
|
* @param locationString The location represented as a string (WORLD:X,Y,Z:yaw:pitch)
|
||||||
* @param xStr
|
* @return A new location defined by the string or null if the string was invalid.
|
||||||
* @param yStr
|
|
||||||
* @param zStr
|
|
||||||
* @param yawStr
|
|
||||||
* @param pitchStr
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public Location stringToLocation(World world, String xStr, String yStr, String zStr, String yawStr, String pitchStr) {
|
public static Location stringToLocation(String locationString) {
|
||||||
double x = Double.parseDouble(xStr);
|
//format:
|
||||||
double y = Double.parseDouble(yStr);
|
//world:x,y,z:pitch:yaw
|
||||||
double z = Double.parseDouble(zStr);
|
if (locationString == null) {
|
||||||
float yaw = Float.valueOf(yawStr);
|
return null;
|
||||||
float pitch = Float.valueOf(pitchStr);
|
}
|
||||||
|
|
||||||
return new Location(world, x, y, z, yaw, pitch);
|
// Split the whole string, format is:
|
||||||
|
// {'world', 'x,y,z'[, 'pitch', 'yaw']}
|
||||||
|
String[] split = locationString.split(":");
|
||||||
|
if (split.length < 2 || split.length > 4) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// Split the xyz string, format is:
|
||||||
|
// {'x', 'y', 'z'}
|
||||||
|
String[] xyzsplit = split[1].split(",");
|
||||||
|
if (xyzsplit.length != 3) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify the world is valid
|
||||||
|
World w = Bukkit.getWorld(split[0]);
|
||||||
|
if (w == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
float pitch = 0;
|
||||||
|
float yaw = 0;
|
||||||
|
if (split.length == 3) {
|
||||||
|
yaw = (float) Double.parseDouble(split[2]);
|
||||||
|
}
|
||||||
|
if (split.length == 4) {
|
||||||
|
pitch = (float) Double.parseDouble(split[2]);
|
||||||
|
}
|
||||||
|
return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]), yaw, pitch);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -221,43 +251,4 @@ public class LocationManipulation {
|
|||||||
int z = vector.getZ() < 0 ? vector.getZ() == 0 ? 0 : -1 : 1;
|
int z = vector.getZ() < 0 ? vector.getZ() == 0 ? 0 : -1 : 1;
|
||||||
return location.add(x, 0, z);
|
return location.add(x, 0, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Location getLocationFromString(String value) {
|
|
||||||
//format:
|
|
||||||
//world:x,y,z:pitch:yaw
|
|
||||||
if (value == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Split the whole string, format is:
|
|
||||||
// {'world', 'x,y,z'[, 'pitch', 'yaw']}
|
|
||||||
String[] split = value.split(":");
|
|
||||||
if (split.length < 2 || split.length > 4) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// Split the xyz string, format is:
|
|
||||||
// {'x', 'y', 'z'}
|
|
||||||
String[] xyzsplit = split[1].split(",");
|
|
||||||
if (xyzsplit.length != 3) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify the world is valid
|
|
||||||
World w = Bukkit.getWorld(split[0]);
|
|
||||||
if (w == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (split.length == 2) {
|
|
||||||
return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]));
|
|
||||||
}
|
|
||||||
if (split.length == 3) {
|
|
||||||
return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]), (float) Double.parseDouble(split[2]), (float) 0.0);
|
|
||||||
}
|
|
||||||
return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]), (float) Double.parseDouble(split[2]), (float) Double.parseDouble(split[3]));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user