use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class IslandGuard1_8 method ArmorStandDestroy.
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void ArmorStandDestroy(EntityDamageByEntityEvent e) {
if (DEBUG) {
plugin.getLogger().info("1.8 " + "IslandGuard New " + e.getEventName());
}
if (!(e.getEntity() instanceof LivingEntity)) {
return;
}
if (!IslandGuard.inWorld(e.getEntity())) {
return;
}
final LivingEntity livingEntity = (LivingEntity) e.getEntity();
if (!livingEntity.getType().equals(EntityType.ARMOR_STAND)) {
return;
}
if (e.getDamager() instanceof Player) {
Player p = (Player) e.getDamager();
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.getEntity().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.setCancelled(true);
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class JoinLeaveEvents method onPlayerJoin.
/**
* @param event
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerJoin(final PlayerJoinEvent event) {
if (DEBUG)
plugin.getLogger().info("DEBUG: on PlayerJoin");
final Player player = event.getPlayer();
final UUID playerUUID = player.getUniqueId();
if (DEBUG)
plugin.getLogger().info("DEBUG: got player UUID");
if (playerUUID == null) {
plugin.getLogger().severe("Player " + player.getName() + " has a null UUID!");
return;
}
// Check language permission
if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.lang")) {
// Default locale
if (DEBUG)
plugin.getLogger().info("DEBUG: using default locale");
plugin.getPlayers().setLocale(playerUUID, "");
}
// Check updates
if (player.isOp() && plugin.getUpdateCheck() != null) {
if (DEBUG)
plugin.getLogger().info("DEBUG: checking Updates");
plugin.checkUpdatesNotify(player);
}
if (players == null) {
plugin.getLogger().severe("players is NULL");
return;
}
// If this player is not an island player just skip all this
if (DEBUG)
plugin.getLogger().info("DEBUG: checking if player has island or is in team");
if (!players.hasIsland(playerUUID) && !players.inTeam(playerUUID)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: not in team and does not have island");
return;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: has island");
UUID leader = null;
Location loc = null;
/*
* This should not be needed
*/
if (players.inTeam(playerUUID) && players.getTeamIslandLocation(playerUUID) == null) {
if (DEBUG)
plugin.getLogger().info("DEBUG: reseting team island");
leader = players.getTeamLeader(playerUUID);
players.setTeamIslandLocation(playerUUID, players.getIslandLocation(leader));
}
// Only happens when the team leader logs in
if (players.inTeam(playerUUID) && players.getTeamLeader(playerUUID).equals(playerUUID)) {
// Run through this team leader's players and check they are correct
for (UUID member : players.getMembers(playerUUID)) {
if (players.getTeamLeader(member) != null && !players.getTeamLeader(member).equals(playerUUID)) {
plugin.getLogger().warning(plugin.getPlayers().getName(member) + " is on more than one team. Fixing...");
plugin.getLogger().warning("Removing " + player.getName() + " as team leader, keeping " + plugin.getPlayers().getName(players.getTeamLeader(member)));
players.removeMember(players.getTeamLeader(member), member);
}
}
}
// Leader or solo
if (DEBUG)
plugin.getLogger().info("DEBUG: Getting island info");
if (players.hasIsland(playerUUID)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: owner");
loc = players.getIslandLocation(playerUUID);
leader = playerUUID;
} else if (players.inTeam(playerUUID)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: team");
// Team player
loc = players.getTeamIslandLocation(playerUUID);
leader = players.getTeamLeader(playerUUID);
if (leader == null) {
plugin.getLogger().severe("Player " + player.getName() + " is in a team but leader's UUID is missing. Leaving team.");
players.setLeaveTeam(playerUUID);
}
}
// If the player has an island location of some kind
if (loc != null && leader != null) {
if (DEBUG)
plugin.getLogger().info("DEBUG: getting island");
// Check if the island location is on the grid
Island island = plugin.getGrid().getIslandAt(loc);
if (island == null) {
if (DEBUG)
plugin.getLogger().info("DEBUG: getIslandLoc is null!");
// Island isn't in the grid, so add it
// See if this owner is tagged as having an island elsewhere
Island islandByOwner = plugin.getGrid().getIsland(leader);
if (islandByOwner == null) {
// No previous ownership, so just create the new island in the grid
if (plugin.getGrid().onGrid(loc)) {
plugin.getGrid().addIsland(loc.getBlockX(), loc.getBlockZ(), leader);
} else {
plugin.getLogger().severe(player.getName() + " joined and has an island at " + loc + " but those coords are NOT on the grid! Use admin register commands to correct!");
}
} else {
// We have a mismatch - correct in favor of the player info
if (DEBUG)
plugin.getLogger().info("DEBUG: getIslandLoc is null but there is a player listing");
plugin.getLogger().severe(player.getName() + " login: mismatch - player.yml and islands.yml are out of sync!");
// If player is owner of the island
if (playerUUID.equals(leader)) {
// Cannot delete by location
plugin.getGrid().deleteIslandOwner(playerUUID);
if (plugin.getGrid().onGrid(loc)) {
plugin.getGrid().addIsland(loc.getBlockX(), loc.getBlockZ(), playerUUID);
} else {
plugin.getLogger().severe(player.getName() + " joined and has an island at " + loc + " but those coords are NOT on the grid! Use admin register commands to correct!");
}
} else {
plugin.getGrid().deleteIslandOwner(playerUUID);
plugin.getLogger().severe(player.getName() + " login: mismatch - player file says they are in a team, but it's unlikely.");
player.sendMessage(ChatColor.RED + "Your player file had an issue and had to be reset.");
plugin.deletePlayerIsland(playerUUID, false);
}
}
} else {
if (DEBUG)
plugin.getLogger().info("DEBUG: island is not null");
// Island at this location exists
// plugin.getLogger().info("DEBUG: getIslandLoc is not null - island exists");
// See if this owner is tagged as having an island elsewhere
Island islandByOwner = plugin.getGrid().getIsland(leader);
if (islandByOwner == null) {
plugin.getLogger().warning(player.getName() + " login: has island, but islands.yml says it is unowned, correcting...");
// No previous ownership, so just assign ownership
plugin.getGrid().setIslandOwner(island, leader);
} else {
if (DEBUG)
plugin.getLogger().info("DEBUG: island by owner found");
if (!islandByOwner.equals(island)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: mismatch");
plugin.getLogger().warning(player.getName() + " login: mismatch - islands.yml and player.yml are out of sync. Fixing...");
// We have a mismatch - correct in favor of the player info
plugin.getGrid().deleteIsland(islandByOwner.getCenter());
plugin.getGrid().setIslandOwner(island, leader);
} else {
if (island.getOwner().equals(player.getUniqueId())) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: This player owns the island and island protection size is " + islandByOwner.getProtectionSize());
plugin.getLogger().info("DEBUG: everything looks good");
}
// Dynamic island range sizes with permissions
boolean hasARangePerm = false;
int range = Settings.islandProtectionRange;
// Check for zero protection range
if (island.getProtectionSize() == 0) {
plugin.getLogger().warning("Player " + player.getName() + "'s island had a protection range of 0. Setting to default " + range);
island.setProtectionSize(range);
}
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.range.")) {
if (DEBUG)
plugin.getLogger().info("DEBUG: perm found");
if (perms.getPermission().contains(Settings.PERMPREFIX + "island.range.*")) {
// Ignore
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 {
if (DEBUG)
plugin.getLogger().info("DEBUG: found number perm");
hasARangePerm = true;
range = Math.max(range, Integer.valueOf(spl[1]));
if (DEBUG)
plugin.getLogger().info("DEBUG: highest range is " + range);
}
}
}
}
}
// Only set the island range if the player has a perm to override the default
if (hasARangePerm) {
// Do some sanity checking
if (range > Settings.islandDistance) {
range = Settings.islandDistance;
}
if (range % 2 != 0) {
range--;
if (DEBUG)
plugin.getLogger().warning("Login range setting: Protection range must be even, using " + range + " for " + player.getName());
}
if (DEBUG)
plugin.getLogger().info("DEBUG: final range is " + range + " island protection size = " + islandByOwner.getProtectionSize());
// Range can go up or down
if (range != islandByOwner.getProtectionSize()) {
plugin.getMessages().storeMessage(playerUUID, plugin.myLocale(playerUUID).adminSetRangeUpdated.replace("[number]", String.valueOf(range)));
plugin.getLogger().info("Login range setting: Island protection range changed from " + islandByOwner.getProtectionSize() + " to " + range + " for " + player.getName() + " due to permission.");
}
islandByOwner.setProtectionSize(range);
}
}
}
}
}
}
// Run the level command
if (Settings.loginLevel) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Run level calc");
new LevelCalcByChunk(plugin, plugin.getGrid().getIsland(playerUUID), playerUUID, player, false);
}
// Reset resets if the admin changes it to or from unlimited
if (Settings.resetLimit < players.getResetsLeft(playerUUID) || (Settings.resetLimit >= 0 && players.getResetsLeft(playerUUID) < 0)) {
players.setResetsLeft(playerUUID, Settings.resetLimit);
}
if (DEBUG)
plugin.getLogger().info("DEBUG: Setting player's name");
// Set the player's name (it may have changed), but only if it isn't empty
if (!player.getName().isEmpty()) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Player name is " + player.getName());
players.setPlayerName(playerUUID, player.getName());
} else {
plugin.getLogger().warning("Player that just logged in has no name! " + playerUUID.toString());
}
if (DEBUG)
plugin.getLogger().info("DEBUG: Saving player");
players.save(playerUUID);
if (Settings.logInRemoveMobs) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Removing mobs");
plugin.getGrid().removeMobs(player.getLocation());
}
// Set the TEAMNAME and TEAMSUFFIX variable if required
if (Settings.setTeamName) {
if (DEBUG)
plugin.getLogger().info("DEBUG: setTeamName");
Scoreboards.getInstance().setLevel(playerUUID);
}
// Check if they logged in to a locked island and expel them or if they are banned
Island currentIsland = plugin.getGrid().getIslandAt(player.getLocation());
if (currentIsland != null && (currentIsland.isLocked() || plugin.getPlayers().isBanned(currentIsland.getOwner(), player.getUniqueId()))) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Current island is locked, or player is banned");
if (!currentIsland.getMembers().contains(playerUUID) && !player.isOp() && !VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")) {
if (DEBUG)
plugin.getLogger().info("DEBUG: No bypass - teleporting");
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).lockIslandLocked);
plugin.getGrid().homeTeleport(player);
}
}
if (DEBUG)
plugin.getLogger().info("DEBUG: Setting the player's level in chat listener");
// Set the player's level
plugin.getChatListener().setPlayerLevel(playerUUID, plugin.getPlayers().getIslandLevel(player.getUniqueId()));
if (DEBUG)
plugin.getLogger().info("DEBUG: Remove from top ten if excluded");
// Remove from TopTen if the player has the permission
if (!player.hasPermission(Settings.PERMPREFIX + "intopten")) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Removing from top ten");
plugin.getTopTen().topTenRemoveEntry(playerUUID);
}
// Load any messages for the player
if (DEBUG)
plugin.getLogger().info("DEBUG: checking messages for " + player.getName());
final List<String> messages = plugin.getMessages().getMessages(playerUUID);
if (messages != null) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Messages waiting!");
plugin.getServer().getScheduler().runTaskLater(plugin, () -> {
Util.sendMessage(player, ChatColor.AQUA + plugin.myLocale(playerUUID).newsHeadline);
int i = 1;
for (String message : messages) {
Util.sendMessage(player, i++ + ": " + message);
}
// Clear the messages
plugin.getMessages().clearMessages(playerUUID);
}, 40L);
}
// }
if (DEBUG)
plugin.getLogger().info("DEBUG: Log in completed, passing to other plugins.");
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class IslandGuard1_9 method onRodDamage.
@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);
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class IslandGuard1_9 method onBlockForm.
/**
* 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);
}
}
use of com.wasteofplastic.askyblock.Island in project askyblock by tastybento.
the class IslandGuard1_9 method placeEndCrystalEvent.
// End crystal
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
void placeEndCrystalEvent(final PlayerInteractEvent e) {
Player p = e.getPlayer();
if (!IslandGuard.inWorld(p)) {
return;
}
if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
// You can do anything if you are Op
return;
}
// Check if they are holding armor stand
for (ItemStack inHand : Util.getPlayerInHandItems(e.getPlayer())) {
if (inHand.getType().equals(Material.END_CRYSTAL)) {
// Check island
Island island = plugin.getGrid().getIslandAt(e.getPlayer().getLocation());
if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) {
return;
}
if (island != null && (island.getMembers().contains(p.getUniqueId()) || island.getIgsFlag(SettingsFlag.PLACE_BLOCKS))) {
// plugin.getLogger().info("1.9 " +"DEBUG: armor stand place check");
if (Settings.limitedBlocks.containsKey("END_CRYSTAL") && Settings.limitedBlocks.get("END_CRYSTAL") > -1) {
// plugin.getLogger().info("1.9 " +"DEBUG: count armor stands");
int count = island.getTileEntityCount(Material.END_CRYSTAL, e.getPlayer().getWorld());
// plugin.getLogger().info("1.9 " +"DEBUG: count is " + count + " limit is " + Settings.limitedBlocks.get("ARMOR_STAND"));
if (Settings.limitedBlocks.get("END_CRYSTAL") <= count) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + (plugin.myLocale(e.getPlayer().getUniqueId()).entityLimitReached.replace("[entity]", Util.prettifyText(Material.END_CRYSTAL.toString()))).replace("[number]", String.valueOf(Settings.limitedBlocks.get("END_CRYSTAL"))));
e.setCancelled(true);
return;
}
}
return;
}
// plugin.getLogger().info("1.9 " +"DEBUG: stand place cancelled");
e.setCancelled(true);
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.getPlayer().updateInventory();
}
}
}
Aggregations