mirror of
https://github.com/nkomarn/harbor.git
synced 2025-03-11 06:00:51 +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 hook
|
||||||
essentials = (Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials");
|
essentials = (Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDisable() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ public class AccelerateNightTask extends BukkitRunnable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
final long time = world.getTime();
|
final long time = world.getTime();
|
||||||
if (!(time >= 450 && time <= 1000)) {
|
if (!(time >= 450 && time <= 1000)) {
|
||||||
world.setTime(time + 60);
|
world.setTime(time + Config.getInteger("values.timeSkipInterval"));
|
||||||
} else {
|
} else {
|
||||||
// Announce night skip and clear queue
|
// Announce night skip and clear queue
|
||||||
Message.SendRandomChatMessage("messages.chat.skipped");
|
Message.SendRandomChatMessage("messages.chat.skipped");
|
||||||
|
@ -6,6 +6,7 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import xyz.nkomarn.Harbor.Harbor;
|
import xyz.nkomarn.Harbor.Harbor;
|
||||||
import xyz.nkomarn.Harbor.util.Config;
|
import xyz.nkomarn.Harbor.util.Config;
|
||||||
|
import xyz.nkomarn.Harbor.util.Message;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -77,7 +78,8 @@ public class Checker implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void accelerateNight(final World world) {
|
private void accelerateNight(final World world) {
|
||||||
Bukkit.broadcastMessage(Config.getString("messages.chat.accelerateNight"));
|
Message.SendChatMessage(world, "messages.chat.accelerateNight", "", 0);
|
||||||
new AccelerateNightTask(world).runTaskTimer(Harbor.instance, 20, 1);
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class Config {
|
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
|
* Fetches a boolean from the configuration
|
||||||
|
* if location is not found, <code>false</code> is returned
|
||||||
|
*
|
||||||
* @param location Configuration location of the boolean
|
* @param location Configuration location of the boolean
|
||||||
*/
|
*/
|
||||||
public static boolean getBoolean(String location) {
|
public static boolean getBoolean(final String location) {
|
||||||
try {
|
return Harbor.instance.getConfig().getBoolean(location, false);
|
||||||
return Harbor.instance.getConfig().getBoolean(location);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
error(e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches a string from the configuration
|
* Fetches a string from the configuration
|
||||||
|
* if location is not found, <code>empty String</code> is returned
|
||||||
|
*
|
||||||
* @param location Configuration location of the string
|
* @param location Configuration location of the string
|
||||||
*/
|
*/
|
||||||
public static String getString(String location) {
|
public static String getString(final String location) {
|
||||||
try {
|
return Harbor.instance.getConfig().getString(location, "");
|
||||||
return Harbor.instance.getConfig().getString(location);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
error(e);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches an integer from the configuration
|
* Fetches an integer from the configuration
|
||||||
|
* if location is not found, <code>0</code> is returned
|
||||||
|
*
|
||||||
* @param location Configuration location of the integer
|
* @param location Configuration location of the integer
|
||||||
*/
|
*/
|
||||||
public static int getInteger(String location) {
|
public static int getInteger(final String location) {
|
||||||
try {
|
return Harbor.instance.getConfig().getInt(location, 0);
|
||||||
return Harbor.instance.getConfig().getInt(location);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
error(e);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches a double from the configuration
|
* Fetches a double from the configuration
|
||||||
|
* if location is not found, <code>0.0</code> is returned
|
||||||
|
*
|
||||||
* @param location Configuration location of the double
|
* @param location Configuration location of the double
|
||||||
*/
|
*/
|
||||||
public static double getDouble(String location) {
|
public static double getDouble(final String location) {
|
||||||
try {
|
return Harbor.instance.getConfig().getDouble(location, 0.0);
|
||||||
return Double.parseDouble(Objects.requireNonNull(Harbor.instance.getConfig().getString(location)));
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
error(e);
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches a double from the configuration
|
* Fetches a list from the configuration
|
||||||
* @param location Configuration location of the double
|
* 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) {
|
public static List<String> getList(final String location) {
|
||||||
try {
|
return (List<String>) Harbor.instance.getConfig().getList(location, new ArrayList<>());
|
||||||
return Harbor.instance.getConfig().getStringList(location);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
error(e);
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
values:
|
values:
|
||||||
timer: 2 # How often to run the clock task (used to detect sleep, AFK players, time actionbar, etc.)
|
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)
|
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:
|
features:
|
||||||
skip: true # Toggle night skipping feature. Configure amount of players needed to skip above (percent)
|
skip: true # Toggle night skipping feature. Configure amount of players needed to skip above (percent)
|
||||||
|
Loading…
Reference in New Issue
Block a user