use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class IslandCmd method newIsland.
/**
* Makes an island using schematic. No permission checks are made. They have to be decided
* before this method is called.
* @param player
* @param schematic
*/
public void newIsland(final Player player, final Schematic schematic) {
// long time = System.nanoTime();
final UUID playerUUID = player.getUniqueId();
boolean firstTime = false;
if (!plugin.getPlayers().hasIsland(playerUUID)) {
firstTime = true;
}
// plugin.getLogger().info("DEBUG: finding island location");
Location next = getNextIsland(player.getUniqueId());
// plugin.getLogger().info("DEBUG: found " + next);
// Set the player's parameters to this island
plugin.getPlayers().setHasIsland(playerUUID, true);
// Clear any old home locations (they should be clear, but just in case)
plugin.getPlayers().clearHomeLocations(playerUUID);
// Set the player's island location to this new spot
plugin.getPlayers().setIslandLocation(playerUUID, next);
// Teleport to the new home
if (schematic.isPlayerSpawn()) {
// Set home and teleport
plugin.getPlayers().setHomeLocation(playerUUID, schematic.getPlayerSpawn(next), 1);
// Save it for later reference
plugin.getPlayers().setHomeLocation(playerUUID, schematic.getPlayerSpawn(next), -1);
}
// Sets a flag to temporarily disable cleanstone generation
plugin.setNewIsland(true);
// Create island based on schematic
if (schematic != null) {
// Paste the starting island. If it is a HELL biome, then we start in the Nether
if (Settings.createNether && schematic.isInNether() && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
// Paste the overworld if it exists
if (!schematic.getPartnerName().isEmpty() && schematics.containsKey(schematic.getPartnerName())) {
// A partner schematic is available
pastePartner(schematics.get(schematic.getPartnerName()), next, player);
}
// Switch home location to the Nether
next = next.toVector().toLocation(ASkyBlock.getNetherWorld());
// Set the player's island location to this new spot
plugin.getPlayers().setIslandLocation(playerUUID, next);
schematic.pasteSchematic(next, player, true, firstTime ? PasteReason.NEW_ISLAND : PasteReason.RESET);
} else {
// Over world start
// plugin.getLogger().info("DEBUG: pasting");
// long timer = System.nanoTime();
// Paste the island and teleport the player home
schematic.pasteSchematic(next, player, true, firstTime ? PasteReason.NEW_ISLAND : PasteReason.RESET);
// plugin.getLogger().info("DEBUG: pasted overworld");
if (Settings.createNether && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
// Paste the other world schematic
final Location netherLoc = next.toVector().toLocation(ASkyBlock.getNetherWorld());
if (schematic.getPartnerName().isEmpty()) {
// This will paste the over world schematic again
// plugin.getLogger().info("DEBUG: pasting nether");
pastePartner(schematic, netherLoc, player);
// plugin.getLogger().info("DEBUG: pasted nether");
} else {
if (schematics.containsKey(schematic.getPartnerName())) {
// plugin.getLogger().info("DEBUG: pasting partner");
// A partner schematic is available
pastePartner(schematics.get(schematic.getPartnerName()), netherLoc, player);
} else {
plugin.getLogger().severe("Partner schematic heading '" + schematic.getPartnerName() + "' does not exist");
}
}
}
}
// Record the rating of this schematic - not used for anything right now
plugin.getPlayers().setStartIslandRating(playerUUID, schematic.getRating());
}
// Clear the cleanstone flag so events can happen again
plugin.setNewIsland(false);
// Add to the grid
Island myIsland = plugin.getGrid().addIsland(next.getBlockX(), next.getBlockZ(), playerUUID);
myIsland.setLevelHandicap(schematic.getLevelHandicap());
// Save the player so that if the server is reset weird things won't happen
plugin.getPlayers().save(playerUUID);
// Start the reset cooldown
if (!firstTime) {
setResetWaitTime(player);
}
// Set the custom protection range if appropriate
// Dynamic island range sizes with permissions
int range = Settings.islandProtectionRange;
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.range.")) {
if (perms.getPermission().contains(Settings.PERMPREFIX + "island.range.*")) {
range = Settings.islandProtectionRange;
break;
} else {
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.range.");
if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[1])) {
plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
} else {
range = Math.max(range, Integer.valueOf(spl[1]));
}
}
}
}
}
// Do some sanity checking
if (range % 2 != 0) {
range--;
plugin.getLogger().warning("Protection range must be even, using " + range + " for " + player.getName());
}
if (range > Settings.islandDistance) {
plugin.getLogger().warning("Player has " + Settings.PERMPREFIX + "island.range." + range);
range = Settings.islandDistance;
plugin.getLogger().warning("Island protection range must be " + Settings.islandDistance + " or less. Setting to: " + range);
}
myIsland.setProtectionSize(range);
// Save grid just in case there's a crash
plugin.getGrid().saveGrid();
// Done - fire event
final IslandNewEvent event = new IslandNewEvent(player, schematic, myIsland);
plugin.getServer().getPluginManager().callEvent(event);
// plugin.getLogger().info("DEBUG: Done! " + (System.nanoTime()- time) * 0.000001);
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class IslandCmd method removePlayerFromTeam.
/**
* Removes a player from a team run by teamleader
*
* @param playerUUID - the player's UUID
* @param teamLeader
* @param makeLeader - true if this is the result of switching leader
* @return true if successful, false if not
*/
public boolean removePlayerFromTeam(final UUID playerUUID, final UUID teamLeader, boolean makeLeader) {
// Remove player from the team
plugin.getPlayers().removeMember(teamLeader, playerUUID);
// If player is not the leader of their own team
if (teamLeader == null || !playerUUID.equals(teamLeader)) {
if (!plugin.getPlayers().setLeaveTeam(playerUUID)) {
return false;
}
// plugin.getPlayers().setHomeLocation(player, null);
plugin.getPlayers().clearHomeLocations(playerUUID);
plugin.getPlayers().setIslandLocation(playerUUID, null);
plugin.getPlayers().setTeamIslandLocation(playerUUID, null);
if (!makeLeader) {
OfflinePlayer offlinePlayer = plugin.getServer().getOfflinePlayer(playerUUID);
if (offlinePlayer.isOnline()) {
// Check perms
if (!((Player) offlinePlayer).hasPermission(Settings.PERMPREFIX + "command.leaveexempt")) {
runCommands(Settings.leaveCommands, offlinePlayer);
}
} else {
// If offline, all commands are run, sorry
runCommands(Settings.leaveCommands, offlinePlayer);
}
// Deduct a reset
if (Settings.leaversLoseReset && Settings.resetLimit >= 0) {
int resetsLeft = plugin.getPlayers().getResetsLeft(playerUUID);
if (resetsLeft > 0) {
resetsLeft--;
plugin.getPlayers().setResetsLeft(playerUUID, resetsLeft);
}
}
}
// Fire event
if (teamLeader != null) {
final Island island = plugin.getGrid().getIsland(teamLeader);
final IslandLeaveEvent event = new IslandLeaveEvent(playerUUID, island);
plugin.getServer().getPluginManager().callEvent(event);
}
} else {
// removed
if (!plugin.getPlayers().setLeaveTeam(playerUUID)) {
// Event was cancelled for some reason
return false;
}
}
return true;
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class IslandCmd method getNextIsland.
/**
* Get the location of next free island spot
* @param playerUUID - the player's UUID
* @return Location of island spot
*/
private Location getNextIsland(UUID playerUUID) {
// See if there is a reserved spot
if (islandSpot.containsKey(playerUUID)) {
Location next = plugin.getGrid().getClosestIsland(islandSpot.get(playerUUID));
// Single shot only
islandSpot.remove(playerUUID);
// Check if it is already occupied (shouldn't be)
Island island = plugin.getGrid().getIslandAt(next);
if (island == null || island.getOwner() == null) {
// it's still free
return next;
}
// Else, fall back to the random pick
}
// Find the next free spot
if (last == null) {
last = new Location(ASkyBlock.getIslandWorld(), Settings.islandXOffset + Settings.islandStartX, Settings.islandHeight, Settings.islandZOffset + Settings.islandStartZ);
}
Location next = last.clone();
while (plugin.getGrid().islandAtLocation(next) || islandSpot.containsValue(next)) {
next = nextGridLocation(next);
}
// Make the last next, last
last = next.clone();
return next;
}
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(final 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 AcidEffect method isSafeFromAcid.
/**
* Check if player can be burned by acid
* @param player
* @return true if player is not safe
*/
private boolean isSafeFromAcid(Player player) {
if (DEBUG)
plugin.getLogger().info("DEBUG: safe from acid");
if (!player.getWorld().equals(ASkyBlock.getIslandWorld())) {
if (DEBUG)
plugin.getLogger().info("DEBUG: wrong world");
return true;
}
// In liquid
Material bodyMat = player.getLocation().getBlock().getType();
Material headMat = player.getLocation().getBlock().getRelative(BlockFace.UP).getType();
if (bodyMat.equals(Material.STATIONARY_WATER))
bodyMat = Material.WATER;
if (headMat.equals(Material.STATIONARY_WATER))
headMat = Material.WATER;
if (bodyMat != Material.WATER && headMat != Material.WATER) {
if (DEBUG)
plugin.getLogger().info("DEBUG: not in water " + player.getLocation().getBlock().isLiquid() + " " + player.getLocation().getBlock().getRelative(BlockFace.UP).isLiquid());
return true;
}
// Check if player is in a boat
Entity playersVehicle = player.getVehicle();
if (playersVehicle != null) {
// They are in a Vehicle
if (playersVehicle.getType().equals(EntityType.BOAT)) {
// I'M ON A BOAT! I'M ON A BOAT! A %^&&* BOAT!
if (DEBUG)
plugin.getLogger().info("DEBUG: boat");
return true;
}
}
// Check if full armor protects
if (Settings.fullArmorProtection) {
boolean fullArmor = true;
for (ItemStack item : player.getInventory().getArmorContents()) {
if (item == null || (item != null && item.getType().equals(Material.AIR))) {
fullArmor = false;
break;
}
}
if (fullArmor) {
if (DEBUG)
plugin.getLogger().info("DEBUG: full armor");
return true;
}
}
// Check if player has an active water potion or not
Collection<PotionEffect> activePotions = player.getActivePotionEffects();
for (PotionEffect s : activePotions) {
// s.getType().toString());
if (s.getType().equals(PotionEffectType.WATER_BREATHING)) {
// Safe!
if (DEBUG)
plugin.getLogger().info("DEBUG: Water breathing potion protection!");
return true;
}
}
// Check if water above sea-level is not acid
Island island = plugin.getGrid().getIslandAt(player.getLocation());
if (island != null && !island.getIgsFlag(SettingsFlag.ACID_DAMAGE) && player.getLocation().getBlockY() > Settings.seaHeight) {
if (DEBUG)
plugin.getLogger().info("DEBUG:no acid damage above sea level 1");
return true;
}
if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.ACID_DAMAGE) && player.getLocation().getBlockY() > Settings.seaHeight) {
if (DEBUG)
plugin.getLogger().info("DEBUG: no acid damage above sea level");
return true;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: burn in acid");
return false;
}
Aggregations