mirror of
https://github.com/array-in-a-matrix/brainwine.git
synced 2025-04-02 11:11:58 -04:00
Add commands for zone time, weather and acidity
This commit is contained in:
parent
6ed5948818
commit
dce8304c68
6 changed files with 215 additions and 0 deletions
|
@ -13,6 +13,7 @@ import java.util.Set;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import brainwine.gameserver.command.commands.AcidityCommand;
|
||||
import brainwine.gameserver.command.commands.AdminCommand;
|
||||
import brainwine.gameserver.command.commands.BanCommand;
|
||||
import brainwine.gameserver.command.commands.BroadcastCommand;
|
||||
|
@ -39,8 +40,10 @@ import brainwine.gameserver.command.commands.SkillPointsCommand;
|
|||
import brainwine.gameserver.command.commands.StopCommand;
|
||||
import brainwine.gameserver.command.commands.TeleportCommand;
|
||||
import brainwine.gameserver.command.commands.ThinkCommand;
|
||||
import brainwine.gameserver.command.commands.TimeCommand;
|
||||
import brainwine.gameserver.command.commands.UnbanCommand;
|
||||
import brainwine.gameserver.command.commands.UnmuteCommand;
|
||||
import brainwine.gameserver.command.commands.WeatherCommand;
|
||||
import brainwine.gameserver.command.commands.ZoneIdCommand;
|
||||
import brainwine.gameserver.entity.player.Player;
|
||||
|
||||
|
@ -93,6 +96,9 @@ public class CommandManager {
|
|||
registerCommand(new LevelCommand());
|
||||
registerCommand(new SkillPointsCommand());
|
||||
registerCommand(new SettleLiquidsCommand());
|
||||
registerCommand(new WeatherCommand());
|
||||
registerCommand(new AcidityCommand());
|
||||
registerCommand(new TimeCommand());
|
||||
}
|
||||
|
||||
public static void executeCommand(CommandExecutor executor, String commandLine) {
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package brainwine.gameserver.command.commands;
|
||||
|
||||
import static brainwine.gameserver.entity.player.NotificationType.SYSTEM;
|
||||
|
||||
import brainwine.gameserver.command.Command;
|
||||
import brainwine.gameserver.command.CommandExecutor;
|
||||
import brainwine.gameserver.entity.player.Player;
|
||||
import brainwine.gameserver.zone.Zone;
|
||||
|
||||
public class AcidityCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void execute(CommandExecutor executor, String[] args) {
|
||||
Zone zone = ((Player)executor).getZone();
|
||||
|
||||
if(args.length < 1) {
|
||||
executor.notify(String.format("The current acidity of %s is %s", zone.getName(), zone.getAcidity()), SYSTEM);
|
||||
return;
|
||||
}
|
||||
|
||||
float value = 0.0f;
|
||||
|
||||
try {
|
||||
value = Float.parseFloat(args[0]);
|
||||
} catch(NumberFormatException e) {
|
||||
executor.notify("Acidity must be a number between 0.0 and 1.0", SYSTEM);
|
||||
return;
|
||||
}
|
||||
|
||||
if(value < 0.0f || value > 1.0f) {
|
||||
executor.notify("Acidity must be a number between 0.0 and 1.0", SYSTEM);
|
||||
return;
|
||||
}
|
||||
|
||||
zone.setAcidity(value);
|
||||
executor.notify(String.format("Acidity has been set to %s in %s.", value, zone.getName()), SYSTEM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "acidity";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Displays or changes the acidity in the current zone.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(CommandExecutor executor) {
|
||||
return "/acidity [value]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecute(CommandExecutor executor) {
|
||||
return executor.isAdmin() && executor instanceof Player;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package brainwine.gameserver.command.commands;
|
||||
|
||||
import static brainwine.gameserver.entity.player.NotificationType.SYSTEM;
|
||||
|
||||
import brainwine.gameserver.command.Command;
|
||||
import brainwine.gameserver.command.CommandExecutor;
|
||||
import brainwine.gameserver.entity.player.Player;
|
||||
import brainwine.gameserver.zone.Zone;
|
||||
|
||||
public class TimeCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void execute(CommandExecutor executor, String[] args) {
|
||||
Zone zone = ((Player)executor).getZone();
|
||||
|
||||
if(args.length < 1) {
|
||||
executor.notify(String.format("The current time in %s is %s", zone.getName(), zone.getTime()), SYSTEM);
|
||||
return;
|
||||
}
|
||||
|
||||
String time = args[0].toLowerCase();
|
||||
float value = 0.0f;
|
||||
|
||||
switch(time) {
|
||||
case "day": value = 0.5f; break;
|
||||
case "night": value = 0.0f; break;
|
||||
case "dawn": value = 0.25f; break;
|
||||
case "dusk": value = 0.75f; break;
|
||||
default:
|
||||
try {
|
||||
value = Float.parseFloat(time);
|
||||
} catch(NumberFormatException e) {
|
||||
executor.notify("Time must be day, night, dawn, dusk or a number between 0.0 and 1.0", SYSTEM);
|
||||
return;
|
||||
}
|
||||
|
||||
if(value < 0.0f || value > 1.0f) {
|
||||
executor.notify("Time must be a number between 0.0 and 1.0", SYSTEM);
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
zone.setTime(value);
|
||||
executor.notify(String.format("Time has been set to %s in %s.", value, zone.getName()), SYSTEM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "time";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Displays or changes the time in the current zone.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(CommandExecutor executor) {
|
||||
return "/time [value|(day|night|dawn|dusk)]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecute(CommandExecutor executor) {
|
||||
return executor.isAdmin() && executor instanceof Player;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package brainwine.gameserver.command.commands;
|
||||
|
||||
import static brainwine.gameserver.entity.player.NotificationType.SYSTEM;
|
||||
|
||||
import brainwine.gameserver.command.Command;
|
||||
import brainwine.gameserver.command.CommandExecutor;
|
||||
import brainwine.gameserver.entity.player.Player;
|
||||
import brainwine.gameserver.zone.Biome;
|
||||
import brainwine.gameserver.zone.WeatherManager;
|
||||
import brainwine.gameserver.zone.Zone;
|
||||
|
||||
public class WeatherCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void execute(CommandExecutor executor, String[] args) {
|
||||
Zone zone = ((Player)executor).getZone();
|
||||
WeatherManager weatherManager = zone.getWeatherManager();
|
||||
|
||||
if(args.length < 1) {
|
||||
if(weatherManager.isRaining()) {
|
||||
String rainString = zone.getBiome() == Biome.ARCTIC ? "snowing" : zone.getBiome() == Biome.HELL ? "raining ash" : "raining";
|
||||
executor.notify(String.format("It is currently %s in %s with an intensity of %s",
|
||||
rainString, zone.getName(), weatherManager.getPrecipitation()), SYSTEM);
|
||||
} else {
|
||||
executor.notify(String.format("It is currently dry in %s.", zone.getName()), SYSTEM);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
boolean dry = args[0].equalsIgnoreCase("clear");
|
||||
zone.getWeatherManager().createRandomRain(dry);
|
||||
executor.notify(String.format("Weather has been %s in %s.", dry ? "cleared" : "made rainy", zone.getName()), SYSTEM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "weather";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Displays or changes the weather in the current zone.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(CommandExecutor executor) {
|
||||
return "/weather [clear|rain]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecute(CommandExecutor executor) {
|
||||
return executor.isAdmin() && executor instanceof Player;
|
||||
}
|
||||
}
|
|
@ -47,6 +47,22 @@ public class WeatherManager {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isRaining() {
|
||||
return rainPower > 0;
|
||||
}
|
||||
|
||||
public long getRainStart() {
|
||||
return rainStart;
|
||||
}
|
||||
|
||||
public long getRainDuration() {
|
||||
return rainDuration;
|
||||
}
|
||||
|
||||
public float getRainPower() {
|
||||
return rainPower;
|
||||
}
|
||||
|
||||
public float getPrecipitation() {
|
||||
return precipitation;
|
||||
}
|
||||
|
|
|
@ -1068,6 +1068,10 @@ public class Zone {
|
|||
return chunkManager;
|
||||
}
|
||||
|
||||
public WeatherManager getWeatherManager() {
|
||||
return weatherManager;
|
||||
}
|
||||
|
||||
public void setSurface(int x, int surface) {
|
||||
if(areCoordinatesInBounds(x, surface)) {
|
||||
this.surface[x] = surface;
|
||||
|
@ -1237,6 +1241,14 @@ public class Zone {
|
|||
return numChunksWidth * numChunksHeight;
|
||||
}
|
||||
|
||||
public void setTime(float time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public float getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setAcidity(float acidity) {
|
||||
this.acidity = acidity;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue