mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-23 08:41:21 +01:00
Add anchors
This commit is contained in:
parent
803eb84f3f
commit
e110b1f6a5
@ -23,7 +23,6 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.omg.CosNaming._BindingIteratorImplBase;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -721,4 +720,15 @@ public class MVWorld implements MultiverseWorld {
|
||||
public boolean getBedRespawn() {
|
||||
return ((BooleanConfigProperty) this.getKnownProperty("bedrespawn")).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAllPropertyNames() {
|
||||
ChatColor color = ChatColor.AQUA;
|
||||
String result = "";
|
||||
for(String name : this.propertyList.keySet()) {
|
||||
result += color + name + " ";
|
||||
color = (color == ChatColor.AQUA)? ChatColor.GOLD:ChatColor.AQUA;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
public static boolean EnforceGameModes;
|
||||
public static boolean PrefixChat;
|
||||
public static Map<String, String> teleportQueue = new HashMap<String, String>();
|
||||
private AnchorManager anchorManager = new AnchorManager(this);
|
||||
|
||||
/**
|
||||
* This method is used to find out who is teleporting a player.
|
||||
@ -197,6 +198,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
} else {
|
||||
this.log(Level.SEVERE, "Your configs were not loaded. Very little will function in Multiverse.");
|
||||
}
|
||||
this.anchorManager.loadAnchors();
|
||||
}
|
||||
|
||||
private boolean validateAllpay() {
|
||||
@ -251,6 +253,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
this.destFactory.registerDestinationType(PlayerDestination.class, "pl");
|
||||
this.destFactory.registerDestinationType(CannonDestination.class, "ca");
|
||||
this.destFactory.registerDestinationType(BedDestination.class, "b");
|
||||
this.destFactory.registerDestinationType(AnchorDestination.class, "a");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -339,6 +342,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
this.commandHandler.registerCommand(new ModifyRemoveCommand(this));
|
||||
this.commandHandler.registerCommand(new ModifyClearCommand(this));
|
||||
this.commandHandler.registerCommand(new ConfigCommand(this));
|
||||
this.commandHandler.registerCommand(new AnchorCommand(this));
|
||||
// Misc Commands
|
||||
this.commandHandler.registerCommand(new EnvironmentCommand(this));
|
||||
this.commandHandler.registerCommand(new DebugCommand(this));
|
||||
@ -671,4 +675,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public AnchorManager getAnchorManager() {
|
||||
return this.anchorManager;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,9 +36,7 @@ public interface MultiverseWorld {
|
||||
* @param property The name of a world property to set.
|
||||
* @param value A value in string representation, it will be parsed to the correct type.
|
||||
* @param sender The sender who wants this value to be set.
|
||||
*
|
||||
* @return True if the value was set, false if not.
|
||||
*
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||
*/
|
||||
public boolean setProperty(String property, String value, CommandSender sender) throws PropertyDoesNotExistException;
|
||||
@ -48,9 +46,7 @@ public interface MultiverseWorld {
|
||||
* It will throw a PropertyDoesNotExistException if the property is not found.
|
||||
*
|
||||
* @param property The name of a world property to get.
|
||||
*
|
||||
* @return A valid MVWorldProperty.
|
||||
*
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||
*/
|
||||
public MVConfigProperty getProperty(String property) throws PropertyDoesNotExistException;
|
||||
@ -60,9 +56,7 @@ public interface MultiverseWorld {
|
||||
* It will throw a PropertyDoesNotExistException if the property is not found.
|
||||
*
|
||||
* @param property The name of a world property to get.
|
||||
*
|
||||
* @return A valid MVWorldProperty.
|
||||
*
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||
*/
|
||||
public String getPropertyValue(String property) throws PropertyDoesNotExistException;
|
||||
@ -71,7 +65,6 @@ public interface MultiverseWorld {
|
||||
* Removes all values from the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
||||
*
|
||||
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.AddProperties} to clear.
|
||||
*
|
||||
* @return True if it was cleared, false if not.
|
||||
*/
|
||||
public boolean clearVariable(String property);
|
||||
@ -81,7 +74,6 @@ public interface MultiverseWorld {
|
||||
*
|
||||
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.AddProperties} to add a value to.
|
||||
* @param value A value in string representation, it will be parsed to the correct type.
|
||||
*
|
||||
* @return True if the value was added, false if not.
|
||||
*/
|
||||
public boolean addToVariable(String property, String value);
|
||||
@ -92,7 +84,6 @@ public interface MultiverseWorld {
|
||||
* @param property The name of a {@link com.onarandombox.MultiverseCore.enums.AddProperties} to remove a value
|
||||
* from.
|
||||
* @param value A value in string representation, it will be parsed to the correct type.
|
||||
*
|
||||
* @return True if the value was removed, false if not.
|
||||
*/
|
||||
public boolean removeFromVariable(String property, String value);
|
||||
@ -154,7 +145,6 @@ public interface MultiverseWorld {
|
||||
* Sets the color that this world's name/alias will display as.
|
||||
*
|
||||
* @param color A valid color name.
|
||||
*
|
||||
* @return True if the color was set, false if not.
|
||||
*/
|
||||
public boolean setColor(String color);
|
||||
@ -170,7 +160,6 @@ public interface MultiverseWorld {
|
||||
* Tells you if someone entered a valid color.
|
||||
*
|
||||
* @param color A string that may translate to a color.
|
||||
*
|
||||
* @return True if it is a color, false if not.
|
||||
*/
|
||||
public boolean isValidAliasColor(String color);
|
||||
@ -271,7 +260,6 @@ public interface MultiverseWorld {
|
||||
* the name that resides in the Bukkit enum, ex. PEACEFUL
|
||||
*
|
||||
* @param difficulty The difficulty to set the world to as a string.
|
||||
*
|
||||
* @return True if success, false if the provided string
|
||||
* could not be translated to a difficulty.
|
||||
*/
|
||||
@ -318,7 +306,6 @@ public interface MultiverseWorld {
|
||||
*
|
||||
* @param gameMode A valid game mode string (either
|
||||
* an int ex. 0 or a string ex. creative).
|
||||
*
|
||||
* @return True if the game mode was successfully changed, false if not.
|
||||
*/
|
||||
public boolean setGameMode(String gameMode);
|
||||
@ -380,7 +367,6 @@ public interface MultiverseWorld {
|
||||
* Returns true upon success, false upon failure.
|
||||
*
|
||||
* @param respawnWorld The name of a world that exists on the server.
|
||||
*
|
||||
* @return True if respawnWorld existed, false if not.
|
||||
*/
|
||||
public boolean setRespawnToWorld(String respawnWorld);
|
||||
@ -449,11 +435,10 @@ public interface MultiverseWorld {
|
||||
public void setAllowMonsterSpawn(boolean allowMonsterSpawn);
|
||||
|
||||
/**
|
||||
* TODO: Write these docs.
|
||||
* Clears a list property (sets it to []).
|
||||
*
|
||||
* @param property
|
||||
*
|
||||
* @return
|
||||
* @param property The property to clear.
|
||||
* @return True if success, false if fail.
|
||||
*/
|
||||
public boolean clearList(String property);
|
||||
|
||||
@ -519,5 +504,10 @@ public interface MultiverseWorld {
|
||||
*/
|
||||
public boolean getBedRespawn();
|
||||
|
||||
|
||||
/**
|
||||
* Gets all the names of all properties that can be SET
|
||||
*
|
||||
* @return All property names, with alternating colors.
|
||||
*/
|
||||
public String getAllPropertyNames();
|
||||
}
|
||||
|
@ -0,0 +1,133 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AnchorCommand extends PaginatedCoreCommand<String> {
|
||||
|
||||
public AnchorCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Create, Delete and Manage Anchor Destinations.");
|
||||
this.setCommandUsage("/mv anchor " + ChatColor.GREEN + "{name}" + ChatColor.GOLD + " [-d]");
|
||||
this.setArgRange(0, 2);
|
||||
this.addKey("mv anchor");
|
||||
this.addKey("mv anchors");
|
||||
this.addKey("mvanchor");
|
||||
this.addKey("mvanchors");
|
||||
this.addCommandExample("/mv anchor " + ChatColor.GREEN + "awesomething");
|
||||
this.addCommandExample("/mv anchor " + ChatColor.GREEN + "otherthing");
|
||||
this.addCommandExample("/mv anchor " + ChatColor.GREEN + "awesomething " + ChatColor.RED + "-d");
|
||||
this.addCommandExample("/mv anchors ");
|
||||
this.setPermission("multiverse.core.anchor", "Allows management of Anchor Destinations.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
private List<String> getFancyAnchorList(Player p) {
|
||||
List<String> anchorList = new ArrayList<String>();
|
||||
ChatColor color = ChatColor.GREEN;
|
||||
for (String anchor : this.plugin.getAnchorManager().getAnchors(p)) {
|
||||
anchorList.add(color + anchor);
|
||||
color = (color == ChatColor.GREEN) ? ChatColor.GOLD : ChatColor.GREEN;
|
||||
}
|
||||
return anchorList;
|
||||
}
|
||||
|
||||
private void showList(CommandSender sender, List<String> args) {
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + "====[ Multiverse Anchor List ]====");
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
|
||||
|
||||
FilterObject filterObject = this.getPageAndFilter(args);
|
||||
|
||||
List<String> availableAnchors = new ArrayList<String>(this.getFancyAnchorList(p));
|
||||
if (filterObject.getFilter().length() > 0) {
|
||||
availableAnchors = this.getFilteredItems(availableAnchors, filterObject.getFilter());
|
||||
if (availableAnchors.size() == 0) {
|
||||
sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE + "No anchors matched your filter: " + ChatColor.AQUA + filterObject.getFilter());
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (availableAnchors.size() == 0) {
|
||||
sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE + "No anchors were defined.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
for (String c : availableAnchors) {
|
||||
sender.sendMessage(c);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int totalPages = (int) Math.ceil(availableAnchors.size() / (this.ITEMS_PER_PAGE + 0.0));
|
||||
|
||||
if (filterObject.getPage() > totalPages) {
|
||||
filterObject.setPage(totalPages);
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.AQUA + " Page " + filterObject.getPage() + " of " + totalPages);
|
||||
|
||||
this.showPage(filterObject.getPage(), sender, availableAnchors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (args.size() == 0) {
|
||||
this.showList(sender, args);
|
||||
return;
|
||||
}
|
||||
if (args.size() == 2) {
|
||||
if (this.plugin.getAnchorManager().deleteAnchor(args.get(0))) {
|
||||
sender.sendMessage("Anchor '" + args.get(0) + "' was successfully " + ChatColor.RED + "deleted!");
|
||||
} else {
|
||||
sender.sendMessage("Anchor '" + args.get(0) + "' was " + ChatColor.RED + " NOT " + ChatColor.WHITE + "deleted!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("You must be a player to create Anchors.");
|
||||
return;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
if (this.plugin.getAnchorManager().saveAnchorLocation(args.get(0), player.getLocation())) {
|
||||
sender.sendMessage("Anchor '" + args.get(0) + "' was successfully " + ChatColor.GREEN + "created!");
|
||||
} else {
|
||||
sender.sendMessage("Anchor '" + args.get(0) + "' was " + ChatColor.RED + " NOT " + ChatColor.WHITE + "created!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getFilteredItems(List<String> availableItems, String filter) {
|
||||
List<String> filtered = new ArrayList<String>();
|
||||
for (String s : availableItems) {
|
||||
if (s.matches("(?i).*" + filter + ".*")) {
|
||||
filtered.add(s);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getItemText(String item) {
|
||||
return item;
|
||||
}
|
||||
}
|
@ -49,6 +49,13 @@ public class HelpCommand extends PaginatedCoreCommand<Command> {
|
||||
filtered.add(c);
|
||||
} else if (c.getCommandUsage().matches("(?i).*" + filter + ".*")) {
|
||||
filtered.add(c);
|
||||
} else {
|
||||
for(String example : c.getCommandExamples()) {
|
||||
if(example.matches("(?i).*" + filter + ".*")) {
|
||||
filtered.add(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
|
@ -34,7 +34,11 @@ public class ModifyCommand extends MultiverseCommand {
|
||||
children.put("multiverse.core.modify.modify", true);
|
||||
children.put("multiverse.core.modify.clear", true);
|
||||
children.put("multiverse.core.modify.remove", true);
|
||||
Permission modify = new Permission("multiverse.core.modify", "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used.", PermissionDefault.OP, children);
|
||||
Permission modify = new Permission("multiverse.core.modify", "Modify various aspects of worlds. It requires add/set/clear/remove. See the examples below", PermissionDefault.OP, children);
|
||||
this.addCommandExample(ChatColor.AQUA + "/mv modify set ?");
|
||||
this.addCommandExample(ChatColor.GREEN + "/mv modify add ?");
|
||||
this.addCommandExample(ChatColor.BLUE + "/mv modify clear ?");
|
||||
this.addCommandExample(ChatColor.RED + "/mv modify remove ?");
|
||||
this.setPermission(modify);
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@ public class ModifySetCommand extends MultiverseCommand {
|
||||
|
||||
public ModifySetCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
this.setName("Modify a World (Set a value)");
|
||||
this.setCommandUsage("/mv modify" + ChatColor.GREEN + " set {PROPERTY} {VALUE}" + ChatColor.GOLD + " [WORLD]");
|
||||
this.setArgRange(1, 3);
|
||||
@ -49,7 +50,6 @@ public class ModifySetCommand extends MultiverseCommand {
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "adjustspawn " + ChatColor.RED + "false");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "spawn");
|
||||
this.setPermission("multiverse.core.modify.set", "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,11 +33,13 @@ public class ReloadCommand extends MultiverseCommand {
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
sender.sendMessage(ChatColor.GOLD + "Reloading all Multiverse Plugin configs...");
|
||||
this.plugin.loadConfigs();
|
||||
this.plugin.getAnchorManager().loadAnchors();
|
||||
this.plugin.getMVWorldManager().loadWorlds(true);
|
||||
|
||||
List<String> configsLoaded = new ArrayList<String>();
|
||||
configsLoaded.add("Multiverse-Core - config.yml");
|
||||
configsLoaded.add("Multiverse-Core - worlds.yml");
|
||||
configsLoaded.add("Multiverse-Core - anchors.yml");
|
||||
// Create the event
|
||||
MVConfigReloadEvent configReload = new MVConfigReloadEvent(configsLoaded);
|
||||
// Fire it off
|
||||
|
@ -0,0 +1,113 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class AnchorDestination implements MVDestination {
|
||||
private boolean isValid;
|
||||
private Location location;
|
||||
private MultiverseCore plugin;
|
||||
private String name;
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "a";
|
||||
}
|
||||
|
||||
public Vector getVelocity() {
|
||||
return new Vector(0, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isThisType(JavaPlugin plugin, String destination) {
|
||||
if (!(plugin instanceof MultiverseCore)) {
|
||||
return false;
|
||||
}
|
||||
this.plugin = (MultiverseCore) plugin;
|
||||
List<String> parsed = Arrays.asList(destination.split(":"));
|
||||
// Need at least: a:name
|
||||
if (!(parsed.size() == 2)) {
|
||||
return false;
|
||||
}
|
||||
// If it's not an Anchor type
|
||||
return parsed.get(0).equalsIgnoreCase("a");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation(Entity e) {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return this.isValid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDestination(JavaPlugin plugin, String destination) {
|
||||
if (!(plugin instanceof MultiverseCore)) {
|
||||
return;
|
||||
}
|
||||
this.plugin = (MultiverseCore) plugin;
|
||||
List<String> parsed = Arrays.asList(destination.split(":"));
|
||||
// Need at least: e:world:x,y,z
|
||||
// OR e:world:x,y,z:pitch:yaw
|
||||
// so basically 3 or 5
|
||||
if (!(parsed.size() == 2)) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
this.name = parsed.get(1);
|
||||
this.location = this.plugin.getAnchorManager().getAnchorLocation(parsed.get(1));
|
||||
if(this.location == null) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
if (!parsed.get(0).equalsIgnoreCase(this.getIdentifier())) {
|
||||
this.isValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Anchor";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Anchor: " + this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (isValid) {
|
||||
return "a:" + this.name;
|
||||
}
|
||||
return "i:Invalid Destination";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRequiredPermission() {
|
||||
return "multiverse.access." + this.location.getWorld().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useSafeTeleporter() {
|
||||
// This is an ANCHOR destination, don't safely teleport here.
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Multiverse 2
|
||||
*
|
||||
* @author fernferret
|
||||
*/
|
||||
public class AnchorManager {
|
||||
private MultiverseCore plugin;
|
||||
private Map<String, Location> anchors;
|
||||
private FileConfiguration anchorConfig;
|
||||
|
||||
public AnchorManager(MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
this.anchors = new HashMap<String, Location>();
|
||||
}
|
||||
|
||||
public void loadAnchors() {
|
||||
this.anchors = new HashMap<String, Location>();
|
||||
this.anchorConfig = YamlConfiguration.loadConfiguration(new File(this.plugin.getDataFolder(), "anchors.yml"));
|
||||
this.ensureConfigIsPrepared();
|
||||
ConfigurationSection anchors = this.anchorConfig.getConfigurationSection("anchors");
|
||||
Set<String> anchorKeys = anchors.getKeys(false);
|
||||
for (String key : anchorKeys) {
|
||||
//world:x,y,z:pitch:yaw
|
||||
Location anchorLocation = LocationManipulation.getLocationFromString(anchors.getString(key, ""));
|
||||
if (anchorLocation != null) {
|
||||
MultiverseCore.staticLog(Level.INFO, "Loading anchor: '" + key + "'...");
|
||||
this.anchors.put(key, anchorLocation);
|
||||
} else {
|
||||
MultiverseCore.staticLog(Level.WARNING, "The location for anchor '" + key + "' is INVALID.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureConfigIsPrepared() {
|
||||
if (this.anchorConfig.getConfigurationSection("anchors") == null) {
|
||||
this.anchorConfig.createSection("anchors");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean saveAnchors() {
|
||||
try {
|
||||
this.anchorConfig.save(new File(this.plugin.getDataFolder(), "anchors.yml"));
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
this.plugin.log(Level.SEVERE, "Failed to save anchors.yml. Please check your file permissions.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Location getAnchorLocation(String anchor) {
|
||||
if (this.anchors.containsKey(anchor)) {
|
||||
return this.anchors.get(anchor);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean saveAnchorLocation(String anchor, String location) {
|
||||
Location parsed = LocationManipulation.getLocationFromString(location);
|
||||
return parsed != null && this.saveAnchorLocation(anchor, parsed);
|
||||
}
|
||||
|
||||
public boolean saveAnchorLocation(String anchor, Location l) {
|
||||
if (l == null) {
|
||||
return false;
|
||||
}
|
||||
this.anchorConfig.set("anchors." + anchor, LocationManipulation.locationToString(l));
|
||||
this.anchors.put(anchor, l);
|
||||
return this.saveAnchors();
|
||||
}
|
||||
|
||||
public Set<String> getAllAnchors() {
|
||||
return this.anchors.keySet();
|
||||
}
|
||||
|
||||
public Set<String> getAnchors(Player p) {
|
||||
if (p == null) {
|
||||
return this.anchors.keySet();
|
||||
}
|
||||
Set<String> anchors = new HashSet<String>();
|
||||
for(String anchor : this.anchors.keySet()) {
|
||||
Location ancLoc = this.anchors.get(anchor);
|
||||
if(ancLoc == null) {
|
||||
continue;
|
||||
}
|
||||
if(p.hasPermission("multiverse.access." + ancLoc.getWorld().getName())) {
|
||||
anchors.add(anchor);
|
||||
}
|
||||
}
|
||||
return anchors;
|
||||
}
|
||||
|
||||
public boolean deleteAnchor(String s) {
|
||||
if(this.anchors.containsKey(s)) {
|
||||
this.anchors.remove(s);
|
||||
this.anchorConfig.set("anchors." + s, null);
|
||||
return this.saveAnchors();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -35,18 +35,22 @@ public class LocationManipulation {
|
||||
|
||||
/**
|
||||
* Convert a Location into a Colon separated string to allow us to store it in text.
|
||||
* world:x,y,z:pitch:yaw
|
||||
*
|
||||
* @param location
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String locationToString(Location location) {
|
||||
if (location == null) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder l = new StringBuilder();
|
||||
l.append(location.getBlockX() + ":");
|
||||
l.append(location.getBlockY() + ":");
|
||||
l.append(location.getWorld() + ":");
|
||||
l.append(location.getBlockX() + ",");
|
||||
l.append(location.getBlockY() + ",");
|
||||
l.append(location.getBlockZ() + ":");
|
||||
l.append(location.getYaw() + ":");
|
||||
l.append(location.getPitch());
|
||||
l.append(location.getPitch() + ":");
|
||||
l.append(location.getYaw());
|
||||
return l.toString();
|
||||
}
|
||||
|
||||
@ -59,15 +63,14 @@ public class LocationManipulation {
|
||||
* @param zStr
|
||||
* @param yawStr
|
||||
* @param pitchStr
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Location stringToLocation(World world, String xStr, String yStr, String zStr, String yawStr, String pitchStr) {
|
||||
double x = Double.parseDouble(xStr);
|
||||
double y = Double.parseDouble(yStr);
|
||||
double z = Double.parseDouble(zStr);
|
||||
float yaw = Float.valueOf(yawStr).floatValue();
|
||||
float pitch = Float.valueOf(pitchStr).floatValue();
|
||||
float yaw = Float.valueOf(yawStr);
|
||||
float pitch = Float.valueOf(pitchStr);
|
||||
|
||||
return new Location(world, x, y, z, yaw, pitch);
|
||||
}
|
||||
@ -76,7 +79,6 @@ public class LocationManipulation {
|
||||
* Returns a colored string with the coords
|
||||
*
|
||||
* @param l
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String strCoords(Location l) {
|
||||
@ -96,7 +98,6 @@ public class LocationManipulation {
|
||||
* Converts a location to a printable readable formatted string including pitch/yaw
|
||||
*
|
||||
* @param l
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String strCoordsRaw(Location l) {
|
||||
@ -116,7 +117,6 @@ public class LocationManipulation {
|
||||
* Return the NESW Direction a Location is facing.
|
||||
*
|
||||
* @param location
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getDirection(Location location) {
|
||||
@ -149,7 +149,6 @@ public class LocationManipulation {
|
||||
* Returns the float yaw position for the given cardianl direction
|
||||
*
|
||||
* @param orientation
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static float getYaw(String orientation) {
|
||||
@ -166,7 +165,6 @@ public class LocationManipulation {
|
||||
* Returns a speed float from a given vector.
|
||||
*
|
||||
* @param v
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static float getSpeed(Vector v) {
|
||||
@ -181,7 +179,6 @@ public class LocationManipulation {
|
||||
*
|
||||
* @param v
|
||||
* @param direction
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Vector getTranslatedVector(Vector v, String direction) {
|
||||
@ -215,7 +212,6 @@ public class LocationManipulation {
|
||||
* Returns the next Location that an entity is traveling at
|
||||
*
|
||||
* @param v
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Location getNextBlock(Vehicle v) {
|
||||
|
Loading…
Reference in New Issue
Block a user