Further improve armor stand protection. We must block place an break too, obviously.

This commit is contained in:
Olof Larsson 2014-12-19 11:50:28 +01:00
parent bb1d2e9c54
commit 40bf1af44a
2 changed files with 74 additions and 57 deletions

View File

@ -22,7 +22,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Enderman; import org.bukkit.entity.Enderman;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Wither; import org.bukkit.entity.Wither;
@ -85,7 +84,6 @@ import com.massivecraft.factions.event.EventFactionsPvpDisallowed;
import com.massivecraft.factions.event.EventFactionsPowerChange; import com.massivecraft.factions.event.EventFactionsPowerChange;
import com.massivecraft.factions.event.EventFactionsPowerChange.PowerChangeReason; import com.massivecraft.factions.event.EventFactionsPowerChange.PowerChangeReason;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.spigot.SpigotFeatures;
import com.massivecraft.factions.util.VisualizeUtil; import com.massivecraft.factions.util.VisualizeUtil;
import com.massivecraft.massivecore.EngineAbstract; import com.massivecraft.massivecore.EngineAbstract;
import com.massivecraft.massivecore.PriorityLines; import com.massivecraft.massivecore.PriorityLines;
@ -1312,49 +1310,6 @@ public class EngineMain extends EngineAbstract
return MPerm.getPermBuild().has(mplayer, ps, verboose); return MPerm.getPermBuild().has(mplayer, ps, verboose);
} }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void blockBuild(HangingPlaceEvent event)
{
if (canPlayerBuildAt(event.getPlayer(), PS.valueOf(event.getEntity().getLocation()), true)) return;
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void blockBuild(HangingBreakEvent event)
{
if (! (event instanceof HangingBreakByEntityEvent)) return;
HangingBreakByEntityEvent entityEvent = (HangingBreakByEntityEvent)event;
Entity breaker = entityEvent.getRemover();
if (! (breaker instanceof Player)) return;
if ( ! canPlayerBuildAt(breaker, PS.valueOf(event.getEntity().getLocation()), true))
{
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void itemFrameDamage(EntityDamageByEntityEvent event)
{
// If the damagee is an ItemFrame ...
Entity edamagee = event.getEntity();
if (!(edamagee instanceof ItemFrame)) return;
ItemFrame itemFrame = (ItemFrame)edamagee;
// ... and the liable damager is a player ...
Entity edamager = MUtil.getLiableDamager(event);
if (!(edamager instanceof Player)) return;
Player player = (Player)edamager;
// ... and the player can't build there ...
if (canPlayerBuildAt(player, PS.valueOf(itemFrame.getLocation()), true)) return;
// ... then cancel the event.
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void blockBuild(BlockPlaceEvent event) public void blockBuild(BlockPlaceEvent event)
{ {
@ -1435,10 +1390,53 @@ public class EngineMain extends EngineAbstract
} }
} }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void blockBuild(HangingPlaceEvent event)
{
if (canPlayerBuildAt(event.getPlayer(), PS.valueOf(event.getEntity().getLocation()), true)) return;
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void blockBuild(HangingBreakEvent event)
{
if (! (event instanceof HangingBreakByEntityEvent)) return;
HangingBreakByEntityEvent entityEvent = (HangingBreakByEntityEvent)event;
Entity breaker = entityEvent.getRemover();
if (! (breaker instanceof Player)) return;
if ( ! canPlayerBuildAt(breaker, PS.valueOf(event.getEntity().getLocation()), true))
{
event.setCancelled(true);
}
}
// -------------------------------------------- // // -------------------------------------------- //
// ASSORTED BUILD AND INTERACT // ASSORTED BUILD AND INTERACT
// -------------------------------------------- // // -------------------------------------------- //
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerDamageEntity(EntityDamageByEntityEvent event)
{
// If a player ...
Entity edamager = MUtil.getLiableDamager(event);
if (!(edamager instanceof Player)) return;
Player player = (Player)edamager;
// ... damages an entity which is edited on damage ...
Entity edamagee = event.getEntity();
if (edamagee == null) return;
if ( ! MConf.get().entityTypesEditOnDamage.contains(edamagee.getType())) return;
// ... and the player can't build there ...
if (canPlayerBuildAt(player, PS.valueOf(edamagee.getLocation()), true)) return;
// ... then cancel the event.
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) public void onPlayerInteract(PlayerInteractEvent event)
{ {
@ -1521,6 +1519,8 @@ public class EngineMain extends EngineAbstract
// ... interacts with an entity ... // ... interacts with an entity ...
if (entity == null) return true; if (entity == null) return true;
EntityType type = entity.getType();
PS ps = PS.valueOf(entity.getLocation());
// ... and the player does not bypass all protections ... // ... and the player does not bypass all protections ...
String name = player.getName(); String name = player.getName();
@ -1530,16 +1530,14 @@ public class EngineMain extends EngineAbstract
MPlayer me = MPlayer.get(player); MPlayer me = MPlayer.get(player);
if (me.isUsingAdminMode()) return true; if (me.isUsingAdminMode()) return true;
// ... and the entity is of a container type ... // ... check container entity rights ...
EntityType type = entity.getType(); if (MConf.get().entityTypesContainer.contains(type) && ! MPerm.getPermContainer().has(me, ps, verboose)) return false;
if ( ! MConf.get().entityTypesContainer.contains(type)) return true;
// ... and the player lacks the container perm ... // ... check build entity rights ...
PS ps = PS.valueOf(entity.getLocation()); if (MConf.get().entityTypesEditOnInteract.contains(type) && ! MPerm.getPermBuild().has(me, ps, verboose)) return false;
if (MPerm.getPermContainer().has(me, ps, verboose)) return true;
// ... then we can't use the entity. // ... otherwise we may use the entity.
return false; return true;
} }
// For some reason onPlayerInteract() sometimes misses bucket events depending on distance (something like 2-3 blocks away isn't detected), // For some reason onPlayerInteract() sometimes misses bucket events depending on distance (something like 2-3 blocks away isn't detected),

View File

@ -467,6 +467,7 @@ public class MConf extends Entity<MConf>
// If you however are using Forge with mods that add new container types you might want to add them here. // If you however are using Forge with mods that add new container types you might want to add them here.
// This way they can be protected in Faction territory. // This way they can be protected in Faction territory.
// Interacting with these materials when they are already placed in the terrain results in an edit.
public BackstringEnumSet<Material> materialsEditOnInteract = new BackstringEnumSet<Material>(Material.class, public BackstringEnumSet<Material> materialsEditOnInteract = new BackstringEnumSet<Material>(Material.class,
"DIODE_BLOCK_OFF", // Minecraft 1.? "DIODE_BLOCK_OFF", // Minecraft 1.?
"DIODE_BLOCK_ON", // Minecraft 1.? "DIODE_BLOCK_ON", // Minecraft 1.?
@ -475,12 +476,15 @@ public class MConf extends Entity<MConf>
"SOIL" // Minecraft 1.? "SOIL" // Minecraft 1.?
); );
// Interacting with the the terrain holding this item in hand results in an edit.
// There's no need to add all block materials here. Only special items other than blocks.
public BackstringEnumSet<Material> materialsEditTools = new BackstringEnumSet<Material>(Material.class, public BackstringEnumSet<Material> materialsEditTools = new BackstringEnumSet<Material>(Material.class,
"FIREBALL", // Minecraft 1.? "FIREBALL", // Minecraft 1.?
"FLINT_AND_STEEL", // Minecraft 1.? "FLINT_AND_STEEL", // Minecraft 1.?
"BUCKET", // Minecraft 1.? "BUCKET", // Minecraft 1.?
"WATER_BUCKET", // Minecraft 1.? "WATER_BUCKET", // Minecraft 1.?
"LAVA_BUCKET" // Minecraft 1.? "LAVA_BUCKET", // Minecraft 1.?
"ARMOR_STAND" // Minecraft 1.8
); );
// The duplication bug found in Spigot 1.8 protocol patch // The duplication bug found in Spigot 1.8 protocol patch
@ -494,6 +498,7 @@ public class MConf extends Entity<MConf>
"IRON_DOOR" // Minecraft 1.? "IRON_DOOR" // Minecraft 1.?
); );
// Interacting with these materials placed in the terrain results in door toggling.
public BackstringEnumSet<Material> materialsDoor = new BackstringEnumSet<Material>(Material.class, public BackstringEnumSet<Material> materialsDoor = new BackstringEnumSet<Material>(Material.class,
"WOODEN_DOOR", // Minecraft 1.? "WOODEN_DOOR", // Minecraft 1.?
"ACACIA_DOOR", // Minecraft 1.8 "ACACIA_DOOR", // Minecraft 1.8
@ -510,6 +515,7 @@ public class MConf extends Entity<MConf>
"SPRUCE_FENCE_GATE" // Minecraft 1.8 "SPRUCE_FENCE_GATE" // Minecraft 1.8
); );
// Interacting with these materials placed in the terrain results in opening a container.
public BackstringEnumSet<Material> materialsContainer = new BackstringEnumSet<Material>(Material.class, public BackstringEnumSet<Material> materialsContainer = new BackstringEnumSet<Material>(Material.class,
"DISPENSER", // Minecraft 1.? "DISPENSER", // Minecraft 1.?
"CHEST", // Minecraft 1.? "CHEST", // Minecraft 1.?
@ -525,12 +531,25 @@ public class MConf extends Entity<MConf>
"DROPPER" // Minecraft 1.? "DROPPER" // Minecraft 1.?
); );
public BackstringEnumSet<EntityType> entityTypesContainer = new BackstringEnumSet<EntityType>(EntityType.class, // Interacting with these entities results in an edit.
"MINECART_CHEST", // Minecraft 1.? public BackstringEnumSet<EntityType> entityTypesEditOnInteract = new BackstringEnumSet<EntityType>(EntityType.class,
"MINECART_HOPPER", // Minecraft 1.? "ITEM_FRAME", // Minecraft 1.?
"ARMOR_STAND" // Minecraft 1.8 "ARMOR_STAND" // Minecraft 1.8
); );
// Damaging these entities results in an edit.
public BackstringEnumSet<EntityType> entityTypesEditOnDamage = new BackstringEnumSet<EntityType>(EntityType.class,
"ITEM_FRAME", // Minecraft 1.?
"ARMOR_STAND" // Minecraft 1.8
);
// Interacting with these entities results in opening a container.
public BackstringEnumSet<EntityType> entityTypesContainer = new BackstringEnumSet<EntityType>(EntityType.class,
"MINECART_CHEST", // Minecraft 1.?
"MINECART_HOPPER" // Minecraft 1.?
);
// The complete list of entities considered to be monsters.
public BackstringEnumSet<EntityType> entityTypesMonsters = new BackstringEnumSet<EntityType>(EntityType.class, public BackstringEnumSet<EntityType> entityTypesMonsters = new BackstringEnumSet<EntityType>(EntityType.class,
"BLAZE", // Minecraft 1.? "BLAZE", // Minecraft 1.?
"CAVE_SPIDER", // Minecraft 1.? "CAVE_SPIDER", // Minecraft 1.?