use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class NetherPortals method onPlayerPortal.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerPortal(PlayerPortalEvent event) {
if (DEBUG)
plugin.getLogger().info("Player portal event - reason =" + event.getCause());
UUID playerUUID = event.getPlayer().getUniqueId();
// If the nether is disabled then quit immediately
if (!Settings.createNether || ASkyBlock.getNetherWorld() == null) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Disabled nether: Settings create nether = " + Settings.createNether + " " + (ASkyBlock.getNetherWorld() == null ? "Nether world is null" : "Nether world is not null"));
return;
}
Location currentLocation = event.getFrom().clone();
String currentWorld = currentLocation.getWorld().getName();
if (!currentWorld.equalsIgnoreCase(Settings.worldName) && !currentWorld.equalsIgnoreCase(Settings.worldName + "_nether") && !currentWorld.equalsIgnoreCase(Settings.worldName + "_the_end")) {
if (DEBUG)
plugin.getLogger().info("DEBUG: not island world");
return;
}
// Check if player has permission
Island island = plugin.getGrid().getIslandAt(currentLocation);
if ((island == null && !Settings.defaultWorldSettings.get(SettingsFlag.PORTAL)) || (island != null && !(island.getIgsFlag(SettingsFlag.PORTAL) || island.getMembers().contains(event.getPlayer().getUniqueId())))) {
// Portals use is not allowed
if (!event.getPlayer().isOp() && !VaultHelper.checkPerm(event.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
Util.sendMessage(event.getPlayer(), ChatColor.RED + plugin.myLocale(event.getPlayer().getUniqueId()).islandProtected);
event.setCancelled(true);
return;
}
}
// Determine what portal it is
switch(event.getCause()) {
case END_PORTAL:
// Same action for all worlds except the end itself
if (!event.getFrom().getWorld().getEnvironment().equals(Environment.THE_END)) {
if (plugin.getServer().getWorld(Settings.worldName + "_the_end") != null) {
// The end exists
event.setCancelled(true);
Location end_place = plugin.getServer().getWorld(Settings.worldName + "_the_end").getSpawnLocation();
if (GridManager.isSafeLocation(end_place)) {
event.getPlayer().teleport(end_place);
// end_place.getBlock().getType(),end_place.getBlock().getData());
return;
} else {
Util.sendMessage(event.getPlayer(), ChatColor.RED + plugin.myLocale(event.getPlayer().getUniqueId()).warpserrorNotSafe);
plugin.getGrid().homeTeleport(event.getPlayer());
return;
}
}
} else {
event.setCancelled(true);
plugin.getGrid().homeTeleport(event.getPlayer());
}
break;
case NETHER_PORTAL:
// Get the home world of this player
World homeWorld = ASkyBlock.getIslandWorld();
Location home = plugin.getPlayers().getHomeLocation(event.getPlayer().getUniqueId());
if (home != null) {
homeWorld = home.getWorld();
}
if (!Settings.newNether) {
// Legacy action
if (event.getFrom().getWorld().getEnvironment().equals(Environment.NORMAL)) {
// Going to Nether
if (homeWorld.getEnvironment().equals(Environment.NORMAL)) {
// Home world is over world
event.setTo(ASkyBlock.getNetherWorld().getSpawnLocation());
event.useTravelAgent(true);
} else {
// Home world is nether - going home
event.useTravelAgent(false);
Location dest = plugin.getGrid().getSafeHomeLocation(playerUUID, 1);
if (dest != null) {
event.setTo(dest);
} else {
event.setCancelled(true);
new SafeTeleportBuilder(plugin).entity(event.getPlayer()).location(plugin.getPlayers().getIslandLocation(playerUUID)).portal().homeNumber(1).build();
}
}
} else {
// Going to Over world
if (homeWorld.getEnvironment().equals(Environment.NORMAL)) {
// Home world is over world
event.useTravelAgent(false);
Location dest = plugin.getGrid().getSafeHomeLocation(playerUUID, 1);
if (dest != null) {
event.setTo(dest);
// Fire entry event
Island islandTo = plugin.getGrid().getIslandAt(dest);
final IslandEnterEvent event2 = new IslandEnterEvent(event.getPlayer().getUniqueId(), islandTo, dest);
plugin.getServer().getPluginManager().callEvent(event2);
} else {
event.setCancelled(true);
new SafeTeleportBuilder(plugin).entity(event.getPlayer()).location(plugin.getPlayers().getIslandLocation(playerUUID)).portal().homeNumber(1).build();
// Fire entry event
Island islandTo = plugin.getGrid().getIslandAt(plugin.getPlayers().getIslandLocation(playerUUID));
final IslandEnterEvent event2 = new IslandEnterEvent(event.getPlayer().getUniqueId(), islandTo, plugin.getPlayers().getIslandLocation(playerUUID));
plugin.getServer().getPluginManager().callEvent(event2);
}
} else {
// Home world is nether
event.setTo(ASkyBlock.getIslandWorld().getSpawnLocation());
event.useTravelAgent(true);
}
}
} else {
// Get location of the island where the player is at
if (island == null) {
event.setCancelled(true);
return;
}
// Can go both ways now
Location overworldIsland = island.getCenter().toVector().toLocation(ASkyBlock.getIslandWorld());
Location netherIsland = island.getCenter().toVector().toLocation(ASkyBlock.getNetherWorld());
// Location dest = event.getFrom().toVector().toLocation(ASkyBlock.getIslandWorld());
if (event.getFrom().getWorld().getEnvironment().equals(Environment.NORMAL)) {
// Check that there is a nether island there. Due to legacy reasons it may not exist
if (DEBUG)
plugin.getLogger().info("DEBUG: island center = " + island.getCenter());
if (netherIsland.getBlock().getType() != Material.BEDROCK) {
// Check to see if there is anything there
if (plugin.getGrid().bigScan(netherIsland, 20) == null) {
if (DEBUG)
plugin.getLogger().info("DEBUG: big scan is null");
plugin.getLogger().warning("Creating nether island for " + event.getPlayer().getName() + " using default nether schematic");
Schematic nether = IslandCmd.getSchematics().get("nether");
if (nether != null) {
if (DEBUG)
plugin.getLogger().info("DEBUG: pasting at " + island.getCenter().toVector());
plugin.getIslandCmd().pasteSchematic(nether, netherIsland, event.getPlayer(), PasteReason.PARTNER);
if (nether.isPlayerSpawn()) {
// Set partner home
plugin.getPlayers().setHomeLocation(event.getPlayer().getUniqueId(), nether.getPlayerSpawn(netherIsland), -2);
}
} else {
plugin.getLogger().severe("Cannot teleport player to nether because there is no nether schematic");
event.setCancelled(true);
Util.sendMessage(event.getPlayer(), ChatColor.RED + plugin.myLocale(event.getPlayer().getUniqueId()).warpserrorNotSafe);
return;
}
}
}
if (DEBUG)
plugin.getLogger().info("DEBUG: Teleporting to " + event.getFrom().toVector().toLocation(ASkyBlock.getNetherWorld()));
event.setCancelled(true);
// Teleport using the new safeSpot teleport
new SafeTeleportBuilder(plugin).entity(event.getPlayer()).location(netherIsland).portal().build();
return;
}
// Going to the over world - if there isn't an island, do nothing
event.setCancelled(true);
// Teleport using the new safeSpot teleport
new SafeTeleportBuilder(plugin).entity(event.getPlayer()).location(overworldIsland).portal().build();
}
break;
default:
break;
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class PlayerEvents method onVistorDeath.
/*
* Prevent dropping items if player dies on another island
* This option helps reduce the down side of dying due to traps, etc.
* Also handles muting of death messages
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVistorDeath(final PlayerDeathEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
if (!IslandGuard.inWorld(e.getEntity())) {
return;
}
// Mute death messages
if (Settings.muteDeathMessages) {
e.setDeathMessage(null);
}
// This will override any global settings
if (Settings.allowVisitorKeepInvOnDeath) {
// If the player is not a visitor then they die and lose everything -
// sorry :-(
Island island = plugin.getGrid().getProtectedIslandAt(e.getEntity().getLocation());
if (island != null && !island.getMembers().contains(e.getEntity().getUniqueId())) {
// They are a visitor
InventorySave.getInstance().savePlayerInventory(e.getEntity());
e.getDrops().clear();
e.setKeepLevel(true);
e.setDroppedExp(0);
}
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class PlayerEvents2 method onVisitorPickup.
/*
* Prevent item pickup by visitors for servers before 1.12.
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVisitorPickup(final PlayerPickupItemEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
if (!IslandGuard.inWorld(e.getPlayer())) {
return;
}
Island island = plugin.getGrid().getIslandAt(e.getItem().getLocation());
if ((island != null && island.getIgsFlag(SettingsFlag.VISITOR_ITEM_PICKUP)) || e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect") || plugin.getGrid().locationIsOnIsland(e.getPlayer(), e.getItem().getLocation())) {
return;
}
e.setCancelled(true);
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class PlayerEvents3 method onVisitorPickup.
/*
* Prevent item pickup by visitors for 1.12+.
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVisitorPickup(final EntityPickupItemEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
if (e.getEntity() instanceof Player) {
Player player = (Player) e.getEntity();
if (!IslandGuard.inWorld(player)) {
return;
}
Island island = plugin.getGrid().getIslandAt(e.getItem().getLocation());
if ((island != null && island.getIgsFlag(SettingsFlag.VISITOR_ITEM_PICKUP)) || player.isOp() || VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect") || plugin.getGrid().locationIsOnIsland(player, e.getItem().getLocation())) {
return;
}
e.setCancelled(true);
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class PlayerEvents method onPlayerJoin.
/**
* Handle player joining
* @param event
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerJoin(final PlayerJoinEvent event) {
final Island island = plugin.getGrid().getProtectedIslandAt(event.getPlayer().getLocation());
if (island != null) {
processPerms(event.getPlayer(), island);
// Fire entry event
final IslandEnterEvent e = new IslandEnterEvent(event.getPlayer().getUniqueId(), island, event.getPlayer().getLocation());
plugin.getServer().getPluginManager().callEvent(e);
}
}
Aggregations