add a command and things
school is finally coming to an end so I'll try to make bigger changes
This commit is contained in:
parent
cca6788b4d
commit
8abb6cff93
15 changed files with 123 additions and 39 deletions
2
pom.xml
2
pom.xml
|
@ -30,7 +30,7 @@
|
|||
<dependency>
|
||||
<groupId>eu.m724</groupId>
|
||||
<artifactId>wtapi</artifactId>
|
||||
<version>0.4</version>
|
||||
<version>0.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -3,7 +3,9 @@ package eu.m724.realweather;
|
|||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import eu.m724.realweather.mapper.Mapper;
|
||||
import eu.m724.realweather.mapper.MapperConfig;
|
||||
import eu.m724.realweather.thunder.ThunderConfig;
|
||||
import eu.m724.realweather.thunder.ThunderMaster;
|
||||
import eu.m724.realweather.time.TimeConfig;
|
||||
import eu.m724.realweather.weather.PlayerWeatherDirectory;
|
||||
import eu.m724.realweather.weather.WeatherConfig;
|
||||
|
@ -12,6 +14,10 @@ public class GlobalConstants {
|
|||
static WeatherConfig weatherConfig;
|
||||
static TimeConfig timeConfig;
|
||||
static ThunderConfig thunderConfig;
|
||||
static MapperConfig mapperConfig;
|
||||
|
||||
static ThunderMaster thunderMaster;
|
||||
|
||||
static Mapper mapper;
|
||||
static Plugin plugin;
|
||||
static PlayerWeatherDirectory playerWeatherDirectory;
|
||||
|
@ -25,6 +31,12 @@ public class GlobalConstants {
|
|||
public static ThunderConfig getThunderConfig() {
|
||||
return thunderConfig;
|
||||
}
|
||||
public static MapperConfig getMapperConfig() {
|
||||
return mapperConfig;
|
||||
}
|
||||
public static ThunderMaster getThunderMaster() {
|
||||
return thunderMaster;
|
||||
}
|
||||
public static Mapper getMapper() {
|
||||
return mapper;
|
||||
}
|
||||
|
|
|
@ -11,11 +11,11 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
import eu.m724.realweather.commands.AdminCommand;
|
||||
import eu.m724.realweather.commands.GeoCommand;
|
||||
import eu.m724.realweather.commands.LocalTimeCommand;
|
||||
import eu.m724.realweather.mapper.Mapper;
|
||||
import eu.m724.realweather.mapper.MapperConfig;
|
||||
import eu.m724.realweather.mapper.MapperEventHandler;
|
||||
import eu.m724.realweather.object.UserException;
|
||||
import eu.m724.realweather.thunder.ThunderConfig;
|
||||
import eu.m724.realweather.thunder.ThunderMaster;
|
||||
|
@ -26,7 +26,6 @@ import eu.m724.realweather.weather.WeatherMaster;
|
|||
import eu.m724.wtapi.provider.exception.ProviderException;
|
||||
|
||||
public class RealWeatherPlugin extends JavaPlugin {
|
||||
private Mapper mapper;
|
||||
private WeatherMaster weatherMaster;
|
||||
private ThunderMaster thunderMaster;
|
||||
private TimeMaster timeMaster;
|
||||
|
@ -81,8 +80,8 @@ public class RealWeatherPlugin extends JavaPlugin {
|
|||
GlobalConstants.plugin = this;
|
||||
|
||||
DebugLogger.info("loading mapper", 1);
|
||||
GlobalConstants.mapper = new Mapper(
|
||||
MapperConfig.fromConfiguration(mapConfiguration));
|
||||
GlobalConstants.mapperConfig = MapperConfig.fromConfiguration(mapConfiguration);
|
||||
GlobalConstants.mapper = new Mapper();
|
||||
GlobalConstants.mapper.registerEvents(this);
|
||||
|
||||
try {
|
||||
|
@ -117,6 +116,9 @@ public class RealWeatherPlugin extends JavaPlugin {
|
|||
return;
|
||||
}
|
||||
|
||||
GlobalConstants.thunderMaster = thunderMaster;
|
||||
|
||||
getCommand("rwadmin").setExecutor(new AdminCommand());
|
||||
getCommand("geo").setExecutor(new GeoCommand());
|
||||
|
||||
if (GlobalConstants.timeConfig.enabled)
|
||||
|
|
97
src/main/java/eu/m724/realweather/commands/AdminCommand.java
Normal file
97
src/main/java/eu/m724/realweather/commands/AdminCommand.java
Normal file
|
@ -0,0 +1,97 @@
|
|||
package eu.m724.realweather.commands;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import eu.m724.realweather.GlobalConstants;
|
||||
import eu.m724.realweather.mapper.MapperConfig;
|
||||
import eu.m724.realweather.thunder.ThunderConfig;
|
||||
import eu.m724.realweather.thunder.ThunderMaster;
|
||||
import eu.m724.realweather.time.TimeConfig;
|
||||
import eu.m724.realweather.weather.WeatherConfig;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
public class AdminCommand implements CommandExecutor {
|
||||
private Plugin plugin = GlobalConstants.getPlugin();
|
||||
|
||||
private WeatherConfig weatherConfig = GlobalConstants.getWeatherConfig();
|
||||
private TimeConfig timeConfig = GlobalConstants.getTimeConfig();
|
||||
private ThunderConfig thunderConfig = GlobalConstants.getThunderConfig();
|
||||
private MapperConfig mapperConfig = GlobalConstants.getMapperConfig();
|
||||
|
||||
private ThunderMaster thunderMaster = GlobalConstants.getThunderMaster();
|
||||
|
||||
private BaseComponent enabledComponent = TextComponent.fromLegacy("YES\n", ChatColor.GREEN);
|
||||
private BaseComponent disabledComponent = TextComponent.fromLegacy("NO\n", ChatColor.RED);
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
ComponentBuilder componentBuilder =
|
||||
new ComponentBuilder("\nRealWeather " + plugin.getDescription().getVersion() + "\n\n")
|
||||
.color(ChatColor.YELLOW);
|
||||
|
||||
componentBuilder.append("Coordinate scale: ").color(ChatColor.GOLD);
|
||||
componentBuilder.append(String.format("%d, %d blocks / deg\n", mapperConfig.scaleLatitude, mapperConfig.scaleLongitude)).color(ChatColor.AQUA);
|
||||
|
||||
componentBuilder.append("\nWeather: ").color(ChatColor.GOLD);
|
||||
componentBuilder.append(weatherConfig.enabled ? enabledComponent : disabledComponent);
|
||||
|
||||
if (weatherConfig.enabled) {
|
||||
componentBuilder.append(" Provider: ").color(ChatColor.GOLD);
|
||||
componentBuilder.append(weatherConfig.provider + "\n").color(ChatColor.AQUA);
|
||||
|
||||
componentBuilder.append(" Dynamic: ").color(ChatColor.GOLD);
|
||||
componentBuilder.append(weatherConfig.dynamic ? enabledComponent : disabledComponent);
|
||||
}
|
||||
|
||||
componentBuilder.append("\nTime: ").color(ChatColor.GOLD);
|
||||
componentBuilder.append(timeConfig.enabled ? enabledComponent : disabledComponent);
|
||||
|
||||
if (timeConfig.enabled) {
|
||||
componentBuilder.append(" Scale: ").color(ChatColor.GOLD);
|
||||
componentBuilder.append(Double.toString(timeConfig.scale) + "\n").color(ChatColor.AQUA);
|
||||
|
||||
long worldTime = timeConfig.calculateWorldTimeSeconds();
|
||||
Duration worldTimeDuration = Duration.ofSeconds(worldTime);
|
||||
|
||||
String worldTimeFormatted = String.format("%d:%02d:%02d\n",
|
||||
worldTimeDuration.toHours(),
|
||||
worldTimeDuration.toMinutesPart(),
|
||||
worldTimeDuration.toSecondsPart());
|
||||
|
||||
componentBuilder.append(" World time: ").color(ChatColor.GOLD);
|
||||
componentBuilder.append(worldTimeFormatted).color(ChatColor.AQUA);
|
||||
|
||||
componentBuilder.append(" Dynamic: ").color(ChatColor.GOLD);
|
||||
componentBuilder.append(timeConfig.dynamic ? enabledComponent : disabledComponent);
|
||||
}
|
||||
|
||||
componentBuilder.append("\nThunder: ").color(ChatColor.GOLD);
|
||||
componentBuilder.append(thunderConfig.enabled ? enabledComponent : disabledComponent);
|
||||
|
||||
if (thunderConfig.enabled) {
|
||||
componentBuilder.append(" Provider: ").color(ChatColor.GOLD);
|
||||
componentBuilder.append(thunderConfig.provider + "\n").color(ChatColor.AQUA);
|
||||
|
||||
componentBuilder.append(" Refresh: ").color(ChatColor.GOLD);
|
||||
componentBuilder.append(String.format("%d ticks\n", thunderConfig.refresh)).color(ChatColor.AQUA);
|
||||
|
||||
componentBuilder.append(" Latency: ").color(ChatColor.GOLD);
|
||||
componentBuilder.append(String.format("avg %dms\n", thunderMaster.getLatency())).color(ChatColor.AQUA);
|
||||
|
||||
}
|
||||
|
||||
sender.spigot().sendMessage(componentBuilder.create());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -12,7 +12,6 @@ import eu.m724.wtapi.object.Coordinates;
|
|||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
public class GeoCommand implements CommandExecutor {
|
||||
|
||||
|
|
|
@ -2,8 +2,6 @@ package eu.m724.realweather.commands;
|
|||
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.time.temporal.TemporalUnit;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
|
|
@ -1,31 +1,24 @@
|
|||
package eu.m724.realweather.mapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import eu.m724.realweather.GlobalConstants;
|
||||
import eu.m724.wtapi.object.Coordinates;
|
||||
|
||||
public class Mapper {
|
||||
private MapperConfig config;
|
||||
private MapperConfig config = GlobalConstants.getMapperConfig();
|
||||
private List<World> worlds = new ArrayList<>();
|
||||
|
||||
private List<Consumer<World>> worldLoadConsumers = new ArrayList<>();
|
||||
private List<Consumer<World>> worldUnloadConsumers = new ArrayList<>();
|
||||
// TODO game rules
|
||||
|
||||
public Mapper(MapperConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a consumer which will be called on world load
|
||||
* @param consumer
|
||||
|
|
|
@ -7,8 +7,6 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||
import eu.m724.wtapi.object.Coordinates;
|
||||
|
||||
public class MapperConfig {
|
||||
public boolean enabled;
|
||||
|
||||
public boolean worldBlacklist;
|
||||
public List<String> worlds;
|
||||
|
||||
|
@ -20,8 +18,6 @@ public class MapperConfig {
|
|||
public static MapperConfig fromConfiguration(ConfigurationSection configuration) {
|
||||
MapperConfig mapperConfig = new MapperConfig();
|
||||
|
||||
mapperConfig.enabled = configuration.getBoolean("enabled");
|
||||
|
||||
mapperConfig.worldBlacklist = configuration.getBoolean("worldBlacklist");
|
||||
mapperConfig.worlds = configuration.getStringList("worlds");
|
||||
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package eu.m724.realweather.thunder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import eu.m724.realweather.DebugLogger;
|
||||
import eu.m724.realweather.GlobalConstants;
|
||||
import eu.m724.realweather.mapper.Mapper;
|
||||
import eu.m724.realweather.object.UserException;
|
||||
import eu.m724.wtapi.provider.exception.ProviderException;
|
||||
import eu.m724.wtapi.thunder.ThunderProvider;
|
||||
|
@ -17,7 +14,6 @@ public class ThunderMaster {
|
|||
private ThunderProvider provider;
|
||||
private ThunderTask thunderTask;
|
||||
|
||||
private Mapper mapper = GlobalConstants.getMapper();
|
||||
private Plugin plugin = GlobalConstants.getPlugin();
|
||||
|
||||
public ThunderMaster(ThunderConfig config) {
|
||||
|
@ -55,4 +51,8 @@ public class ThunderMaster {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
public long getLatency() {
|
||||
return provider.getLatency();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package eu.m724.realweather.thunder;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import eu.m724.realweather.DebugLogger;
|
||||
|
|
|
@ -7,13 +7,9 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||
import eu.m724.realweather.DebugLogger;
|
||||
import eu.m724.realweather.GlobalConstants;
|
||||
import eu.m724.realweather.mapper.Mapper;
|
||||
import eu.m724.realweather.weather.PlayerWeatherDirectory;
|
||||
import eu.m724.wtapi.object.Coordinates;
|
||||
import eu.m724.wtapi.object.Weather;
|
||||
|
||||
public class AsyncPlayerTimeTask extends BukkitRunnable {
|
||||
private PlayerWeatherDirectory playerWeatherDirectory =
|
||||
GlobalConstants.getPlayerWeatherDirectory();
|
||||
private Server server = GlobalConstants.getPlugin().getServer();
|
||||
private Mapper mapper = GlobalConstants.getMapper();
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import org.bukkit.plugin.Plugin;
|
|||
|
||||
import eu.m724.realweather.DebugLogger;
|
||||
import eu.m724.realweather.GlobalConstants;
|
||||
import eu.m724.realweather.commands.LocalTimeCommand;
|
||||
import eu.m724.realweather.mapper.Mapper;
|
||||
import eu.m724.realweather.object.UserException;
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package eu.m724.realweather.weather;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Server;
|
||||
|
|
|
@ -10,8 +10,6 @@ public class WeatherConfig {
|
|||
|
||||
// state is per player
|
||||
public boolean dynamic;
|
||||
// prevent other stuff from changing weather
|
||||
public boolean lock;
|
||||
|
||||
public static WeatherConfig fromConfiguration(ConfigurationSection configuration) {
|
||||
WeatherConfig weatherConfig = new WeatherConfig();
|
||||
|
@ -22,7 +20,6 @@ public class WeatherConfig {
|
|||
weatherConfig.apiKey = configuration.getString("apiKey");
|
||||
|
||||
weatherConfig.dynamic = configuration.getBoolean("dynamic");
|
||||
weatherConfig.lock = configuration.getBoolean("lock");
|
||||
|
||||
return weatherConfig;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,3 @@ apiKey: REPLACE ME
|
|||
# - dynamic (true): weather is per player, however it's only cosmetical so it will not match mobs spawning etc
|
||||
# settings for both are in map.yml
|
||||
dynamic: true
|
||||
|
||||
# prevent the game, players or other plugins from changing the weather
|
||||
lock: true
|
Loading…
Reference in a new issue