Esempio n. 1
0
  public void onEntityDamage(EntityDamageEvent event) {
    if (event instanceof EntityDamageByEntityEvent
        || event instanceof EntityDamageByProjectileEvent) {
      handlerAttackDefend((EntityDamageByEntityEvent) event);
    } else if (event.getCause() == DamageCause.FIRE_TICK) {
      Entity entity = event.getEntity();
      if (entity instanceof Player) {
        Player player = (Player) entity;
        Team team = war.getPlayerTeam(player.getName());
        if (team != null && team.getSpawnVolume().contains(player.getLocation())) {
          // smother out the fire that didn't burn out when you respawned
          // Stop fire (upcast, watch out!)
          if (player instanceof CraftPlayer) {
            net.minecraft.server.Entity playerEntity = ((CraftPlayer) player).getHandle();
            playerEntity.fireTicks = 0;
          }
          event.setCancelled(true);
        }
      }

    } else if (event.getCause() == DamageCause.DROWNING) {
      Entity entity = event.getEntity();
      if (entity instanceof Player) {
        Player player = (Player) entity;
        Team team = war.getPlayerTeam(player.getName());
        if (team != null && player.getHealth() <= 0) {
          // don't keep killing drowing player: trying to stop "Player moved wrongly!" error at
          // respawn.
          event.setCancelled(true);
        }
      }
    }
  }
Esempio n. 2
0
  public static void main(String[] args) {

    int selection = 1;

    switch (selection) {
      case 1:
        War warGame = new War();
        warGame.playWarGame();
        break;
      case 2:
        BlackJack blackJack = new BlackJack();
        blackJack.playBlackJack();
        break;
    }
  }
Esempio n. 3
0
 public void onEntityDeath(EntityDeathEvent event) {
   Entity e = event.getEntity();
   if (e instanceof Player) {
     Player player = (Player) e;
     Team team = war.getPlayerTeam(player.getName());
     if (team != null) {
       Warzone zone = war.getPlayerTeamWarzone(player.getName());
       zone.handleDeath(player);
       //				if(zone.isDropLootOnDeath()) {
       //					war.getServer().getScheduler().scheduleAsyncDelayedTask(war,
       //							new LootDropperTask(player.getLocation(), event.getDrops()),
       //							750);
       //				}
       event.getDrops().clear(); // no loot
     }
   }
 }
Esempio n. 4
0
 public void onCreatureSpawn(CreatureSpawnEvent event) {
   Location location = event.getLocation();
   Warzone zone = war.warzone(location);
   if (zone != null && zone.isNoCreatures()) {
     event.setCancelled(true);
     // war.logInfo("Prevented " + event.getMobType().getName() + " from spawning in zone " +
     // zone.getName());
   }
 }
Esempio n. 5
0
 public void onEntityCombust(EntityCombustEvent event) {
   Entity entity = event.getEntity();
   if (entity instanceof Player) {
     Player player = (Player) entity;
     Team team = war.getPlayerTeam(player.getName());
     if (team != null && team.getSpawnVolume().contains(player.getLocation())) {
       // smother out the fire that didn't burn out when you respawned
       // Stop fire (upcast, watch out!)
       if (player instanceof CraftPlayer) {
         net.minecraft.server.Entity playerEntity = ((CraftPlayer) player).getHandle();
         playerEntity.fireTicks = 0;
       }
       event.setCancelled(true);
     }
   }
 }
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled()) {
      return;
    }

    if (!War.isWarTime()) {
      return;
    }

    coord.setFromLocation(event.getBlock().getLocation());
    CultureChunk cc = CivGlobal.getCultureChunk(coord);

    if (cc == null) {
      return;
    }

    if (!cc.getCiv().getDiplomacyManager().isAtWar()) {
      return;
    }

    if (event.getBlock().getType().equals(Material.DIRT)
        || event.getBlock().getType().equals(Material.GRASS)
        || event.getBlock().getType().equals(Material.SAND)
        || event.getBlock().getType().equals(Material.GRAVEL)
        || event.getBlock().getType().equals(Material.TORCH)
        || event.getBlock().getType().equals(Material.REDSTONE_TORCH_OFF)
        || event.getBlock().getType().equals(Material.REDSTONE_TORCH_ON)
        || event.getBlock().getType().equals(Material.REDSTONE)
        || event.getBlock().getType().equals(Material.TNT)
        || event.getBlock().getType().equals(Material.LADDER)
        || event.getBlock().getType().equals(Material.VINE)
        || event.getBlock().getType().equals(Material.IRON_BLOCK)
        || event.getBlock().getType().equals(Material.GOLD_BLOCK)
        || event.getBlock().getType().equals(Material.DIAMOND_BLOCK)
        || event.getBlock().getType().equals(Material.EMERALD_BLOCK)
        || !event.getBlock().getType().isSolid()) {
      return;
    }

    CivMessage.sendError(event.getPlayer(), CivSettings.localize.localizedString("war_mustUseTNT"));
    event.setCancelled(true);
  }
Esempio n. 7
0
 public void onEntityExplode(EntityExplodeEvent event) {
   // protect zones elements, lobbies and warhub from creepers
   List<Block> explodedBlocks = event.blockList();
   for (Block block : explodedBlocks) {
     if (war.getWarHub() != null && war.getWarHub().getVolume().contains(block)) {
       event.setCancelled(true);
       war.logInfo("Explosion prevented at warhub.");
       return;
     }
     for (Warzone zone : war.getWarzones()) {
       if (zone.isImportantBlock(block)) {
         event.setCancelled(true);
         war.logInfo("Explosion prevented in zone " + zone.getName() + ".");
         return;
       } else if (zone.getLobby() != null && zone.getLobby().getVolume().contains(block)) {
         event.setCancelled(true);
         war.logInfo("Explosion prevented at zone " + zone.getName() + " lobby.");
         return;
       }
     }
   }
 }
Esempio n. 8
0
  private void handlerAttackDefend(EntityDamageByEntityEvent event) {
    Entity attacker = event.getDamager();
    Entity defender = event.getEntity();

    if (attacker != null
        && defender != null
        && attacker instanceof Player
        && defender instanceof Player) {
      // only let adversaries (same warzone, different team) attack each other
      Player a = (Player) attacker;
      Player d = (Player) defender;
      Warzone attackerWarzone = war.getPlayerTeamWarzone(a.getName());
      Team attackerTeam = war.getPlayerTeam(a.getName());
      Warzone defenderWarzone = war.getPlayerTeamWarzone(d.getName());
      Team defenderTeam = war.getPlayerTeam(d.getName());
      if (attackerTeam != null
          && defenderTeam != null
          && attackerTeam != defenderTeam
          && attackerWarzone == defenderWarzone) {
        // Make sure one of the players isn't in the spawn
        //				if(!){
        //				// A real attack: handle death scenario. ==> now handled in entity damage as well
        //				//synchronized(d) {
        ////					if(d.getHealth() <= 0) {
        //////						// Player died, loot him!
        //////						PlayerInventory attackerInv = a.getInventory();
        //////						PlayerInventory defenderInv = d.getInventory();
        //////						HashMap<Integer, ItemStack> noMorePlace = new HashMap<Integer, ItemStack>();
        //////						for(ItemStack stack : defenderInv.getContents()) {
        //////							HashMap<Integer, ItemStack> newNoMorePlace = attackerInv.addItem(stack);
        //////							noMorePlace.putAll(newNoMorePlace);
        //////						}
        //////
        //////						// attacker inventory is full, drop the rest.
        //////						if(!noMorePlace.isEmpty()) {
        //////							for(Integer key : noMorePlace.keySet()) {
        //////								ItemStack toDrop = noMorePlace.get(key);
        //////								defender.getWorld().dropItem(defender.getLocation(), toDrop);
        //////							}
        //////						}
        ////
        ////						handleDeath(d, defenderWarzone, defenderTeam);
        ////						event.setCancelled(true);
        //					//}
        //				}
        if (defenderTeam.getSpawnVolume().contains(d.getLocation())) { // attacking person in spawn
          war.badMsg(a, "Can't attack a player that's inside his team's spawn.");
          event.setCancelled(true);
        } else if (attackerTeam.getSpawnVolume().contains(a.getLocation())
            && !attackerTeam.getSpawnVolume().contains(d.getLocation())) {
          // only let a player inside spawn attack an enemy player if that player enters the spawn
          war.badMsg(a, "Can't attack a player from inside your spawn.");
          event.setCancelled(true);
        }
        // }
      } else if (attackerTeam != null
          && defenderTeam != null
          && attackerTeam == defenderTeam
          && attackerWarzone == defenderWarzone
          && attacker.getEntityId() != defender.getEntityId()) {
        // same team, but not same person
        if (attackerWarzone.getFriendlyFire()) {
          war.badMsg(
              a,
              "Friendly fire is on! Please, don't hurt your teammates."); // if ff is on, let the
                                                                          // attack go through
        } else {
          war.badMsg(a, "Your attack missed! Your target is on your team.");
          event.setCancelled(true); // ff is off
        }
      } else if (attackerTeam == null && defenderTeam == null && !war.isPvpInZonesOnly()) {
        // let normal PVP through is its not turned off
      } else if (attackerTeam == null && defenderTeam == null && war.isPvpInZonesOnly()) {
        war.badMsg(
            a,
            "Your attack missed! Global PVP is turned off. You can only attack other players in warzones. Try /warhub, /zones and /zone.");
        event.setCancelled(true); // global pvp is off
      } else {
        war.badMsg(a, "Your attack missed!");
        if (attackerTeam == null) {
          war.badMsg(
              a,
              "You must join a team "
                  + ", then you'll be able to damage people "
                  + "in the other teams in that warzone.");
        } else if (defenderTeam == null) {
          war.badMsg(a, "Your target is not in a team.");
        } else if (attackerTeam == defenderTeam) {
          war.badMsg(a, "Your target is on your team.");
        } else if (attackerWarzone != defenderWarzone) {
          war.badMsg(a, "Your target is playing in another warzone.");
        }
        event.setCancelled(true); // can't attack someone inside a warzone if you're not in a team
      }

      //			if(event.isCancelled() && event instanceof EntityDamageByProjectileEvent) {
      //				//((EntityDamageByProjectileEvent)event).setBounce(true);
      //			}
    }
  }
  @SuppressWarnings("deprecation")
  @EventHandler(priority = EventPriority.HIGH)
  public void onBlockPlace(BlockPlaceEvent event) {
    if (event.isCancelled()) {
      return;
    }

    if (!War.isWarTime()) {
      return;
    }

    coord.setFromLocation(event.getBlock().getLocation());
    CultureChunk cc = CivGlobal.getCultureChunk(coord);

    if (cc == null) {
      return;
    }

    if (!cc.getCiv().getDiplomacyManager().isAtWar()) {
      return;
    }

    if (event.getBlock().getType().equals(Material.DIRT)
        || event.getBlock().getType().equals(Material.GRASS)
        || event.getBlock().getType().equals(Material.SAND)
        || event.getBlock().getType().equals(Material.GRAVEL)
        || event.getBlock().getType().equals(Material.TORCH)
        || event.getBlock().getType().equals(Material.REDSTONE_TORCH_OFF)
        || event.getBlock().getType().equals(Material.REDSTONE_TORCH_ON)
        || event.getBlock().getType().equals(Material.REDSTONE)
        || event.getBlock().getType().equals(Material.LADDER)
        || event.getBlock().getType().equals(Material.VINE)
        || event.getBlock().getType().equals(Material.TNT)) {

      if (event.getBlock().getLocation().subtract(0, 1, 0).getBlock().getType() != Material.AIR) {
        return;
      }

      event
          .getBlock()
          .getWorld()
          .spawnFallingBlock(event.getBlock().getLocation(), event.getBlock().getType(), (byte) 0);
      event.getBlock().setType(Material.AIR);

      return;
    }

    if (event.getBlock().getType().equals(Material.IRON_BLOCK)
        || event.getBlock().getType().equals(Material.GOLD_BLOCK)
        || event.getBlock().getType().equals(Material.DIAMOND_BLOCK)
        || event.getBlock().getType().equals(Material.EMERALD_BLOCK)) {

      if (event.getBlock().getLocation().subtract(0, 1, 0).getBlock().getType() != Material.AIR) {
        return;
      }

      return;
    }

    CivMessage.sendError(
        event.getPlayer(), CivSettings.localize.localizedString("war_onlyBuildCertainBlocks"));
    CivMessage.sendError(
        event.getPlayer(), CivSettings.localize.localizedString("war_canAlsoPlaceBridgeBlocks"));
    event.setCancelled(true);
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void onEntityExplode(EntityExplodeEvent event) {

    if (War.isWarTime()) {
      event.setCancelled(false);
    } else {
      event.setCancelled(true);
      return;
    }

    if (event.isCancelled()) {
      return;
    }

    if (event.getEntity() == null) {
      return;
    }

    if (event.getEntityType().equals(EntityType.UNKNOWN)) {
      return;
    }

    if (event.getEntityType().equals(EntityType.PRIMED_TNT)
        || event.getEntityType().equals(EntityType.MINECART_TNT)) {

      HashSet<Buildable> structuresHit = new HashSet<Buildable>();

      for (int y = -yield; y <= yield; y++) {
        for (int x = -yield; x <= yield; x++) {
          for (int z = -yield; z <= yield; z++) {
            Location loc = event.getLocation().clone().add(new Vector(x, y, z));
            Block b = loc.getBlock();
            if (loc.distance(event.getLocation()) < yield) {

              BlockCoord bcoord = new BlockCoord();
              bcoord.setFromLocation(loc);
              //							StructureBlock sb = CivGlobal.getStructureBlock(bcoord);
              //							if (sb == null) {
              //							WarRegen.saveBlock(loc.getBlock(), Cannon.RESTORE_NAME, false);
              //							}
              //							if (sb.getTown() != null) {
              //							WarRegen.destroyThisBlock(loc.getBlock(), sb.getTown());
              //							} else {
              //							ItemManager.setTypeIdAndData(loc.getBlock(), CivData.AIR, 0, false);
              //							}

              StructureBlock sb = CivGlobal.getStructureBlock(bcoord);
              CampBlock cb = CivGlobal.getCampBlock(bcoord);

              if (sb == null && cb == null) {
                explodeBlock(b);
                continue;
              }

              if (sb != null) {

                if (!sb.isDamageable()) {
                  continue;
                }

                if (sb.getOwner() instanceof TownHall) {
                  TownHall th = (TownHall) sb.getOwner();
                  if (th.getControlPoints().containsKey(bcoord)) {
                    continue;
                  }
                }

                if (!sb.getOwner().isDestroyed()) {
                  if (!structuresHit.contains(sb.getOwner())) {

                    structuresHit.add(sb.getOwner());

                    if (sb.getOwner() instanceof TownHall) {
                      TownHall th = (TownHall) sb.getOwner();

                      if (th.getHitpoints() == 0) {
                        explodeBlock(b);
                      } else {
                        th.onTNTDamage(structureDamage);
                      }
                    } else {
                      sb.getOwner()
                          .onDamage(structureDamage, b.getWorld(), null, sb.getCoord(), sb);
                      CivMessage.sendCiv(
                          sb.getCiv(),
                          CivColor.Yellow
                              + CivSettings.localize.localizedString(
                                  "var_war_tntMsg",
                                  sb.getOwner().getDisplayName(),
                                  (sb.getOwner().getCenterLocation().getX()
                                      + ","
                                      + sb.getOwner().getCenterLocation().getY()
                                      + ","
                                      + sb.getOwner().getCenterLocation().getZ()
                                      + ")"),
                                  (sb.getOwner().getHitpoints()
                                      + "/"
                                      + sb.getOwner().getMaxHitPoints())));
                    }
                  }
                } else {
                  explodeBlock(b);
                }
                continue;
              }
            }
          }
        }
      }
      event.setCancelled(true);
    }
  }