Ejemplo n.º 1
0
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onBlockFromTo(BlockFromToEvent event) {
   ZoneManager manager = m_plugin.getZoneManager();
   if (manager.zoneExists(event.getBlock().getLocation())) {
     event.setCancelled(true);
   }
 }
Ejemplo n.º 2
0
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onPistonExtend(BlockPistonExtendEvent event) {
   ZoneManager manager = m_plugin.getZoneManager();
   if (!manager.zoneExists(event.getBlock().getLocation())) {
     for (Block b : event.getBlocks()) {
       if (manager.zoneExists(b.getLocation())) {
         event.setCancelled(true);
         return;
       } else if (manager.zoneExists(b.getRelative(event.getDirection()).getLocation())) {
         event.setCancelled(true);
         return;
       }
     }
   } else {
     Zone zone = manager.getZone(event.getBlock().getLocation());
     for (Block b : event.getBlocks()) {
       if (manager.zoneExists(b.getLocation())) {
         if (!zone.getName().equals(manager.getZone(b.getLocation()).getName())) {
           event.setCancelled(true);
           return;
         }
       }
     }
   }
 }
Ejemplo n.º 3
0
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onBreakDoor(EntityBreakDoorEvent event) {
   ZoneManager manager = m_plugin.getZoneManager();
   if (manager.zoneExists(event.getBlock().getLocation())) {
     if (!(event.getEntity() instanceof Player)) {
       event.setCancelled(true);
     }
   }
 }
Ejemplo n.º 4
0
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onCreatureSpawn(CreatureSpawnEvent event) {
   ZoneManager manager = m_plugin.getZoneManager();
   if (manager.zoneExists(event.getLocation())) {
     if (!manager.getZone(event.getLocation()).canMobsSpawn()) {
       if (event.getEntity() instanceof Monster || event.getEntity() instanceof Slime) {
         event.setCancelled(true);
       }
     }
   }
 }
Ejemplo n.º 5
0
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onBlockIgnite(BlockIgniteEvent event) {
   ZoneManager manager = m_plugin.getZoneManager();
   if (manager.zoneExists(event.getBlock().getLocation())) {
     if (!manager
         .getZone(event.getBlock().getLocation())
         .canPlayerUse(event.getPlayer(), event.getBlock())) {
       event.setCancelled(true);
       sendMessageNoSpam(event.getPlayer(), UI.getMessage("NoBuild"));
     }
   }
 }
Ejemplo n.º 6
0
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onDamageByEntity(EntityDamageByEntityEvent event) {
   if (event.getDamager() instanceof Player) {
     if (event.getEntity() instanceof Player) {
       ZoneManager manager = m_plugin.getZoneManager();
       if (manager.zoneExists(event.getDamager().getLocation())) {
         if (!manager.getZone(event.getDamager().getLocation()).canPVP()) {
           event.setCancelled(true);
         }
       } else {
         if (manager.zoneExists(event.getEntity().getLocation())) {
           if (!manager.getZone(event.getEntity().getLocation()).canPVP()) {
             event.setCancelled(true);
           }
         } else {
           event.setCancelled(true);
         }
       }
     }
   } else if (event.getDamager() instanceof Arrow) {
     if (event.getEntity() instanceof Player) {
       ZoneManager manager = m_plugin.getZoneManager();
       if (manager.zoneExists(event.getDamager().getLocation())) {
         if (!manager.getZone(event.getDamager().getLocation()).canPVP()) {
           event.setCancelled(true);
         }
       } else {
         if (manager.zoneExists(event.getEntity().getLocation())) {
           if (!manager.getZone(event.getEntity().getLocation()).canPVP()) {
             event.setCancelled(true);
           }
         } else {
           event.setCancelled(true);
         }
       }
     }
   }
 }
Ejemplo n.º 7
0
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onPlayerMove(PlayerMoveEvent event) {
    ZoneManager manager = m_plugin.getZoneManager();
    Zone fromZone = manager.getZone(event.getFrom());
    Zone toZone = manager.getZone(event.getTo());
    if (toZone != null) {
      if (!toZone.canPlayerMove(event.getPlayer())) {
        Vector direction =
            event.getFrom().toVector().subtract(event.getTo().toVector()).normalize();
        event.getPlayer().setVelocity(direction.multiply(2));
        sendMessageNoSpam(event.getPlayer(), UI.getMessage("NoMove"));
        return;
      }
    }

    if (event.getTo().equals(event.getFrom())) {
      return;
    }

    if ((fromZone == null && toZone != null)
        || (fromZone != null && toZone != null && !fromZone.getName().equals(toZone.getName()))) {
      event.getPlayer().sendMessage(toZone.getEnterMessage());
    } else if ((toZone == null && fromZone != null)
        || (fromZone != null && toZone != null && !toZone.getName().equals(fromZone.getName()))) {
      event.getPlayer().sendMessage(fromZone.getExitMessage());
    }

    if (toZone != null && fromZone != null) {
      if (toZone.getName() == fromZone.getName()) {
        Plot toPlot = toZone.getPlot(event.getTo());
        Plot fromPlot = fromZone.getPlot(event.getFrom());

        if ((fromPlot == null && toPlot != null)
            || (fromPlot != null
                && toPlot != null
                && !fromPlot.getName().equals(toPlot.getName()))) {
          sendZonePrefix(
              event.getPlayer(), toZone, "\u00A7bNow entering plot \u00A7c" + toPlot.getName());
        } else if ((toPlot == null && fromPlot != null)
            || (fromPlot != null
                && toPlot != null
                && !toPlot.getName().equals(fromPlot.getName()))) {
          sendZonePrefix(
              event.getPlayer(), toZone, "\u00A7bNow leaving plot \u00A7c" + fromPlot.getName());
        }
      }
    }
  }
Ejemplo n.º 8
0
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onExplode(EntityExplodeEvent event) {
    ZoneManager manager = m_plugin.getZoneManager();

    List<Block> saveList = new ArrayList<Block>();

    for (Block b : event.blockList()) {
      if (manager.zoneExists(b.getLocation())) {
        saveList.add(b);
      }
    }

    for (Block b : saveList) {
      event.blockList().remove(b);
    }
  }
Ejemplo n.º 9
0
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onPistonRetract(BlockPistonRetractEvent event) {
   ZoneManager manager = m_plugin.getZoneManager();
   if (!manager.zoneExists(event.getBlock().getLocation())) {
     if (manager.zoneExists(event.getRetractLocation())) {
       event.setCancelled(true);
       return;
     }
   } else if (!manager
       .getZone(event.getBlock().getLocation())
       .getName()
       .equals(manager.getZone(event.getRetractLocation()).getName())) {
     event.setCancelled(true);
     return;
   }
 }
Ejemplo n.º 10
0
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onBlockBreak(BlockBreakEvent event) {
    ZoneManager manager = m_plugin.getZoneManager();
    Zone zone = manager.getZone(event.getBlock().getLocation());

    if (zone == null) {
      return;
    }

    if (!zone.canPlayerUse(event.getPlayer(), event.getBlock())) {
      sendMessageNoSpam(event.getPlayer(), UI.getMessage("NoBuild"));
      event.setCancelled(true);
      if (shouldBurn(event.getBlock())) {
        event.getPlayer().setFireTicks(100);
      }
    }
  }
Ejemplo n.º 11
0
  /** Handle teleport messages */
  @EventHandler(ignoreCancelled = true)
  private void onPlayerTeleport(PlayerTeleportEvent event) {
    ZoneManager manager = m_plugin.getZoneManager();
    Zone fromZone = manager.getZone(event.getFrom());
    Zone toZone = manager.getZone(event.getTo());
    if (toZone != null) {
      if (!toZone.canPlayerMove(event.getPlayer())) {
        event.setCancelled(true);
        sendMessageNoSpam(event.getPlayer(), UI.getMessage("NoMove"));
        return;
      }
    }

    if (event.getTo().equals(event.getFrom())) {
      return;
    }

    if ((fromZone == null && toZone != null)
        || (fromZone != null && toZone != null && !fromZone.getName().equals(toZone.getName()))) {
      event.getPlayer().sendMessage(toZone.getEnterMessage());
    } else if ((toZone == null && fromZone != null)
        || (fromZone != null && toZone != null && !toZone.getName().equals(fromZone.getName()))) {
      event.getPlayer().sendMessage(fromZone.getExitMessage());
    }

    if (toZone != null && fromZone != null) {
      if (toZone.getName() == fromZone.getName()) {
        Plot toPlot = toZone.getPlot(event.getTo());
        Plot fromPlot = fromZone.getPlot(event.getFrom());

        if ((fromPlot == null && toPlot != null)
            || (fromPlot != null
                && toPlot != null
                && !fromPlot.getName().equals(toPlot.getName()))) {
          sendZonePrefix(
              event.getPlayer(), toZone, "\u00A7bNow entering plot \u00A7c" + toPlot.getName());
        } else if ((toPlot == null && fromPlot != null)
            || (fromPlot != null
                && toPlot != null
                && !toPlot.getName().equals(fromPlot.getName()))) {
          sendZonePrefix(
              event.getPlayer(), toZone, "\u00A7bNow leaving plot \u00A7c" + fromPlot.getName());
        }
      }
    }
  }
Ejemplo n.º 12
0
 /*
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onPlayerUseBukkit(PlayerBucketEvent event) {
     ZoneManager manager = m_plugin.getZoneManager();
     Zone zone = manager.getZone(event.getBlockClicked().getLocation());
     if (zone != null) {
         if (!zone.canPlayerUse(event.getPlayer(), event.getBlockClicked())) {
             event.setCancelled(true);
             sendMessageNoSpam(event.getPlayer(), UI.getMessage("NoBuild"));
         }
     }
 }
 */
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onPlayerInteractEvent(PlayerInteractEvent event) {
   ZoneManager manager = m_plugin.getZoneManager();
   Zone zone = manager.getZone(event.getClickedBlock().getLocation());
   if (zone != null) {
     if (!zone.canPlayerUse(event.getPlayer(), event.getClickedBlock())) {
       if (event.getAction() == Action.PHYSICAL
           || (event.getAction() == Action.RIGHT_CLICK_BLOCK && !event.isBlockInHand())) {
         if (event.getAction() == Action.PHYSICAL) {
           return;
         }
         event.setUseInteractedBlock(Event.Result.DENY);
         sendMessageNoSpam(event.getPlayer(), UI.getMessage("NoBuild"));
       }
     }
   }
 }