From 2cb042088947c79ccde8d49ad957a861120ba57d Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Wed, 21 Oct 2015 04:57:46 +1300 Subject: [PATCH] Add Mineplex chunk events, misc modifications. diff --git a/src/main/java/com/mineplex/spigot/ChunkAddEntityEvent.java b/src/main/java/com/mineplex/spigot/ChunkAddEntityEvent.java new file mode 100644 index 0000000..3f16935 --- /dev/null +++ b/src/main/java/com/mineplex/spigot/ChunkAddEntityEvent.java @@ -0,0 +1,31 @@ +package com.mineplex.spigot; + +import org.bukkit.entity.Entity; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class ChunkAddEntityEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + private Entity _entity; + + public ChunkAddEntityEvent(Entity _entity) + { + this._entity = _entity; + } + + public Entity getEntity() + { + return _entity; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } +} diff --git a/src/main/java/com/mineplex/spigot/ChunkPreLoadEvent.java b/src/main/java/com/mineplex/spigot/ChunkPreLoadEvent.java new file mode 100644 index 0000000..564efe6 --- /dev/null +++ b/src/main/java/com/mineplex/spigot/ChunkPreLoadEvent.java @@ -0,0 +1,60 @@ +package com.mineplex.spigot; + +import org.bukkit.World; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class ChunkPreLoadEvent extends Event implements Cancellable +{ + private static final HandlerList handlers = new HandlerList(); + private boolean _cancelled; + private World _world; + private int _x; + private int _z; + + public ChunkPreLoadEvent(World world, int x, int z) + { + _world = world; + _x = x; + _z = z; + } + + public World getWorld() + { + return _world; + } + + public int getX() + { + return _x; + } + + public int getZ() + { + return _z; + } + + @Override + public boolean isCancelled() + { + return _cancelled; + } + + @Override + public void setCancelled(boolean cancel) + { + _cancelled = cancel; + } + + @Override + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } +} diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java index 022ba31..464d0c2 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -11,6 +11,8 @@ import java.util.Map; import java.util.Random; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentLinkedQueue; + +import com.mineplex.spigot.ChunkAddEntityEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -660,6 +662,9 @@ public class Chunk { entity.die(); } + ChunkAddEntityEvent event = new ChunkAddEntityEvent(entity.bukkitEntity); + Bukkit.getServer().getPluginManager().callEvent(event); + int k = MathHelper.floor(entity.locY / 16.0D); if (k < 0) { @@ -1317,6 +1322,10 @@ public class Chunk { return this.done; } + public void setDone(boolean done) { + this.done = done; + } + public void d(boolean flag) { this.done = flag; } diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java index 975d666..a55bd6c 100644 --- a/src/main/java/net/minecraft/server/ChunkProviderServer.java +++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java @@ -8,6 +8,8 @@ import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; + +import com.mineplex.spigot.ChunkPreLoadEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -88,6 +90,13 @@ public class ChunkProviderServer implements IChunkProvider { } + private boolean callChunkPreLoad(int i, int j) + { + ChunkPreLoadEvent event = new ChunkPreLoadEvent(world.getWorld(), i, j); + world.getServer().getPluginManager().callEvent(event); + return event.isCancelled(); + } + // CraftBukkit start - Add async variant, provide compatibility public Chunk getChunkIfLoaded(int x, int z) { return chunks.get(LongHash.toLong(x, z)); @@ -109,10 +118,30 @@ public class ChunkProviderServer implements IChunkProvider { // We can only use the queue for already generated chunks if (chunk == null && loader != null && loader.chunkExists(world, i, j)) { if (runnable != null) { - ChunkIOExecutor.queueChunkLoad(world, loader, this, i, j, runnable); + if (callChunkPreLoad(i, j)) + { + runnable.run(); + chunk = new EmptyChunk(world, i, j); + chunk.setDone(true); + chunks.put(LongHash.toLong(i, j), chunk); + } + else + { + ChunkIOExecutor.queueChunkLoad(world, loader, this, i, j, runnable); + } + return null; } else { - chunk = ChunkIOExecutor.syncChunkLoad(world, loader, this, i, j); + if (callChunkPreLoad(i, j)) + { + chunk = new EmptyChunk(world, i, j); + chunk.setDone(true); + chunks.put(LongHash.toLong(i, j), chunk); + } + else + { + chunk = ChunkIOExecutor.syncChunkLoad(world, loader, this, i, j); + } } } else if (chunk == null) { chunk = originalGetChunkAt(i, j); @@ -131,6 +160,20 @@ public class ChunkProviderServer implements IChunkProvider { boolean newChunk = false; // CraftBukkit end + Server server = world.getServer(); + + if (chunk == null && server != null) + { + if (callChunkPreLoad(i, j)) + { + chunk = new EmptyChunk(world, i, j); + chunk.setDone(true); + chunks.put(LongHash.toLong(i, j), chunk); + + return chunk; + } + } + if (chunk == null) { world.timings.syncChunkLoadTimer.startTiming(); // Spigot chunk = this.loadChunk(i, j); @@ -158,7 +201,6 @@ public class ChunkProviderServer implements IChunkProvider { chunk.addEntities(); // CraftBukkit start - Server server = world.getServer(); if (server != null) { /* * If it's a new world, the first few chunks are generated inside diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java index c30867d..b86369b 100644 --- a/src/main/java/net/minecraft/server/DedicatedServer.java +++ b/src/main/java/net/minecraft/server/DedicatedServer.java @@ -132,7 +132,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer System.err.println( "If you do not agree to the above EULA please stop your server and remove this flag immediately." ); } // Spigot End - if (!this.p.a() && !eulaAgreed) { // Spigot + if (false && !this.p.a() && !eulaAgreed) { // Spigot DedicatedServer.LOGGER.info("You need to agree to the EULA in order to run the server. Go to eula.txt for more info."); this.p.b(); return false; diff --git a/src/main/java/net/minecraft/server/TileEntityBeacon.java b/src/main/java/net/minecraft/server/TileEntityBeacon.java index 4f280dd..73a288c 100644 --- a/src/main/java/net/minecraft/server/TileEntityBeacon.java +++ b/src/main/java/net/minecraft/server/TileEntityBeacon.java @@ -59,7 +59,7 @@ public class TileEntityBeacon extends TileEntityContainer implements IUpdatePlay this.A(); } - private void A() { + public void A() { if (this.i && this.j > 0 && !this.world.isClientSide && this.k > 0) { double d0 = (double) (this.j * 10 + 10); byte b0 = 0; @@ -94,7 +94,7 @@ public class TileEntityBeacon extends TileEntityContainer implements IUpdatePlay } - private void B() { + public void B() { int i = this.j; int j = this.position.getX(); int k = this.position.getY(); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 2759425..f57c785 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -412,7 +412,7 @@ public final class CraftServer implements Server { int delta = Integer.MAX_VALUE; for (Player player : getOnlinePlayers()) { if (player.getName().toLowerCase().startsWith(lowerName)) { - int curDelta = Math.abs(player.getName().length() - lowerName.length()); + int curDelta = player.getName().length() - lowerName.length(); if (curDelta < delta) { found = player; delta = curDelta; -- 1.9.5.msysgit.0