Merge pull request #15 from thomastanck/master

Offline protection (and code cleaning)
This commit is contained in:
Brett Flannigan 2011-06-05 20:02:41 -07:00
commit 58a62977fe
3 changed files with 33 additions and 10 deletions

View File

@ -90,6 +90,8 @@ public class Conf {
public static Set<Material> territoryProtectedMaterials = new HashSet<Material>(); public static Set<Material> territoryProtectedMaterials = new HashSet<Material>();
public static Set<Material> territoryDenyUseageMaterials = new HashSet<Material>(); public static Set<Material> territoryDenyUseageMaterials = new HashSet<Material>();
public static Set<Material> territoryProtectedMaterialsWhenOffline = new HashSet<Material>();
public static Set<Material> territoryDenyUseageMaterialsWhenOffline = new HashSet<Material>();
public static transient Set<CreatureType> safeZoneNerfedCreatureTypes = new HashSet<CreatureType>(); public static transient Set<CreatureType> safeZoneNerfedCreatureTypes = new HashSet<CreatureType>();
@ -112,6 +114,17 @@ public class Conf {
territoryDenyUseageMaterials.add(Material.WATER_BUCKET); territoryDenyUseageMaterials.add(Material.WATER_BUCKET);
territoryDenyUseageMaterials.add(Material.LAVA_BUCKET); territoryDenyUseageMaterials.add(Material.LAVA_BUCKET);
territoryProtectedMaterialsWhenOffline.add(Material.WOODEN_DOOR);
territoryProtectedMaterialsWhenOffline.add(Material.TRAP_DOOR);
territoryProtectedMaterialsWhenOffline.add(Material.DISPENSER);
territoryProtectedMaterialsWhenOffline.add(Material.CHEST);
territoryProtectedMaterialsWhenOffline.add(Material.FURNACE);
territoryDenyUseageMaterialsWhenOffline.add(Material.FLINT_AND_STEEL);
territoryDenyUseageMaterialsWhenOffline.add(Material.BUCKET);
territoryDenyUseageMaterialsWhenOffline.add(Material.WATER_BUCKET);
territoryDenyUseageMaterialsWhenOffline.add(Material.LAVA_BUCKET);
safeZoneNerfedCreatureTypes.add(CreatureType.CREEPER); safeZoneNerfedCreatureTypes.add(CreatureType.CREEPER);
safeZoneNerfedCreatureTypes.add(CreatureType.GHAST); safeZoneNerfedCreatureTypes.add(CreatureType.GHAST);
safeZoneNerfedCreatureTypes.add(CreatureType.PIG_ZOMBIE); safeZoneNerfedCreatureTypes.add(CreatureType.PIG_ZOMBIE);

View File

@ -24,7 +24,6 @@ import org.mcteam.factions.gson.GsonBuilder;
import org.mcteam.factions.listeners.FactionsBlockListener; import org.mcteam.factions.listeners.FactionsBlockListener;
import org.mcteam.factions.listeners.FactionsEntityListener; import org.mcteam.factions.listeners.FactionsEntityListener;
import org.mcteam.factions.listeners.FactionsPlayerListener; import org.mcteam.factions.listeners.FactionsPlayerListener;
import org.mcteam.factions.util.MiscUtil;
import com.nijiko.permissions.PermissionHandler; import com.nijiko.permissions.PermissionHandler;
@ -57,8 +56,6 @@ public class Factions extends JavaPlugin {
private String baseCommand; private String baseCommand;
private static boolean lock = false;
public Factions() { public Factions() {
Factions.instance = this; Factions.instance = this;
} }

View File

@ -202,12 +202,18 @@ public class FactionsPlayerListener extends PlayerListener{
return true; return true;
} }
if ( ! Conf.territoryDenyUseageMaterials.contains(material)) {
return true; // Item isn't one we're preventing.
}
Faction otherFaction = Board.getFactionAt(new FLocation(block)); Faction otherFaction = Board.getFactionAt(new FLocation(block));
if (otherFaction.getOnlinePlayers()!=null){
if ( ! Conf.territoryDenyUseageMaterials.contains(material)) {
return true; // Item isn't one we're preventing for online factions.
}
}else{
if ( ! Conf.territoryDenyUseageMaterialsWhenOffline.contains(material)) {
return true; // Item isn't one we're preventing for offline factions.
}
}
FPlayer me = FPlayer.get(player); FPlayer me = FPlayer.get(player);
if (otherFaction.isNone()) { if (otherFaction.isNone()) {
@ -252,14 +258,21 @@ public class FactionsPlayerListener extends PlayerListener{
Material material = block.getType(); Material material = block.getType();
Faction otherFaction = Board.getFactionAt(new FLocation(block));
// We only care about some material types. // We only care about some material types.
if ( ! Conf.territoryProtectedMaterials.contains(material)) { if (otherFaction.getOnlinePlayers()!=null){
return true; if ( ! Conf.territoryProtectedMaterials.contains(material)) {
return true;
}
} else {
if ( ! Conf.territoryProtectedMaterialsWhenOffline.contains(material)) {
return true;
}
} }
FPlayer me = FPlayer.get(player); FPlayer me = FPlayer.get(player);
Faction myFaction = me.getFaction(); Faction myFaction = me.getFaction();
Faction otherFaction = Board.getFactionAt(new FLocation(block));
// In safe zones you may use any block... // In safe zones you may use any block...
if (otherFaction.isNormal() && myFaction != otherFaction) { if (otherFaction.isNormal() && myFaction != otherFaction) {