@Override public void onPreBuild(Location loc) throws CivException { TownHall oldTownHall = this.getTown().getTownHall(); if (oldTownHall != null) { ChunkCoord coord = new ChunkCoord(loc); TownChunk tc = CivGlobal.getTownChunk(coord); if (tc == null || tc.getTown() != this.getTown()) { throw new CivException("Cannot rebuild your town hall outside of your town borders."); } if (War.isWarTime()) { throw new CivException("Cannot rebuild your town hall during war time."); } this.getTown().clearBonusGoods(); try { this.getTown().demolish(oldTownHall, true); } catch (CivException e) { e.printStackTrace(); } CivMessage.sendTown( this.getTown(), "Your old town hall or capitol was demolished to make way for your new one."); this.autoClaim = false; } else { this.autoClaim = true; } }
@Override public void onInteract(PlayerInteractEvent event) { try { if (War.isWarTime()) { throw new CivException("Cannot use spy missions during war time."); } ConfigMission mission = CivSettings.missions.get(this.getId()); if (mission == null) { throw new CivException("Unknown mission " + this.getId()); } Resident resident = CivGlobal.getResident(event.getPlayer()); if (resident == null || !resident.hasTown()) { throw new CivException("Only residents of towns can perform spy missions."); } Date now = new Date(); if (!event.getPlayer().isOp()) { try { int spyRegisterTime = CivSettings.getInteger(CivSettings.espionageConfig, "espionage.spy_register_time"); int spyOnlineTime = CivSettings.getInteger(CivSettings.espionageConfig, "espionage.spy_online_time"); long expire = resident.getRegistered() + (spyRegisterTime * 60 * 1000); if (now.getTime() <= expire) { throw new CivException( "You cannot use a spy yet, you must play CivCraft a bit longer before you can use it."); } expire = resident.getLastOnline() + (spyOnlineTime * 60 * 1000); if (now.getTime() <= expire) { throw new CivException("You must be online longer before you can use a spy."); } } catch (InvalidConfiguration e) { e.printStackTrace(); } } ConfigUnit unit = Unit.getPlayerUnit(event.getPlayer()); if (unit == null || !unit.id.equals("u_spy")) { event.getPlayer().getInventory().remove(event.getItem()); throw new CivException("Only spies can use mission books."); } ChunkCoord coord = new ChunkCoord(event.getPlayer().getLocation()); CultureChunk cc = CivGlobal.getCultureChunk(coord); TownChunk tc = CivGlobal.getTownChunk(coord); if (cc == null || cc.getCiv() == resident.getCiv()) { throw new CivException( "You must be in a civilization's culture that's not your own to spy on them."); } if ((cc != null && cc.getCiv().isAdminCiv()) || (tc != null && tc.getTown().getCiv().isAdminCiv())) { throw new CivException("You cannot spy on an admin civ."); } if (CivGlobal.isCasualMode()) { if (!cc.getCiv().getDiplomacyManager().isHostileWith(resident.getCiv()) && !cc.getCiv().getDiplomacyManager().atWarWith(resident.getCiv())) { throw new CivException( "You must be hostile or at war with " + cc.getCiv().getName() + " in order to perform spy missions in casual mode."); } } resident.setInteractiveMode( new InteractiveSpyMission( mission, event.getPlayer().getName(), event.getPlayer().getLocation(), cc.getTown())); } catch (CivException e) { CivMessage.sendError(event.getPlayer(), e.getMessage()); } }
public void onControlBlockCannonDestroy(ControlPoint cp, Player player, StructureBlock hit) { // Should always have a resident and a town at this point. Resident attacker = CivGlobal.getResident(player); ItemManager.setTypeId(hit.getCoord().getLocation().getBlock(), CivData.AIR); boolean allDestroyed = true; for (ControlPoint c : this.controlPoints.values()) { if (c.isDestroyed() == false) { allDestroyed = false; break; } } CivMessage.sendTownSound(hit.getTown(), Sound.AMBIENCE_CAVE, 1.0f, 0.5f); if (allDestroyed) { if (this.getTown().getCiv().getCapitolName().equals(this.getTown().getName())) { CivMessage.global( CivColor.LightBlue + ChatColor.BOLD + "The civilization of " + this.getTown().getCiv().getName() + " has been conquered by " + attacker.getCiv().getName() + "!"); for (Town town : this.getTown().getCiv().getTowns()) { town.defeated = true; } War.transferDefeated(this.getTown().getCiv(), attacker.getTown().getCiv()); WarStats.logCapturedCiv(attacker.getTown().getCiv(), this.getTown().getCiv()); War.saveDefeatedCiv(this.getCiv(), attacker.getTown().getCiv()); if (CivGlobal.isCasualMode()) { HashMap<Integer, ItemStack> leftovers = player .getInventory() .addItem( this.getCiv() .getRandomLeaderSkull("Victory Over " + this.getCiv().getName() + "!")); for (ItemStack stack : leftovers.values()) { player.getWorld().dropItem(player.getLocation(), stack); } } } else { CivMessage.global( CivColor.Yellow + ChatColor.BOLD + "The town of " + getTown().getName() + " in " + this.getCiv().getName() + " has been conquered by " + attacker.getCiv().getName() + "!"); // this.getTown().onDefeat(attacker.getTown().getCiv()); this.getTown().defeated = true; // War.defeatedTowns.put(this.getTown().getName(), attacker.getTown().getCiv()); WarStats.logCapturedTown(attacker.getTown().getCiv(), this.getTown()); War.saveDefeatedTown(this.getTown().getName(), attacker.getTown().getCiv()); } } else { CivMessage.sendTown( hit.getTown(), CivColor.Rose + "One of our Town Hall's Control Points has been destroyed!"); CivMessage.sendCiv( attacker.getTown().getCiv(), CivColor.LightGreen + "We've destroyed a control block in " + hit.getTown().getName() + "!"); CivMessage.sendCiv( hit.getTown().getCiv(), CivColor.Rose + "A control block in " + hit.getTown().getName() + " has been destroyed!"); } }
public void onControlBlockDestroy( ControlPoint cp, World world, Player player, StructureBlock hit) { // Should always have a resident and a town at this point. Resident attacker = CivGlobal.getResident(player); ItemManager.setTypeId(hit.getCoord().getLocation().getBlock(), CivData.AIR); world.playSound(hit.getCoord().getLocation(), Sound.ANVIL_BREAK, 1.0f, -1.0f); world.playSound(hit.getCoord().getLocation(), Sound.EXPLODE, 1.0f, 1.0f); FireworkEffect effect = FireworkEffect.builder() .with(Type.BURST) .withColor(Color.YELLOW) .withColor(Color.RED) .withTrail() .withFlicker() .build(); FireworkEffectPlayer fePlayer = new FireworkEffectPlayer(); for (int i = 0; i < 3; i++) { try { fePlayer.playFirework(world, hit.getCoord().getLocation(), effect); } catch (Exception e) { e.printStackTrace(); } } boolean allDestroyed = true; for (ControlPoint c : this.controlPoints.values()) { if (c.isDestroyed() == false) { allDestroyed = false; break; } } CivMessage.sendTownSound(hit.getTown(), Sound.AMBIENCE_CAVE, 1.0f, 0.5f); if (allDestroyed) { if (this.getTown().getCiv().getCapitolName().equals(this.getTown().getName())) { CivMessage.global( CivColor.LightBlue + ChatColor.BOLD + "The civilization of " + this.getTown().getCiv().getName() + " has been conquered by " + attacker.getCiv().getName() + "!"); for (Town town : this.getTown().getCiv().getTowns()) { town.defeated = true; } War.transferDefeated(this.getTown().getCiv(), attacker.getTown().getCiv()); WarStats.logCapturedCiv(attacker.getTown().getCiv(), this.getTown().getCiv()); War.saveDefeatedCiv(this.getCiv(), attacker.getTown().getCiv()); if (CivGlobal.isCasualMode()) { HashMap<Integer, ItemStack> leftovers = player .getInventory() .addItem( this.getCiv() .getRandomLeaderSkull("Victory Over " + this.getCiv().getName() + "!")); for (ItemStack stack : leftovers.values()) { player.getWorld().dropItem(player.getLocation(), stack); } } } else { CivMessage.global( CivColor.Yellow + ChatColor.BOLD + "The town of " + getTown().getName() + " in " + this.getCiv().getName() + " has been conquered by " + attacker.getCiv().getName() + "!"); // this.getTown().onDefeat(attacker.getTown().getCiv()); this.getTown().defeated = true; // War.defeatedTowns.put(this.getTown().getName(), attacker.getTown().getCiv()); WarStats.logCapturedTown(attacker.getTown().getCiv(), this.getTown()); War.saveDefeatedTown(this.getTown().getName(), attacker.getTown().getCiv()); } } else { CivMessage.sendTown( hit.getTown(), CivColor.Rose + "One of our Town Hall's Control Points has been destroyed!"); CivMessage.sendCiv( attacker.getTown().getCiv(), CivColor.LightGreen + "We've destroyed a control block in " + hit.getTown().getName() + "!"); CivMessage.sendCiv( hit.getTown().getCiv(), CivColor.Rose + "A control block in " + hit.getTown().getName() + " has been destroyed!"); } }