SimpleProtect/src/cn/citycraft/SimpleProtect/listen/NetherDoor.java

71 lines
2.4 KiB
Java

package cn.citycraft.SimpleProtect.listen;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.scheduler.BukkitRunnable;
import cn.citycraft.SimpleProtect.SimpleProtect;
import cn.citycraft.SimpleProtect.config.Config;
public class NetherDoor implements Listener {
public FileConfiguration getConfig;
public Location spawn;
SimpleProtect plugin;
public NetherDoor(SimpleProtect main) {
plugin = main;
}
// public NetherDoor() {
// throw new UnsupportedOperationException("Not yet implemented");
// }
@EventHandler
public void onJoin(final PlayerJoinEvent e) {
new BukkitRunnable() {
@Override
public void run() {
Player p = e.getPlayer();
Location loc = p.getLocation();
World world = loc.getWorld();
double x = loc.getX();
double y = loc.getY();
double z = loc.getZ();
Location loc_top = new Location(world, x, y + 1.0D, z);
Location loc_bottom = new Location(world, x, y - 1.0D, z);
Location loc_xleft = new Location(world, x + 1.0D, y, z);
Location loc_xright = new Location(world, x - 1.0D, y, z);
Location loc_zleft = new Location(world, x, y, z + 1.0D);
Location loc_zright = new Location(world, x, y, z - 1.0D);
if (loc_top.getBlock().getType() == Material.PORTAL
|| loc_bottom.getBlock().getType() == Material.PORTAL
|| loc_xleft.getBlock().getType() == Material.PORTAL
|| loc_xright.getBlock().getType() == Material.PORTAL
|| loc_zleft.getBlock().getType() == Material.PORTAL
|| loc_zright.getBlock().getType() == Material.PORTAL) {
p.sendMessage(plugin.getfullmsg("SafeNetherDoor.Tip"));
World lworld = Bukkit
.getWorld((String) Config.getInstance().get(
"SafeNetherDoor.World", "world"));
double lx = Config.getInstance().getInt("SafeNetherDoor.X",
0);
double ly = Config.getInstance().getInt("SafeNetherDoor.Y",
0);
double lz = Config.getInstance().getInt("SafeNetherDoor.Z",
0);
spawn = new Location(lworld, lx, ly, lz);
p.teleport(spawn);
}
}
}.runTaskLater(plugin, 15);
}
}