mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-25 12:05:14 +01:00
Here it goes again
This commit is contained in:
parent
0efc0c98ff
commit
a5df509fdf
133
src/com/onarandombox/MultiVerseCore/MVTeleport.java
Normal file
133
src/com/onarandombox/MultiVerseCore/MVTeleport.java
Normal file
@ -0,0 +1,133 @@
|
||||
package com.onarandombox.MultiVerseCore;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class MVTeleport {
|
||||
|
||||
MultiVerseCore plugin;
|
||||
|
||||
public MVTeleport(MultiVerseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function gets a safe place to teleport to.
|
||||
*
|
||||
* @param world
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public Location getDestination(World world, Player player) {
|
||||
|
||||
Location location = player.getLocation();
|
||||
|
||||
double srcComp = plugin.worlds.get(player.getWorld().getName()).compression;
|
||||
double trgComp = plugin.worlds.get(world.getName()).compression;
|
||||
|
||||
double x = location.getX() / (srcComp != 0 ? srcComp : 1) * trgComp + 0.5;
|
||||
double y = location.getY();
|
||||
double z = location.getZ() / (srcComp != 0 ? srcComp : 1) * trgComp + 0.5;
|
||||
|
||||
if (y < 1 && world.getEnvironment() == Environment.NORMAL)
|
||||
y = 1;
|
||||
|
||||
while (this.blockIsAboveAir(world, x, y, z)) {
|
||||
y--;
|
||||
}
|
||||
while (this.blockIsNotSafe(world, x, y, z)) {
|
||||
y++;
|
||||
if (y == 110) {
|
||||
y = 1;
|
||||
x = x + 1;
|
||||
z = z + 1;
|
||||
}
|
||||
}
|
||||
return new Location(world, x, y, z, location.getYaw(),
|
||||
location.getPitch());
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks whether the block at the given coordinates are above
|
||||
* air or not.
|
||||
*
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @return
|
||||
*/
|
||||
private boolean blockIsAboveAir(World world, double x, double y, double z) {
|
||||
return (world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1),
|
||||
(int) Math.floor(z)).getType() == Material.AIR);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks whether the block at the coordinates given is safe
|
||||
* or not by checking for Laval/Fire/Air etc.
|
||||
*
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @return
|
||||
*/
|
||||
private boolean blockIsNotSafe(World world, double x, double y, double z) {
|
||||
if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1),
|
||||
(int) Math.floor(z)).getType() == Material.LAVA))
|
||||
return true;
|
||||
if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1),
|
||||
(int) Math.floor(z)).getType() == Material.STATIONARY_LAVA))
|
||||
return true;
|
||||
if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1),
|
||||
(int) Math.floor(z)).getType() == Material.FIRE))
|
||||
return true;
|
||||
if (world.getBlockAt((int) Math.floor(x), (int) Math.floor(y),
|
||||
(int) Math.floor(z)).getType() != Material.AIR
|
||||
|| world.getBlockAt((int) Math.floor(x),
|
||||
(int) Math.floor(y + 1), (int) Math.floor(z)).getType() != Material.AIR)
|
||||
return true;
|
||||
if (blockIsAboveAir(world, x, y, z))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a Player can teleport to the Destination world from there
|
||||
* current world. This checks against the Worlds Blacklist
|
||||
*
|
||||
* @param p
|
||||
* @param w
|
||||
* @return
|
||||
*/
|
||||
public Boolean canTravelToWorld(World w, Player p) {
|
||||
List<String> blackList = this.plugin.worlds.get(w.getName()).worldBlacklist;
|
||||
|
||||
boolean returnValue = true;
|
||||
|
||||
if (blackList.size() == 0)
|
||||
returnValue = true;
|
||||
|
||||
for (int i = 0; i < blackList.size(); i++)
|
||||
if (blackList.get(i).equalsIgnoreCase(p.getWorld().getName())) {
|
||||
returnValue = false;
|
||||
break;
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
public boolean teleport(World w, Player p) {
|
||||
if (canTravelToWorld(w, p)) {
|
||||
p.teleportTo(getDestination(w, p));
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
}
|
@ -1,21 +1,26 @@
|
||||
package com.onarandombox.MultiVerseCore;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
import com.onarandombox.utils.stringLocation;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class MVWorld {
|
||||
|
||||
private MultiVerseCore plugin; // Hold the Plugin Instance.
|
||||
private Configuration config; // Hold the Configuration File.
|
||||
|
||||
public World world; // The World Instance.
|
||||
public Environment environment; // Hold the Environment type EG Environment.NETHER / Environment.NORMAL
|
||||
public Location spawn; // Location of the Spawn Point.
|
||||
public Double compression; //How stretched/compressed distances are
|
||||
|
||||
public String name; // The Worlds Name, EG its folder name.
|
||||
public String alias = ""; // Short Alias for the World, this will be used in Chat Prefixes.
|
||||
@ -31,29 +36,40 @@ public class MVWorld {
|
||||
public List<String> editBlacklist; // Contain a list of Players/Groups which cannot edit this World. (Place/Destroy Blocks)
|
||||
public List<String> worldBlacklist; // Contain a list of Worlds which Players cannot use to Portal to this World.
|
||||
|
||||
public int compression = 0; // TODO: Needs a description, minds blank and can't think :).
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* @param handle - If the World was loaded by MultiVerse then this will be true and means we can do
|
||||
* what we wan't with it else it's only here to be read from.
|
||||
*/
|
||||
public MVWorld(World world, boolean handle){
|
||||
public MVWorld(World world, Configuration config, MultiVerseCore instance){
|
||||
this.config = config;
|
||||
this.plugin = instance;
|
||||
|
||||
this.world = world;
|
||||
this.name = world.getName();
|
||||
|
||||
this.alias = config.getString("worlds." + this.name + ".alias","");
|
||||
|
||||
this.environment = world.getEnvironment();
|
||||
|
||||
// The following should already of been set when the World was created, so we don't wan't to overwrite these values we'll just grab them.
|
||||
this.monsters = ((CraftWorld) world).getHandle().D = monsters; // TODO: Swap to Bukkit Function when implemented.
|
||||
this.animals = ((CraftWorld) world).getHandle().E = animals; // TODO: Swap to Bukkit Function when implemented.
|
||||
this.spawn = getSpawn(this.config.getString("worlds." + name + ".spawn", "").split(":"));
|
||||
this.compression = config.getDouble("worlds." + this.name + ".compression", 1.0);
|
||||
|
||||
// If MultiVerse created/loaded the World then it means we wan't to handle it as well, otherwise
|
||||
// we don't touch any settings unless the user specifically asks us to.
|
||||
if(handle==true){
|
||||
this.alias = MultiVerseCore.configWorlds.getString("worlds." + this.name + ".alias","");
|
||||
this.compression = MultiVerseCore.configWorlds.getInt("worlds." + this.name + ".compression", 0);
|
||||
this.pvp = MultiVerseCore.configWorlds.getBoolean("worlds." + this.name + ".pvp", false);
|
||||
this.monsters = config.getBoolean("worlds." + this.name + ".monsters", true);
|
||||
this.animals = config.getBoolean("worlds." + this.name + ".animals", true);
|
||||
this.pvp = config.getBoolean("worlds." + this.name + ".pvp", true);
|
||||
|
||||
this.joinWhitelist = config.getStringList("worlds." + name + ".playerWhitelist", new ArrayList<String>());
|
||||
this.joinBlacklist = config.getStringList("worlds." + name + ".playerBlacklist", new ArrayList<String>());
|
||||
this.worldBlacklist = config.getStringList("worlds." + name + ".worldBlacklist", new ArrayList<String>());
|
||||
this.blockBlacklist = config.getStringList("worlds." + name + ".blockBlacklist", new ArrayList<String>());
|
||||
this.editWhitelist = config.getStringList("worlds." + name + ".editWhitelist", new ArrayList<String>());
|
||||
this.editBlacklist = config.getStringList("worlds." + name + ".editBlacklist", new ArrayList<String>());
|
||||
}
|
||||
|
||||
private Location getSpawn(String[] spawn){
|
||||
Location l = null;
|
||||
|
||||
if(spawn.length!=5){
|
||||
return this.world.getSpawnLocation();
|
||||
} else {
|
||||
return new stringLocation().stringToLocation(world, spawn[0], spawn[1], spawn[2], spawn[3], spawn[4]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -58,10 +58,10 @@ public class MultiVerseCore extends JavaPlugin {
|
||||
private MVWorldListener worldListener = new MVWorldListener(this);
|
||||
|
||||
// HashMap to contain all the Worlds which this Plugin will manage.
|
||||
public static HashMap<String,MVWorld> worlds = new HashMap<String,MVWorld>();
|
||||
public HashMap<String,MVWorld> worlds = new HashMap<String,MVWorld>();
|
||||
|
||||
// HashMap to contain information relating to the Players.
|
||||
public static HashMap<String, MVPlayerSession> playerSessions = new HashMap<String, MVPlayerSession>();
|
||||
public HashMap<String, MVPlayerSession> playerSessions = new HashMap<String, MVPlayerSession>();
|
||||
|
||||
/**
|
||||
* Constructor... Perform the Necessary tasks here.
|
||||
@ -152,14 +152,14 @@ public class MultiVerseCore extends JavaPlugin {
|
||||
int count = 0;
|
||||
|
||||
// Grab all the Worlds that already exist.
|
||||
List<World> worlds = getServer().getWorlds();
|
||||
List<World> lworlds = getServer().getWorlds();
|
||||
|
||||
// You never know these days... bloody NPE's.
|
||||
if(worlds != null && worlds.size()>0){
|
||||
for (World world : worlds){
|
||||
if(lworlds != null && lworlds.size()>0){
|
||||
for (World world : lworlds){
|
||||
log.info(logPrefix + "Loading existing World - '" + world.getName() + "' - " + world.getEnvironment().toString()); // Output to the Log that wea re loading a world, specify the name and environment type.
|
||||
|
||||
MultiVerseCore.worlds.put(world.getName(), new MVWorld(world, false)); // Place the World into the HashMap.
|
||||
worlds.put(world.getName(), new MVWorld(world, MultiVerseCore.configWorlds, this)); // Place the World into the HashMap.
|
||||
count++; // Increment the World Count.
|
||||
}
|
||||
}
|
||||
@ -171,7 +171,7 @@ public class MultiVerseCore extends JavaPlugin {
|
||||
if(worldKeys != null){
|
||||
for (String worldKey : worldKeys){
|
||||
// If this World already exists within the HashMap then we don't need to process it.
|
||||
if(MultiVerseCore.worlds.containsKey(worldKey)){
|
||||
if(worlds.containsKey(worldKey)){
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -258,7 +258,7 @@ public class MultiVerseCore extends JavaPlugin {
|
||||
* Basic Debug Output function, if we've enabled debugging we'll output more information.
|
||||
*/
|
||||
public void debugMsg(String msg, Player p){
|
||||
if(this.debug){
|
||||
if(debug){
|
||||
log.info(msg);
|
||||
if(p!=null){
|
||||
p.sendMessage(msg);
|
||||
|
Loading…
Reference in New Issue
Block a user