Skip to content

Commit

Permalink
fire/lava near players config can be changed in non-PvP worlds (#371)
Browse files Browse the repository at this point in the history
Also allows this feature to be disabled in worlds where PvP rules aren't applied.
  • Loading branch information
Kittencore2608 authored and RoboMWM committed Sep 15, 2018
1 parent a764eea commit 393aa27
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand Down Expand Up @@ -182,6 +183,14 @@ public void onBlocksPlace(BlockMultiPlaceEvent placeEvent)
}
}

private boolean doesAllowFireProximityInWorld(World world) {
if (GriefPrevention.instance.pvpRulesApply(world)) {
return GriefPrevention.instance.config_pvp_allowFireNearPlayers;
} else {
return GriefPrevention.instance.config_pvp_allowFireNearPlayers_NonPvp;
}
}

//when a player places a block...
@SuppressWarnings("null")
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
Expand All @@ -193,7 +202,7 @@ public void onBlockPlace(BlockPlaceEvent placeEvent)
//FEATURE: limit fire placement, to prevent PvP-by-fire

//if placed block is fire and pvp is off, apply rules for proximity to other players
if(block.getType() == Material.FIRE && (!GriefPrevention.instance.pvpRulesApply(block.getWorld()) || !GriefPrevention.instance.config_pvp_allowFireNearPlayers))
if(block.getType() == Material.FIRE && !doesAllowFireProximityInWorld(block.getWorld()))
{
List<Player> players = block.getWorld().getPlayers();
for(int i = 0; i < players.size(); i++)
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ public class GriefPrevention extends JavaPlugin
public boolean config_pvp_noCombatInAdminLandClaims; //whether players may fight in admin-owned land claims
public boolean config_pvp_noCombatInAdminSubdivisions; //whether players may fight in subdivisions of admin-owned land claims
public boolean config_pvp_allowLavaNearPlayers; //whether players may dump lava near other players in pvp worlds
public boolean config_pvp_allowLavaNearPlayers_NonPvp; //whather this applies in non-PVP rules worlds <ArchdukeLiamus>
public boolean config_pvp_allowFireNearPlayers; //whether players may start flint/steel fires near other players in pvp worlds
public boolean config_pvp_protectPets; //whether players may damage pets outside of land claims in pvp worlds
public boolean config_pvp_allowFireNearPlayers_NonPvp; //whether this applies in non-PVP rules worlds <ArchdukeLiamus>
public boolean config_pvp_protectPets; //whether players may damage pets outside of land claims in pvp worlds

public boolean config_lockDeathDropsInPvpWorlds; //whether players' dropped on death items are protected in pvp worlds
public boolean config_lockDeathDropsInNonPvpWorlds; //whether players' dropped on death items are protected in non-pvp worlds
Expand Down Expand Up @@ -435,6 +437,11 @@ private void loadConfig()
}
}

//get (deprecated) pvp fire placement proximity note and use it if it exists (in the new config format it will be overwritten later).
config_pvp_allowFireNearPlayers = config.getBoolean("GriefPrevention.PvP.AllowFlintAndSteelNearOtherPlayers",false);
//get (deprecated) pvp lava dump proximity note and use it if it exists (in the new config format it will be overwritten later).
config_pvp_allowLavaNearPlayers = config.getBoolean("GriefPrevention.PvP.AllowLavaDumpingNearOtherPlayers",false);

//decide claim mode for each world
this.config_claims_worldModes = new ConcurrentHashMap<World, ClaimsMode>();
this.config_creativeWorldsExist = false;
Expand Down Expand Up @@ -744,8 +751,10 @@ else if(world.getEnvironment() == Environment.NORMAL)
this.config_pvp_noCombatInPlayerLandClaims = config.getBoolean("GriefPrevention.PvP.ProtectPlayersInLandClaims.PlayerOwnedClaims", this.config_siege_enabledWorlds.size() == 0);
this.config_pvp_noCombatInAdminLandClaims = config.getBoolean("GriefPrevention.PvP.ProtectPlayersInLandClaims.AdministrativeClaims", this.config_siege_enabledWorlds.size() == 0);
this.config_pvp_noCombatInAdminSubdivisions = config.getBoolean("GriefPrevention.PvP.ProtectPlayersInLandClaims.AdministrativeSubdivisions", this.config_siege_enabledWorlds.size() == 0);
this.config_pvp_allowLavaNearPlayers = config.getBoolean("GriefPrevention.PvP.AllowLavaDumpingNearOtherPlayers", true);
this.config_pvp_allowFireNearPlayers = config.getBoolean("GriefPrevention.PvP.AllowFlintAndSteelNearOtherPlayers", true);
this.config_pvp_allowLavaNearPlayers = config.getBoolean("GriefPrevention.PvP.AllowLavaDumpingNearOtherPlayers.PvPWorlds", true);
this.config_pvp_allowLavaNearPlayers_NonPvp = config.getBoolean("GriefPrevention.PvP.AllowLavaDumpingNearOtherPlayers.NonPvPWorlds", false);
this.config_pvp_allowFireNearPlayers = config.getBoolean("GriefPrevention.PvP.AllowFlintAndSteelNearOtherPlayers.PvPWorlds", true);
this.config_pvp_allowFireNearPlayers_NonPvp = config.getBoolean("GriefPrevention.PvP.AllowFlintAndSteelNearOtherPlayers.NonPvPWorlds", false);
this.config_pvp_protectPets = config.getBoolean("GriefPrevention.PvP.ProtectPetsOutsideLandClaims", false);

//optional database settings
Expand Down Expand Up @@ -845,8 +854,10 @@ else if(world.getEnvironment() == Environment.NORMAL)
outConfig.set("GriefPrevention.PvP.ProtectPlayersInLandClaims.PlayerOwnedClaims", this.config_pvp_noCombatInPlayerLandClaims);
outConfig.set("GriefPrevention.PvP.ProtectPlayersInLandClaims.AdministrativeClaims", this.config_pvp_noCombatInAdminLandClaims);
outConfig.set("GriefPrevention.PvP.ProtectPlayersInLandClaims.AdministrativeSubdivisions", this.config_pvp_noCombatInAdminSubdivisions);
outConfig.set("GriefPrevention.PvP.AllowLavaDumpingNearOtherPlayers", this.config_pvp_allowLavaNearPlayers);
outConfig.set("GriefPrevention.PvP.AllowFlintAndSteelNearOtherPlayers", this.config_pvp_allowFireNearPlayers);
outConfig.set("GriefPrevention.PvP.AllowLavaDumpingNearOtherPlayers.PvPWorlds", this.config_pvp_allowLavaNearPlayers);
outConfig.set("GriefPrevention.PvP.AllowLavaDumpingNearOtherPlayers.NonPvPWorlds", this.config_pvp_allowLavaNearPlayers_NonPvp);
outConfig.set("GriefPrevention.PvP.AllowFlintAndSteelNearOtherPlayers.PvPWorlds", this.config_pvp_allowFireNearPlayers);
outConfig.set("GriefPrevention.PvP.AllowFlintAndSteelNearOtherPlayers.NonPvPWorlds", this.config_pvp_allowFireNearPlayers_NonPvp);
outConfig.set("GriefPrevention.PvP.ProtectPetsOutsideLandClaims", this.config_pvp_protectPets);

outConfig.set("GriefPrevention.Economy.ClaimBlocksPurchaseCost", this.config_economy_claimBlocksPurchaseCost);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.bukkit.OfflinePlayer;
import org.bukkit.Tag;
import org.bukkit.TravelAgent;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand Down Expand Up @@ -1487,7 +1488,7 @@ else if(instance.creativeRulesApply(block.getLocation()))
}

//lava buckets can't be dumped near other players unless pvp is on
if((!instance.pvpRulesApply(block.getWorld()) || !instance.config_pvp_allowLavaNearPlayers) && !player.hasPermission("griefprevention.lava"))
if(!doesAllowLavaProximityInWorld(block.getWorld()) && !player.hasPermission("griefprevention.lava"))
{
if(bucketEvent.getBucket() == Material.LAVA_BUCKET)
{
Expand Down Expand Up @@ -1535,6 +1536,14 @@ else if(instance.creativeRulesApply(block.getLocation()))
}
}

private boolean doesAllowLavaProximityInWorld(World world) {
if (GriefPrevention.instance.pvpRulesApply(world)) {
return GriefPrevention.instance.config_pvp_allowLavaNearPlayers;
} else {
return GriefPrevention.instance.config_pvp_allowLavaNearPlayers_NonPvp;
}
}

//see above
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerBucketFill (PlayerBucketFillEvent bucketEvent)
Expand Down

0 comments on commit 393aa27

Please sign in to comment.