Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.betanyan.povertycraft.poverty;
- import me.betanyan.povertycraft.PovertyCraft;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.Sound;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.EventPriority;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.block.BlockBreakEvent;
- import org.bukkit.event.block.BlockPlaceEvent;
- import org.bukkit.event.entity.EntityDamageByEntityEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.event.player.PlayerMoveEvent;
- import org.bukkit.event.world.ChunkLoadEvent;
- public class ProtectionStone implements Listener {
- private static double x1;
- private static double y1;
- private static double z1;
- private static double x2;
- private static double y2;
- private static double z2;
- private static Location l1;
- private static Location l2;
- private static int bdis = PovertyCraft.c.getInt("protection-blocks.beacon");
- private static int sdis = PovertyCraft.c.getInt("protection-blocks.sponge");
- @EventHandler
- public void onPlace(BlockPlaceEvent e) {
- Player p = e.getPlayer();
- int notallowed = 0;
- int max = PovertyCraft.ps.getList("protections.all").size();
- int counter = 0;
- double x = 0;
- double y = 0;
- double z = 0;
- Location l = null;
- Location bl = e.getBlock().getLocation();
- Location ploc = p.getLocation();
- String ltostring = ""+(int) bl.getX()+"{"+ (int) bl.getY()+"}"+(int)bl.getZ();
- if (!e.getBlock().getLocation().getWorld().getName().equals("world_the_end") || !e.getBlock().getLocation().getWorld().getName().equals("world_nether")) {
- if(e.getBlock().getType() == Material.FLOWER_POT) {
- if (!e.getBlock().getLocation().getWorld().getName().equalsIgnoreCase("shop") && !e.getBlock().getLocation().getWorld().getName().equalsIgnoreCase("world_nether") && !e.getBlock().getLocation().getWorld().getName().equalsIgnoreCase("world_the_end")) {
- if (p.hasPermission("povertycraft.protections.beacon")) {
- for (String s : PovertyCraft.ps.getList("protections.all")) {
- counter++;
- if (PovertyCraft.ps.contains("protections."+s+".1")) {
- x = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.x"));
- y = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.y"));
- z = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.z"));
- l = new Location(p.getWorld(), x, y, z);
- }
- if (PovertyCraft.ps.contains("protections."+s+".2")) {
- x1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.x"));
- y1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.y"));
- z1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.z"));
- l1 = new Location(p.getWorld(), x1, y1, z1);
- }
- if (PovertyCraft.ps.contains("protections."+s+".3")) {
- x2 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".3.x"));
- y2 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".3.y"));
- z2 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".3.z"));
- l2 = new Location(p.getWorld(), x2, y2, z2);
- }
- Location s1 = new Location(p.getWorld(), PovertyCraft.c.getInt("spawnblock1.x"), PovertyCraft.c.getInt("spawnblock1.y"), PovertyCraft.c.getInt("spawnblock1.z"));
- Location s2 = new Location(p.getWorld(), PovertyCraft.c.getInt("spawnblock2.x"), PovertyCraft.c.getInt("spawnblock2.y"), PovertyCraft.c.getInt("spawnblock2.z"));
- if (e.getBlock().getLocation().distance(s1) < 100 || e.getBlock().getLocation().distance(s2) < 100) {
- p.sendMessage(PovertyCraft.prefix + "You can not place here!");
- e.setCancelled(true);
- p.updateInventory();
- break;
- }
- if (x != 0 && l.distance(e.getBlock().getLocation()) < bdis * 2) {
- notallowed++;
- e.setCancelled(true);
- } else {
- e.setCancelled(false);
- }
- if (x1 != 0 && l1.distance(e.getBlock().getLocation()) < bdis * 2) {
- notallowed++;
- e.setCancelled(true);
- } else {
- e.setCancelled(false);
- }
- if (x2 != 0 && l2.distance(e.getBlock().getLocation()) < bdis * 2) {
- notallowed++;
- e.setCancelled(true);
- } else {
- e.setCancelled(false);
- }
- if (notallowed > 0) {
- p.sendMessage(PovertyCraft.prefix + "You are too close to someone elses claim.");
- e.setCancelled(true);
- p.updateInventory();
- break;
- }
- if (counter != max) {
- continue;
- } else {
- if (notallowed == 0) {
- s1 = new Location(p.getWorld(), PovertyCraft.c.getInt("spawnblock1.x"), PovertyCraft.c.getInt("spawnblock1.y"), PovertyCraft.c.getInt("spawnblock1.z"));
- s2 = new Location(p.getWorld(), PovertyCraft.c.getInt("spawnblock2.x"), PovertyCraft.c.getInt("spawnblock2.y"), PovertyCraft.c.getInt("spawnblock2.z"));
- if (e.getBlock().getLocation().distance(s1) < 100 || e.getBlock().getLocation().distance(s2) < 100) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not place here!");
- p.updateInventory();
- break;
- }
- if (PovertyCraft.ps.contains("protections."+p.getName()+".1")) {
- if (!PovertyCraft.ps.contains("protections."+p.getName()+".2")) {
- if (p.hasPermission("povertycraft.protections.2")) {
- PovertyCraft.ps.createPath("protections."+p.getName(), null);
- PovertyCraft.ps.createList("protections."+p.getName()+".2.allowed");
- PovertyCraft.ps.createPath("protections."+p.getName()+".2.x", e.getBlock().getLocation().getX());
- PovertyCraft.ps.createPath("protections."+p.getName()+".2.y", e.getBlock().getLocation().getY());
- PovertyCraft.ps.createPath("protections."+p.getName()+".2.z", e.getBlock().getLocation().getZ());
- PovertyCraft.ps.createPath("protections."+p.getName()+".2"+".type", "beacon");
- PovertyCraft.ps.getList("protections."+p.getName()+".2.allowed").add(p.getName());
- PovertyCraft.ps.save();
- p.sendMessage(PovertyCraft.prefix + "Protection block placed! You can not place anymore!");
- } else {
- p.sendMessage(PovertyCraft.prefix + "You do not have permission to place a second protection block.");
- }
- break;
- } else if (PovertyCraft.ps.contains("protections."+p.getName()+".2")) {
- p.sendMessage(PovertyCraft.prefix + "Sorry! A maximum amount of 2 protection blocks can be placed.");
- break;
- }
- } else {
- PovertyCraft.ps.createPath("protections."+p.getName(), null);
- PovertyCraft.ps.createList("protections."+p.getName()+".1.allowed");
- PovertyCraft.ps.createPath("protections."+p.getName()+".1.x", e.getBlock().getLocation().getX());
- PovertyCraft.ps.createPath("protections."+p.getName()+".1.y", e.getBlock().getLocation().getY());
- PovertyCraft.ps.createPath("protections."+p.getName()+".1.z", e.getBlock().getLocation().getZ());
- PovertyCraft.ps.createPath("protections."+p.getName()+".1"+".type", "beacon");
- PovertyCraft.ps.getList("protections.all").add(p.getName());
- PovertyCraft.ps.getList("protections."+p.getName()+".1.allowed").add(p.getName());
- PovertyCraft.ps.save();
- if (p.hasPermission("povertycraft.protections.2")) {
- p.sendMessage(PovertyCraft.prefix + "Protection block placed! You can place 1 more blocks!");
- } else {
- p.sendMessage(PovertyCraft.prefix + "Protection block placed! You can not place anymore protection blocks!");
- p.updateInventory();
- }
- break;
- }
- }
- }
- }
- } else {
- p.sendMessage(PovertyCraft.prefix + "You are not allowed to place bedrock blocks.");
- }
- } else {
- p.sendMessage(PovertyCraft.prefix + "You can not claim here!");
- e.setCancelled(true);
- p.updateInventory();
- }
- } else if (e.getBlock().getType() == Material.SPONGE) {
- if (!p.getWorld().getName().equalsIgnoreCase("shop") || !p.getWorld().getName().equalsIgnoreCase("world_nether") || !p.getWorld().getName().equalsIgnoreCase("world_the_end")) {
- if (p.hasPermission("povertycraft.protections.sponge")) {
- for (String s : PovertyCraft.ps.getList("protections.all")) {
- counter++;
- if (PovertyCraft.ps.contains("protections."+s+".1")) {
- x = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.x"));
- y = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.y"));
- z = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.z"));
- l = new Location(p.getWorld(), x, y, z);
- }
- if (PovertyCraft.ps.contains("protections."+s+".2")) {
- x1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.x"));
- y1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.y"));
- z1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.z"));
- l1 = new Location(p.getWorld(), x1, y1, z1);
- }
- Location s1 = new Location(p.getWorld(), PovertyCraft.c.getInt("spawnblock1.x"), PovertyCraft.c.getInt("spawnblock1.y"), PovertyCraft.c.getInt("spawnblock1.z"));
- Location s2 = new Location(p.getWorld(), PovertyCraft.c.getInt("spawnblock2.x"), PovertyCraft.c.getInt("spawnblock2.y"), PovertyCraft.c.getInt("spawnblock2.z"));
- if (e.getBlock().getLocation().distance(s1) < 100 || e.getBlock().getLocation().distance(s2) < 100) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not place here!");
- p.updateInventory();
- }
- if (x != 0 && l.distance(e.getBlock().getLocation()) < sdis * 2) {
- notallowed++;
- e.setCancelled(true);
- } else {
- e.setCancelled(false);
- }
- if (x1 != 0 && l1.distance(e.getBlock().getLocation()) < sdis * 2) {
- notallowed++;
- e.setCancelled(true);
- } else {
- e.setCancelled(false);
- }
- if (x2 != 0 && l2.distance(e.getBlock().getLocation()) < sdis * 2) {
- notallowed++;
- e.setCancelled(true);
- } else {
- e.setCancelled(false);
- }
- if (notallowed > 0) {
- p.sendMessage(PovertyCraft.prefix + "You are too close to someone elses claim.");
- e.setCancelled(true);
- break;
- }
- if (counter != max) {
- continue;
- } else {
- if (notallowed == 0) {
- s1 = new Location(p.getWorld(), PovertyCraft.c.getInt("spawnblock1.x"), PovertyCraft.c.getInt("spawnblock1.y"), PovertyCraft.c.getInt("spawnblock1.z"));
- s2 = new Location(p.getWorld(), PovertyCraft.c.getInt("spawnblock2.x"), PovertyCraft.c.getInt("spawnblock2.y"), PovertyCraft.c.getInt("spawnblock2.z"));
- if (e.getBlock().getLocation().distance(s1) < 100 || e.getBlock().getLocation().distance(s2) < 100) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not place here!");
- p.updateInventory();
- break;
- }
- if (PovertyCraft.ps.contains("protections."+p.getName())) {
- if (!PovertyCraft.ps.contains("protections."+p.getName()+".2")) {
- if (p.hasPermission("povertycraft.protections.2")) {
- PovertyCraft.ps.createPath("protections."+p.getName(), null);
- PovertyCraft.ps.createList("protections."+p.getName()+".2.allowed");
- PovertyCraft.ps.createPath("protections."+p.getName()+".2.x", e.getBlock().getLocation().getX());
- PovertyCraft.ps.createPath("protections."+p.getName()+".2.y", e.getBlock().getLocation().getY());
- PovertyCraft.ps.createPath("protections."+p.getName()+".2.z", e.getBlock().getLocation().getZ());
- PovertyCraft.ps.createPath("protections."+p.getName()+".2"+".type", "sponge");
- PovertyCraft.ps.getList("protections."+p.getName()+".2.allowed").add(p.getName());
- PovertyCraft.ps.save();
- if (p.hasPermission("povertycraft.protections.3")) {
- p.sendMessage(PovertyCraft.prefix + "Protection block placed! You can place 1 more block!");
- } else {
- p.sendMessage(PovertyCraft.prefix + "Protection block placed! You cannot place anymore!");
- }
- } else {
- p.sendMessage(PovertyCraft.prefix + "You do not have permission to place a second protection block.");
- }
- break;
- } else if (PovertyCraft.ps.contains("protections."+p.getName()+".2")) {
- p.sendMessage(PovertyCraft.prefix + "Sorry! Only a maximum amount of 2 protection blocks can be placed.");
- break;
- }
- } else {
- PovertyCraft.ps.createPath("protections."+p.getName(), null);
- PovertyCraft.ps.createList("protections."+p.getName()+".1.allowed");
- PovertyCraft.ps.createPath("protections."+p.getName()+".1.x", p.getLocation().getX());
- PovertyCraft.ps.createPath("protections."+p.getName()+".1.y", p.getLocation().getY());
- PovertyCraft.ps.createPath("protections."+p.getName()+".1.z", p.getLocation().getZ());
- PovertyCraft.ps.createPath("protections."+p.getName()+".1"+".type", "sponge");
- PovertyCraft.ps.getList("protections.all").add(p.getName());
- PovertyCraft.ps.getList("protections."+p.getName()+".1.allowed").add(p.getName());
- PovertyCraft.ps.save();
- if (p.hasPermission("povertycraft.protections.2")) {
- p.sendMessage(PovertyCraft.prefix + "Protection block placed! You can place 1 more blocks!");
- } else {
- p.sendMessage(PovertyCraft.prefix + "Protection block placed! You cannot place anymore!");
- }
- break;
- }
- }
- }
- }
- } else {
- p.sendMessage(PovertyCraft.prefix + "You are not allowed to place sponge blocks.");
- }
- } else {
- p.sendMessage(PovertyCraft.prefix + "You can not claim here!");
- e.setCancelled(true);
- p.updateInventory();
- }
- } else if (e.getBlock().getType() == Material.ENDER_PORTAL_FRAME) {
- if (!PovertyCraft.c.contains("spawnblock1")) {
- PovertyCraft.c.createPath("spawnblock1", null);
- PovertyCraft.c.createPath("spawnblock1.x", e.getBlock().getX());
- PovertyCraft.c.createPath("spawnblock1.y", e.getBlock().getY());
- PovertyCraft.c.createPath("spawnblock1.z", e.getBlock().getZ());
- p.sendMessage(PovertyCraft.prefix + "You have placed a spawn block.");
- } else {
- PovertyCraft.c.createPath("spawnblock2", null);
- PovertyCraft.c.createPath("spawnblock2.x", e.getBlock().getX());
- PovertyCraft.c.createPath("spawnblock2.y", e.getBlock().getY());
- PovertyCraft.c.createPath("spawnblock2.z", e.getBlock().getZ());
- p.sendMessage(PovertyCraft.prefix + "You have placed a spawn block.");
- }
- Location s1 = new Location(p.getWorld(), PovertyCraft.c.getInt("spawnblock1.x"), PovertyCraft.c.getInt("spawnblock1.y"), PovertyCraft.c.getInt("spawnblock1.z"));
- Location s2 = new Location(p.getWorld(), PovertyCraft.c.getInt("spawnblock2.x"), PovertyCraft.c.getInt("spawnblock2.y"), PovertyCraft.c.getInt("spawnblock2.z"));
- if (e.getBlock().getLocation().distance(s1) < 100 || e.getBlock().getLocation().distance(s2) < 100) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not place here!");
- p.updateInventory();
- return;
- }
- } else {
- for (String s : PovertyCraft.ps.getList("protections.all")) {
- if (PovertyCraft.ps.contains("protections."+s+".1")) {
- x = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.x"));
- y = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.y"));
- z = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.z"));
- l = new Location(p.getWorld(), x, y, z);
- }
- if (PovertyCraft.ps.contains("protections."+s+".2")) {
- x1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.x"));
- y1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.y"));
- z1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.z"));
- l1 = new Location(p.getWorld(), x1, y1, z1);
- }
- Location s1 = new Location(p.getWorld(), PovertyCraft.c.getInt("spawnblock1.x"), PovertyCraft.c.getInt("spawnblock1.y"), PovertyCraft.c.getInt("spawnblock1.z"));
- Location s2 = new Location(p.getWorld(), PovertyCraft.c.getInt("spawnblock2.x"), PovertyCraft.c.getInt("spawnblock2.y"), PovertyCraft.c.getInt("spawnblock2.z"));
- if (e.getBlock().getLocation().distance(s1) < 100 || e.getBlock().getLocation().distance(s2) < 100) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not place here!");
- p.updateInventory();
- break;
- }
- if (PovertyCraft.ps.contains("protections."+s+".1")) {
- if (PovertyCraft.ps.getString("protections."+s+".1.type").equals("beacon") || (PovertyCraft.ps.contains("protections."+s+".2") && PovertyCraft.ps.getString("protections."+s+".2.type").equals("beacon"))) {
- if (x != 0 && l.distance(e.getBlock().getLocation()) < bdis) {
- if (PovertyCraft.ps.contains("protections."+s+".1") && !PovertyCraft.ps.getList("protections."+s+".1.allowed").contains(p.getName())) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not place here!");
- p.updateInventory();
- break;
- } else {
- e.setCancelled(false);
- }
- } else if (x1 != 0 && l1.distance(e.getBlock().getLocation()) < bdis) {
- if (PovertyCraft.ps.contains("protections."+s+".2") && !PovertyCraft.ps.getList("protections."+s+".2.allowed").contains(p.getName())) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not place here!");
- p.updateInventory();
- break;
- } else {
- e.setCancelled(false);
- }
- }
- } else {
- if (x != 0 && l.distance(e.getBlock().getLocation()) < sdis) {
- if (PovertyCraft.ps.contains("protections."+s+".1") && !PovertyCraft.ps.getList("protections."+s+".1.allowed").contains(p.getName())) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not place here!");
- p.updateInventory();
- break;
- } else {
- e.setCancelled(false);
- }
- } else if (x1 != 0 && l1.distance(e.getBlock().getLocation()) < sdis) {
- if (PovertyCraft.ps.contains("protections."+s+".2") && !PovertyCraft.ps.getList("protections."+s+".2.allowed").contains(p.getName())) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not place here!");
- p.updateInventory();
- break;
- } else {
- e.setCancelled(false);
- }
- }
- }
- }
- }
- }
- } else {
- return;
- }
- }
- /* @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onTp(PlayerTeleportEvent e) {
- Player p = e.getPlayer();
- if (!p.hasPermission("povertycraft.admin")) {
- for (String s : PovertyCraft.ps.getList("protections.all")) {
- double x;
- double y;
- double z;
- Location l = null;
- if (PovertyCraft.ps.contains("protections."+s+".1")) {
- x = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.x"));
- y = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.y"));
- z = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.z"));
- l = new Location(p.getWorld(), x, y, z);
- }
- if (PovertyCraft.ps.contains("protections."+s+".2")) {
- x1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.x"));
- y1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.y"));
- z1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.z"));
- l1 = new Location(p.getWorld(), x1, y1, z1);
- }
- if (PovertyCraft.ps.contains("protections."+s+".3")) {
- x2 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".3.x"));
- y2 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".3.y"));
- z2 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".3.z"));
- l2 = new Location(p.getWorld(), x2, y2, z2);
- }
- if (l.distance(e.getTo()) < 10) {
- if (!PovertyCraft.ps.getList("protections."+s+".1.allowed").contains(p.getName())) {
- p.sendMessage(ChatColor.RED + "You can not teleport here!");
- p.teleport(e.getFrom());
- } else {
- e.setCancelled(false);
- }
- } else if (l1.distance(e.getTo()) < 10) {
- if (!PovertyCraft.ps.getList("protections."+s+".2.allowed").contains(p.getName())) {
- p.sendMessage(ChatColor.RED + "You can not teleport here!");
- p.teleport(e.getFrom());
- } else {
- e.setCancelled(false);
- }
- } else if (l2.distance(e.getTo()) < 10) {
- if (!PovertyCraft.ps.getList("protections."+s+".3.allowed").contains(p.getName())) {
- p.sendMessage(ChatColor.RED + "You can not teleport here!");
- p.teleport(e.getFrom());
- } else {
- e.setCancelled(false);
- }
- }
- }
- } else {
- e.setCancelled(false);
- }
- }
- */
- @SuppressWarnings("deprecation")
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onMove(PlayerMoveEvent e) {
- Player p = e.getPlayer();
- Location l = null;
- boolean bec = false;
- double mx,my,mz;
- if (!e.getPlayer().getLocation().getWorld().getName().equals("world_the_end") || !e.getPlayer().getLocation().getWorld().getName().equals("world_nether")) {
- for (String s : PovertyCraft.ps.getList("protections.all")) {
- if (PovertyCraft.ps.contains("protections."+s+".2")) {
- mx = PovertyCraft.ps.getDouble("protections."+s+".2.x");
- my = PovertyCraft.ps.getDouble("protections."+s+".2.y");
- mz = PovertyCraft.ps.getDouble("protections."+s+".2.z");
- } else {
- mx = PovertyCraft.ps.getDouble("protections."+s+".1.x");
- my = PovertyCraft.ps.getDouble("protections."+s+".1.y");
- mz = PovertyCraft.ps.getDouble("protections."+s+".1.z");
- }
- l = new Location(p.getWorld(), mx, my, mz);
- if (PovertyCraft.ps.contains("protections."+s+".1")) {
- if (PovertyCraft.ps.getString("protections."+s+".1.type").equals("beacon") || (PovertyCraft.ps.contains("protections."+s+".2") && PovertyCraft.ps.getString("protections."+s+".2").equals("beacon"))) {
- bec = true;
- }
- } else {
- continue;
- }
- if (bec) {
- if (Bukkit.getPlayer(s) != null) {
- if (e.getTo().distance(l) < bdis && e.getFrom().distance(l) > bdis) {
- p.sendMessage(ChatColor.translateAlternateColorCodes('&',PovertyCraft.prefix + "Now entering " + getPrefix(Bukkit.getPlayer(s)) + ChatColor.RESET + ChatColor.AQUA + "" + ChatColor.BOLD + s + " protected area."));
- } else if (e.getTo().distance(l) > bdis && e.getFrom().distance(l) < bdis) {
- p.sendMessage(ChatColor.translateAlternateColorCodes('&',PovertyCraft.prefix + "Now leaving " + getPrefix(Bukkit.getPlayer(s)) + ChatColor.RESET + ChatColor.AQUA + "" + ChatColor.BOLD + s + " protected area."));
- }
- } else {
- if (e.getTo().distance(l) < bdis && e.getFrom().distance(l) > bdis) {
- p.sendMessage(ChatColor.translateAlternateColorCodes('&',PovertyCraft.prefix + "Now entering " + s + " protected area."));
- } else if (e.getTo().distance(l) > bdis && e.getFrom().distance(l) < bdis) {
- p.sendMessage(ChatColor.translateAlternateColorCodes('&',PovertyCraft.prefix + "Now leaving " + s + " protected area."));
- }
- }
- } else {
- if (Bukkit.getPlayer(s) != null) {
- if (e.getTo().distance(l) < sdis && e.getFrom().distance(l) > sdis) {
- p.sendMessage(ChatColor.translateAlternateColorCodes('&',PovertyCraft.prefix + "Now entering " + getPrefix(Bukkit.getPlayer(s)) + ChatColor.RESET + ChatColor.AQUA + "" + ChatColor.BOLD + s + " protected area."));
- } else if (e.getTo().distance(l) > bdis && e.getFrom().distance(l) < bdis) {
- p.sendMessage(ChatColor.translateAlternateColorCodes('&',PovertyCraft.prefix + "Now leaving " + getPrefix(Bukkit.getPlayer(s)) + ChatColor.RESET + ChatColor.AQUA + "" + ChatColor.BOLD + s + " protected area."));
- }
- } else {
- if (e.getTo().distance(l) < sdis && e.getFrom().distance(l) > sdis) {
- p.sendMessage(ChatColor.translateAlternateColorCodes('&',PovertyCraft.prefix + "Now entering " + s + " protected area."));
- } else if (e.getTo().distance(l) > sdis && e.getFrom().distance(l) < sdis) {
- p.sendMessage(ChatColor.translateAlternateColorCodes('&',PovertyCraft.prefix + "Now leaving " + s + " protected area."));
- }
- }
- }
- }
- }
- }
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onBreak(BlockBreakEvent e) {
- Player p = e.getPlayer();
- double x = 0;
- double y = 0;
- double z = 0;
- Location l = null;
- boolean bec= false;
- if (!e.getBlock().getLocation().getWorld().getName().equals("world_the_end") || !e.getBlock().getLocation().getWorld().getName().equals("world_nether")) {
- if (e.getBlock().getType() != Material.FLOWER_POT && e.getBlock().getType() != Material.SPONGE) {
- if (!p.hasPermission("povertycraft.admin")) {
- if (!p.getWorld().getName().equalsIgnoreCase("shop")) {
- for (String s : PovertyCraft.ps.getList("protections.all")) {
- if (PovertyCraft.ps.contains("protections."+s+".1")) {
- if (PovertyCraft.ps.getString("protections."+s+".1.type").equals("beacon")) {
- bec = true;
- if (PovertyCraft.ps.contains("protections."+s+".2")) {
- if (PovertyCraft.ps.getString("protections."+s+".2.type").equals("beacon")) {
- bec = true;
- }
- }
- }
- } else {
- continue;
- }
- if (PovertyCraft.ps.contains("protections."+s+".1")) {
- x = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.x"));
- y = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.y"));
- z = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.z"));
- l = new Location(p.getWorld(), x, y, z);
- }
- if (PovertyCraft.ps.contains("protections."+s+".2")) {
- x1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.x"));
- y1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.y"));
- z1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.z"));
- l1 = new Location(p.getWorld(), x1, y1, z1);
- }
- if (bec) {
- if (x != 0 && l != null && l.distance(e.getBlock().getLocation()) < bdis) {
- if (PovertyCraft.ps.contains("protections."+s+".1") && !PovertyCraft.ps.getList("protections."+s+".1.allowed").contains(p.getName())) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not break here!");
- PovertyCraft.playSound(p, Sound.BLAZE_HIT);
- break;
- } else {
- e.setCancelled(false);
- continue;
- }
- } else if (x1 != 0 && l1 != null && l1.distance(e.getBlock().getLocation()) < bdis) {
- if (PovertyCraft.ps.contains("protections."+s+".2") && !PovertyCraft.ps.getList("protections."+s+".2.allowed").contains(p.getName())) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not break here!");
- PovertyCraft.playSound(p, Sound.BLAZE_HIT);
- break;
- } else {
- e.setCancelled(false);
- continue;
- }
- }
- } else {
- if (x != 0 && l != null && l.distance(e.getBlock().getLocation()) < sdis) {
- if (PovertyCraft.ps.contains("protections."+s+".1") && !PovertyCraft.ps.getList("protections."+s+".1.allowed").contains(p.getName())) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not break here!");
- PovertyCraft.playSound(p, Sound.BLAZE_HIT);
- break;
- } else {
- e.setCancelled(false);
- continue;
- }
- } else if (x1 != 0 && l1 != null && l1.distance(e.getBlock().getLocation()) < sdis) {
- if (PovertyCraft.ps.contains("protections."+s+".2") && !PovertyCraft.ps.getList("protections."+s+".2.allowed").contains(p.getName())) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not break here!");
- PovertyCraft.playSound(p, Sound.BLAZE_HIT);
- break;
- } else {
- e.setCancelled(false);
- continue;
- }
- }
- }
- }
- } else {
- e.setCancelled(true);
- }
- } else {
- e.setCancelled(false);
- }
- } else {
- Location loc = e.getBlock().getLocation();
- if (contains("protections."+p.getName()+".1") && !contains("protections."+p.getName()+".2")) {
- if (PovertyCraft.ps.getDouble("protections."+p.getName()+".1.x")==loc.getX()
- && PovertyCraft.ps.getDouble("protections."+p.getName()+".1.y")==loc.getY()
- && PovertyCraft.ps.getDouble("protections."+p.getName()+".1.z")==loc.getZ()) {
- PovertyCraft.ps.setPath("protections."+p.getName(), null);
- PovertyCraft.ps.getList("protections.all").remove(p.getName());
- PovertyCraft.ps.save();
- PovertyCraft.ps.reload();
- if (p.hasPermission("povertycraft.protections.2")) {
- p.sendMessage(PovertyCraft.prefix + "You have removed the claim! You can now place 2 more!");
- return;
- } else {
- p.sendMessage(PovertyCraft.prefix + "You have removed the claim! You can now place 1 more!");
- return;
- }
- } else {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You do not own this claim!");
- return;
- }
- } else if (contains("protections."+p.getName()+".1") && contains("protections."+p.getName()+".2")) {
- if (PovertyCraft.ps.getDouble("protections."+p.getName()+".1.x")==loc.getX()
- && PovertyCraft.ps.getDouble("protections."+p.getName()+".1.y")==loc.getY()
- && PovertyCraft.ps.getDouble("protections."+p.getName()+".1.z")==loc.getZ()) {
- PovertyCraft.ps.setPath("protections."+p.getName()+".1.allowed", PovertyCraft.ps.getList("protections."+p.getName()+".2.allowed"));
- PovertyCraft.ps.setPath("protections."+p.getName()+".1.x", PovertyCraft.ps.getDouble("protections."+p.getName()+".2.x"));
- PovertyCraft.ps.setPath("protections."+p.getName()+".1.y", PovertyCraft.ps.getDouble("protections."+p.getName()+".2.y"));
- PovertyCraft.ps.setPath("protections."+p.getName()+".1.z", PovertyCraft.ps.getDouble("protections."+p.getName()+".2.z"));
- PovertyCraft.ps.setPath("protections."+p.getName()+".1.type", PovertyCraft.ps.getString("protections."+p.getName()+".2.type"));
- PovertyCraft.ps.setPath("protections."+p.getName()+".2", null);
- PovertyCraft.ps.save();
- PovertyCraft.ps.reload();
- if (p.hasPermission("povertycraft.protections.2")) {
- p.sendMessage(PovertyCraft.prefix + "You have removed the claim! You can now place 1 more!");
- return;
- } else {
- p.sendMessage(PovertyCraft.prefix + "You have removed the claim! You can now place no more!");
- return;
- }
- } else if (PovertyCraft.ps.getDouble("protections."+p.getName()+".2.x")==loc.getX()
- && PovertyCraft.ps.getDouble("protections."+p.getName()+".2.y")==loc.getY()
- && PovertyCraft.ps.getDouble("protections."+p.getName()+".2.z")==loc.getZ()) {
- PovertyCraft.ps.setPath("protections."+p.getName()+".2", null);
- PovertyCraft.ps.save();
- PovertyCraft.ps.reload();
- if (p.hasPermission("povertycraft.protections.2")) {
- p.sendMessage(PovertyCraft.prefix + "You have removed the claim! You can now place 1 more!");
- return;
- } else {
- p.sendMessage(PovertyCraft.prefix + "You have removed the claim! You can now place no more!");
- return;
- }
- } else {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You do not own this claim!");
- return;
- }
- } else {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You do not own this claim!");
- return;
- }
- }
- }
- }
- @EventHandler
- public void onInteract(PlayerInteractEvent e) {
- Location one = null;
- Location two = null;
- double x = 0;
- double y = 0;
- double z = 0;
- boolean bec = false;
- Location l = null;
- Player p = e.getPlayer();
- if (e.getClickedBlock() != null)
- if (!e.getClickedBlock().getLocation().getWorld().getName().equals("world_the_end") || !e.getClickedBlock().getLocation().getWorld().getName().equals("world_nether")) {
- if (!p.hasPermission("povertycraft.admin")) {
- if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
- if (e.getClickedBlock().getType() == Material.CHEST || e.getClickedBlock().getType() == Material.FURNACE || e.getClickedBlock().getType() == Material.BURNING_FURNACE || e.getPlayer().getItemInHand().getType() == Material.WATER_BUCKET || e.getPlayer().getItemInHand().getType() == Material.LAVA_BUCKET || e.getPlayer().getItemInHand().getType() == Material.BUCKET || e.getClickedBlock().getType() == Material.WOODEN_DOOR || e.getClickedBlock().getType() == Material.TRAP_DOOR
- || e.getClickedBlock().getType() == Material.FENCE_GATE || e.getClickedBlock().getType() == Material.ENDER_CHEST || e.getClickedBlock().getType() == Material.ANVIL || e.getClickedBlock().getType() == Material.ENCHANTMENT_TABLE || e.getClickedBlock().getType() == Material.HOPPER || e.getClickedBlock().getType() == Material.DROPPER || e.getClickedBlock().getType() == Material.DISPENSER || e.getClickedBlock().getType() == Material.LEVER || e.getClickedBlock().getType() == Material.STONE_BUTTON || e.getClickedBlock().getType() == Material.WOOD_BUTTON
- || e.getClickedBlock().getType() == Material.JUKEBOX || e.getClickedBlock().getType() == Material.MONSTER_EGG || e.getClickedBlock().getType() == Material.MONSTER_EGGS) {
- for (String s : PovertyCraft.ps.getList("protections.all")) {
- if (PovertyCraft.ps.contains("protections."+s+".1")) {
- if (PovertyCraft.ps.getString("protections."+s+".1.type").equals("beacon") || (PovertyCraft.ps.contains("protections."+s+".2") && PovertyCraft.ps.getString("protections."+s+".2.type").equals("beacon"))) {
- bec = true;
- }
- }
- if (PovertyCraft.ps.contains("protections."+s+".1") && !contains("protections."+s+".2")) {
- x = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.x"));
- y = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.y"));
- z = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.z"));
- l = new Location(p.getWorld(), x, y, z);
- }
- if (PovertyCraft.ps.contains("protections."+s+".2")) {
- x1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.x"));
- y1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.y"));
- z1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.z"));
- l1 = new Location(p.getWorld(), x1, y1, z1);
- }
- if (PovertyCraft.ps.contains("protections."+s+".1")) {
- if (PovertyCraft.ps.getString("protections."+s+".1.type").equals("beacon") || (PovertyCraft.ps.contains("protections."+s+".2") && PovertyCraft.ps.getString("protections."+s+".2.type").equals("beacon"))) {
- if (x != 0 && l.distance(e.getClickedBlock().getLocation()) < bdis) {
- if (PovertyCraft.ps.contains("protections."+s+".1") && !PovertyCraft.ps.getList("protections."+s+".1.allowed").contains(p.getName())) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not interact here!");
- p.updateInventory();
- break;
- } else {
- e.setCancelled(false);
- }
- } else if (x1 != 0 && l1.distance(e.getClickedBlock().getLocation()) < bdis) {
- if (PovertyCraft.ps.contains("protections."+s+".2") && !PovertyCraft.ps.getList("protections."+s+".2.allowed").contains(p.getName())) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not interact here!");
- p.updateInventory();
- break;
- } else {
- e.setCancelled(false);
- }
- }
- } else {
- if (x != 0 && l.distance(e.getClickedBlock().getLocation()) < sdis) {
- if (PovertyCraft.ps.contains("protections."+s+".1") && !PovertyCraft.ps.getList("protections."+s+".1.allowed").contains(p.getName())) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not interact here!");
- p.updateInventory();
- break;
- } else {
- e.setCancelled(false);
- }
- } else if (x1 != 0 && l1.distance(e.getClickedBlock().getLocation()) < sdis) {
- if (PovertyCraft.ps.contains("protections."+s+".2") && !PovertyCraft.ps.getList("protections."+s+".2.allowed").contains(p.getName())) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not interact here!");
- p.updateInventory();
- break;
- } else {
- e.setCancelled(false);
- }
- }
- }
- }
- }
- }
- }
- } else {
- e.setCancelled(false);
- }
- }
- }
- @EventHandler
- public void onHit(EntityDamageByEntityEvent e) {
- Location one = null;
- Location two = null;
- double x = 0;
- double y = 0;
- double z = 0;
- boolean bec = false;
- Location l = null;
- if (!e.getEntity().getLocation().getWorld().getName().equals("world_the_end") || !e.getEntity().getLocation().getWorld().getName().equals("world_nether")) {
- if (e.getDamager() instanceof Player) {
- Player p = (Player) e.getDamager();
- if (!p.hasPermission("povertycraft.admin")) {
- for (String s : PovertyCraft.ps.getList("protections.all")) {
- if (PovertyCraft.ps.contains("protections."+s+".1")) {
- if (PovertyCraft.ps.getString("protections."+s+".1.type").equals("beacon") || (PovertyCraft.ps.contains("protections."+s+".2") && PovertyCraft.ps.getString("protections."+s+".2.type").equals("beacon"))) {
- bec = true;
- }
- }
- if (PovertyCraft.ps.contains("protections."+s+".1") && !contains("protections."+s+".2")) {
- x = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.x"));
- y = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.y"));
- z = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".1.z"));
- l = new Location(p.getWorld(), x, y, z);
- }
- if (PovertyCraft.ps.contains("protections."+s+".2")) {
- x1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.x"));
- y1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.y"));
- z1 = Double.parseDouble(PovertyCraft.ps.getString("protections."+s+".2.z"));
- l1 = new Location(p.getWorld(), x1, y1, z1);
- }
- if (PovertyCraft.ps.contains("protections."+s+".1")) {
- if (PovertyCraft.ps.getString("protections."+s+".1.type").equals("beacon") || (PovertyCraft.ps.contains("protections."+s+".2") && PovertyCraft.ps.getString("protections."+s+".2.type").equals("beacon"))) {
- if (x != 0 && l.distance(e.getEntity().getLocation()) < bdis) {
- if (PovertyCraft.ps.contains("protections."+s+".1") && !PovertyCraft.ps.getList("protections."+s+".1.allowed").contains(p.getName())) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not damage animals here!");
- p.updateInventory();
- break;
- } else {
- e.setCancelled(false);
- }
- } else if (x1 != 0 && l1.distance(e.getEntity().getLocation()) < bdis) {
- if (PovertyCraft.ps.contains("protections."+s+".2") && !PovertyCraft.ps.getList("protections."+s+".2.allowed").contains(p.getName())) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not damage animals here!");
- p.updateInventory();
- break;
- } else {
- e.setCancelled(false);
- }
- }
- } else {
- if (x != 0 && l.distance(e.getEntity().getLocation()) < sdis) {
- if (PovertyCraft.ps.contains("protections."+s+".1") && !PovertyCraft.ps.getList("protections."+s+".1.allowed").contains(p.getName())) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not damage animals here!");
- p.updateInventory();
- break;
- } else {
- e.setCancelled(false);
- }
- } else if (x1 != 0 && l1.distance(e.getEntity().getLocation()) < sdis) {
- if (PovertyCraft.ps.contains("protections."+s+".2") && !PovertyCraft.ps.getList("protections."+s+".2.allowed").contains(p.getName())) {
- e.setCancelled(true);
- p.sendMessage(PovertyCraft.prefix + "You can not damage animals here!");
- p.updateInventory();
- break;
- } else {
- e.setCancelled(false);
- }
- }
- }
- }
- }
- } else {
- e.setCancelled(false);
- }
- }
- }
- }
- private boolean contains(String path) {
- return PovertyCraft.ps.contains(path);
- }
- void debug(String str) {
- Bukkit.getPlayer("BetaNyan").sendMessage("[DEBUG] "+ str);
- }
- private String getPrefix(Player p) {
- try {
- return PovertyCraft.chat.getPlayerPrefix(p);
- } catch (NullPointerException e) {
- return "";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement