下面列出了org.bukkit.entity.Slime#com.wasteofplastic.askyblock.Island 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Gets a set of chunk coords that will be scanned.
* @param entity
* @param location
* @return
*/
private List<Pair<Integer, Integer>> getChunksToScan() {
List<Pair<Integer, Integer>> result = new ArrayList<>();
// Get island if available
Island island = plugin.getGrid().getIslandAt(location);
int maxRadius = island == null ? Settings.islandProtectionRange/2 : island.getProtectionSize()/2;
maxRadius = maxRadius > MAX_RADIUS ? MAX_RADIUS : maxRadius;
int x = location.getBlockX();
int z = location.getBlockZ();
// Create ever increasing squares around the target location
int radius = 0;
do {
for (int i = x - radius; i <= x + radius; i+=16) {
for (int j = z - radius; j <= z + radius; j+=16) {
addChunk(result, island, new Pair<>(i,j), new Pair<>(i/16, j/16));
}
}
radius++;
} while (radius < maxRadius);
return result;
}
/**
* Checks if action is allowed for player in location for flag
* @param uuid
* @param location
* @param flag
* @return true if allowed
*/
private boolean actionAllowed(UUID uuid, Location location, SettingsFlag flag) {
Player player = plugin.getServer().getPlayer(uuid);
if (player == null) {
return actionAllowed(location, flag);
}
// This permission bypasses protection
if (player.isOp() || VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")) {
return true;
}
Island island = plugin.getGrid().getProtectedIslandAt(location);
if (island != null && (island.getIgsFlag(flag) || island.getMembers().contains(player.getUniqueId()))){
return true;
}
if (island == null && Settings.defaultWorldSettings.get(flag)) {
return true;
}
return false;
}
@EventHandler(priority = EventPriority.LOW)
public void onPistonExtend(BlockPistonExtendEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
Location pistonLoc = e.getBlock().getLocation();
if (Settings.allowPistonPush || !inWorld(pistonLoc)) {
//plugin.getLogger().info("DEBUG: Not in world");
return;
}
Island island = plugin.getGrid().getProtectedIslandAt(pistonLoc);
if (island == null || !island.onIsland(pistonLoc)) {
//plugin.getLogger().info("DEBUG: Not on is island protection zone");
return;
}
// We need to check where the blocks are going to go, not where they are
for (Block b : e.getBlocks()) {
if (!island.onIsland(b.getRelative(e.getDirection()).getLocation())) {
//plugin.getLogger().info("DEBUG: Block is outside protected area");
e.setCancelled(true);
return;
}
}
}
/**
* Handle visitor chicken egg throwing
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEggThrow(PlayerEggThrowEvent e) {
if (DEBUG) {
plugin.getLogger().info("egg throwing = " + e.getEventName());
}
if (!inWorld(e.getPlayer()) || e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
|| plugin.getGrid().playerIsOnIsland(e.getPlayer()) || plugin.getGrid().isAtSpawn(e.getPlayer().getLocation())) {
return;
}
// Check island
Island island = plugin.getGrid().getProtectedIslandAt(e.getPlayer().getLocation());
if (island == null) {
return;
}
if (!island.getIgsFlag(SettingsFlag.EGGS)) {
e.setHatching(false);
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
//e.getPlayer().updateInventory();
}
return;
}
/**
* Stop redstone if team members are offline and disableOfflineRedstone is TRUE.
* @param e - event
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockRedstone(final BlockRedstoneEvent e){
if(Settings.disableOfflineRedstone) {
// Check world
if (!inWorld(e.getBlock())) {
return;
}
// Check if this is on an island
Island island = plugin.getGrid().getIslandAt(e.getBlock().getLocation());
if (island == null || island.isSpawn()) {
return;
}
for(UUID member : island.getMembers()){
if(plugin.getServer().getPlayer(member) != null) return;
}
e.setNewCurrent(0);
}
}
/**
* Prevents trees from growing outside of the protected area.
*
* @param e - event
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTreeGrow(final StructureGrowEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
// Check world
if (!IslandGuard.inWorld(e.getLocation())) {
return;
}
// Check if this is on an island
Island island = plugin.getGrid().getIslandAt(e.getLocation());
if (island == null || island.isSpawn()) {
return;
}
Iterator<BlockState> it = e.getBlocks().iterator();
while (it.hasNext()) {
BlockState b = it.next();
if (b.getType() == Material.LOG || b.getType() == Material.LOG_2
|| b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
if (!island.onIsland(b.getLocation())) {
it.remove();
}
}
}
}
/**
* 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);
}
}
}
}
@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);
}
@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);
}
}
@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);
}
/**
* Track where the mob was created. This will determine its allowable movement zone.
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void mobSpawn(CreatureSpawnEvent e) {
// Only cover withers in the island world
if (!IslandGuard.inWorld(e.getEntity())) {
return;
}
if (!e.getEntityType().equals(EntityType.WITHER) && !e.getEntityType().equals(EntityType.BLAZE) && !e.getEntityType().equals(EntityType.GHAST)) {
return;
}
if (DEBUG) {
plugin.getLogger().info("Flying mobs " + e.getEventName());
}
// Store where this mob originated
Island island = plugin.getGrid().getIslandAt(e.getLocation());
if (island != null) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: Mob spawned on known island - id = " + e.getEntity().getUniqueId());
}
mobSpawnInfo.put(e.getEntity(),island);
} // Else do nothing - maybe an Op spawned it? If so, on their head be it!
}
@Override
public boolean doesTeamMatch(Player player1, Player player2) {
if(player1 == null || player2 == null) return false;
UUID uuid1 = player1.getUniqueId();
UUID uuid2 = player2.getUniqueId();
if(uuid1.equals(uuid2)) return true;
Island island = getIslandFor(player1);
if(island == null) return false;
List<UUID> memberList = island.getMembers();
return memberList.contains(uuid2);
}
@Override
public Island getIslandFor(Player player) {
if(player == null) return null;
UUID uuid = player.getUniqueId();
ASkyBlockAPI api = ASkyBlockAPI.getInstance();
return api.getIslandOwnedBy(uuid);
}
@Override
public Island getIslandAt(Location location) {
if(location == null) return null;
ASkyBlockAPI api = ASkyBlockAPI.getInstance();
return api.getIslandAt(location);
}
private boolean handleForLocation(Player player, Location loc, Cancellable e) {
Island island = ASkyBlockAPI.getInstance().getIslandAt(loc);
if (island == null)
return false;
if (!player.getUniqueId().equals(island.getOwner()) && !island.getMembers().contains(player.getUniqueId())) {
e.setCancelled(true);
plugin.debug("Cancel Reason: ASkyBlock");
return true;
}
return false;
}
/**
* Deletes the overworld and nether islands together
* @param island
* @param sender
*/
private void deleteIslands(Island island, CommandSender sender) {
plugin.getGrid().removePlayersFromIsland(island,null);
// Reset the biome
new SetBiome(plugin, island, Settings.defaultBiome, null);
new DeleteIslandChunk(plugin, island);
//new DeleteIslandByBlock(plugin, island);
plugin.getGrid().saveGrid();
}
/**
* Purges the unowned islands upon direction from sender
* @param sender
*/
private void purgeUnownedIslands(final CommandSender sender) {
purgeFlag = true;
final int total = unowned.size();
new BukkitRunnable() {
@Override
public void run() {
if (unowned.isEmpty()) {
purgeFlag = false;
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().purgefinished);
this.cancel();
plugin.getGrid().saveGrid();
}
if (unowned.size() > 0) {
Iterator<Entry<String, Island>> it = unowned.entrySet().iterator();
Entry<String,Island> entry = it.next();
if (entry.getValue().getOwner() == null) {
Util.sendMessage(sender, ChatColor.YELLOW + "[" + (total - unowned.size() + 1) + "/" + total + "] " + plugin.myLocale().purgeRemovingAt.replace("[location]",
entry.getValue().getCenter().getWorld().getName() + " " + entry.getValue().getCenter().getBlockX()
+ "," + entry.getValue().getCenter().getBlockZ()));
deleteIslands(entry.getValue(),sender);
}
// Remove from the list
it.remove();
}
Util.sendMessage(sender, plugin.myLocale().purgeNowWaiting);
}
}.runTaskTimer(plugin, 0L, 20L);
}
/**
* Updates the meta text on the warp sign icon by looking at the warp sign
* This MUST be run 1 TICK AFTER the sign has been created otherwise the sign is blank
* @param playerSign
* @param playerUUID - the player's UUID
* @return updated skull item stack
*/
private ItemStack updateText(ItemStack playerSign, final UUID playerUUID) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Updating text on item");
ItemMeta meta = playerSign.getItemMeta();
//get the sign info
Location signLocation = plugin.getWarpSignsListener().getWarp(playerUUID);
if (signLocation == null) {
plugin.getWarpSignsListener().removeWarp(playerUUID);
return playerSign;
}
//plugin.getLogger().info("DEBUG: block type = " + signLocation.getBlock().getType());
// Get the sign info if it exists
if (signLocation.getBlock().getType().equals(Material.SIGN_POST) || signLocation.getBlock().getType().equals(Material.WALL_SIGN)) {
Sign sign = (Sign)signLocation.getBlock().getState();
List<String> lines = new ArrayList<String>(Arrays.asList(sign.getLines()));
// Check for PVP and add warning
Island island = plugin.getGrid().getIsland(playerUUID);
if (island != null) {
if ((signLocation.getWorld().equals(ASkyBlock.getIslandWorld()) && island.getIgsFlag(SettingsFlag.PVP))
|| (signLocation.getWorld().equals(ASkyBlock.getNetherWorld()) && island.getIgsFlag(SettingsFlag.NETHER_PVP))) {
if (DEBUG)
plugin.getLogger().info("DEBUG: pvp warning added");
lines.add(ChatColor.RED + plugin.myLocale().igs.get(SettingsFlag.PVP));
}
}
meta.setLore(lines);
if (DEBUG)
plugin.getLogger().info("DEBUG: lines = " + lines);
} else {
// No sign there - remove the warp
plugin.getWarpSignsListener().removeWarp(playerUUID);
}
playerSign.setItemMeta(meta);
return playerSign;
}
/**
* @param player
* @param island
* @param inviter
*/
public CoopJoinEvent(UUID player, Island island, UUID inviter) {
super(player, island);
this.inviter = inviter;
//Bukkit.getLogger().info("DEBUG: Coop join event " + Bukkit.getServer().getOfflinePlayer(player).getName() + " joined "
//+ Bukkit.getServer().getOfflinePlayer(inviter).getName() + "'s island.");
}
private void addChunk(List<Pair<Integer, Integer>> result, Island island, Pair<Integer, Integer> blockCoord, Pair<Integer, Integer> chunkCoord) {
if (!result.contains(chunkCoord)) {
// Add the chunk coord
if (island == null) {
// If there is no island, just add it
result.add(chunkCoord);
} else {
// If there is an island, only add it if the coord is in island space
if (island.inIslandSpace(blockCoord.x, blockCoord.z)) {
result.add(chunkCoord);
}
}
}
}
/**
* Handles Frost Walking on visitor's islands
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onBlockForm(final EntityBlockFormEvent e) {
if (e.getEntity() instanceof Player && e.getNewState().getType().equals(Material.FROSTED_ICE)) {
Player player= (Player) e.getEntity();
if (!IslandGuard.inWorld(player)) {
return;
}
if (player.isOp()) {
return;
}
// This permission bypasses protection
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")) {
return;
}
// Check island
Island island = plugin.getGrid().getIslandAt(player.getLocation());
if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) {
return;
}
if (island !=null) {
if (island.getMembers().contains(player.getUniqueId()) || island.getIgsFlag(SettingsFlag.PLACE_BLOCKS)) {
return;
}
}
// Silently cancel the event
e.setCancelled(true);
}
}
/**
* Handle interaction with end crystals 1.9
*
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onHitEndCrystal(final PlayerInteractAtEntityEvent e) {
if (!IslandGuard.inWorld(e.getPlayer())) {
return;
}
if (e.getPlayer().isOp()) {
return;
}
// This permission bypasses protection
if (VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
return;
}
if (e.getRightClicked() != null && e.getRightClicked().getType().equals(EntityType.ENDER_CRYSTAL)) {
// Check island
Island island = plugin.getGrid().getIslandAt(e.getRightClicked().getLocation());
if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) {
return;
}
if (island !=null) {
if (island.getMembers().contains(e.getPlayer().getUniqueId()) || island.getIgsFlag(SettingsFlag.BREAK_BLOCKS)) {
return;
}
}
e.setCancelled(true);
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
}
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onRodDamage(final PlayerFishEvent e) {
if (e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
return;
}
if (!IslandGuard.inWorld(e.getPlayer().getLocation())) {
return;
}
Player p = e.getPlayer();
if (e.getCaught() != null && (e.getCaught().getType().equals(EntityType.ARMOR_STAND) || e.getCaught().getType().equals(EntityType.ENDER_CRYSTAL))) {
if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
return;
}
// Check if on island
if (plugin.getGrid().playerIsOnIsland(p)) {
return;
}
// Check island
Island island = plugin.getGrid().getIslandAt(e.getCaught().getLocation());
if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) {
return;
}
if (island != null && island.getIgsFlag(SettingsFlag.BREAK_BLOCKS)) {
return;
}
Util.sendMessage(p, ChatColor.RED + plugin.myLocale(p.getUniqueId()).islandProtected);
e.getHook().remove();
e.setCancelled(true);
}
}
/**
* Action allowed in this location
* @param location
* @param flag
* @return true if allowed
*/
private boolean actionAllowed(Location location, SettingsFlag flag) {
Island island = plugin.getGrid().getProtectedIslandAt(location);
if (island != null && island.getIgsFlag(flag)){
return true;
}
return island == null && Settings.defaultWorldSettings.get(flag);
}
/**
* Checks if action is allowed for player in location for flag
* @param player
* @param location
* @param flag
* @return true if allowed
*/
private boolean actionAllowed(Player player, Location location, SettingsFlag flag) {
if (player == null) {
return actionAllowed(location, flag);
}
// This permission bypasses protection
if (player.isOp() || VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")) {
return true;
}
Island island = plugin.getGrid().getProtectedIslandAt(location);
if (island != null && (island.getIgsFlag(flag) || island.getMembers().contains(player.getUniqueId()))){
return true;
}
return island == null && Settings.defaultWorldSettings.get(flag);
}
/**
* Action allowed in this location
* @param location
* @param flag
* @return true if allowed
*/
private boolean actionAllowed(Location location, SettingsFlag flag) {
Island island = plugin.getGrid().getProtectedIslandAt(location);
if (island != null && island.getIgsFlag(flag)){
return true;
}
return island == null && Settings.defaultWorldSettings.get(flag);
}
@EventHandler(priority = EventPriority.LOW)
public void onBucketFill(final PlayerBucketFillEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
if (inWorld(e.getPlayer())) {
// This permission bypasses protection
if (VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
return;
}
Island island = plugin.getGrid().getProtectedIslandAt(e.getBlockClicked().getLocation());
if (island != null) {
if (island.getMembers().contains(e.getPlayer().getUniqueId())) {
return;
}
if (island.getIgsFlag(SettingsFlag.COLLECT_LAVA) && e.getItemStack().getType().equals(Material.LAVA_BUCKET)) {
return;
}
if (island.getIgsFlag(SettingsFlag.COLLECT_WATER) && e.getItemStack().getType().equals(Material.WATER_BUCKET)) {
return;
}
if (island.getIgsFlag(SettingsFlag.MILKING) && e.getItemStack().getType().equals(Material.MILK_BUCKET)) {
return;
}
if (island.getIgsFlag(SettingsFlag.BUCKET)) {
return;
}
} else {
// Null
if (Settings.defaultWorldSettings.get(SettingsFlag.BUCKET)) {
return;
}
}
// Not allowed
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
}
/**
* Pressure plates
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlateStep(PlayerInteractEvent e) {
if (DEBUG) {
plugin.getLogger().info("pressure plate = " + e.getEventName());
plugin.getLogger().info("action = " + e.getAction());
}
if (!inWorld(e.getPlayer()) || !e.getAction().equals(Action.PHYSICAL)
|| e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
|| plugin.getGrid().playerIsOnIsland(e.getPlayer())) {
//plugin.getLogger().info("DEBUG: Not in world");
return;
}
// Check island
Island island = plugin.getGrid().getProtectedIslandAt(e.getPlayer().getLocation());
if ((island == null && Settings.defaultWorldSettings.get(SettingsFlag.PRESSURE_PLATE))) {
return;
}
if (island != null && island.getIgsFlag(SettingsFlag.PRESSURE_PLATE)) {
return;
}
// Block action
UUID playerUUID = e.getPlayer().getUniqueId();
if (!onPlate.containsKey(playerUUID)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(playerUUID).islandProtected);
Vector v = e.getPlayer().getLocation().toVector();
onPlate.put(playerUUID, new Vector(v.getBlockX(), v.getBlockY(), v.getBlockZ()));
}
e.setCancelled(true);
return;
}
/**
* Action allowed in this location
* @param location
* @param flag
* @return true if allowed
*/
private boolean actionAllowed(Location location, SettingsFlag flag) {
Island island = plugin.getGrid().getProtectedIslandAt(location);
if (island != null && island.getIgsFlag(flag)){
return true;
}
return island == null && Settings.defaultWorldSettings.get(flag);
}
/**
* Checks if action is allowed for player in location for flag
* @param player
* @param location
* @param flag
* @return true if allowed
*/
private boolean actionAllowed(Player player, Location location, SettingsFlag flag) {
if (player == null) {
return actionAllowed(location, flag);
}
// This permission bypasses protection
if (player.isOp() || VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")) {
return true;
}
Island island = plugin.getGrid().getProtectedIslandAt(location);
if (island != null && (island.getIgsFlag(flag) || island.getMembers().contains(player.getUniqueId()))){
return true;
}
return island == null && Settings.defaultWorldSettings.get(flag);
}