mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-16 20:41:59 +01:00
Add ability to disable weather per world.
This commit is contained in:
parent
9b9bbb4091
commit
ff89bda57e
@ -96,6 +96,7 @@ public class MVWorld {
|
|||||||
private Permission exempt;
|
private Permission exempt;
|
||||||
|
|
||||||
private boolean canSave = false; // Prevents all the setters from constantly saving to the config when being called from the constructor.
|
private boolean canSave = false; // Prevents all the setters from constantly saving to the config when being called from the constructor.
|
||||||
|
private boolean allowWeather;
|
||||||
|
|
||||||
public MVWorld(World world, Configuration config, MultiverseCore instance, Long seed, String generatorString) {
|
public MVWorld(World world, Configuration config, MultiverseCore instance, Long seed, String generatorString) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
@ -126,6 +127,7 @@ public class MVWorld {
|
|||||||
this.setPvp(config.getBoolean("worlds." + this.name + ".pvp", true));
|
this.setPvp(config.getBoolean("worlds." + this.name + ".pvp", true));
|
||||||
this.setScaling(config.getDouble("worlds." + this.name + ".scale", 1.0));
|
this.setScaling(config.getDouble("worlds." + this.name + ".scale", 1.0));
|
||||||
this.setRespawnToWorld(config.getString("worlds." + this.name + ".respawnworld", ""));
|
this.setRespawnToWorld(config.getString("worlds." + this.name + ".respawnworld", ""));
|
||||||
|
this.setEnableWeather(config.getBoolean("worlds." + this.name + ".allowweather", true));
|
||||||
|
|
||||||
this.setAnimals(config.getBoolean("worlds." + this.name + ".animals.spawn", true));
|
this.setAnimals(config.getBoolean("worlds." + this.name + ".animals.spawn", true));
|
||||||
this.setMonsters(config.getBoolean("worlds." + this.name + ".monsters.spawn", true));
|
this.setMonsters(config.getBoolean("worlds." + this.name + ".monsters.spawn", true));
|
||||||
@ -152,6 +154,17 @@ public class MVWorld {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setEnableWeather(boolean weather) {
|
||||||
|
this.allowWeather = weather;
|
||||||
|
// Disable any current weather
|
||||||
|
if (!weather) {
|
||||||
|
this.getCBWorld().setStorm(false);
|
||||||
|
this.getCBWorld().setThundering(false);
|
||||||
|
}
|
||||||
|
this.config.setProperty("worlds." + this.name + ".allowweather", weather);
|
||||||
|
saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
private void addToUpperLists(Permission permission) {
|
private void addToUpperLists(Permission permission) {
|
||||||
Permission all = this.plugin.getServer().getPluginManager().getPermission("multiverse.*");
|
Permission all = this.plugin.getServer().getPluginManager().getPermission("multiverse.*");
|
||||||
Permission allWorlds = this.plugin.getServer().getPluginManager().getPermission("multiverse.access.*");
|
Permission allWorlds = this.plugin.getServer().getPluginManager().getPermission("multiverse.access.*");
|
||||||
@ -347,8 +360,10 @@ public class MVWorld {
|
|||||||
this.setMonsters(value);
|
this.setMonsters(value);
|
||||||
} else if (name.equalsIgnoreCase("memory") || name.equalsIgnoreCase("spawnmemory")) {
|
} else if (name.equalsIgnoreCase("memory") || name.equalsIgnoreCase("spawnmemory")) {
|
||||||
this.setSpawnInMemory(value);
|
this.setSpawnInMemory(value);
|
||||||
|
} else if (name.equalsIgnoreCase("weather") || name.equalsIgnoreCase("storm")) {
|
||||||
|
this.setEnableWeather(value);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -375,7 +390,7 @@ public class MVWorld {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the one people have access to. It'll handle the rest.
|
* This is the one people have access to. It'll handle the rest.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* @param value
|
* @param value
|
||||||
* @return
|
* @return
|
||||||
@ -532,7 +547,7 @@ public class MVWorld {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the chat color from a string.
|
* Sets the chat color from a string.
|
||||||
*
|
*
|
||||||
* @param aliasColor
|
* @param aliasColor
|
||||||
*/
|
*/
|
||||||
public void setAliasColor(String aliasColor) {
|
public void setAliasColor(String aliasColor) {
|
||||||
@ -622,4 +637,8 @@ public class MVWorld {
|
|||||||
this.config.save();
|
this.config.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getWeatherEnabled() {
|
||||||
|
return this.allowWeather;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.Event.Priority;
|
import org.bukkit.event.Event.Priority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
import org.bukkit.permissions.Permission;
|
import org.bukkit.permissions.Permission;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
@ -62,6 +63,7 @@ import com.onarandombox.MultiverseCore.configuration.MVCoreConfigMigrator;
|
|||||||
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
|
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
|
||||||
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
|
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
|
||||||
import com.onarandombox.MultiverseCore.listeners.MVPluginListener;
|
import com.onarandombox.MultiverseCore.listeners.MVPluginListener;
|
||||||
|
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
|
||||||
import com.onarandombox.utils.DebugLog;
|
import com.onarandombox.utils.DebugLog;
|
||||||
import com.onarandombox.utils.DestinationFactory;
|
import com.onarandombox.utils.DestinationFactory;
|
||||||
import com.onarandombox.utils.ExactDestination;
|
import com.onarandombox.utils.ExactDestination;
|
||||||
@ -98,6 +100,7 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
|
|||||||
|
|
||||||
private MVEntityListener entityListener = new MVEntityListener(this);
|
private MVEntityListener entityListener = new MVEntityListener(this);
|
||||||
private MVPluginListener pluginListener = new MVPluginListener(this);
|
private MVPluginListener pluginListener = new MVPluginListener(this);
|
||||||
|
private MVWeatherListener weatherListener = new MVWeatherListener(this);
|
||||||
|
|
||||||
public UpdateChecker updateCheck;
|
public UpdateChecker updateCheck;
|
||||||
|
|
||||||
@ -112,6 +115,7 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
|
|||||||
protected MVConfigMigrator migrator = new MVCoreConfigMigrator(this);
|
protected MVConfigMigrator migrator = new MVCoreConfigMigrator(this);
|
||||||
protected int pluginCount;
|
protected int pluginCount;
|
||||||
private DestinationFactory destFactory;
|
private DestinationFactory destFactory;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
@ -193,6 +197,10 @@ public class MultiverseCore extends JavaPlugin implements LoggablePlugin {
|
|||||||
|
|
||||||
pm.registerEvent(Event.Type.PLUGIN_ENABLE, this.pluginListener, Priority.Monitor, this);
|
pm.registerEvent(Event.Type.PLUGIN_ENABLE, this.pluginListener, Priority.Monitor, this);
|
||||||
pm.registerEvent(Event.Type.PLUGIN_DISABLE, this.pluginListener, Priority.Monitor, this);
|
pm.registerEvent(Event.Type.PLUGIN_DISABLE, this.pluginListener, Priority.Monitor, this);
|
||||||
|
|
||||||
|
pm.registerEvent(Event.Type.WEATHER_CHANGE, this.weatherListener, Priority.Normal, this);
|
||||||
|
pm.registerEvent(Event.Type.THUNDER_CHANGE, this.weatherListener, Priority.Normal, this);
|
||||||
|
pm.registerEvent(Event.Type.LIGHTNING_STRIKE, this.weatherListener, Priority.Normal, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,12 +101,12 @@ public class InfoCommand extends MultiverseCommand {
|
|||||||
|
|
||||||
if (world.getRespawnToWorld() != null) {
|
if (world.getRespawnToWorld() != null) {
|
||||||
MVWorld respawn = this.plugin.getMVWorld(world.getRespawnToWorld());
|
MVWorld respawn = this.plugin.getMVWorld(world.getRespawnToWorld());
|
||||||
if(respawn != null) {
|
if (respawn != null) {
|
||||||
message.add(new FancyMessage("Players will respawn in: ", respawn.getColoredWorldString(), colors));
|
message.add(new FancyMessage("Players will respawn in: ", respawn.getColoredWorldString(), colors));
|
||||||
} else {
|
} else {
|
||||||
message.add(new FancyMessage("Players will respawn in: ", ChatColor.RED + "!!INVALID!!", colors));
|
message.add(new FancyMessage("Players will respawn in: ", ChatColor.RED + "!!INVALID!!", colors));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
worldInfo.add(message);
|
worldInfo.add(message);
|
||||||
|
@ -21,7 +21,7 @@ enum Action {
|
|||||||
|
|
||||||
// Color == Aliascolor
|
// Color == Aliascolor
|
||||||
enum SetProperties {
|
enum SetProperties {
|
||||||
alias, animals, monsters, pvp, scaling, aliascolor, color, respawn, currency, curr, price, scale, spawnmemory, memory
|
alias, animals, monsters, pvp, scaling, aliascolor, color, respawn, currency, curr, price, scale, spawnmemory, memory, weather, storm
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ModifyCommand extends MultiverseCommand {
|
public class ModifyCommand extends MultiverseCommand {
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
package com.onarandombox.MultiverseCore.listeners;
|
||||||
|
|
||||||
|
import org.bukkit.event.weather.LightningStrikeEvent;
|
||||||
|
import org.bukkit.event.weather.ThunderChangeEvent;
|
||||||
|
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||||
|
import org.bukkit.event.weather.WeatherListener;
|
||||||
|
|
||||||
|
import com.onarandombox.MultiverseCore.MVWorld;
|
||||||
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
|
|
||||||
|
public class MVWeatherListener extends WeatherListener {
|
||||||
|
private MultiverseCore plugin;
|
||||||
|
|
||||||
|
public MVWeatherListener(MultiverseCore plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onWeatherChange(WeatherChangeEvent event) {
|
||||||
|
|
||||||
|
MVWorld world = this.plugin.getMVWorld(event.getWorld().getName());
|
||||||
|
if (world != null) {
|
||||||
|
// If it's going to start raining and we have weather disabled
|
||||||
|
event.setCancelled((event.toWeatherState() && !world.getWeatherEnabled()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onThunderChange(ThunderChangeEvent event) {
|
||||||
|
|
||||||
|
MVWorld world = this.plugin.getMVWorld(event.getWorld().getName());
|
||||||
|
if (world != null) {
|
||||||
|
// If it's going to start raining and we have weather disabled
|
||||||
|
event.setCancelled((event.toThunderState() && !world.getWeatherEnabled()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightningStrike(LightningStrikeEvent event) {
|
||||||
|
MVWorld world = this.plugin.getMVWorld(event.getWorld().getName());
|
||||||
|
if (world != null) {
|
||||||
|
// If it's going to start raining and we have weather disabled
|
||||||
|
event.setCancelled((!world.getWeatherEnabled()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user