use of com.wasteofplastic.acidisland.Island in project acidisland by tastybento.
the class LavaCheck method onCobbleGen.
/**
* Magic Cobble Generator
* @param e - event
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onCobbleGen(BlockFromToEvent e) {
// If magic cobble gen isnt used
if (!Settings.useMagicCobbleGen) {
// plugin.getLogger().info("DEBUG: no magic cobble gen");
return;
}
// Only do this in ASkyBlock world
if (!e.getBlock().getWorld().equals(ASkyBlock.getIslandWorld())) {
// plugin.getLogger().info("DEBUG: wrong world");
return;
}
// Do nothing if a new island is being created
if (plugin.isNewIsland()) {
// plugin.getLogger().info("DEBUG: new island in creation");
return;
}
// If only at spawn, do nothing if we're not at spawn
if (Settings.magicCobbleGenOnlyAtSpawn && (!ASkyBlockAPI.getInstance().isAtSpawn(e.getBlock().getLocation()))) {
return;
}
final Block b = e.getBlock();
if (b.getType().equals(Material.WATER) || b.getType().equals(Material.STATIONARY_WATER) || b.getType().equals(Material.LAVA) || b.getType().equals(Material.STATIONARY_LAVA)) {
// plugin.getLogger().info("DEBUG: From block is water or lava. To = " + e.getToBlock().getType());
final Block toBlock = e.getToBlock();
if (toBlock.getType().equals(Material.AIR) && generatesCobble(b, toBlock)) {
// plugin.getLogger().info("DEBUG: potential cobble gen");
// Get island level or use default
long l = Long.MIN_VALUE;
Island island = plugin.getGrid().getIslandAt(b.getLocation());
if (island != null) {
if (island.getOwner() != null) {
l = plugin.getPlayers().getIslandLevel(island.getOwner());
// plugin.getLogger().info("DEBUG: level " + level);
}
}
final long level = l;
// Check if cobble was generated next tick
// Store surrounding blocks and their current material types
final List<Block> prevBlock = new ArrayList<Block>();
final List<Material> prevMat = new ArrayList<Material>();
for (BlockFace face : FACES) {
Block r = toBlock.getRelative(face);
prevBlock.add(r);
prevMat.add(r.getType());
// r = toBlock.getRelative(face,2);
// prevBlock.add(r);
// prevMat.add(r.getType());
}
// Check if they became cobblestone next tick
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
Iterator<Block> blockIt = prevBlock.iterator();
Iterator<Material> matIt = prevMat.iterator();
while (blockIt.hasNext() && matIt.hasNext()) {
Block block = blockIt.next();
Material material = matIt.next();
if (block.getType().equals(Material.COBBLESTONE) && !block.getType().equals(material)) {
// plugin.getLogger().info("DEBUG: Cobble generated. Island level = " + level);
if (!Settings.magicCobbleGenChances.isEmpty()) {
Entry<Long, TreeMap<Double, Material>> entry = Settings.magicCobbleGenChances.floorEntry(level);
double maxValue = entry.getValue().lastKey();
double rnd = Util.randomDouble() * maxValue;
Entry<Double, Material> en = entry.getValue().ceilingEntry(rnd);
// plugin.getLogger().info("DEBUG: material = " + en.getValue());
if (en != null) {
block.setType(en.getValue());
// Record stats, per level
if (stats.containsKey(entry.getKey())) {
stats.get(entry.getKey()).add(en.getValue());
} else {
Multiset<Material> set = HashMultiset.create();
set.add(en.getValue());
stats.put(entry.getKey(), set);
}
}
}
}
}
}
});
}
}
}
use of com.wasteofplastic.acidisland.Island in project acidisland by tastybento.
the class PlayerEvents method onPlayerRespawn.
/**
* Places player back on their island if the setting is true
* @param e - event
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerRespawn(final PlayerRespawnEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
if (!Settings.respawnOnIsland) {
return;
}
if (respawn.contains(e.getPlayer().getUniqueId())) {
respawn.remove(e.getPlayer().getUniqueId());
Location respawnLocation = plugin.getGrid().getSafeHomeLocation(e.getPlayer().getUniqueId(), 1);
if (respawnLocation != null) {
// plugin.getLogger().info("DEBUG: Setting respawn location to " + respawnLocation);
e.setRespawnLocation(respawnLocation);
// Get island
Island island = plugin.getGrid().getIslandAt(respawnLocation);
if (island != null) {
// Run perms etc.
processPerms(e.getPlayer(), island);
}
}
}
}
use of com.wasteofplastic.acidisland.Island in project acidisland by tastybento.
the class PlayerEvents method onPlayerLeave.
/**
* Removes temporary perms when the player log out
* @param event
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerLeave(PlayerQuitEvent event) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Removing fly and all temp perms");
Player player = event.getPlayer();
if (temporaryPerms.containsKey(player.getUniqueId())) {
for (String perm : temporaryPerms.get(player.getUniqueId())) {
VaultHelper.removePerm(player, perm, ASkyBlock.getIslandWorld());
if (Settings.createNether && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
VaultHelper.removePerm(player, perm, ASkyBlock.getNetherWorld());
}
}
temporaryPerms.remove(player.getUniqueId());
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "islandfly")) {
if (player.getGameMode().equals(GameMode.SURVIVAL)) {
player.setAllowFlight(false);
player.setFlying(false);
}
}
final Island island = plugin.getGrid().getProtectedIslandAt(event.getPlayer().getLocation());
if (island != null) {
// Fire exit event
final IslandExitEvent e = new IslandExitEvent(event.getPlayer().getUniqueId(), island, event.getPlayer().getLocation());
plugin.getServer().getPluginManager().callEvent(e);
}
}
use of com.wasteofplastic.acidisland.Island in project acidisland by tastybento.
the class PlayerEvents method onVisitorDrop.
/*
* Prevent item drop by visitors
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVisitorDrop(final PlayerDropItemEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
if (!IslandGuard.inWorld(e.getPlayer())) {
return;
}
Island island = plugin.getGrid().getIslandAt(e.getItemDrop().getLocation());
if ((island != null && island.getIgsFlag(SettingsFlag.VISITOR_ITEM_DROP)) || e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect") || plugin.getGrid().locationIsOnIsland(e.getPlayer(), e.getItemDrop().getLocation())) {
return;
}
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
use of com.wasteofplastic.acidisland.Island in project acidisland 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);
}
Aggregations