1
0
mirror of https://github.com/nkomarn/harbor.git synced 2024-12-18 22:37:36 +01:00

Update 1.4.4, I guess.

This commit is contained in:
Mykyta Komarn 2019-01-24 21:03:18 -08:00
parent 771c81a7df
commit 87a7079e55
7 changed files with 96 additions and 62 deletions

View File

@ -26,6 +26,8 @@ features:
clearWeather: true
# Toggle exclusion of operators/players with permission "harbor.bypass" from sleep count
bypass: false
# Prevent any players from entering a bed (1.13.2 OR NEWER)
blockSleep: false
# Display debug information in console
debug: false
@ -37,6 +39,8 @@ messages:
skipped: "&eThe night has been skipped."
# Display which player went to bed in chat
sleeping: "&e[player] is now sleeping ([sleeping]/[online]. [needed] more needed to skip)."
# Shown when a player tries to sleep and sleeping is blocked
blocked: "&cSleeping is disabled."
# Sent to player when they sleep with "harbor.bypass" permission
bypass: "&eYou've been excluded from the sleep count."
actionbar:
@ -46,6 +50,8 @@ messages:
sleeping: "&e[sleeping] out of [online] players are sleeping ([needed] more needed to skip)."
# Shown when all players are in bed
everyone: "&eEveryone is sleeping. Sweet dreams!"
# Shown when a player tries to sleep and sleeping is blocked
blocked: "&cSleeping is disabled."
miscellaneous:
# Prefix for Harbor command messages
prefix: "&8&l(&6&lHarbor&8&l) "
@ -60,4 +66,4 @@ messages:
permission: "&7Insufficient permissions."
# Version identifier (do not change)
version: 1.4.3
version: 1.4.4

View File

@ -1,5 +1,5 @@
name: Harbor
version: 1.4.3
version: 1.4.4
main: techtoolbox.Harbor.Main
description: Ahoy, matey! Harbor is a Spigot plugin that redefines how sleep works in your server, making it easier for all the online players to get in bed quick and skip through the night!
author: TechToolbox

View File

@ -5,13 +5,27 @@ import org.bukkit.Bukkit;
public class ActionBarMessage implements Runnable {
@Override
public void run() {
<<<<<<< HEAD
for (int i = 0; Main.worlds.size() > i; i++) {
if (((Main.worlds.get(Bukkit.getServer().getWorlds().get(i))).intValue() > 0) && ((Main.worlds.get(Bukkit.getServer().getWorlds().get(i))).intValue() < (Bukkit.getServer().getWorlds().get(i)).getPlayers().size() - Main.bypassers.size())) {
Main.sendActionbar("playersInBed", Bukkit.getServer().getWorlds().get(i));
}
else if (((Main.worlds.get(Bukkit.getServer().getWorlds().get(i))).intValue() == (Bukkit.getServer().getWorlds().get(i)).getPlayers().size() - Main.bypassers.size()) && ((Bukkit.getServer().getWorlds().get(i)).getPlayers().size() - Main.bypassers.size() > 1)) {
Main.sendActionbar("everyoneSleeping", Bukkit.getServer().getWorlds().get(i));
=======
try {
for (int i = 0; Main.worlds.size() > i; i++) {
if (((Main.worlds.get(Bukkit.getServer().getWorlds().get(i))).intValue() > 0) && ((Main.worlds.get(Bukkit.getServer().getWorlds().get(i))).intValue() < (Bukkit.getServer().getWorlds().get(i)).getPlayers().size() - Main.bypassers.size())) {
Main.sendActionbar("playersInBed", Bukkit.getServer().getWorlds().get(i), null);
}
else if (((Main.worlds.get(Bukkit.getServer().getWorlds().get(i))).intValue() == (Bukkit.getServer().getWorlds().get(i)).getPlayers().size() - Main.bypassers.size()) && ((Bukkit.getServer().getWorlds().get(i)).getPlayers().size() - Main.bypassers.size() > 1)) {
Main.sendActionbar("everyoneSleeping", Bukkit.getServer().getWorlds().get(i), null);
}
>>>>>>> Update 1.4.4, I guess.
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -30,7 +30,11 @@ public class Command implements CommandExecutor {
else {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.miscellaneous.prefix") + Main.plugin.getConfig().getString("messages.miscellaneous.permission")));
}
}
}
else if (args[0].equalsIgnoreCase("test")) {
System.out.println(Main.worlds.size());
System.out.println(Main.bypassers.size());
}
return true;
}
}

View File

@ -18,9 +18,67 @@ public class BedEnterEvent implements Listener {
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerBedEnterEvent(PlayerBedEnterEvent event) {
// TEMPORARY SOLUTION FOR 1.13.2: CHECK IF BEDENTERRESULT WORKS, IF NOT THEN RUN 1.13.1 CODE
try {
if (event.getBedEnterResult() == BedEnterResult.OK) {
// Sleep blocking feature
if (Main.plugin.getConfig().getBoolean("features.blockSleep")) {
if (Main.plugin.getConfig().getString("messages.chat.blocked").length() > 0) {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.chat.blocked")));
}
Main.sendActionbar("sleepingBlocked", null, event.getPlayer());
event.setCancelled(true);
}
else {
// TEMPORARY SOLUTION FOR 1.13.2: CHECK IF BEDENTERRESULT WORKS, IF NOT THEN RUN 1.13.1 CODE
try {
if (event.getBedEnterResult() == BedEnterResult.OK) {
Main.bypassers.clear();
if (Main.plugin.getConfig().getBoolean("features.bypass")) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.hasPermission("harbor.bypass")) {
Main.bypassers.add(player.getName());
}
}
}
if (!Main.plugin.getConfig().getBoolean("features.bypass") || !event.getPlayer().hasPermission("harbor.bypass")) {
try {
Main.worlds.put(event.getPlayer().getWorld(), Integer.valueOf((Main.worlds.get(event.getPlayer().getWorld())).intValue() + 1));
}
catch (Exception exception) {
// Create value if it doesn't exist already
Main.worlds.put(event.getPlayer().getWorld(), 1);
}
// Chat messages
if (Main.plugin.getConfig().getBoolean("messages.chat.chat") && (Main.plugin.getConfig().getString("messages.chat.sleeping").length() != 0)) {
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.chat.sleeping")
.replace("[sleeping]", String.valueOf(Main.worlds.get(event.getPlayer().getWorld())))
.replace("[online]", String.valueOf(event.getPlayer().getWorld().getPlayers().size() - Main.bypassers.size()))
.replace("[player]", event.getPlayer().getName())
.replace("[needed]", String.valueOf(Math.max(0, Math.round(event.getPlayer().getWorld().getPlayers().size() * Float.parseFloat(Main.plugin.getConfig().getString("values.percent")) - Main.bypassers.size() - (Main.worlds.get(event.getPlayer().getWorld())).intValue()))))));
}
// Skip night feature
if (Main.plugin.getConfig().getBoolean("features.skipNight") && ((Main.worlds.get(event.getPlayer().getWorld())).intValue() >= event.getPlayer().getWorld().getPlayers().size() * Float.parseFloat(Main.plugin.getConfig().getString("values.percent")) - Main.bypassers.size()) && (event.getPlayer().getWorld().getPlayers().size() > 1)) {
Bukkit.getServer().getWorld(event.getPlayer().getWorld().getName()).setTime(1000L);
// Weather clear feature
if (Main.plugin.getConfig().getBoolean("features.clearWeather")) {
event.getPlayer().getWorld().setStorm(false);
event.getPlayer().getWorld().setThundering(false);
}
// Night skipped message
if (Main.plugin.getConfig().getBoolean("messages.chat.chat") && (Main.plugin.getConfig().getString("messages.chat.skipped").length() != 0)) {
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.chat.skipped")));
}
}
}
else if (Main.plugin.getConfig().getString("messages.chat.bypass").length() != 0) {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.chat.bypass")));
}
}
}
catch (NoSuchMethodError e){
Main.bypassers.clear();
if (Main.plugin.getConfig().getBoolean("features.bypass")) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
@ -47,7 +105,7 @@ public class BedEnterEvent implements Listener {
.replace("[player]", event.getPlayer().getName())
.replace("[needed]", String.valueOf(Math.max(0, Math.round(event.getPlayer().getWorld().getPlayers().size() * Float.parseFloat(Main.plugin.getConfig().getString("values.percent")) - Main.bypassers.size() - (Main.worlds.get(event.getPlayer().getWorld())).intValue()))))));
}
// Skip night feature
if (Main.plugin.getConfig().getBoolean("features.skipNight") && ((Main.worlds.get(event.getPlayer().getWorld())).intValue() >= event.getPlayer().getWorld().getPlayers().size() * Float.parseFloat(Main.plugin.getConfig().getString("values.percent")) - Main.bypassers.size()) && (event.getPlayer().getWorld().getPlayers().size() > 1)) {
Bukkit.getServer().getWorld(event.getPlayer().getWorld().getName()).setTime(1000L);
@ -66,56 +124,8 @@ public class BedEnterEvent implements Listener {
}
else if (Main.plugin.getConfig().getString("messages.chat.bypass").length() != 0) {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.chat.bypass")));
}
}
}
}
catch (NoSuchMethodError e){
Main.bypassers.clear();
if (Main.plugin.getConfig().getBoolean("features.bypass")) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.hasPermission("harbor.bypass")) {
Main.bypassers.add(player.getName());
}
}
}
if (!event.getPlayer().hasPermission("harbor.bypass")) {
try {
Main.worlds.put(event.getPlayer().getWorld(), Integer.valueOf((Main.worlds.get(event.getPlayer().getWorld())).intValue() + 1));
}
catch (Exception exception) {
// Create value if it doesn't exist already
Main.worlds.put(event.getPlayer().getWorld(), 1);
}
// Chat messages
if (Main.plugin.getConfig().getBoolean("messages.chat.chat") && (Main.plugin.getConfig().getString("messages.chat.sleeping").length() != 0)) {
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.chat.sleeping")
.replace("[sleeping]", String.valueOf(Main.worlds.get(event.getPlayer().getWorld())))
.replace("[online]", String.valueOf(event.getPlayer().getWorld().getPlayers().size() - Main.bypassers.size()))
.replace("[player]", event.getPlayer().getName())
.replace("[needed]", String.valueOf(Math.max(0, Math.round(event.getPlayer().getWorld().getPlayers().size() * Float.parseFloat(Main.plugin.getConfig().getString("values.percent")) - Main.bypassers.size() - (Main.worlds.get(event.getPlayer().getWorld())).intValue()))))));
}
// Skip night feature
if (Main.plugin.getConfig().getBoolean("features.skipNight") && ((Main.worlds.get(event.getPlayer().getWorld())).intValue() >= event.getPlayer().getWorld().getPlayers().size() * Float.parseFloat(Main.plugin.getConfig().getString("values.percent")) - Main.bypassers.size()) && (event.getPlayer().getWorld().getPlayers().size() > 1)) {
Bukkit.getServer().getWorld(event.getPlayer().getWorld().getName()).setTime(1000L);
// Weather clear feature
if (Main.plugin.getConfig().getBoolean("features.clearWeather")) {
event.getPlayer().getWorld().setStorm(false);
event.getPlayer().getWorld().setThundering(false);
}
// Night skipped message
if (Main.plugin.getConfig().getBoolean("messages.chat.chat") && (Main.plugin.getConfig().getString("messages.chat.skipped").length() != 0)) {
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.chat.skipped")));
}
}
}
else if (Main.plugin.getConfig().getString("messages.chat.bypass").length() != 0) {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', Main.plugin.getConfig().getString("messages.chat.bypass")));
}
}
}
}

View File

@ -22,7 +22,7 @@ public class BedLeaveEvent implements Listener {
}
}
if (!event.getPlayer().hasPermission("harbor.bypass")) {
if (!Main.plugin.getConfig().getBoolean("features.bypass") || !event.getPlayer().hasPermission("harbor.bypass")) {
Main.worlds.put(event.getPlayer().getWorld(), Integer.valueOf((Main.worlds.get(event.getPlayer().getWorld())).intValue() - 1));
}
}

View File

@ -7,10 +7,7 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.plugin.java.JavaPlugin;
import techtoolbox.Harbor.Actionbar.Actionbar;
@ -30,7 +27,7 @@ import techtoolbox.Harbor.Listeners.QuitEvent;
public class Main extends JavaPlugin implements Listener {
public static Main plugin;
public static String version = "1.4.3";
public static String version = "1.4.4";
public static HashMap<World, Integer> worlds = new HashMap<World, Integer>();
public static ArrayList<String> bypassers = new ArrayList<String>();
public static Actionbar actionbar;
@ -73,7 +70,7 @@ public class Main extends JavaPlugin implements Listener {
}
}
public static void sendActionbar(String type, World world) {
public static void sendActionbar(String type, World world, Player player) {
if (type.equals("playersInBed")) {
for (Player p : world.getPlayers()) {
actionbar.sendActionbar(p, plugin.getConfig().getString("messages.actionbar.sleeping")
@ -90,6 +87,9 @@ public class Main extends JavaPlugin implements Listener {
.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())))));
}
}
else if (type.equals("sleepingBlocked")) {
actionbar.sendActionbar(player, plugin.getConfig().getString("messages.actionbar.blocked"));
}
}
private boolean setupActionbar() {