예제 #1
0
 public void onPlayerMove(PlayerMoveEvent event) {
   Block to = event.getTo().getBlock();
   Block from = event.getFrom().getBlock();
   if (from.getX() == to.getX() && from.getY() == to.getY() && from.getZ() == to.getZ()) return;
   Player p = event.getPlayer();
   TeamMember m = plugin.getBattlefieldManager().getPlayer(p);
   for (Battlefield field : plugin.getBattlefieldManager().getFields()) {
     BFRegion r = field.getRegion();
     int check = r.checkMovement(p, to, from);
     if (check < 0) {
       if (m == null) return;
       if (field.isActive()) {
         event.setTo(plugin.getLastLocation(p));
         Format.sendMessage(p, "Cannot leave battlefield during a match!");
       } else {
         Format.sendMessage(
             p,
             "Leaving the battlefield '"
                 + ChatColor.WHITE
                 + field.getName()
                 + ChatColor.GRAY
                 + "'.");
         field.removePlayer(m);
         r.setPlayerState(p, false);
       }
       return;
     } else if (check > 0) {
       if (field.isActive()) {
         event.setTo(plugin.getLastLocation(p));
         Format.sendMessage(p, "Cannot enter battlefield during a match!");
       } else {
         Format.sendMessage(
             p,
             "Entering the battlefield '"
                 + ChatColor.WHITE
                 + field.getName()
                 + ChatColor.GRAY
                 + "'.");
         field.addPlayer(p);
         r.setPlayerState(p, true);
       }
       return;
     } else {
       if (p.getLocation().getBlock().getRelative(BlockFace.DOWN).getTypeId() != 0)
         plugin.setLastLocation(p);
       if (field.isActive()) field.getGametype().getListener().onPlayerMove(m, from, to);
     }
   }
 }
예제 #2
0
 public void onPlayerInteract(PlayerInteractEvent event) {
   Block b = event.getClickedBlock();
   Player p = event.getPlayer();
   Action a = event.getAction();
   // Handle field building tool operations
   if (p.getItemInHand().getTypeId() == 276) {
     Builder fb = plugin.getBattlefieldManager().getBuilder(p);
     if (fb != null) {
       if (fb.getTool() != null) {
         Tool tool = fb.getTool();
         switch (a) {
           case RIGHT_CLICK_BLOCK:
             tool.rightClick(b);
             break;
           case LEFT_CLICK_BLOCK:
             tool.leftClick(b);
             break;
           case RIGHT_CLICK_AIR:
             tool.rightClick();
             break;
           case LEFT_CLICK_AIR:
             tool.leftClick();
             break;
           default:
             break;
         }
       }
     }
   }
   TeamMember m = plugin.getBattlefieldManager().getPlayer(p);
   if (m != null) {
     Battlefield field = m.getTeam().getField();
     // Handle sign clicks
     if (b != null) {
       if (b.getState() instanceof Sign) {
         Sign sign = (Sign) b.getState();
         String line = sign.getLine(0);
         if (line.equals("[Options]")) {
           BattlefieldSign bs = field.getSign(b);
           if (bs != null) {
             if (field.isActive())
               Format.sendMessage(m, "You cannot change settings during a game.");
             else if (a == Action.LEFT_CLICK_BLOCK) bs.executeOption(m);
             else if (a == Action.RIGHT_CLICK_BLOCK) bs.cycleOption(m);
           }
         }
       }
     }
     if (field.isActive())
       field.getGametype().getListener().onClick(m, event.getClickedBlock(), event.getAction());
   }
 }