下面列出了怎么用org.bukkit.event.world.WorldLoadEvent的API类实例代码及写法,或者点击链接到github查看源代码。
@EventHandler
public void onWorldLoad(WorldLoadEvent e) {
if (!cc.getBrokeCrateLocations().isEmpty()) {
int fixedAmount = 0;
List<BrokeLocation> fixedWorlds = new ArrayList<>();
for (BrokeLocation brokeLocation : cc.getBrokeCrateLocations()) {
Location location = brokeLocation.getLocation();
if (location.getWorld() != null) {
cc.getCrateLocations().add(new CrateLocation(brokeLocation.getLocationName(), brokeLocation.getCrate(), location));
fixedWorlds.add(brokeLocation);
fixedAmount++;
}
}
cc.getBrokeCrateLocations().removeAll(fixedWorlds);
if (fileManager.isLogging()) {
System.out.println(fileManager.getPrefix() + "Fixed " + fixedAmount + " broken crate locations.");
if (cc.getBrokeCrateLocations().isEmpty()) {
System.out.println(fileManager.getPrefix() + "All broken crate locations have been fixed.");
}
}
}
}
@EventHandler()
public void onWorldLoad(WorldLoadEvent evt) {
//Add populator on world load
World world = evt.getWorld();
if (
plugin.getConfig().getStringList("options.worlds").contains(world.getName()) && (
!world.getPopulators().contains(dioritePopulator)
&& !world.getPopulators().contains(andesitePopulator)
&& !world.getPopulators().contains(granitePopulator)
)
) {
Carbon.log.log(Level.INFO, "[Carbon] Editing world: {0}", world.getName());
Carbon.log.log(Level.INFO, "[Carbon] Adding populator for world: {0}", world.getName());
world.getPopulators().add(dioritePopulator);
world.getPopulators().add(andesitePopulator);
world.getPopulators().add(granitePopulator);
Carbon.log.log(Level.INFO, "[Carbon] Done editing world: {0}", world.getName());
}
}
@EventHandler
public void warnRandomTickRate(WorldLoadEvent event) {
String str = event.getWorld().getGameRuleValue("randomTickSpeed");
if (str != null) {
int value = Integer.parseInt(str);
if (value > RANDOM_TICK_SPEED_LIMIT) {
broadcastDeveloperWarning(
"Gamerule 'randomTickSpeed' is set to "
+ value
+ " for this world (normal value is 3). This may overload the server.");
}
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onWorldLoad(WorldLoadEvent e) {
if (!UChat.get().getConfig().contains("general.default-channels.worlds." + e.getWorld().getName())) {
UChat.get().getConfig().set("general.default-channels.worlds." + e.getWorld().getName() + ".channel", UChat.get().getConfig().contains("general.default-channels.default-channel"));
UChat.get().getConfig().set("general.default-channels.worlds." + e.getWorld().getName() + ".force", false);
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onWorldLoadEvent(WorldLoadEvent event)
{
World world = event.getWorld();
this.plugin.getWorldGuardCommunicator().doUnloadChunkFlagCheck(world);
}
@EventHandler
public void onWorldLoad(WorldLoadEvent event) {
ValidWorldsConfig validWorldsConfig = new ValidWorldsConfig();
validWorldsConfig.initializeConfig();
ConfigValues.validWorldsConfig = validWorldsConfig.configuration;
if (event.getWorld().getName().equals(ConfigValues.adventurersGuildConfig.getString(AdventurersGuildConfig.GUILD_WORLD_NAME))) {
NPCInitializer npcInitializer = new NPCInitializer();
}
}
@EventHandler
public void onWorldLoad(WorldLoadEvent event) {
World world = event.getWorld();
for (Entry<UnloadedProtection, String> entry : new HashSet<>(plugin.getGlobalProtectionCache().getUnloadedProtections().entrySet())) {
if (world.getName().equals(entry.getValue())) {
entry.getKey().load(world);
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onWorldLoad(WorldLoadEvent e) {
World w = e.getWorld();
try {
RedProtect.get().rm.load(w.getName());
// RedProtect.get().config.addWorldProperties(w);
RedProtect.get().reloadConfigs();
RedProtect.get().logger.warning("World loaded: " + w.getName());
} catch (Exception ex) {
RedProtect.get().logger.severe("RedProtect problem on load world:");
ex.printStackTrace();
}
}
@EventHandler
public void on(WorldLoadEvent event) {
final World world = event.getWorld();
if (worlds.worldMatches(world)) {
world.setPVP(isEnabled());
}
}
@EventHandler
public void on(WorldLoadEvent event) {
if (isEnabled()) {
if (worlds.worldMatches(event.getWorld())) {
event.getWorld().setDifficulty(Difficulty.HARD);
}
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onWorldLoad(WorldLoadEvent event) {
for (Map.Entry<String, String> entry : new HashMap<>(UNLOADED_HOLOGRAMS).entrySet()) {
if (entry.getValue().equals(event.getWorld().getName())) {
HoloAPI.LOG.info("Loading hologram " + entry.getKey() + " into world " + entry.getValue() + ".");
if (((SimpleHoloManager) HoloAPI.getManager()).loadFromFile(entry.getKey()) != null) {
UNLOADED_HOLOGRAMS.remove(entry.getKey());
}
}
}
}
@Override
public World createWorld(WorldCreator creator) {
Validate.notNull(creator, "Creator may not be null");
String name = creator.name();
ChunkGenerator generator = creator.generator();
File folder = new File(getWorldContainer(), name);
World world = getWorld(name);
WorldType type = WorldType.parseWorldType(creator.type().getName());
boolean generateStructures = creator.generateStructures();
if ((folder.exists()) && (!folder.isDirectory())) {
throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder");
}
if (world != null) {
return world;
}
boolean hardcore = false;
WorldSettings worldSettings = new WorldSettings(creator.seed(), WorldSettings.getGameTypeById(getDefaultGameMode().getValue()), generateStructures, hardcore, type);
WorldServer internal = DimensionManager.initDimension(creator, worldSettings);
pluginManager.callEvent(new WorldInitEvent(internal.getWorld()));
System.out.println("Preparing start region for level " + (console.worldServerList.size() - 1) + " (Seed: " + internal.getSeed() + ")");
if (internal.getWorld().getKeepSpawnInMemory()) {
short short1 = 196;
long i = System.currentTimeMillis();
for (int j = -short1; j <= short1; j += 16) {
for (int k = -short1; k <= short1; k += 16) {
long l = System.currentTimeMillis();
if (l < i) {
i = l;
}
if (l > i + 1000L) {
int i1 = (short1 * 2 + 1) * (short1 * 2 + 1);
int j1 = (j + short1) * (short1 * 2 + 1) + k + 1;
System.out.println("Preparing spawn area for " + name + ", " + (j1 * 100 / i1) + "%");
i = l;
}
BlockPos chunkcoordinates = internal.getSpawnPoint();
internal.getChunkProvider().loadChunk(chunkcoordinates.getX() + j >> 4, chunkcoordinates.getZ() + k >> 4);
}
}
}
pluginManager.callEvent(new WorldLoadEvent(internal.getWorld()));
return internal.getWorld();
}
@EventHandler(ignoreCancelled = true)
public void onWorldLoad(WorldLoadEvent loadEvent) {
gw.getLogger().info("Detected world load after GW enabled, triggering automatic climate engine load.");
ClimateEngine.getInstance().loadWorldClimateEngine(loadEvent.getWorld());
}
@EventHandler
public void onCreateWorld(WorldLoadEvent e) {
UChat.get().reload();
}
@EventHandler
public void onWorldLoad(WorldLoadEvent worldLoadEvent) {
checkSafety(worldLoadEvent);
}
@Override
public World createWorld(WorldCreator creator) {
Validate.notNull(creator, "Creator may not be null");
String name = creator.name();
ChunkGenerator generator = creator.generator();
File folder = new File(getWorldContainer(), name);
World world = getWorld(name);
net.minecraft.world.WorldType type = net.minecraft.world.WorldType.parseWorldType(creator.type().getName());
boolean generateStructures = creator.generateStructures();
if ((folder.exists()) && (!folder.isDirectory())) {
throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder");
}
if (world != null) {
return world;
}
boolean hardcore = false;
WorldSettings worldSettings = new WorldSettings(creator.seed(), net.minecraft.world.WorldSettings.GameType.getByID(getDefaultGameMode().getValue()), generateStructures, hardcore, type);
net.minecraft.world.WorldServer worldserver = DimensionManager.initDimension(creator, worldSettings);
pluginManager.callEvent(new WorldInitEvent(worldserver.getWorld()));
net.minecraftforge.cauldron.CauldronHooks.craftWorldLoading = true;
System.out.print("Preparing start region for level " + (console.worlds.size() - 1) + " (Dimension: " + worldserver.provider.dimensionId + ", Seed: " + worldserver.getSeed() + ")"); // Cauldron - log dimension
if (worldserver.getWorld().getKeepSpawnInMemory()) {
short short1 = 196;
long i = System.currentTimeMillis();
for (int j = -short1; j <= short1; j += 16) {
for (int k = -short1; k <= short1; k += 16) {
long l = System.currentTimeMillis();
if (l < i) {
i = l;
}
if (l > i + 1000L) {
int i1 = (short1 * 2 + 1) * (short1 * 2 + 1);
int j1 = (j + short1) * (short1 * 2 + 1) + k + 1;
System.out.println("Preparing spawn area for " + worldserver.getWorld().getName() + ", " + (j1 * 100 / i1) + "%");
i = l;
}
net.minecraft.util.ChunkCoordinates chunkcoordinates = worldserver.getSpawnPoint();
worldserver.theChunkProviderServer.loadChunk(chunkcoordinates.posX + j >> 4, chunkcoordinates.posZ + k >> 4);
}
}
}
pluginManager.callEvent(new WorldLoadEvent(worldserver.getWorld()));
net.minecraftforge.cauldron.CauldronHooks.craftWorldLoading = false;
return worldserver.getWorld();
}
@EventHandler
public void on(WorldLoadEvent event) {
event.getWorld().setGameRuleValue(GAME_RULE, isEnabled() ? "true" : "false");
}
@EventHandler
public void onWorldLoad(WorldLoadEvent worldLoadEvent) {
checkSafety(worldLoadEvent);
}
@EventHandler
public void onWorldLoad(WorldLoadEvent e) {
SlimefunPlugin.getWorldSettingsService().load(e.getWorld());
BlockStorage.getForcedStorage(e.getWorld());
}
@EventHandler(priority = EventPriority.LOWEST)
void onWorldLoad(WorldLoadEvent event) {
plugin.loadShopkeepersInWorld(event.getWorld());
}