ItemFrames and Leaves

This commit is contained in:
Sam 2017-02-18 10:37:03 +00:00
parent 0fa0d88aac
commit af29135026

View File

@ -8,7 +8,6 @@ import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
@ -20,6 +19,7 @@ import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
@ -40,28 +40,18 @@ import mineplex.gemhunters.debug.DebugModule;
public class WorldListeners implements Listener
{
private static final int VIEW_DISTANCE = 10;
private static final long HUNGER_RECHARGE = TimeUnit.SECONDS.toMillis(15);
private final JavaPlugin _plugin;
public WorldListeners(JavaPlugin plugin)
{
_plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
plugin.getServer().getScheduler().runTaskLater(plugin, () -> {
for (World world : plugin.getServer().getWorlds())
{
((CraftWorld) world).getHandle().spigotConfig.viewDistance = VIEW_DISTANCE;
((CraftWorld) world).getHandle().a(VIEW_DISTANCE);
}
}, 20);
}
@EventHandler
//@EventHandler
public void deletePlayerData(PlayerQuitEvent event)
{
_plugin.getServer().getScheduler().runTaskLater(_plugin, () -> {
@ -71,7 +61,7 @@ public class WorldListeners implements Listener
new File(world.getWorldFolder().getPath() + File.separator + "stats" + File.separator + uuid + ".json").delete();
}, 20);
}
@EventHandler(priority = EventPriority.LOWEST)
public void blockBreak(BlockBreakEvent event)
{
@ -100,7 +90,7 @@ public class WorldListeners implements Listener
}
@EventHandler
public void armorStandDestory(PlayerInteractAtEntityEvent event)
public void entityDestory(PlayerInteractAtEntityEvent event)
{
if (shouldBlock(event.getPlayer()))
{
@ -109,9 +99,9 @@ public class WorldListeners implements Listener
}
@EventHandler
public void armorStandDamage(EntityDamageEvent event)
public void entityDamage(EntityDamageEvent event)
{
if (event.getEntity() instanceof ArmorStand)
if (event.getEntity() instanceof ArmorStand || event.getEntity() instanceof ItemFrame)
{
event.setCancelled(true);
}
@ -122,11 +112,11 @@ public class WorldListeners implements Listener
{
event.setCancelled(true);
}
@EventHandler
public void itemFrames(PlayerInteractEntityEvent event)
{
if (shouldBlock(event.getPlayer()) && event.getRightClicked() instanceof ItemFrame)
if (event.getRightClicked() instanceof ItemFrame)
{
event.setCancelled(true);
}
@ -148,7 +138,7 @@ public class WorldListeners implements Listener
{
return;
}
// Sam don't you dare look here, I understand the implications of this
// but entities, can I just save by UUID? or does not doing this have
// bigger complications?.
@ -172,6 +162,12 @@ public class WorldListeners implements Listener
{
event.setCancelled(true);
}
@EventHandler
public void leavesDecay(LeavesDecayEvent event)
{
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void hungerChange(FoodLevelChangeEvent event)
@ -180,11 +176,11 @@ public class WorldListeners implements Listener
{
return;
}
Player player = (Player) event.getEntity();
DebugModule.getInstance().d(player.getName() + " hunger " + player.getFoodLevel() + " -> " + event.getFoodLevel());
DebugModule.getInstance().d(player.getName() + " hunger " + player.getFoodLevel() + " -> " + event.getFoodLevel());
if (event.getFoodLevel() < player.getFoodLevel() && Recharge.Instance.use((Player) event.getEntity(), "Hunger", HUNGER_RECHARGE, false, false))
{
event.setCancelled(true);