Skip to content

Commit

Permalink
cannons integration - added new rule to improve gameplay (#485)
Browse files Browse the repository at this point in the history
Authored-by: goosius1 <=>
  • Loading branch information
Goosius1 authored Mar 4, 2022
1 parent 0703d3d commit f8cd9eb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.gmail.goosius.siegewar.utils.SiegeWarDistanceUtil;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.util.BukkitTools;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -42,14 +43,26 @@ public void cannonFireEvent(CannonFireEvent event) {
&& SiegeWarSettings.isWallBreachingCannonsIntegrationEnabled()
&& SiegeWarDistanceUtil.isLocationInActiveSiegeZone(event.getCannon().getLocation())) {

//Ensure a battle session is active
Player gunnerPlayer = BukkitTools.getPlayer(event.getPlayer());
if(!BattleSession.getBattleSession().isActive()) {
Messaging.sendErrorMsg(gunnerPlayer, Translation.of("msg_err_cannot_fire_cannon_without_battle_session"));
event.setCancelled(true);
return; //Cannon fire was cancelled
}

//Ensure cannon is fully in the wilderness OR the besieged town
Siege siege = SiegeController.getSiegeAtLocation(event.getCannon().getLocation());
for(Location cannonBlockLocation: event.getCannon().getCannonDesign().getAllCannonBlocks(event.getCannon())) {
if(!TownyAPI.getInstance().isWilderness(cannonBlockLocation)
&& !TownyAPI.getInstance().getTown(cannonBlockLocation).equals(siege.getTown())) {
Messaging.sendErrorMsg(gunnerPlayer, Translation.of("msg_err_cannon_must_be_in_wilderness_or_besieged_town"));
event.setCancelled(true);
return; //Cannon fire was cancelled
}
}

//Ensure player has perms to fire, and there are enough breach points
if(CannonsIntegration.canPlayerUseBreachPointsByCannon(gunnerPlayer, siege)) {
return; //Player can fire cannon

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/english.yml
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,4 @@ msg.installation.complete: "Installation Complete."

#Added in 0.37
msg_siege_zone_proximity_warning_text: "&cWARNING: You are in a SiegeZone!. If you are not prepared for combat, get to a safe location immediately before you get murdered."
msg_err_cannon_must_be_in_wilderness_or_besieged_town: "&cWithin SiegeZones, cannons can only be fired if they are in the wilderness or the besieged town."
1 change: 1 addition & 0 deletions src/main/resources/french.yml
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,4 @@ msg.installation.complete: "Installation Complete."

#Added in 0.37
msg_siege_zone_proximity_warning_text: "&cWARNING: You are in a SiegeZone!. If you are not prepared for combat, get to a safe location immediately before you get murdered."
msg_err_cannon_must_be_in_wilderness_or_besieged_town: "&cWithin SiegeZones, cannons can only be fired if they are in the wilderness or the besieged town."

0 comments on commit f8cd9eb

Please sign in to comment.