mirror of
https://github.com/barkeser2002/CatServer.git
synced 2026-09-25 09:26:08 +03:00
391 lines
20 KiB
Diff
391 lines
20 KiB
Diff
--- ../src-base/minecraft/net/minecraft/world/WorldServer.java
|
|
+++ ../src-work/minecraft/net/minecraft/world/WorldServer.java
|
|
@@ -74,19 +74,23 @@
|
|
import net.minecraft.world.storage.MapStorage;
|
|
import net.minecraft.world.storage.WorldInfo;
|
|
import net.minecraft.world.storage.loot.LootTableManager;
|
|
+import net.minecraftforge.common.WorldSpecificSaveHandler;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
+import org.bukkit.block.BlockState;
|
|
+import org.bukkit.event.block.BlockFormEvent;
|
|
+import org.bukkit.event.weather.LightningStrikeEvent;
|
|
|
|
public class WorldServer extends World implements IThreadListener
|
|
{
|
|
private static final Logger LOGGER = LogManager.getLogger();
|
|
private final MinecraftServer mcServer;
|
|
- private final EntityTracker theEntityTracker;
|
|
+ public final EntityTracker theEntityTracker;
|
|
private final PlayerChunkMap thePlayerManager;
|
|
private final Set<NextTickListEntry> pendingTickListEntriesHashSet = Sets.<NextTickListEntry>newHashSet();
|
|
- private final TreeSet<NextTickListEntry> pendingTickListEntriesTreeSet = new TreeSet();
|
|
+ private final TreeSet<NextTickListEntry> pendingTickListEntriesTreeSet = new TreeSet<NextTickListEntry>();
|
|
private final Map<UUID, Entity> entitiesByUuid = Maps.<UUID, Entity>newHashMap();
|
|
public boolean disableLevelSaving;
|
|
private boolean allPlayersSleeping;
|
|
@@ -101,30 +105,31 @@
|
|
/** Stores the recently processed (lighting) chunks */
|
|
protected Set<ChunkPos> doneChunks = new java.util.HashSet<ChunkPos>();
|
|
public List<Teleporter> customTeleporters = new ArrayList<Teleporter>();
|
|
+ public final int dimension;
|
|
|
|
- public WorldServer(MinecraftServer server, ISaveHandler saveHandlerIn, WorldInfo info, int dimensionId, Profiler profilerIn)
|
|
+ public WorldServer(MinecraftServer server, ISaveHandler saveHandlerIn, WorldInfo info, int dimensionId, Profiler profilerIn, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen)
|
|
{
|
|
- super(saveHandlerIn, info, net.minecraftforge.common.DimensionManager.createProviderFor(dimensionId), profilerIn, false);
|
|
+ super(saveHandlerIn, info, net.minecraftforge.common.DimensionManager.createProviderFor(dimensionId), profilerIn, false, gen, env);
|
|
+ this.dimension = dimensionId;
|
|
+ this.pvpMode = server.isPVPEnabled();
|
|
this.mcServer = server;
|
|
this.theEntityTracker = new EntityTracker(this);
|
|
- this.thePlayerManager = new PlayerChunkMap(this);
|
|
+ this.thePlayerManager = new PlayerChunkMap(this, spigotConfig.viewDistance);
|
|
// Guarantee the dimension ID was not reset by the provider
|
|
int providerDim = this.provider.getDimension();
|
|
this.provider.registerWorld(this);
|
|
this.provider.setDimension(providerDim);
|
|
this.chunkProvider = this.createChunkProvider();
|
|
- perWorldStorage = new MapStorage(new net.minecraftforge.common.WorldSpecificSaveHandler((WorldServer)this, saveHandlerIn));
|
|
- this.worldTeleporter = new Teleporter(this);
|
|
+ this.worldTeleporter = new org.bukkit.craftbukkit.CraftTravelAgent(this); // CraftBukkit
|
|
+ this.perWorldStorage = new MapStorage(new WorldSpecificSaveHandler((WorldServer) this, saveHandler));
|
|
this.calculateInitialSkylight();
|
|
this.calculateInitialWeather();
|
|
this.getWorldBorder().setSize(server.getMaxWorldSize());
|
|
net.minecraftforge.common.DimensionManager.setWorld(dimensionId, this, mcServer);
|
|
- }
|
|
-
|
|
- public World init()
|
|
- {
|
|
- this.mapStorage = new MapStorage(this.saveHandler);
|
|
+ this.worldScoreboard = getServer().getScoreboardManager() == null ? new ServerScoreboard(this.mcServer) : getServer().getScoreboardManager().getMainScoreboard().getHandle(); // CatServer - Use CraftBukit scoreboard
|
|
+ ((WorldServer) this).worldInfo.setDimension(dimensionId);
|
|
String s = VillageCollection.fileNameForProvider(this.provider);
|
|
+ this.lootTable = new LootTableManager(new File(new File(this.saveHandler.getWorldDirectory(), "data"), "loot_tables"));
|
|
VillageCollection villagecollection = (VillageCollection)this.perWorldStorage.getOrLoadData(VillageCollection.class, s);
|
|
|
|
if (villagecollection == null)
|
|
@@ -138,7 +143,20 @@
|
|
this.villageCollectionObj.setWorldsForAll(this);
|
|
}
|
|
|
|
- this.worldScoreboard = new ServerScoreboard(this.mcServer);
|
|
+ }
|
|
+
|
|
+ public WorldServer(MinecraftServer server, ISaveHandler saveHandlerIn, WorldInfo info, int dimensionId, Profiler profilerIn) {
|
|
+ super(saveHandlerIn,info, net.minecraftforge.common.DimensionManager.createProviderFor(dimensionId),profilerIn,false);
|
|
+ this.dimension = dimensionId;
|
|
+ this.pvpMode = server.isPVPEnabled();
|
|
+ this.mcServer = server;
|
|
+ this.theEntityTracker = null;
|
|
+ this.thePlayerManager = null;
|
|
+ this.worldTeleporter = null;
|
|
+ }
|
|
+
|
|
+ public World init()
|
|
+ {
|
|
ScoreboardSaveData scoreboardsavedata = (ScoreboardSaveData)this.mapStorage.getOrLoadData(ScoreboardSaveData.class, "scoreboard");
|
|
|
|
if (scoreboardsavedata == null)
|
|
@@ -146,16 +164,11 @@
|
|
scoreboardsavedata = new ScoreboardSaveData();
|
|
this.mapStorage.setData("scoreboard", scoreboardsavedata);
|
|
}
|
|
-
|
|
- scoreboardsavedata.setScoreboard(this.worldScoreboard);
|
|
+ if (!(this instanceof WorldServerMulti)) //Forge: We fix the global mapStorage, which causes us to share scoreboards early. So don't associate the save data with the temporary scoreboard
|
|
+ {
|
|
+ scoreboardsavedata.setScoreboard(this.worldScoreboard);
|
|
+ }
|
|
((ServerScoreboard)this.worldScoreboard).addDirtyRunnable(new WorldSavedDataCallableSave(scoreboardsavedata));
|
|
- this.lootTable = new LootTableManager(new File(new File(this.saveHandler.getWorldDirectory(), "data"), "loot_tables"));
|
|
- this.getWorldBorder().setCenter(this.worldInfo.getBorderCenterX(), this.worldInfo.getBorderCenterZ());
|
|
- this.getWorldBorder().setDamageAmount(this.worldInfo.getBorderDamagePerBlock());
|
|
- this.getWorldBorder().setDamageBuffer(this.worldInfo.getBorderSafeZone());
|
|
- this.getWorldBorder().setWarningDistance(this.worldInfo.getBorderWarningDistance());
|
|
- this.getWorldBorder().setWarningTime(this.worldInfo.getBorderWarningTime());
|
|
-
|
|
if (this.worldInfo.getBorderLerpTime() > 0L)
|
|
{
|
|
this.getWorldBorder().setTransition(this.worldInfo.getBorderSize(), this.worldInfo.getBorderLerpTarget(), this.worldInfo.getBorderLerpTime());
|
|
@@ -165,6 +178,19 @@
|
|
this.getWorldBorder().setTransition(this.worldInfo.getBorderSize());
|
|
}
|
|
|
|
+ this.lootTable = new LootTableManager(new File(new File(this.saveHandler.getWorldDirectory(), "data"), "loot_tables"));
|
|
+ this.getWorldBorder().setCenter(this.worldInfo.getBorderCenterX(), this.worldInfo.getBorderCenterZ());
|
|
+ this.getWorldBorder().setDamageAmount(this.worldInfo.getBorderDamagePerBlock());
|
|
+ this.getWorldBorder().setDamageBuffer(this.worldInfo.getBorderSafeZone());
|
|
+ this.getWorldBorder().setWarningDistance(this.worldInfo.getBorderWarningDistance());
|
|
+ this.getWorldBorder().setWarningTime(this.worldInfo.getBorderWarningTime());
|
|
+
|
|
+ // CraftBukkit start
|
|
+ if (generator != null) {
|
|
+ getWorld().getPopulators().addAll(generator.getDefaultPopulators(getWorld()));
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
this.initCapabilities();
|
|
return this;
|
|
}
|
|
@@ -193,11 +219,15 @@
|
|
|
|
this.theProfiler.startSection("mobSpawner");
|
|
|
|
- if (this.getGameRules().getBoolean("doMobSpawning") && this.worldInfo.getTerrainType() != WorldType.DEBUG_WORLD)
|
|
+ long time = this.worldInfo.getWorldTotalTime();
|
|
+
|
|
+ if (this.getGameRules().getBoolean("doMobSpawning") && this.worldInfo.getTerrainType() != WorldType.DEBUG_WORLD && this.playerEntities.size() > 0)
|
|
{
|
|
- this.entitySpawner.findChunksForSpawning(this, this.spawnHostileMobs, this.spawnPeacefulMobs, this.worldInfo.getWorldTotalTime() % 400L == 0L);
|
|
+ this.timings.mobSpawn.startTiming();
|
|
+ this.entitySpawner.findChunksForSpawning(this, this.spawnHostileMobs && (this.ticksPerMonsterSpawns != 0 && time % this.ticksPerMonsterSpawns == 0L), this.spawnPeacefulMobs && (this.ticksPerAnimalSpawns != 0 && time % this.ticksPerAnimalSpawns == 0L), this.worldInfo.getWorldTotalTime() % 400L == 0L);
|
|
+ this.timings.mobSpawn.stopTiming();
|
|
}
|
|
-
|
|
+ this.timings.doChunkUnload.startTiming();
|
|
this.theProfiler.endStartSection("chunkSource");
|
|
this.chunkProvider.unloadQueuedChunks();
|
|
int j = this.calculateSkylightSubtracted(1.0F);
|
|
@@ -213,24 +243,39 @@
|
|
{
|
|
this.worldInfo.setWorldTime(this.worldInfo.getWorldTime() + 1L);
|
|
}
|
|
-
|
|
+ this.timings.doChunkUnload.stopTiming();
|
|
this.theProfiler.endStartSection("tickPending");
|
|
+ this.timings.doTickPending.startTiming();
|
|
this.tickUpdates(false);
|
|
+ this.timings.doTickPending.stopTiming();
|
|
this.theProfiler.endStartSection("tickBlocks");
|
|
+ this.timings.doTickTiles.startTiming();
|
|
this.updateBlocks();
|
|
+ this.timings.doTickTiles.stopTiming();
|
|
this.theProfiler.endStartSection("chunkMap");
|
|
+ this.timings.doChunkMap.startTiming();
|
|
this.thePlayerManager.tick();
|
|
+ this.timings.doChunkMap.stopTiming();
|
|
this.theProfiler.endStartSection("village");
|
|
+ this.timings.doVillages.startTiming();
|
|
this.villageCollectionObj.tick();
|
|
this.villageSiege.tick();
|
|
+ this.timings.doVillages.stopTiming();
|
|
this.theProfiler.endStartSection("portalForcer");
|
|
+ this.timings.doPortalForcer.startTiming();
|
|
this.worldTeleporter.removeStalePortalLocations(this.getTotalWorldTime());
|
|
for (Teleporter tele : customTeleporters)
|
|
{
|
|
tele.removeStalePortalLocations(getTotalWorldTime());
|
|
}
|
|
+ this.timings.doPortalForcer.stopTiming();
|
|
this.theProfiler.endSection();
|
|
+ this.timings.doSounds.startTiming();
|
|
this.sendQueuedBlockEvents();
|
|
+ this.timings.doSounds.stopTiming();
|
|
+ this.timings.doChunkGC.startTiming();
|
|
+ this.getWorld().processChunkGC(); // CraftBukkit
|
|
+ this.timings.doChunkGC.stopTiming();
|
|
}
|
|
|
|
@Nullable
|
|
@@ -341,7 +386,7 @@
|
|
this.worldInfo.setSpawnZ(j);
|
|
}
|
|
|
|
- protected boolean isChunkLoaded(int x, int z, boolean allowEmpty)
|
|
+ public boolean isChunkLoaded(int x, int z, boolean allowEmpty)
|
|
{
|
|
return this.getChunkProvider().chunkExists(x, z);
|
|
}
|
|
@@ -393,6 +438,7 @@
|
|
chunk.enqueueRelightChecks();
|
|
this.theProfiler.endStartSection("tickChunk");
|
|
chunk.onTick(false);
|
|
+ if (!chunk.areNeighborsLoaded(1)) continue; // Spigot
|
|
this.theProfiler.endStartSection("thunder");
|
|
|
|
if (this.provider.canDoLightning(chunk) && flag && flag1 && this.rand.nextInt(100000) == 0)
|
|
@@ -433,11 +479,30 @@
|
|
|
|
if (this.canBlockFreezeNoWater(blockpos2))
|
|
{
|
|
- this.setBlockState(blockpos2, Blocks.ICE.getDefaultState());
|
|
+ // CraftBukkit start
|
|
+ BlockState blockState = this.getWorld().getBlockAt(blockpos2.getX(), blockpos2.getY(), blockpos2.getZ()).getState();
|
|
+ blockState.setTypeId(Block.getIdFromBlock(Blocks.ICE));
|
|
+
|
|
+ BlockFormEvent iceBlockForm = new BlockFormEvent(blockState.getBlock(), blockState);
|
|
+ this.getServer().getPluginManager().callEvent(iceBlockForm);
|
|
+ if (!iceBlockForm.isCancelled()) {
|
|
+ blockState.update(true);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
if (flag && this.canSnowAt(blockpos1, true))
|
|
{
|
|
+ // CraftBukkit start
|
|
+ BlockState blockState = this.getWorld().getBlockAt(blockpos1.getX(), blockpos1.getY(), blockpos1.getZ()).getState();
|
|
+ blockState.setTypeId(Block.getIdFromBlock(Blocks.SNOW_LAYER));
|
|
+
|
|
+ BlockFormEvent snow = new BlockFormEvent(blockState.getBlock(), blockState);
|
|
+ this.getServer().getPluginManager().callEvent(snow);
|
|
+ if (!snow.isCancelled()) {
|
|
+ blockState.update(true);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
this.setBlockState(blockpos1, Blocks.SNOW_LAYER.getDefaultState());
|
|
}
|
|
|
|
@@ -618,6 +683,7 @@
|
|
|
|
this.provider.onWorldUpdateEntities();
|
|
super.updateEntities();
|
|
+ spigotConfig.currentPrimedTnt = 0; // Spigot
|
|
}
|
|
|
|
protected void tickPlayers()
|
|
@@ -852,7 +918,38 @@
|
|
protected IChunkProvider createChunkProvider()
|
|
{
|
|
IChunkLoader ichunkloader = this.saveHandler.getChunkLoader(this.provider);
|
|
- return new ChunkProviderServer(this, ichunkloader, this.provider.createChunkGenerator());
|
|
+ // Cauldron start - if provider is vanilla, proceed to create a bukkit compatible chunk generator
|
|
+ if (this.provider.getClass().toString().length() <= 3 || this.provider.getClass().toString().contains("net.minecraft"))
|
|
+ {
|
|
+ // CraftBukkit start
|
|
+ org.bukkit.craftbukkit.generator.InternalChunkGenerator gen;
|
|
+
|
|
+ if (this.generator != null)
|
|
+ {
|
|
+ gen = new org.bukkit.craftbukkit.generator.CustomChunkGenerator(this, this.getSeed(), this.generator);
|
|
+ }
|
|
+ else if (this.provider instanceof WorldProviderHell)
|
|
+ {
|
|
+ gen = new org.bukkit.craftbukkit.generator.NetherChunkGenerator(this, this.getSeed());
|
|
+ }
|
|
+ else if (this.provider instanceof WorldProviderEnd)
|
|
+ {
|
|
+ gen = new org.bukkit.craftbukkit.generator.SkyLandsChunkGenerator(this, this.getSeed());
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ gen = new org.bukkit.craftbukkit.generator.NormalChunkGenerator(this, this.getSeed());
|
|
+ }
|
|
+ this.chunkProvider = new ChunkProviderServer(this, ichunkloader, gen);
|
|
+ // CraftBukkit end
|
|
+ }
|
|
+ else
|
|
+ // custom provider, load normally for forge compatibility
|
|
+ {
|
|
+ this.chunkProvider = new ChunkProviderServer(this, ichunkloader, this.provider.createChunkGenerator());
|
|
+ }
|
|
+ // Cauldron end
|
|
+ return chunkProvider;
|
|
}
|
|
|
|
public boolean isBlockModifiable(EntityPlayer player, BlockPos pos)
|
|
@@ -998,6 +1095,7 @@
|
|
|
|
if (chunkproviderserver.canSave())
|
|
{
|
|
+ org.bukkit.Bukkit.getPluginManager().callEvent(new org.bukkit.event.world.WorldSaveEvent(getWorld())); // CraftBukkit
|
|
if (progressCallback != null)
|
|
{
|
|
progressCallback.displaySavingString("Saving level");
|
|
@@ -1012,9 +1110,10 @@
|
|
|
|
chunkproviderserver.saveChunks(p_73044_1_);
|
|
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.WorldEvent.Save(this));
|
|
-
|
|
- for (Chunk chunk : Lists.newArrayList(chunkproviderserver.getLoadedChunks()))
|
|
- {
|
|
+ Collection<Chunk> chunkList = chunkproviderserver.getLoadedChunks();
|
|
+ Iterator iterator = chunkList.iterator();
|
|
+ while (iterator.hasNext()){
|
|
+ Chunk chunk = (Chunk) iterator.next();
|
|
if (chunk != null && !this.thePlayerManager.contains(chunk.xPosition, chunk.zPosition))
|
|
{
|
|
chunkproviderserver.unload(chunk);
|
|
@@ -1033,7 +1132,7 @@
|
|
}
|
|
}
|
|
|
|
- protected void saveLevel() throws MinecraftException
|
|
+ public void saveLevel() throws MinecraftException
|
|
{
|
|
this.checkSessionLock();
|
|
|
|
@@ -1044,7 +1143,10 @@
|
|
((WorldServerMulti)worldserver).saveAdditionalData();
|
|
}
|
|
}
|
|
-
|
|
+ if (this instanceof WorldServerMulti)
|
|
+ {
|
|
+ ((WorldServerMulti)this).saveAdditionalData();
|
|
+ }
|
|
this.worldInfo.setBorderSize(this.getWorldBorder().getDiameter());
|
|
this.worldInfo.getBorderCenterX(this.getWorldBorder().getCenterX());
|
|
this.worldInfo.getBorderCenterZ(this.getWorldBorder().getCenterZ());
|
|
@@ -1147,9 +1249,17 @@
|
|
|
|
public boolean addWeatherEffect(Entity entityIn)
|
|
{
|
|
+ // CraftBukkit start
|
|
+ LightningStrikeEvent lightning = new LightningStrikeEvent(this.getWorld(), (org.bukkit.entity.LightningStrike) entityIn.getBukkitEntity());
|
|
+ this.getServer().getPluginManager().callEvent(lightning);
|
|
+
|
|
+ if (lightning.isCancelled()) {
|
|
+ return false;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
if (super.addWeatherEffect(entityIn))
|
|
{
|
|
- this.mcServer.getPlayerList().sendToAllNearExcept((EntityPlayer)null, entityIn.posX, entityIn.posY, entityIn.posZ, 512.0D, this.provider.getDimension(), new SPacketSpawnGlobalEntity(entityIn));
|
|
+ this.mcServer.getPlayerList().sendToAllNearExcept((EntityPlayer)null, entityIn.posX, entityIn.posY, entityIn.posZ, 512.0D, this.dimension, new SPacketSpawnGlobalEntity(entityIn)); // CraftBukkit - Use dimension
|
|
return true;
|
|
}
|
|
else
|
|
@@ -1180,6 +1290,10 @@
|
|
explosion.clearAffectedBlockPositions();
|
|
}
|
|
|
|
+ if (explosion.wasCanceled) {
|
|
+ return explosion;
|
|
+ }
|
|
+
|
|
for (EntityPlayer entityplayer : this.playerEntities)
|
|
{
|
|
if (entityplayer.getDistanceSq(x, y, z) < 4096.0D)
|
|
@@ -1304,12 +1418,25 @@
|
|
|
|
public void spawnParticle(EnumParticleTypes particleType, boolean longDistance, double xCoord, double yCoord, double zCoord, int numberOfParticles, double xOffset, double yOffset, double zOffset, double particleSpeed, int... particleArguments)
|
|
{
|
|
- SPacketParticles spacketparticles = new SPacketParticles(particleType, longDistance, (float)xCoord, (float)yCoord, (float)zCoord, (float)xOffset, (float)yOffset, (float)zOffset, (float)particleSpeed, numberOfParticles, particleArguments);
|
|
+ /*SPacketParticles spacketparticles = new SPacketParticles(particleType, longDistance, (float)xCoord, (float)yCoord, (float)zCoord, (float)xOffset, (float)yOffset, (float)zOffset, (float)particleSpeed, numberOfParticles, particleArguments);
|
|
|
|
for (int i = 0; i < this.playerEntities.size(); ++i)
|
|
{
|
|
EntityPlayerMP entityplayermp = (EntityPlayerMP)this.playerEntities.get(i);
|
|
this.sendPacketWithinDistance(entityplayermp, longDistance, xCoord, yCoord, zCoord, spacketparticles);
|
|
+ }*/
|
|
+ sendParticles(null, particleType, longDistance, xCoord, yCoord, zCoord, numberOfParticles, xOffset, yOffset, zOffset, particleSpeed, particleArguments);
|
|
+ }
|
|
+ // CraftBukkit
|
|
+ public void sendParticles(final EntityPlayerMP sender, final EnumParticleTypes enumparticle, final boolean flag, final double d0, final double d1, final double d2, final int i, final double d3, final double d4, final double d5, final double d6, final int... aint) {
|
|
+ final SPacketParticles packetplayoutworldparticles = new SPacketParticles(enumparticle, flag, (float)d0, (float)d1, (float)d2, (float)d3, (float)d4, (float)d5, (float)d6, i, aint);
|
|
+ for (int j = 0; j < this.playerEntities.size(); ++j) {
|
|
+ final EntityPlayerMP entityplayer = (EntityPlayerMP) this.playerEntities.get(j);
|
|
+ if (sender == null || entityplayer.getBukkitEntity().canSee(sender.getBukkitEntity())) {
|
|
+ //final BlockPos blockposition = entityplayer.getPosition();
|
|
+ //blockposition.distanceSq(d0, d1, d2);
|
|
+ this.sendPacketWithinDistance(entityplayer, flag, d0, d1, d2, packetplayoutworldparticles);
|
|
+ }
|
|
}
|
|
}
|
|
|