2019-03-05 04:16:28 +01:00
|
|
|
package mykyta.Harbor;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
2019-03-06 02:47:01 +01:00
|
|
|
import java.util.logging.Logger;
|
2019-03-05 04:16:28 +01:00
|
|
|
|
2019-03-06 02:47:01 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2019-03-06 04:16:39 +01:00
|
|
|
import org.bukkit.GameMode;
|
2019-03-05 04:16:28 +01:00
|
|
|
import org.bukkit.World;
|
2019-03-05 16:18:05 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2019-03-05 04:16:28 +01:00
|
|
|
|
2019-03-05 16:18:05 +01:00
|
|
|
import mykyta.Harbor.Actionbar.Actionbar;
|
2019-03-06 02:47:01 +01:00
|
|
|
import mykyta.Harbor.Actionbar.Actionbar_1_13_R2;
|
|
|
|
import net.md_5.bungee.api.ChatColor;
|
2019-03-05 16:18:05 +01:00
|
|
|
|
2019-03-06 02:47:01 +01:00
|
|
|
public class Util {
|
2019-03-05 16:18:05 +01:00
|
|
|
public static HashMap<World, Integer> sleeping = new HashMap<World, Integer>();
|
2019-03-05 04:16:28 +01:00
|
|
|
public String version = "1.5";
|
2019-03-05 16:27:22 +01:00
|
|
|
public static boolean debug = false;
|
2019-03-06 02:47:01 +01:00
|
|
|
private Logger log = Bukkit.getLogger();
|
|
|
|
private static Actionbar actionbar;
|
|
|
|
Config config = new Config();
|
2019-03-05 16:18:05 +01:00
|
|
|
|
2019-03-06 02:47:01 +01:00
|
|
|
/**
|
|
|
|
* Select the correct NMS classes for the server version
|
|
|
|
*/
|
|
|
|
public void setupNMS() {
|
|
|
|
String version = "";
|
|
|
|
try {version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];}
|
|
|
|
catch (ArrayIndexOutOfBoundsException e) {
|
|
|
|
log.severe("Could not get server version. The plugin may not function correctly as a result.");
|
|
|
|
if (Util.debug) System.err.println(e);
|
|
|
|
}
|
|
|
|
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.prefix") + config.getString("messages.miscellaneous.running").replace("[version]", version)));
|
|
|
|
|
|
|
|
if (version.equals("v1_13_R2")) {
|
|
|
|
actionbar = new Actionbar_1_13_R2();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Increment the sleeping count for a world
|
|
|
|
* @param world World to increment count in
|
|
|
|
*/
|
|
|
|
public void increment(World world) {
|
|
|
|
int count;
|
|
|
|
try {count = Util.sleeping.get(world);}
|
|
|
|
catch (Exception e){count = 0;}
|
|
|
|
Util.sleeping.put(world, count + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decrement the sleeping count for a world
|
|
|
|
* @param world World to increment count in
|
|
|
|
*/
|
|
|
|
public void decrement(World world) {
|
|
|
|
int count;
|
|
|
|
try {count = Util.sleeping.get(world);}
|
|
|
|
catch (Exception e){count = 0;}
|
|
|
|
Util.sleeping.put(world, count - 1);
|
2019-03-05 16:18:05 +01:00
|
|
|
}
|
|
|
|
|
2019-03-06 03:23:00 +01:00
|
|
|
/**
|
|
|
|
* Fetch the sleeping count for a world
|
|
|
|
* @param world World to fetch count for
|
|
|
|
*/
|
|
|
|
public int fetch(World world) {
|
|
|
|
int count;
|
|
|
|
try {count = Util.sleeping.get(world);}
|
|
|
|
catch (Exception e){count = 0;}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2019-03-05 16:18:05 +01:00
|
|
|
/**
|
|
|
|
* Sends an actionbar message to the given player
|
|
|
|
* @param player Player to show actionbar to
|
|
|
|
* @param message Actionbar message with color codes
|
|
|
|
*/
|
|
|
|
public void sendActionbar(Player player, String message) {
|
|
|
|
actionbar.sendActionbar(player, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends actionbar with world information
|
|
|
|
* @see sendActionbar(Player player, String message)
|
|
|
|
* @param player Player to show actionbar to
|
|
|
|
* @param message Actionbar message with color codes
|
|
|
|
* @param world World to fetch information for
|
|
|
|
*/
|
|
|
|
public void sendActionbar(Player player, String message, World world) {
|
2019-03-06 02:47:01 +01:00
|
|
|
Config config = new Config();
|
2019-03-05 16:18:05 +01:00
|
|
|
actionbar.sendActionbar(player, message
|
|
|
|
.replace("[sleeping]", String.valueOf(sleeping.get(world)))
|
|
|
|
//TODO add bypassers functionaliyt .replace("[online]", String.valueOf(world.getPlayers().size() - bypassers.size()))
|
|
|
|
// .replace("[needed]", String.valueOf(Math.max(0, Math.round(world.getPlayers().size() * Float.parseFloat(plugin.getConfig().getString("values.percent")) - bypassers.size() - ((Integer)worlds.get(world)).intValue())))));
|
|
|
|
.replace("[online]", String.valueOf(world.getPlayers().size()))
|
2019-03-06 02:47:01 +01:00
|
|
|
.replace("[needed]", String.valueOf(Math.max(0, Math.round(world.getPlayers().size() * Float.parseFloat(config.getString("values.percent")) - (sleeping.get(world)).intValue())))));
|
2019-03-05 16:18:05 +01:00
|
|
|
}
|
2019-03-06 04:16:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if player is in survival mode
|
|
|
|
* @param player Target player
|
|
|
|
*/
|
|
|
|
public boolean isSurvival(Player player) {
|
|
|
|
if (player.getGameMode() == GameMode.SURVIVAL) return true;
|
|
|
|
else return false;
|
|
|
|
}
|
2019-03-05 04:16:28 +01:00
|
|
|
}
|