mirror of
https://github.com/nkomarn/harbor.git
synced 2024-12-18 22:37:36 +01:00
Minor bug fixes and random skipped messages!
This commit is contained in:
parent
659c850169
commit
7712e8072b
@ -35,7 +35,7 @@ features:
|
||||
ignore: true
|
||||
# Prevent all players from entering a bed
|
||||
block: false
|
||||
# Display a title in the morning and when going to bed
|
||||
# Display a title message in the morning and when going to bed
|
||||
title: true
|
||||
# Displays a notification when a new update is released
|
||||
notifier: true
|
||||
@ -44,8 +44,11 @@ messages:
|
||||
chat:
|
||||
# Toggle chat messages
|
||||
chat: true
|
||||
# "Night skipped" chat message
|
||||
skipped: "&eThe night has been skipped."
|
||||
# "Night skipped" chat messages
|
||||
skipped:
|
||||
- "&eThe night has been skipped."
|
||||
- "&eAhhh, finally morning."
|
||||
- "&eArghh, it's so bright outside."
|
||||
# Display which player went to bed
|
||||
sleeping: "&e[player] is now sleeping ([sleeping]/[online]. [needed] more needed to skip)."
|
||||
# Display when a player left their bed
|
||||
|
@ -1,5 +1,7 @@
|
||||
package mykyta.Harbor.Commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
|
@ -1,5 +1,8 @@
|
||||
package mykyta.Harbor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
@ -81,4 +84,18 @@ public class Config {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a double from the configuration
|
||||
* @param location Configuration location of the double
|
||||
*/
|
||||
public List<String> getList(String location) {
|
||||
try {
|
||||
return harbor.getConfig().getStringList(location);
|
||||
}
|
||||
catch (Exception e) {
|
||||
error(e);
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
}
|
||||
}
|
@ -11,8 +11,7 @@ import mykyta.Harbor.GUI.GUIHolder;
|
||||
public class GUIEvent implements Listener {
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent event) {
|
||||
if (event.getInventory().getHolder() != null && event.getInventory().getHolder() instanceof Holder) {
|
||||
Player p = ((Player) event.getWhoClicked());
|
||||
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);
|
||||
}
|
||||
@ -20,8 +19,7 @@ public class GUIEvent implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onDrag(InventoryDragEvent event) {
|
||||
if (event.getInventory().getHolder() != null && event.getInventory().getHolder() instanceof Holder) {
|
||||
Player p = ((Player) event.getWhoClicked());
|
||||
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);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ public class Task implements Runnable {
|
||||
if (w.getTime() >= 12516 && w.getTime() <= 12547) w.getPlayers().forEach(p -> {
|
||||
util.sendTitle(p, config.getString("messages.title.evening.top"), config.getString("messages.title.evening.bottom"));
|
||||
});
|
||||
if (util.getSleeping(w) > 0 && Math.max(0, util.getNeeded(w) - util.getExcluded(w).size()) == 0) {
|
||||
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);});}
|
||||
|
@ -2,6 +2,8 @@ package mykyta.Harbor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -88,7 +90,8 @@ public class Util {
|
||||
* @param world World to fetch count for
|
||||
*/
|
||||
public int getSleeping(World w) {
|
||||
return Math.max(0, Util.sleeping.get(w).size());
|
||||
try {return Math.max(0, Util.sleeping.get(w).size());}
|
||||
catch (NullPointerException e) {return 0;}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -197,7 +200,12 @@ public class Util {
|
||||
}
|
||||
|
||||
// Display messages
|
||||
if (config.getBoolean("messages.chat.chat") && (config.getString("messages.chat.skipped").length() != 0)) Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', config.getString("messages.chat.skipped")));
|
||||
if (config.getBoolean("messages.chat.chat") && (config.getString("messages.chat.skipped").length() != 0)) {
|
||||
List<String> msgs = config.getList("messages.chat.skipped");
|
||||
Random r = new Random();
|
||||
int n = r.nextInt(msgs.size());
|
||||
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', msgs.get(n)));
|
||||
}
|
||||
if (config.getBoolean("features.title")) {
|
||||
w.getPlayers().forEach(p -> {
|
||||
this.sendTitle(p, config.getString("messages.title.morning.top"), config.getString("messages.title.morning.bottom"));
|
||||
|
Loading…
Reference in New Issue
Block a user