Пример #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 onPlayerQuit(PlayerQuitEvent event) {
    Player p = event.getPlayer();

    // TODO Write stats
    TeamMember m = plugin.getBattlefieldManager().getPlayer(p);
    if (m != null) {
      Team team = m.getTeam();
      Battlefield field = team.getField();
      field.sendMessageToAll(
          Format.pluginTag
              + p.getName()
              + " of "
              + team.getColor().getTeamTag()
              + " has quit the game!");
      field.removePlayer(m);
    }
  }