Spigot 1.8: Armor Stand Support (Somehow. Spigot Implementation is Buggy)

This commit is contained in:
Jascha Starke 2015-04-11 14:09:41 +02:00
parent 7b72e1d5cf
commit d010249107
8 changed files with 234 additions and 144 deletions

4
.gitignore vendored
View file

@ -1,11 +1,13 @@
/bin
# Eclipse stuff
# IDE stuff
/.project
/.classpath
/.settings
/.buildpath
/.checkstyle
/.idea
/LimitedCreative.iml
# maven
/target

View file

@ -4,17 +4,16 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import de.jaschastarke.bukkit.lib.CoreModule;
@ -47,7 +46,7 @@ public class FeatureBlockItemSpawn extends CoreModule<LimitedCreative> implement
private void scheduleCleanUp() {
if (cleanup.maxTime == 0) { // if not scheduled yet
cleanup.maxTime = System.currentTimeMillis();
cleanup.runTaskLater(plugin, TICK_OFFSET);
Bukkit.getScheduler().runTaskLater(plugin, cleanup, TICK_OFFSET);
}
}
@ -96,11 +95,15 @@ public class FeatureBlockItemSpawn extends CoreModule<LimitedCreative> implement
list.add(new BlockItemDrop(l, type));
scheduleCleanUp();
}
public void block(Location l, ItemStack item) {
if (item != null)
block(l, item.getType());
}
@EventHandler(ignoreCancelled = true)
public void onItemSpawn(ItemSpawnEvent event) {
if (event.getEntity() instanceof Item) {
if (this.isBlocked(event.getLocation().getBlock().getLocation(), ((Item) event.getEntity()).getItemStack().getType())) {
if (event.getEntity() != null) {
if (this.isBlocked(event.getLocation().getBlock().getLocation(), event.getEntity().getItemStack().getType())) {
event.setCancelled(true);
}
}
@ -113,8 +116,9 @@ public class FeatureBlockItemSpawn extends CoreModule<LimitedCreative> implement
return debug;
}
private class CleanUp extends BukkitRunnable {
private class CleanUp implements Runnable {
public long maxTime = 0;
@Override
public void run() {
if (plugin.isDebug())

View file

@ -15,7 +15,7 @@ import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockListener;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateCommand;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateConfig;
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel;
import de.jaschastarke.minecraft.limitedcreative.blockstate.HangingListener;
import de.jaschastarke.minecraft.limitedcreative.blockstate.HangingStandingListener;
import de.jaschastarke.minecraft.limitedcreative.blockstate.PlayerListener;
import de.jaschastarke.minecraft.limitedcreative.blockstate.SyncronizedModel;
import de.jaschastarke.minecraft.limitedcreative.blockstate.ThreadedModel;
@ -50,7 +50,7 @@ public class ModBlockStates extends CoreModule<LimitedCreative> {
this.addModule(new BlockFall(plugin));
listeners.addListener(new BlockListener(this));
listeners.addListener(new HangingListener(this));
listeners.addListener(new HangingStandingListener(this));
listeners.addListener(new PlayerListener(this));
command = new BlockStateCommand(this);

View file

@ -93,11 +93,11 @@ public class BlockStateConfig extends Configuration implements IConfigurationSub
*
* Without threading, huge WorldEdits becomes much noticeable slower.
*
* default: false
* default: true
*/
@IsConfigurationNode(order = 150)
public boolean getUseThreading() {
return config.getBoolean("useThreading", false);
return config.getBoolean("useThreading", true);
}
/**

View file

@ -4,21 +4,27 @@ import java.util.Date;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
public class HangingListener implements Listener {
public class HangingStandingListener implements Listener {
private ModBlockStates mod;
public HangingListener(ModBlockStates mod) {
public HangingStandingListener(ModBlockStates mod) {
this.mod = mod;
}
@ -35,7 +41,27 @@ public class HangingListener implements Listener {
if (mod.isDebug())
mod.getLog().debug("... was placed by creative. Modify prevented");
event.setCancelled(true);
return;
}
} else {
BlockState s = new BlockState();
s.setLocation(event.getRightClicked().getLocation().getBlock().getLocation());
s.setPlayer(event.getPlayer());
s.setDate(new Date());
if (mod.isDebug())
mod.getLog().debug("Saving BlockState: " + s.toString());
mod.getModel().setState(s);
}
} else if (event.getRightClicked() instanceof ArmorStand) {
if (mod.getModel().isRestricted(event.getRightClicked().getLocation().getBlock())) {
if (mod.isDebug())
mod.getLog().debug("Modifying standing: " + event.getRightClicked().getLocation().toString());
if (event.getPlayer().getGameMode() != GameMode.CREATIVE) {
if (mod.isDebug())
mod.getLog().debug("... was placed by creative. Modify prevented");
event.setCancelled(true);
}
} else {
BlockState s = new BlockState();
@ -50,6 +76,15 @@ public class HangingListener implements Listener {
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) {
onPlayerInteractEntity(event);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onArmorStandManipulateEvent(PlayerArmorStandManipulateEvent event) {
onPlayerInteractEntity(event);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerLeftInteractEntity(EntityDamageByEntityEvent event) {
if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName()))
@ -63,7 +98,6 @@ public class HangingListener implements Listener {
if (mod.isDebug())
mod.getLog().debug("... was placed by creative. Modify prevented");
event.setCancelled(true);
return;
}
} else {
BlockState s = new BlockState();
@ -99,6 +133,61 @@ public class HangingListener implements Listener {
}
}
protected void checkArmoryDestroy(ArmorStand entity, boolean deRemove) {
if (mod.isDebug())
mod.getLog().debug("Breaking standing: " + entity.getLocation().toString());
if (mod.getModel().isRestricted(entity.getLocation().getBlock())) {
if (mod.isDebug())
mod.getLog().debug("... was placed by creative. Drop prevented");
mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), Material.ARMOR_STAND);
mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), Material.ARMOR_STAND);
mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getHelmet());
mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getChestplate());
mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getBoots());
mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getItemInHand());
mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getLeggings());
mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getHelmet());
mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getChestplate());
mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getBoots());
mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getItemInHand());
mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getLeggings());
/*entity.setBoots(null);
entity.setChestplate(null);
entity.setHelmet(null);
entity.setItemInHand(null);
entity.setLeggings(null);*/
}
if (deRemove)
mod.getModel().removeState(entity.getLocation().getBlock());
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onStandingBreak(EntityDeathEvent event) {
if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName()))
return;
if (event.getEntity() instanceof ArmorStand) {
checkArmoryDestroy((ArmorStand) event.getEntity(), true);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onStandingBreaking(EntityDamageByEntityEvent event) {
if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName()))
return;
if (event.getEntity() instanceof ArmorStand) {
// TODO: Bug in Spigot, we can not check for destroying yet. so the block state stays in DB :(
//if (event.getEntity().isDead() || ((ArmorStand) event.getEntity()).getHealth() <= event.getFinalDamage()) {
checkArmoryDestroy((ArmorStand) event.getEntity(), false);
//}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onHangingPlace(HangingPlaceEvent event) {
if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName()))

View file

@ -19,7 +19,6 @@ package de.jaschastarke.minecraft.limitedcreative.limits;
import org.bukkit.GameMode;
import org.bukkit.entity.Creature;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -53,7 +52,7 @@ public class EntityListener implements Listener {
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
if (event.getEntity() instanceof LivingEntity && event.getDroppedExp() > 0) {
if (event.getEntity() != null && event.getDroppedExp() > 0) {
if (mod.getNoDropMobs().isXPPrevented(event.getEntity())) {
event.setDroppedExp(0);
event.getDrops().clear();

View file

@ -125,7 +125,7 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
}
public static enum BlockPickup implements IToGeneric {
public enum BlockPickup implements IToGeneric {
PREVENT,
REMOVE;
@ -289,7 +289,7 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
public Object getValue(final IConfigurationNode node) {
Object val = super.getValue(node);
if (node.getName().equals("pickup") && val == null) {
return new Boolean(false);
return false;
} else {
return val;
}

View file

@ -35,13 +35,7 @@ import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerExpChangeEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.*;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.material.DirectionalContainer;
import org.bukkit.potion.PotionEffect;
@ -185,13 +179,11 @@ public class PlayerListener implements Listener {
if (!checkPermission(event, NoLimitPermissions.CHEST)) {
event.setCancelled(true);
event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.chest"));
return;
}
} else if (mod.getConfig().getBlockInteraction().isListed(block)) {
if (!checkPermission(event, NoLimitPermissions.INTERACT(block))) {
event.setCancelled(true);
event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.interact"));
return;
}
}
}
@ -213,12 +205,16 @@ public class PlayerListener implements Listener {
if (!checkPermission(event, NoLimitPermissions.BASE_INTERACT)) {
event.setCancelled(true);
event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.entity"));
return;
}
}
}
}
@EventHandler
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) {
onPlayerInteractEntity(event);
}
@EventHandler(ignoreCancelled = true)
public void onEntityDamageByEntity(EntityDamageEvent rawevent) {
if (rawevent instanceof EntityDamageByEntityEvent && !rawevent.isCancelled()) {