mirror of
https://github.com/nkomarn/harbor.git
synced 2024-12-18 22:37:36 +01:00
Add time skip interval to config and more refactoring
This commit is contained in:
parent
ca00415213
commit
b496a022c9
@ -32,9 +32,4 @@ public class Harbor extends JavaPlugin {
|
||||
// Essentials hook
|
||||
essentials = (Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials");
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public class AccelerateNightTask extends BukkitRunnable {
|
||||
public void run() {
|
||||
final long time = world.getTime();
|
||||
if (!(time >= 450 && time <= 1000)) {
|
||||
world.setTime(time + 60);
|
||||
world.setTime(time + Config.getInteger("values.timeSkipInterval"));
|
||||
} else {
|
||||
// Announce night skip and clear queue
|
||||
Message.SendRandomChatMessage("messages.chat.skipped");
|
||||
|
@ -6,6 +6,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.nkomarn.Harbor.Harbor;
|
||||
import xyz.nkomarn.Harbor.util.Config;
|
||||
import xyz.nkomarn.Harbor.util.Message;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -77,7 +78,8 @@ public class Checker implements Runnable {
|
||||
}
|
||||
|
||||
private void accelerateNight(final World world) {
|
||||
Bukkit.broadcastMessage(Config.getString("messages.chat.accelerateNight"));
|
||||
new AccelerateNightTask(world).runTaskTimer(Harbor.instance, 20, 1);
|
||||
Message.SendChatMessage(world, "messages.chat.accelerateNight", "", 0);
|
||||
Message.SendActionbarMessage(world, "messages.actionbar.everyone", "", 0);
|
||||
new AccelerateNightTask(world).runTaskTimer(Harbor.instance, 0L, 1);
|
||||
}
|
||||
}
|
||||
|
@ -4,84 +4,55 @@ import xyz.nkomarn.Harbor.Harbor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Config {
|
||||
/**
|
||||
* Report an error in reading the configuration
|
||||
* @param e Exception generated from reading configuration
|
||||
*/
|
||||
private static void error(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a boolean from the configuration
|
||||
* if location is not found, <code>false</code> is returned
|
||||
*
|
||||
* @param location Configuration location of the boolean
|
||||
*/
|
||||
public static boolean getBoolean(String location) {
|
||||
try {
|
||||
return Harbor.instance.getConfig().getBoolean(location);
|
||||
}
|
||||
catch (Exception e) {
|
||||
error(e);
|
||||
return false;
|
||||
}
|
||||
public static boolean getBoolean(final String location) {
|
||||
return Harbor.instance.getConfig().getBoolean(location, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a string from the configuration
|
||||
* if location is not found, <code>empty String</code> is returned
|
||||
*
|
||||
* @param location Configuration location of the string
|
||||
*/
|
||||
public static String getString(String location) {
|
||||
try {
|
||||
return Harbor.instance.getConfig().getString(location);
|
||||
}
|
||||
catch (Exception e) {
|
||||
error(e);
|
||||
return "";
|
||||
}
|
||||
public static String getString(final String location) {
|
||||
return Harbor.instance.getConfig().getString(location, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches an integer from the configuration
|
||||
* if location is not found, <code>0</code> is returned
|
||||
*
|
||||
* @param location Configuration location of the integer
|
||||
*/
|
||||
public static int getInteger(String location) {
|
||||
try {
|
||||
return Harbor.instance.getConfig().getInt(location);
|
||||
}
|
||||
catch (Exception e) {
|
||||
error(e);
|
||||
return 0;
|
||||
}
|
||||
public static int getInteger(final String location) {
|
||||
return Harbor.instance.getConfig().getInt(location, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a double from the configuration
|
||||
* if location is not found, <code>0.0</code> is returned
|
||||
*
|
||||
* @param location Configuration location of the double
|
||||
*/
|
||||
public static double getDouble(String location) {
|
||||
try {
|
||||
return Double.parseDouble(Objects.requireNonNull(Harbor.instance.getConfig().getString(location)));
|
||||
}
|
||||
catch (Exception e) {
|
||||
error(e);
|
||||
return 0.0;
|
||||
}
|
||||
public static double getDouble(final String location) {
|
||||
return Harbor.instance.getConfig().getDouble(location, 0.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a double from the configuration
|
||||
* @param location Configuration location of the double
|
||||
* Fetches a list from the configuration
|
||||
* if location is not found, <code>empty list</code> is returned
|
||||
*
|
||||
* @param location Configuration location of the list
|
||||
*/
|
||||
public static List<String> getList(String location) {
|
||||
try {
|
||||
return Harbor.instance.getConfig().getStringList(location);
|
||||
}
|
||||
catch (Exception e) {
|
||||
error(e);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
public static List<String> getList(final String location) {
|
||||
return (List<String>) Harbor.instance.getConfig().getList(location, new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
values:
|
||||
timer: 2 # How often to run the clock task (used to detect sleep, AFK players, time actionbar, etc.)
|
||||
percent: 100 # Percent of players that need to sleep to skip night (must be between 0 to 100)
|
||||
timeSkipInterval: 60 # Time skip interval that is added when the night get accelerated.
|
||||
|
||||
features:
|
||||
skip: true # Toggle night skipping feature. Configure amount of players needed to skip above (percent)
|
||||
|
Loading…
Reference in New Issue
Block a user