Add new PlayerDestination, this build should be treated as unstable

This commit is contained in:
Eric Stokes 2011-08-07 08:29:23 -06:00
parent c9f8b06f34
commit 23ea0e0c37
10 changed files with 136 additions and 32 deletions

View File

@ -83,14 +83,14 @@ public class MVPermissions implements PermissionsInterface {
}
public Boolean canEnterDestination(Player p, MVDestination d) {
if (d == null || d.getLocation() == null) {
if (d == null || d.getLocation(p) == null) {
return false;
}
String worldName = d.getLocation().getWorld().getName();
String worldName = d.getLocation(p).getWorld().getName();
if (!this.plugin.isMVWorld(worldName)) {
return false;
}
if(!canEnterLocation(p, d.getLocation())) {
if(!canEnterLocation(p, d.getLocation(p))) {
return false;
}
return this.hasPermission(p, d.getRequiredPermission(), false);

View File

@ -56,7 +56,7 @@ import com.onarandombox.MultiverseCore.commands.TeleportCommand;
import com.onarandombox.MultiverseCore.commands.UnloadCommand;
import com.onarandombox.MultiverseCore.commands.VersionCommand;
import com.onarandombox.MultiverseCore.commands.WhoCommand;
import com.onarandombox.MultiverseCore.configuration.DefaultConfiguration;
import com.onarandombox.MultiverseCore.configuration.DefaultConfig;
import com.onarandombox.MultiverseCore.configuration.MVConfigMigrator;
import com.onarandombox.MultiverseCore.configuration.MVCoreConfigMigrator;
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
@ -65,6 +65,7 @@ import com.onarandombox.MultiverseCore.listeners.MVPluginListener;
import com.onarandombox.utils.DebugLog;
import com.onarandombox.utils.DestinationFactory;
import com.onarandombox.utils.ExactDestination;
import com.onarandombox.utils.PlayerDestination;
import com.onarandombox.utils.PurgeWorlds;
import com.onarandombox.utils.UpdateChecker;
import com.onarandombox.utils.WorldDestination;
@ -171,6 +172,7 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
this.destFactory.registerDestinationType(WorldDestination.class, "");
this.destFactory.registerDestinationType(WorldDestination.class, "w");
this.destFactory.registerDestinationType(ExactDestination.class, "e");
this.destFactory.registerDestinationType(PlayerDestination.class, "pl");
}
/**
@ -199,8 +201,8 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
public void loadConfigs() {
// Call the defaultConfiguration class to create the config files if they don't already exist.
new DefaultConfiguration(getDataFolder(), "config.yml", this.migrator);
new DefaultConfiguration(getDataFolder(), "worlds.yml", this.migrator);
new DefaultConfig(getDataFolder(), "config.yml", this.migrator);
new DefaultConfig(getDataFolder(), "worlds.yml", this.migrator);
// Now grab the Configuration Files.
this.configMV = new Configuration(new File(getDataFolder(), "config.yml"));
this.configWorlds = new Configuration(new File(getDataFolder(), "worlds.yml"));
@ -423,7 +425,7 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
this.log(Level.INFO, "World " + name + " was unloaded from memory.");
this.unloadWorld(name, true);
return true;
} else if(this.getServer().getWorld(name) != null) {
} else if (this.getServer().getWorld(name) != null) {
this.log(Level.WARNING, "Hmm Multiverse does not know about this world but it's still loaded in memory.");
this.log(Level.WARNING, "To be on the safe side, you should import it then try unloading again...");
} else {

View File

@ -87,7 +87,7 @@ public class TeleportCommand extends MultiverseCommand {
teleporter.sendMessage("Doesn't look like you're allowed to send " + ChatColor.GOLD + teleportee.getName() + ChatColor.WHITE + " to " + ChatColor.RED + "there...");
}
return;
} else if (teleporter != null && !this.plugin.getPermissions().canTravelFromLocation(teleporter, d.getLocation())) {
} else if (teleporter != null && !this.plugin.getPermissions().canTravelFromLocation(teleporter, d.getLocation(teleportee))) {
if (teleportee.equals(teleporter)) {
teleporter.sendMessage("DOH! Doesn't look like you can get to " + ChatColor.RED + "THERE from " + ChatColor.GREEN + teleporter.getWorld().getName());
} else {
@ -95,7 +95,7 @@ public class TeleportCommand extends MultiverseCommand {
}
return;
}
Location l = d.getLocation();
Location l = d.getLocation(teleportee);
if (l == null) {
teleporter.sendMessage("Sorry Boss, I tried everything, but just couldn't teleport ya there!");
return;

View File

@ -28,14 +28,20 @@ public class WhoCommand extends MultiverseCommand {
public void runCommand(CommandSender sender, List<String> args) {
// If this command was sent from a Player then we need to check Permissions
Player p = null;
// By default, show all from the console
boolean showAll = true;
if (sender instanceof Player) {
p = (Player) sender;
showAll = false;
}
List<MVWorld> worlds = new ArrayList<MVWorld>();
if (args.size() > 0) {
if (this.plugin.isMVWorld(args.get(0))) {
if (args.get(0).equalsIgnoreCase("--all") || args.get(0).equalsIgnoreCase("-a")) {
showAll = true;
worlds = new ArrayList<MVWorld>(this.plugin.getMVWorlds());
} else if (this.plugin.isMVWorld(args.get(0))) {
worlds.add(this.plugin.getMVWorld(args.get(0)));
} else {
sender.sendMessage(ChatColor.RED + "World does not exist");
@ -45,6 +51,14 @@ public class WhoCommand extends MultiverseCommand {
worlds = new ArrayList<MVWorld>(this.plugin.getMVWorlds());
}
if (worlds.size() == 0) {
sender.sendMessage("Multiverse does not know about any of your worlds :(");
} else if (worlds.size() == 1) {
sender.sendMessage(ChatColor.AQUA + "--- " + "Players in" + ChatColor.YELLOW + worlds.get(0) + ChatColor.AQUA + " ---");
} else {
sender.sendMessage(ChatColor.AQUA + "--- There are players in ---");
}
for (MVWorld world : worlds) {
if (!(this.plugin.isMVWorld(world.getName()))) {
continue;
@ -56,6 +70,10 @@ public class WhoCommand extends MultiverseCommand {
List<Player> players = world.getCBWorld().getPlayers();
String result = "";
if (players.size() <= 0 && !showAll) {
continue;
}
if (players.size() <= 0) {
result = "Empty";
} else {

View File

@ -4,32 +4,27 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
/**
* https://github.com/Nijikokun/iConomy3/blob/master/com/nijiko/coelho/iConomy/iConomy.java
*
* @author Nijikokun & Coelho
*/
public class DefaultConfiguration {
public class DefaultConfig {
public DefaultConfiguration(File folder, String name, MVConfigMigrator migrator) {
public DefaultConfig(File folder, String name, MVConfigMigrator migrator) {
File actual = new File(folder, name);
if(actual.exists() && migrator.createdDefaults.contains(name)) {
if (actual.exists() && migrator.createdDefaults.contains(name)) {
actual.delete();
}
// If defaults have been created, and we're being called again, we should try to migrate
if (!actual.exists() && !migrator.migrate(name, folder)) {
InputStream input = this.getClass().getResourceAsStream("/defaults/" + name);
if (input != null) {
FileOutputStream output = null;
InputStream defConfig = this.getClass().getResourceAsStream("/defaults/" + name);
if (defConfig != null) {
FileOutputStream newConfig = null;
try {
output = new FileOutputStream(actual);
newConfig = new FileOutputStream(actual);
byte[] buf = new byte[8192];
int length = 0;
while ((length = input.read(buf)) > 0) {
output.write(buf, 0, length);
while ((length = defConfig.read(buf)) > 0) {
newConfig.write(buf, 0, length);
}
migrator.createdDefaults.add(name);
@ -37,14 +32,14 @@ public class DefaultConfiguration {
e.printStackTrace();
} finally {
try {
if (input != null)
input.close();
if (defConfig != null)
defConfig.close();
} catch (Exception e) {
}
try {
if (output != null)
output.close();
if (newConfig != null)
newConfig.close();
} catch (Exception e) {
}

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin;
import com.onarandombox.MultiverseCore.MultiverseCore;
@ -64,7 +65,7 @@ public class ExactDestination implements MVDestination {
}
@Override
public Location getLocation() {
public Location getLocation(Entity e) {
return this.location;
}

View File

@ -2,6 +2,7 @@ package com.onarandombox.utils;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin;
public class InvalidDestination implements MVDestination {
@ -17,7 +18,7 @@ public class InvalidDestination implements MVDestination {
}
@Override
public Location getLocation() {
public Location getLocation(Entity e) {
return null;
}

View File

@ -1,12 +1,13 @@
package com.onarandombox.utils;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin;
public interface MVDestination {
public String getIdentifer();
public boolean isThisType(JavaPlugin plugin, String dest);
public Location getLocation();
public Location getLocation(Entity e);
public boolean isValid();
public void setDestination(JavaPlugin plugin, String dest);
public String getType();

View File

@ -0,0 +1,85 @@
package com.onarandombox.utils;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class PlayerDestination implements MVDestination {
String player;
private boolean isValid;
private JavaPlugin plugin;
@Override
public String getIdentifer() {
return "pl";
}
@Override
public boolean isThisType(JavaPlugin plugin, String dest) {
String[] items = dest.split(":");
if (items.length != 2) {
return false;
}
if (!items[0].equalsIgnoreCase("pl")) {
return false;
}
return true;
}
@Override
public Location getLocation(Entity e) {
Player p = plugin.getServer().getPlayer(this.player);
Player plLoc = null;
if (e instanceof Player) {
plLoc = (Player) e;
} else if (e.getPassenger() instanceof Player) {
plLoc = (Player) e.getPassenger();
}
if (p != null && plLoc != null && plLoc.getName().equalsIgnoreCase(p.getName())) {
return p.getLocation();
}
return null;
}
@Override
public boolean isValid() {
return this.isValid;
}
@Override
public void setDestination(JavaPlugin plugin, String dest) {
String[] items = dest.split(":");
if (items.length != 2) {
this.isValid = false;
}
if (!items[0].equalsIgnoreCase("pl")) {
this.isValid = false;
}
this.isValid = true;
this.player = items[1];
this.plugin = plugin;
}
@Override
public String getType() {
return "Player";
}
@Override
public String getName() {
return this.player;
}
@Override
public String toString() {
return "pl:" + this.player;
}
@Override
public String getRequiredPermission() {
return null;
}
}

View File

@ -1,6 +1,7 @@
package com.onarandombox.utils;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin;
import com.onarandombox.MultiverseCore.MVWorld;
@ -39,7 +40,7 @@ public class WorldDestination implements MVDestination {
}
@Override
public Location getLocation() {
public Location getLocation(Entity e) {
Location spawnLoc = this.world.getCBWorld().getSpawnLocation();
if (this.yaw >= 0) {
// Only modify the yaw if its set.