mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-02 17:32:03 +01:00
Added events related to weather in 1.5. Thanks wizjany!
By: EvilSeph <evilseph@unaligned.org>
This commit is contained in:
parent
18394a8207
commit
2980396ae5
3 changed files with 55 additions and 23 deletions
|
@ -11,6 +11,8 @@ import java.util.Random;
|
|||
import net.minecraft.server.*;
|
||||
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||
import org.bukkit.event.weather.ThunderChangeEvent;
|
||||
import org.bukkit.event.world.SpawnChangeEvent;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Boat;
|
||||
|
@ -121,16 +123,16 @@ public class CraftWorld implements World {
|
|||
public boolean unloadChunk(int x, int z, boolean save) {
|
||||
return unloadChunk(x, z, save, false);
|
||||
}
|
||||
|
||||
|
||||
public boolean unloadChunkRequest(int x, int z) {
|
||||
return unloadChunkRequest(x, z, true);
|
||||
}
|
||||
|
||||
|
||||
public boolean unloadChunkRequest(int x, int z, boolean safe) {
|
||||
if (safe && isChunkInUse(x, z)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
provider.queueUnload(x, z);
|
||||
|
||||
return true;
|
||||
|
@ -554,13 +556,19 @@ public class CraftWorld implements World {
|
|||
}
|
||||
|
||||
public void setStorm(boolean hasStorm) {
|
||||
world.worldData.b(hasStorm);
|
||||
|
||||
// These numbers are from Minecraft
|
||||
if (hasStorm) {
|
||||
setWeatherDuration(rand.nextInt(12000) + 12000);
|
||||
} else {
|
||||
setWeatherDuration(rand.nextInt(168000) + 12000);
|
||||
CraftServer server = world.getServer();
|
||||
|
||||
WeatherChangeEvent weather = new WeatherChangeEvent((org.bukkit.World) this, hasStorm);
|
||||
server.getPluginManager().callEvent(weather);
|
||||
if (!weather.isCancelled()) {
|
||||
world.worldData.b(hasStorm);
|
||||
|
||||
// These numbers are from Minecraft
|
||||
if (hasStorm) {
|
||||
setWeatherDuration(rand.nextInt(12000) + 12000);
|
||||
} else {
|
||||
setWeatherDuration(rand.nextInt(168000) + 12000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -577,22 +585,28 @@ public class CraftWorld implements World {
|
|||
}
|
||||
|
||||
public void setThundering(boolean thundering) {
|
||||
world.worldData.a(thundering);
|
||||
|
||||
// These numbers are from Minecraft
|
||||
if (thundering) {
|
||||
setThunderDuration(rand.nextInt(12000) + 3600);
|
||||
} else {
|
||||
setThunderDuration(rand.nextInt(168000) + 12000);
|
||||
CraftServer server = world.getServer();
|
||||
|
||||
ThunderChangeEvent thunder = new ThunderChangeEvent((org.bukkit.World) this, thundering);
|
||||
server.getPluginManager().callEvent(thunder);
|
||||
if (!thunder.isCancelled()) {
|
||||
world.worldData.a(thundering);
|
||||
|
||||
// These numbers are from Minecraft
|
||||
if (thundering) {
|
||||
setThunderDuration(rand.nextInt(12000) + 3600);
|
||||
} else {
|
||||
setThunderDuration(rand.nextInt(168000) + 12000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getThunderDuration() {
|
||||
return world.worldData.k();
|
||||
}
|
||||
|
||||
public void setThunderDuration(int duration) {
|
||||
world.worldData.b(duration);
|
||||
world.worldData.b(duration);
|
||||
}
|
||||
|
||||
public long getSeed() {
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import net.minecraft.server.EntityCreeper;
|
||||
import net.minecraft.server.WorldServer;
|
||||
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.event.entity.CreeperPowerEvent;
|
||||
|
||||
public class CraftCreeper extends CraftMonster implements Creeper {
|
||||
|
||||
|
@ -20,11 +23,28 @@ public class CraftCreeper extends CraftMonster implements Creeper {
|
|||
}
|
||||
|
||||
public void setPowered(boolean powered) {
|
||||
// CraftBukkit start
|
||||
CraftServer server = this.server;
|
||||
org.bukkit.entity.Entity entity = this.getHandle().getBukkitEntity();
|
||||
|
||||
if (powered) {
|
||||
getHandle().W().b(17, (byte)1);
|
||||
CreeperPowerEvent event = new CreeperPowerEvent(entity, CreeperPowerEvent.PowerCause.SET_ON);
|
||||
server.getPluginManager().callEvent(event);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
getHandle().W().b(17, (byte)1);
|
||||
}
|
||||
} else {
|
||||
getHandle().W().b(17, (byte)0);
|
||||
CreeperPowerEvent event = new CreeperPowerEvent(entity, CreeperPowerEvent.PowerCause.SET_OFF);
|
||||
server.getPluginManager().callEvent(event);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
getHandle().W().b(17, (byte)0);
|
||||
}
|
||||
}
|
||||
|
||||
// CraftBukkit end
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import net.minecraft.server.EntityPig;
|
||||
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftAnimals;
|
||||
import org.bukkit.entity.Pig;
|
||||
|
||||
public class CraftPig extends CraftAnimals implements Pig {
|
||||
|
|
Loading…
Reference in a new issue