Protection of Minecraft 1.8 armor stands.
This commit is contained in:
parent
cc31d334bf
commit
bb1d2e9c54
@ -39,6 +39,7 @@ import com.massivecraft.factions.integration.herochat.IntegrationHerochat;
|
|||||||
import com.massivecraft.factions.integration.lwc.IntegrationLwc;
|
import com.massivecraft.factions.integration.lwc.IntegrationLwc;
|
||||||
import com.massivecraft.factions.mixin.PowerMixin;
|
import com.massivecraft.factions.mixin.PowerMixin;
|
||||||
import com.massivecraft.factions.mixin.PowerMixinDefault;
|
import com.massivecraft.factions.mixin.PowerMixinDefault;
|
||||||
|
import com.massivecraft.factions.spigot.SpigotFeatures;
|
||||||
import com.massivecraft.factions.task.TaskFlagPermCreate;
|
import com.massivecraft.factions.task.TaskFlagPermCreate;
|
||||||
import com.massivecraft.factions.task.TaskPlayerDataRemove;
|
import com.massivecraft.factions.task.TaskPlayerDataRemove;
|
||||||
import com.massivecraft.factions.task.TaskEconLandReward;
|
import com.massivecraft.factions.task.TaskEconLandReward;
|
||||||
@ -158,6 +159,9 @@ public class Factions extends MassivePlugin
|
|||||||
IntegrationLwc.get()
|
IntegrationLwc.get()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Spigot
|
||||||
|
SpigotFeatures.activate();
|
||||||
|
|
||||||
// Modulo Repeat Tasks
|
// Modulo Repeat Tasks
|
||||||
TaskPlayerPowerUpdate.get().activate(this);
|
TaskPlayerPowerUpdate.get().activate(this);
|
||||||
TaskPlayerDataRemove.get().activate(this);
|
TaskPlayerDataRemove.get().activate(this);
|
||||||
|
@ -85,6 +85,7 @@ 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;
|
||||||
@ -1496,37 +1497,49 @@ public class EngineMain extends EngineAbstract
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This event will not fire for Minecraft 1.8 armor stands.
|
||||||
|
// Armor stands are handled in EngineSpigot instead.
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event)
|
public void onPlayerInteractEntity(PlayerInteractEntityEvent event)
|
||||||
{
|
{
|
||||||
// If a player ...
|
// Gather Info
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
// ... right clicked an entity ...
|
|
||||||
final Entity entity = event.getRightClicked();
|
final Entity entity = event.getRightClicked();
|
||||||
if (entity == null) return;
|
final boolean verboose = true;
|
||||||
|
|
||||||
// ... and using that entity is forbidden ...
|
// If we can't use ...
|
||||||
if (canPlayerUseEntity(player, entity, true)) return;
|
if (EngineMain.canPlayerUseEntity(player, entity, verboose)) return;
|
||||||
|
|
||||||
// ... then cancel the event.
|
// ... block use.
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canPlayerUseEntity(Player player, Entity entity, boolean verboose)
|
public static boolean canPlayerUseEntity(Player player, Entity entity, boolean verboose)
|
||||||
{
|
{
|
||||||
|
// If a player ...
|
||||||
|
if (player == null) return true;
|
||||||
|
|
||||||
|
// ... interacts with an entity ...
|
||||||
|
if (entity == null) return true;
|
||||||
|
|
||||||
|
// ... and the player does not bypass all protections ...
|
||||||
String name = player.getName();
|
String name = player.getName();
|
||||||
if (MConf.get().playersWhoBypassAllProtection.contains(name)) return true;
|
if (MConf.get().playersWhoBypassAllProtection.contains(name)) return true;
|
||||||
|
|
||||||
|
// ... and the player is not using admin mode ...
|
||||||
MPlayer me = MPlayer.get(player);
|
MPlayer me = MPlayer.get(player);
|
||||||
if (me.isUsingAdminMode()) return true;
|
if (me.isUsingAdminMode()) return true;
|
||||||
|
|
||||||
PS ps = PS.valueOf(entity.getLocation());
|
// ... and the entity is of a container type ...
|
||||||
EntityType type = entity.getType();
|
EntityType type = entity.getType();
|
||||||
|
if ( ! MConf.get().entityTypesContainer.contains(type)) return true;
|
||||||
|
|
||||||
if (MConf.get().entityTypesContainer.contains(type) && ! MPerm.getPermContainer().has(me, ps, verboose)) return false;
|
// ... and the player lacks the container perm ...
|
||||||
|
PS ps = PS.valueOf(entity.getLocation());
|
||||||
|
if (MPerm.getPermContainer().has(me, ps, verboose)) return true;
|
||||||
|
|
||||||
return true;
|
// ... then we can't use the entity.
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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),
|
||||||
|
@ -528,7 +528,7 @@ public class MConf extends Entity<MConf>
|
|||||||
public BackstringEnumSet<EntityType> entityTypesContainer = new BackstringEnumSet<EntityType>(EntityType.class,
|
public BackstringEnumSet<EntityType> entityTypesContainer = new BackstringEnumSet<EntityType>(EntityType.class,
|
||||||
"MINECART_CHEST", // Minecraft 1.?
|
"MINECART_CHEST", // Minecraft 1.?
|
||||||
"MINECART_HOPPER", // Minecraft 1.?
|
"MINECART_HOPPER", // Minecraft 1.?
|
||||||
"ARMOR_STAND" // Minecraft 1.?
|
"ARMOR_STAND" // Minecraft 1.8
|
||||||
);
|
);
|
||||||
|
|
||||||
public BackstringEnumSet<EntityType> entityTypesMonsters = new BackstringEnumSet<EntityType>(EntityType.class,
|
public BackstringEnumSet<EntityType> entityTypesMonsters = new BackstringEnumSet<EntityType>(EntityType.class,
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
package com.massivecraft.factions.spigot;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import com.massivecraft.factions.Factions;
|
||||||
|
import com.massivecraft.factions.engine.EngineMain;
|
||||||
|
import com.massivecraft.massivecore.EngineAbstract;
|
||||||
|
|
||||||
|
|
||||||
|
public class EngineSpigot extends EngineAbstract
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// INSTANCE & CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private static EngineSpigot i = new EngineSpigot();
|
||||||
|
public static EngineSpigot get() { return i; }
|
||||||
|
private EngineSpigot() {}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// OVERRIDE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Plugin getPlugin()
|
||||||
|
{
|
||||||
|
return Factions.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void activate()
|
||||||
|
{
|
||||||
|
super.activate();
|
||||||
|
SpigotFeatures.setActive(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deactivate()
|
||||||
|
{
|
||||||
|
super.deactivate();
|
||||||
|
SpigotFeatures.setActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// LISTENER
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
// This is a special Spigot event that fires for Minecraft 1.8 armor stands.
|
||||||
|
// It also fires for other entity types but for those the event is buggy.
|
||||||
|
// It seems we can only cancel interaction with armor stands from here.
|
||||||
|
// Thus we only handle armor stands from here and handle everything else in EngineMain.
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
|
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event)
|
||||||
|
{
|
||||||
|
// Gather Info
|
||||||
|
final Player player = event.getPlayer();
|
||||||
|
final Entity entity = event.getRightClicked();
|
||||||
|
final boolean verboose = true;
|
||||||
|
|
||||||
|
// Only care for armor stands.
|
||||||
|
if (entity.getType() != EntityType.ARMOR_STAND) return;
|
||||||
|
|
||||||
|
// If we can't use ...
|
||||||
|
if (EngineMain.canPlayerUseEntity(player, entity, verboose)) return;
|
||||||
|
|
||||||
|
// ... block use.
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.massivecraft.factions.spigot;
|
||||||
|
|
||||||
|
public class SpigotFeatures
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// STATIC FIELDS
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
// The "active" field is set from inside the EngineSpigot
|
||||||
|
|
||||||
|
private static boolean active = false;
|
||||||
|
public static boolean isActive() { return active; }
|
||||||
|
public static void setActive(boolean active) { SpigotFeatures.active = active; }
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// ACTIVATE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static void activate()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
EngineSpigot.get().activate();
|
||||||
|
}
|
||||||
|
catch (Throwable t)
|
||||||
|
{
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user