diff --git a/pom.xml b/pom.xml
index 3b2e3a4..eed1b17 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,6 +19,13 @@
+
+ spigotmc.org
+ spigot-1.14.1
+ system
+ ${spigot}/1.14.1.jar
+ 1.14.1
+
spigotmc.org
spigot-1.14
@@ -100,7 +107,7 @@
- /home/nkomarn/Documents/Spigot Servers/1.14/plugins/
+ /home/nkomarn/Documents/Spigot Servers/1.14.1/plugins/
${basedir}/src/
diff --git a/src/main/java/mykyta/Harbor/Events/ChatEvent.java b/src/main/java/mykyta/Harbor/Events/ChatEvent.java
new file mode 100644
index 0000000..97980f9
--- /dev/null
+++ b/src/main/java/mykyta/Harbor/Events/ChatEvent.java
@@ -0,0 +1,15 @@
+package mykyta.Harbor.Events;
+
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.AsyncPlayerChatEvent;
+import mykyta.Harbor.Util;
+
+public class ChatEvent implements Listener {
+ Util util = new Util();
+
+ @EventHandler
+ public void onChat(AsyncPlayerChatEvent event) {
+ util.updateActivity(event.getPlayer());
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/mykyta/Harbor/Events/CommandEvent.java b/src/main/java/mykyta/Harbor/Events/CommandEvent.java
new file mode 100644
index 0000000..d139ffa
--- /dev/null
+++ b/src/main/java/mykyta/Harbor/Events/CommandEvent.java
@@ -0,0 +1,15 @@
+package mykyta.Harbor.Events;
+
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerCommandPreprocessEvent;
+import mykyta.Harbor.Util;
+
+public class CommandEvent implements Listener {
+ Util util = new Util();
+
+ @EventHandler
+ public void onCommand(PlayerCommandPreprocessEvent event) {
+ util.updateActivity(event.getPlayer());
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/mykyta/Harbor/Events/GUIEvent.java b/src/main/java/mykyta/Harbor/Events/GUIEvent.java
index ce61f9d..f2e270b 100644
--- a/src/main/java/mykyta/Harbor/Events/GUIEvent.java
+++ b/src/main/java/mykyta/Harbor/Events/GUIEvent.java
@@ -1,20 +1,24 @@
package mykyta.Harbor.Events;
+import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
-
import mykyta.Harbor.GUI.GUIType;
+import mykyta.Harbor.Util;
import mykyta.Harbor.GUI.GUIHolder;
public class GUIEvent implements Listener {
+ Util util = new Util();
+
@EventHandler
public void onClick(InventoryClickEvent event) {
if (event.getInventory().getHolder() != null && event.getInventory().getHolder() instanceof GUIHolder) {
GUIType t = ((GUIHolder) event.getInventory().getHolder()).getType();
if (t.equals(GUIType.SLEEPING)) event.setCancelled(true);
}
+ util.updateActivity((Player) event.getWhoClicked());
}
@EventHandler
@@ -23,5 +27,6 @@ public class GUIEvent implements Listener {
GUIType t = ((GUIHolder) event.getInventory().getHolder()).getType();
if (t.equals(GUIType.SLEEPING)) event.setCancelled(true);
}
+ util.updateActivity((Player) event.getWhoClicked());
}
}
\ No newline at end of file
diff --git a/src/main/java/mykyta/Harbor/Events/Move.java b/src/main/java/mykyta/Harbor/Events/Move.java
index 74c1a02..fcbcb70 100644
--- a/src/main/java/mykyta/Harbor/Events/Move.java
+++ b/src/main/java/mykyta/Harbor/Events/Move.java
@@ -6,22 +6,12 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
-
-import mykyta.Harbor.Config;
import mykyta.Harbor.Util;
public class Move implements Listener {
@EventHandler
public void onPlayerMovement(PlayerMoveEvent event) {
- Player p = event.getPlayer();
- Config config = new Config();
-
- if (Util.afk.contains(p)) {
- Util.afk.remove(p);
- p.setPlayerListName(ChatColor.translateAlternateColorCodes('&', p.getName()));
- Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.unafk")
- .replace("[player]", p.getName())));
- }
- Util.activity.put(event.getPlayer(), System.currentTimeMillis());
+ Util util = new Util();
+ util.updateActivity(event.getPlayer());
}
}
\ No newline at end of file
diff --git a/src/main/java/mykyta/Harbor/Harbor.java b/src/main/java/mykyta/Harbor/Harbor.java
index 1013ea3..4f998b6 100644
--- a/src/main/java/mykyta/Harbor/Harbor.java
+++ b/src/main/java/mykyta/Harbor/Harbor.java
@@ -10,6 +10,8 @@ import mykyta.Harbor.Commands.Command;
import mykyta.Harbor.Commands.Sleeping;
import mykyta.Harbor.Events.BedEnter;
import mykyta.Harbor.Events.BedLeave;
+import mykyta.Harbor.Events.ChatEvent;
+import mykyta.Harbor.Events.CommandEvent;
import mykyta.Harbor.Events.GUIEvent;
import mykyta.Harbor.Events.Move;
import mykyta.Harbor.Events.PlayerJoin;
@@ -31,6 +33,8 @@ public class Harbor extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new GUIEvent(), this);
Bukkit.getPluginManager().registerEvents(new PlayerJoin(), this);
Bukkit.getPluginManager().registerEvents(new PlayerLeave(), this);
+ Bukkit.getPluginManager().registerEvents(new CommandEvent(), this);
+ Bukkit.getPluginManager().registerEvents(new ChatEvent(), this);
util.setupNMS();
Bukkit.getServer().getWorlds().forEach(w -> {
diff --git a/src/main/java/mykyta/Harbor/Task.java b/src/main/java/mykyta/Harbor/Task.java
index b0938f8..3f88677 100644
--- a/src/main/java/mykyta/Harbor/Task.java
+++ b/src/main/java/mykyta/Harbor/Task.java
@@ -12,30 +12,33 @@ public class Task implements Runnable {
@Override
public void run() {
- Bukkit.getServer().getWorlds().forEach(w -> {
- if (w.getTime() >= 12516 && w.getTime() <= 12537 && config.getBoolean("features.title")) w.getPlayers().forEach(p -> {
- util.sendTitle(p, config.getString("messages.title.evening.top"), config.getString("messages.title.evening.bottom"));
- });
- if (util.getSleeping(w) > 0 && util.getNeeded(w) == 0) {
- util.skip(w);
- }
- if (util.getSleeping(w) > 0 && util.getSleeping(w) < w.getPlayers().size()) {w.getPlayers().forEach(p -> {util.sendActionbar(p, config.getString("messages.actionbar.sleeping"), w);});}
- else if (util.getSleeping(w) == util.getNeeded(w)) {w.getPlayers().forEach(p -> {util.sendActionbar(p, config.getString("messages.actionbar.everyone"), w);});}
-
- w.getPlayers().forEach(p -> {
- if (TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - Util.activity.get(p)) >= config.getInteger("values.timeout")) {
- if (Util.sleeping.get(w).contains(p)) {
- Util.activity.put(p, System.currentTimeMillis());
- return;
+ try {
+ Bukkit.getServer().getWorlds().forEach(w -> {
+ if (w.getTime() >= 12516 && w.getTime() <= 12537 && config.getBoolean("features.title")) w.getPlayers().forEach(p -> {
+ util.sendTitle(p, config.getString("messages.title.evening.top"), config.getString("messages.title.evening.bottom"));
+ });
+ if (util.getSleeping(w) > 0 && util.getNeeded(w) == 0) {
+ util.skip(w);
+ }
+ if (util.getSleeping(w) > 0 && util.getSleeping(w) < w.getPlayers().size()) {w.getPlayers().forEach(p -> {util.sendActionbar(p, config.getString("messages.actionbar.sleeping"), w);});}
+ else if (util.getSleeping(w) == util.getNeeded(w)) {w.getPlayers().forEach(p -> {util.sendActionbar(p, config.getString("messages.actionbar.everyone"), w);});}
+
+ w.getPlayers().forEach(p -> {
+ if (TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - Util.activity.get(p)) >= config.getInteger("values.timeout")) {
+ if (Util.sleeping.get(w).contains(p)) {
+ Util.activity.put(p, System.currentTimeMillis());
+ return;
+ }
+ if (!Util.afk.contains(p)) {
+ Util.afk.add(p);
+ p.setPlayerListName(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.afkprefix") + p.getName()));
+ Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.afk")
+ .replace("[player]", p.getName())));
+ }
}
- if (!Util.afk.contains(p)) {
- Util.afk.add(p);
- p.setPlayerListName(ChatColor.translateAlternateColorCodes('&', config.getString("messages.miscellaneous.afkprefix") + p.getName()));
- Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.afk")
- .replace("[player]", p.getName())));
- }
- }
+ });
});
- });
+ }
+ catch (Exception e) {if (Util.debug) e.printStackTrace();}
}
}
\ No newline at end of file
diff --git a/src/main/java/mykyta/Harbor/Util.java b/src/main/java/mykyta/Harbor/Util.java
index d510f47..2e57d3d 100644
--- a/src/main/java/mykyta/Harbor/Util.java
+++ b/src/main/java/mykyta/Harbor/Util.java
@@ -100,7 +100,8 @@ public class Util {
*/
public int getNeeded(World w) {
//FIXME make sure to remove excluded players
- return Math.max(0, (int) Math.ceil(w.getPlayers().size() * (config.getDouble("values.percent") / 100) - this.getSleeping(w)));
+ try {return Math.max(0, (int) Math.ceil(w.getPlayers().size() * (config.getDouble("values.percent") / 100) - this.getSleeping(w)));}
+ catch (NullPointerException e) {return 0;}
}
/**
@@ -108,7 +109,8 @@ public class Util {
* @param world World to check player count for
*/
public int getOnline(World w) {
- return Math.max(0, w.getPlayers().size() - getExcluded(w).size());
+ try {return Math.max(0, w.getPlayers().size() - getExcluded(w).size());}
+ catch (NullPointerException e) {return 0;}
}
/**
@@ -213,4 +215,17 @@ public class Util {
}
}
}
+
+ /**
+ * Updates the current player activity (AFK system)
+ * @param p Player to update activity for
+ */
+ public void updateActivity(Player p) {
+ if (afk.contains(p)) {
+ afk.remove(p);
+ p.setPlayerListName(ChatColor.translateAlternateColorCodes('&', p.getName()));
+ Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.unafk").replace("[player]", p.getName())));
+ }
+ activity.put(p, System.currentTimeMillis());
+ }
}
\ No newline at end of file