mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 19:45:43 +01:00
Fix entity protection game rules
This commit is contained in:
parent
0b0b8c6eff
commit
109dfd72c9
@ -17,6 +17,8 @@
|
||||
package de.erethon.dungeonsxl.game;
|
||||
|
||||
import de.erethon.caliburn.item.ExItem;
|
||||
import de.erethon.caliburn.mob.ExMob;
|
||||
import de.erethon.caliburn.mob.VanillaMob;
|
||||
import de.erethon.dungeonsxl.requirement.Requirement;
|
||||
import de.erethon.dungeonsxl.reward.Reward;
|
||||
import java.util.ArrayList;
|
||||
@ -28,7 +30,6 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
/**
|
||||
* See {@link de.erethon.dungeonsxl.config.WorldConfig}
|
||||
@ -53,13 +54,13 @@ public class GameRuleProvider {
|
||||
DEFAULT_VALUES.breakPlacedBlocks = false;
|
||||
DEFAULT_VALUES.breakWhitelist = null;
|
||||
DEFAULT_VALUES.damageProtectedEntities = new HashSet<>(Arrays.asList(
|
||||
EntityType.ARMOR_STAND,
|
||||
EntityType.ITEM_FRAME,
|
||||
EntityType.PAINTING
|
||||
VanillaMob.ARMOR_STAND,
|
||||
VanillaMob.ITEM_FRAME,
|
||||
VanillaMob.PAINTING
|
||||
));
|
||||
DEFAULT_VALUES.interactionProtectedEntities = new HashSet<>(Arrays.asList(
|
||||
EntityType.ARMOR_STAND,
|
||||
EntityType.ITEM_FRAME
|
||||
VanillaMob.ARMOR_STAND,
|
||||
VanillaMob.ITEM_FRAME
|
||||
));
|
||||
DEFAULT_VALUES.placeBlocks = false;
|
||||
DEFAULT_VALUES.placeWhitelist = null;
|
||||
@ -117,8 +118,8 @@ public class GameRuleProvider {
|
||||
protected Boolean breakBlocks;
|
||||
protected Boolean breakPlacedBlocks;
|
||||
protected Map<ExItem, HashSet<ExItem>> breakWhitelist;
|
||||
protected Set<EntityType> damageProtectedEntities;
|
||||
protected Set<EntityType> interactionProtectedEntities;
|
||||
protected Set<ExMob> damageProtectedEntities;
|
||||
protected Set<ExMob> interactionProtectedEntities;
|
||||
protected Boolean placeBlocks;
|
||||
protected Set<ExItem> placeWhitelist;
|
||||
protected Boolean rain;
|
||||
@ -235,14 +236,14 @@ public class GameRuleProvider {
|
||||
/**
|
||||
* @return a Set of all entity types that cannot be damaged
|
||||
*/
|
||||
public Set<EntityType> getDamageProtectedEntities() {
|
||||
public Set<ExMob> getDamageProtectedEntities() {
|
||||
return damageProtectedEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a Set of all entity types that cannot be damaged
|
||||
*/
|
||||
public Set<EntityType> getInteractionProtectedEntities() {
|
||||
public Set<ExMob> getInteractionProtectedEntities() {
|
||||
return interactionProtectedEntities;
|
||||
}
|
||||
|
||||
|
@ -569,7 +569,7 @@ public class DGameWorld extends DInstanceWorld {
|
||||
}
|
||||
if (entity.getLocation().getBlock().getRelative(((Hanging) entity).getAttachedFace()).equals(block)) {
|
||||
Hanging hanging = (Hanging) entity;
|
||||
if (rules.getDamageProtectedEntities().contains(hanging.getType())) {
|
||||
if (rules.getDamageProtectedEntities().contains(CaliburnAPI.getInstance().getExMob(hanging))) {
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
|
@ -16,10 +16,15 @@
|
||||
*/
|
||||
package de.erethon.dungeonsxl.world;
|
||||
|
||||
import de.erethon.caliburn.CaliburnAPI;
|
||||
import de.erethon.caliburn.item.VanillaItem;
|
||||
import de.erethon.caliburn.mob.ExMob;
|
||||
import de.erethon.dungeonsxl.game.Game;
|
||||
import java.util.Set;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -30,6 +35,8 @@ import org.bukkit.event.block.BlockSpreadEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakEvent;
|
||||
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
@ -126,24 +133,37 @@ public class DWorldListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(event.getEntity().getWorld());
|
||||
if (gameWorld == null) {
|
||||
return;
|
||||
}
|
||||
Game game = Game.getByGameWorld(gameWorld);
|
||||
if (game.getRules().getDamageProtectedEntities().contains(event.getEntityType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
onTouch(event, event.getEntity(), false);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onHangingBreak(HangingBreakEvent event) {
|
||||
onTouch(event, event.getEntity(), false);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(event.getPlayer().getWorld());
|
||||
onTouch(event, event.getRightClicked(), true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onArmorStandManipulate(PlayerArmorStandManipulateEvent event) {
|
||||
onTouch(event, event.getRightClicked(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param event the event
|
||||
* @param entity the entity
|
||||
* @param interact true = interact; false = break
|
||||
*/
|
||||
public void onTouch(Cancellable event, Entity entity, boolean interact) {
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(entity.getWorld());
|
||||
if (gameWorld == null) {
|
||||
return;
|
||||
}
|
||||
Game game = Game.getByGameWorld(gameWorld);
|
||||
if (game.getRules().getInteractionProtectedEntities().contains(event.getRightClicked().getType())) {
|
||||
Set<ExMob> prot = interact ? game.getRules().getInteractionProtectedEntities() : game.getRules().getDamageProtectedEntities();
|
||||
if (prot.contains(CaliburnAPI.getInstance().getExMob(entity))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ import org.bukkit.World.Environment;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
/**
|
||||
* The world configuration is a simple game rule source. Besides game rules, WorldConfig also stores some map specific data such as the invited players. It is
|
||||
@ -166,12 +165,12 @@ public class WorldConfig extends GameRuleProvider {
|
||||
|
||||
if (configFile.contains("damageProtectedEntities")) {
|
||||
damageProtectedEntities = new HashSet<>();
|
||||
configFile.getStringList("damageProtectedEntities").forEach(e -> damageProtectedEntities.add(EnumUtil.getEnumIgnoreCase(EntityType.class, e)));
|
||||
configFile.getStringList("damageProtectedEntities").forEach(e -> damageProtectedEntities.add(caliburn.getExMob(e)));
|
||||
}
|
||||
|
||||
if (configFile.contains("interactionProtectedEntities")) {
|
||||
interactionProtectedEntities = new HashSet<>();
|
||||
configFile.getStringList("interactionProtectedEntities").forEach(e -> interactionProtectedEntities.add(EnumUtil.getEnumIgnoreCase(EntityType.class, e)));
|
||||
configFile.getStringList("interactionProtectedEntities").forEach(e -> interactionProtectedEntities.add(caliburn.getExMob(e)));
|
||||
}
|
||||
|
||||
if (configFile.contains("placeBlocks")) {
|
||||
|
Loading…
Reference in New Issue
Block a user