public void setgov_cmd() throws CivException { Civilization civ = getNamedCiv(1); if (args.length < 3) { throw new CivException(CivSettings.localize.localizedString("adcmd_civ_setgovPrompt")); } ConfigGovernment gov = CivSettings.governments.get(args[2]); if (gov == null) { throw new CivException( CivSettings.localize.localizedString("adcmd_civ_setGovInvalidGov") + " gov_monarchy, gov_depostism... etc"); } // Remove any anarchy timers String key = "changegov_" + civ.getId(); CivGlobal.getSessionDB().delete_all(key); civ.setGovernment(gov.id); CivMessage.global( CivSettings.localize.localizedString( "var_adcmd_civ_setGovSuccessBroadcast", civ.getName(), CivSettings.governments.get(gov.id).displayName)); CivMessage.sendSuccess(sender, CivSettings.localize.localizedString("adcmd_civ_setGovSuccess")); }
public void bankrupt_cmd() throws CivException { Civilization civ = getNamedCiv(1); if (args.length < 3) { CivMessage.send( sender, CivColor.Yellow + ChatColor.BOLD + CivSettings.localize.localizedString("adcmd_civ_bankruptConfirmPrompt")); CivMessage.send(sender, CivSettings.localize.localizedString("adcmd_civ_bankruptConfirmCmd")); } civ.getTreasury().setBalance(0); for (Town town : civ.getTowns()) { town.getTreasury().setBalance(0); town.save(); for (Resident resident : town.getResidents()) { resident.getTreasury().setBalance(0); resident.save(); } } civ.save(); CivMessage.sendSuccess( sender, CivSettings.localize.localizedString("var_adcmd_civ_bankruptSuccess", civ.getName())); }
@Override public void respond(String message, Resident resident) { Player player; try { player = CivGlobal.getPlayer(resident); } catch (CivException e) { return; } resident.clearInteractiveMode(); if (!message.equalsIgnoreCase("yes")) { CivMessage.sendError(player, "Mission Aborted."); return; } if (!TaskMaster.hasTask("missiondelay:" + playerName)) { TaskMaster.asyncTask( "missiondelay:" + playerName, (new EspionageMissionTask(mission, playerName, playerLocation, target, mission.length)), 0); } else { CivMessage.sendError(player, "Waiting on countdown to start mission."); return; } }
private void showPermCmdHelp() { CivMessage.send( sender, CivColor.LightGray + CivSettings.localize.localizedString("cmd_plot_perm_help1")); CivMessage.send( sender, CivColor.LightGray + " " + CivSettings.localize.localizedString("cmd_plot_perm_help2")); CivMessage.send( sender, CivColor.LightGray + " " + CivSettings.localize.localizedString("cmd_plot_perm_help3")); }
public void start(Town town) { this.town = town; /* Show message to town */ CivMessage.sendTownHeading(town, "Event: " + this.configRandomEvent.name); for (String str : this.configRandomEvent.message) { CivMessage.sendTown(town, str); savedMessages.add(str); } town.setActiveEvent(this); this.start(); }
public void disband_cmd() throws CivException { Civilization civ = getNamedCiv(1); CivMessage.sendCiv(civ, CivSettings.localize.localizedString("adcmd_civ_disbandAlert")); try { civ.delete(); } catch (SQLException e) { e.printStackTrace(); } CivMessage.sendSuccess( sender, CivSettings.localize.localizedString("adcmd_civ_disbandSuccess")); }
public void onCannonDamage(int damage, CannonProjectile projectile) throws CivException { this.hitpoints -= damage; Resident resident = projectile.whoFired; if (hitpoints <= 0) { for (BlockCoord coord : this.controlPoints.keySet()) { ControlPoint cp = this.controlPoints.get(coord); if (cp != null) { if (cp.getHitpoints() > CannonProjectile.controlBlockHP) { cp.damage(cp.getHitpoints() - 1); this.hitpoints = this.getMaxHitPoints() / 2; StructureBlock hit = CivGlobal.getStructureBlock(coord); onControlBlockCannonDestroy(cp, CivGlobal.getPlayer(resident), hit); CivMessage.sendCiv( getCiv(), "Our " + this.getDisplayName() + " has been hit by a cannon and a control block was set to " + CannonProjectile.controlBlockHP + " HP!"); CivMessage.sendCiv( getCiv(), "Our " + this.getDisplayName() + " has regenerated " + this.getMaxHitPoints() / 2 + " HP! If it drops to zero, we will lose another Control Point."); return; } } } CivMessage.sendCiv( getCiv(), "Our " + this.getDisplayName() + " is out of hitpoints, walls can be destroyed by cannon and TNT blasts!"); hitpoints = 0; } CivMessage.sendCiv( getCiv(), "Our " + this.getDisplayName() + " has been hit by a cannon! (" + this.hitpoints + "/" + this.getMaxHitPoints() + ")"); }
public void onControlBlockHit(ControlPoint cp, World world, Player player, StructureBlock hit) { world.playSound(hit.getCoord().getLocation(), Sound.ANVIL_USE, 0.2f, 1); world.playEffect(hit.getCoord().getLocation(), Effect.MOBSPAWNER_FLAMES, 0); CivMessage.send( player, CivColor.LightGray + "Damaged Control Block (" + cp.getHitpoints() + " / " + cp.getMaxHitpoints() + ")"); CivMessage.sendTown( hit.getTown(), CivColor.Yellow + "One of our Town Hall's Control Points is under attack!"); }
public void givetech_cmd() throws CivException { Civilization civ = getNamedCiv(1); if (args.length < 3) { throw new CivException(CivSettings.localize.localizedString("adcmd_civ_giveTechPrompt")); } ConfigTech tech = CivSettings.techs.get(args[2]); if (tech == null) { throw new CivException( CivSettings.localize.localizedString("adcmd_civ_giveTechInvalid") + args[2]); } if (civ.hasTechnology(tech.id)) { throw new CivException( CivSettings.localize.localizedString( "var_adcmd_civ_giveTechAlreadyhas", civ.getName(), tech.id)); } civ.addTech(tech); civ.save(); CivMessage.sendSuccess( sender, CivSettings.localize.localizedString( "var_adcmd_civ_giveTechSuccess", tech.name, civ.getName())); }
@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; } }
private static void performPirate(Player player, ConfigMission mission) throws CivException { Resident resident = CivGlobal.getResident(player); if (resident == null || !resident.hasTown()) { throw new CivException("Only residents of towns can perform spy missions."); } // Must be within enemy town borders. ChunkCoord coord = new ChunkCoord(player.getLocation()); CultureChunk cc = CivGlobal.getCultureChunk(coord); if (cc == null || cc.getCiv() == resident.getTown().getCiv()) { throw new CivException("Must be in another civilization's borders."); } // Check that the player is within range of the town hall. Structure tradeoutpost = cc.getCiv().getNearestStructureInTowns(player.getLocation()); if (!(tradeoutpost instanceof TradeOutpost)) { throw new CivException("The closest structure to you must be a trade outpost."); } double distance = player .getLocation() .distance(((TradeOutpost) tradeoutpost).getTradeOutpostTower().getLocation()); if (distance > mission.range) { throw new CivException("Too far away from the trade outpost to pirate it."); } TradeOutpost outpost = (TradeOutpost) tradeoutpost; ItemStack stack = outpost.getItemFrameStore().getItem(); if (stack == null || ItemManager.getId(stack) == CivData.AIR) { throw new CivException("No trade goodie item at this location."); } if (processMissionResult(player, cc.getTown(), mission)) { outpost.getItemFrameStore().clearItem(); player.getWorld().dropItem(player.getLocation(), stack); CivMessage.sendSuccess(player, "Arg! Got the booty!"); CivMessage.sendTown( cc.getTown(), CivColor.Rose + "Avast! Someone stole our trade goodie " + outpost.getGood().getInfo().name + " at " + outpost.getCorner()); } }
private static void performStealTreasury(Player player, ConfigMission mission) throws CivException { Resident resident = CivGlobal.getResident(player); if (resident == null || !resident.hasTown()) { throw new CivException("Only residents of towns can perform spy missions."); } // Must be within enemy town borders. ChunkCoord coord = new ChunkCoord(player.getLocation()); TownChunk tc = CivGlobal.getTownChunk(coord); if (tc == null || tc.getTown().getCiv() == resident.getTown().getCiv()) { throw new CivException("Must be in another civilization's town's borders."); } // Check that the player is within range of the town hall. TownHall townhall = tc.getTown().getTownHall(); if (townhall == null) { throw new CivException("This town doesnt have a town hall... that sucks."); } double distance = player.getLocation().distance(townhall.getCorner().getLocation()); if (distance > mission.range) { throw new CivException("Too far away from town hall to steal treasury."); } double failMod = 1.0; if (resident.getTown().getBuffManager().hasBuff("buff_dirty_money")) { failMod = resident.getTown().getBuffManager().getEffectiveDouble("buff_dirty_money"); CivMessage.send( player, CivColor.LightGray + "Your goodie buff 'Dirty Money' will come in handy here."); } if (processMissionResult(player, tc.getTown(), mission, failMod, 1.0)) { double amount = (int) (tc.getTown().getTreasury().getBalance() * 0.2); if (amount > 0) { tc.getTown().getTreasury().withdraw(amount); resident.getTown().getTreasury().deposit(amount); } CivMessage.sendSuccess( player, "Success! Stole " + amount + " coins from " + tc.getTown().getName()); } }
public void rmleader_cmd() throws CivException { Civilization civ = getNamedCiv(1); Resident resident = getNamedResident(2); if (civ.getLeaderGroup().hasMember(resident)) { civ.getLeaderGroup().removeMember(resident); civ.save(); CivMessage.sendSuccess( sender, CivSettings.localize.localizedString( "var_adcmd_civ_rmLeaderSuccess", resident.getName(), civ.getName())); } else { CivMessage.sendError( sender, CivSettings.localize.localizedString( "var_adcmd_civ_rmLeaderNotInGroup", resident.getName(), civ.getName())); } }
public void setvotes_cmd() throws CivException { Civilization civ = getNamedCiv(1); Integer votes = getNamedInteger(2); EndConditionDiplomacy.setVotes(civ, votes); CivMessage.sendSuccess( sender, CivSettings.localize.localizedString( "var_adcmd_civ_setVotesSuccess", civ.getName(), votes)); }
public void toggleadminciv_cmd() throws CivException { Civilization civ = getNamedCiv(1); civ.setAdminCiv(!civ.isAdminCiv()); civ.save(); CivMessage.sendSuccess( sender, CivSettings.localize.localizedString( "var_adcmd_civ_toggleAdminCivSuccess", civ.getName(), civ.isAdminCiv())); }
public void conquered_cmd() throws CivException { Civilization civ = getNamedCiv(1); civ.setConquered(true); CivGlobal.removeCiv(civ); CivGlobal.addConqueredCiv(civ); civ.save(); CivMessage.sendSuccess( sender, CivSettings.localize.localizedString("adcmd_civ_conqueredSuccess")); }
@Override public void onDamage( int amount, World world, Player player, BlockCoord coord, BuildableDamageBlock hit) { ControlPoint cp = this.controlPoints.get(coord); Resident resident = CivGlobal.getResident(player); if (!resident.canDamageControlBlock()) { CivMessage.send( player, CivColor.Rose + "Cannot damage control blocks due to missing/invalid Town Hall or Capitol structure."); return; } if (cp != null) { if (!cp.isDestroyed()) { if (resident.isControlBlockInstantBreak()) { cp.damage(cp.getHitpoints()); } else { cp.damage(amount); } if (cp.isDestroyed()) { onControlBlockDestroy(cp, world, player, (StructureBlock) hit); } else { onControlBlockHit(cp, world, player, (StructureBlock) hit); } } else { CivMessage.send(player, CivColor.Rose + "Control Block already destroyed."); } } else { CivMessage.send( player, CivColor.Rose + "Cannot Damage " + this.getDisplayName() + ", go after the control points!"); } }
public void beakerrate_cmd() throws CivException { Civilization civ = getNamedCiv(1); Double amount = getNamedDouble(2); civ.setBaseBeakers(amount); civ.save(); CivMessage.sendSuccess( sender, CivSettings.localize.localizedString( "var_adcmd_civ_beakerRateSuccess", civ.getName(), amount)); }
public void merge_cmd() throws CivException { Civilization oldciv = getNamedCiv(1); Civilization newciv = getNamedCiv(2); if (oldciv == newciv) { throw new CivException(CivSettings.localize.localizedString("adcmd_civ_mergeSameError")); } newciv.mergeInCiv(oldciv); CivMessage.global( CivSettings.localize.localizedString( "var_adcmd_civ_mergeSuccess", oldciv.getName(), newciv.getName())); }
public void alltech_cmd() throws CivException { Civilization civ = getNamedCiv(1); for (ConfigTech tech : CivSettings.techs.values()) { civ.addTech(tech); } civ.save(); CivMessage.sendSuccess( sender, CivSettings.localize.localizedString("adcmd_civ_alltechSuccess")); }
public void addleader_cmd() throws CivException { Civilization civ = getNamedCiv(1); Resident resident = getNamedResident(2); civ.getLeaderGroup().addMember(resident); civ.getLeaderGroup().save(); civ.save(); CivMessage.sendSuccess( sender, CivSettings.localize.localizedString( "var_adcmd_civ_addLeaderSuccess", resident.getName(), civ.getName())); }
public void onTNTDamage(int damage) { if (hitpoints >= damage + 1) { this.hitpoints -= damage; CivMessage.sendCiv( getCiv(), "Our " + this.getDisplayName() + " has been hit by TNT! (" + this.hitpoints + "/" + this.getMaxHitPoints() + ")"); } }
public void rename_cmd() throws CivException, InvalidNameException { Civilization civ = getNamedCiv(1); String name = getNamedString(2, CivSettings.localize.localizedString("adcmd_civ_newNamePrompt")); if (args.length < 3) { throw new CivException( CivSettings.localize.localizedString("adcmd_civ_renameUseUnderscores")); } civ.rename(name); CivMessage.sendSuccess( sender, CivSettings.localize.localizedString("adcmd_civ_renameCivSuccess")); }
@Override public void run() { Player player; try { player = CivGlobal.getPlayer(playerName); } catch (CivException e) { return; } Resident resident = CivGlobal.getResident(playerName); if (resident == null) { return; } CivMessage.send(player, TownCommand.survey(player.getLocation())); CivMessage.send(player, ""); CivMessage.send( player, CivColor.LightGreen + ChatColor.BOLD + CivSettings.localize.localizedString("interactive_capitol_confirmPrompt")); resident.setInteractiveMode(new InteractiveConfirmCivCreation()); }
@Override public void run() { if (playerName == null) { return; } Player player = Bukkit.getPlayer(playerName); if (dmgBlock.allowDamageNow(player)) { /* Do our damage. */ int damage = 1; LoreMaterial material = LoreMaterial.getMaterial(player.getItemInHand()); if (material != null) { damage = material.onStructureBlockBreak(dmgBlock, damage); } if (player.getItemInHand() != null && !player.getItemInHand().getType().equals(Material.AIR)) { AttributeUtil attrs = new AttributeUtil(player.getItemInHand()); for (LoreEnhancement enhance : attrs.getEnhancements()) { damage = enhance.onStructureBlockBreak(dmgBlock, damage); } } if (damage > 1) { CivMessage.send( player, CivColor.LightGray + "Punchout does " + (damage - 1) + " extra damage!"); } dmgBlock.getOwner().onDamage(damage, world, player, dmgBlock.getCoord(), dmgBlock); } else { CivMessage.sendErrorNoRepeat( player, "This block belongs to a " + dmgBlock.getOwner().getDisplayName() + " and cannot be destroyed right now."); } }
public void markAsUsed(Resident resident) { this.getParent().count--; if (this.getParent().count <= 0) { resident.perks.remove(this.getParent().getIdent()); } try { CivGlobal.perkManager.markAsUsed(resident, this.getParent()); } catch (SQLException e) { e.printStackTrace(); } catch (NotVerifiedException e) { CivMessage.send( resident, CivColor.Rose + CivSettings.localize.localizedString("PerkComponent_notValidated")); e.printStackTrace(); } }
public boolean isAvailable(Town town) { if (CivGlobal.testFileFlag("debug-norequire")) { CivMessage.global("Ignoring requirements! debug-norequire found."); return true; } if (town.hasUpgrade(this.require_upgrade)) { if (town.getCiv().hasTechnology(this.require_tech)) { if (town.hasStructure(require_structure)) { if (!town.hasUpgrade(this.id)) { return true; } } } } return false; }
@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); }
/* * Private for now, since we only allow random events on towns atm. */ private void start() { /* Loop through all components for onStart() */ for (RandomEventComponent comp : this.actions.values()) { comp.onStart(); } for (RandomEventComponent comp : this.requirements.values()) { comp.onStart(); } for (RandomEventComponent comp : this.success.values()) { comp.onStart(); } for (RandomEventComponent comp : this.failure.values()) { comp.onStart(); } /* Start by processing all of the action components. */ boolean requireActivation = false; for (RandomEventComponent comp : this.actions.values()) { if (!comp.requiresActivation()) { comp.process(); } else { requireActivation = true; CivMessage.sendTown( this.town, CivColor.Yellow + "This event requires activation! use '/town event activate' to activate it."); } } if (!requireActivation) { this.active = true; } /* Register this random event with the sweeper until complete. */ RandomEventSweeper.register(this); /* Setup start date. */ this.startDate = new Date(); this.save(); }
@Override public void onInvalidPunish() { int invalid_respawn_penalty; try { invalid_respawn_penalty = CivSettings.getInteger(CivSettings.warConfig, "war.invalid_respawn_penalty"); } catch (InvalidConfiguration e) { e.printStackTrace(); return; } CivMessage.sendTown( this.getTown(), CivColor.Rose + CivColor.BOLD + "Our town's town hall cannot be supported by the blocks underneath!" + " It will take us an extra " + invalid_respawn_penalty + " mins to respawn during war if its not fixed in time!"); }