Skip to content

Commit

Permalink
Readded the notice feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwantux committed Nov 10, 2024
1 parent f64d79d commit 4d4056e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/java/de/kwantux/networks/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.kwantux.networks.commands.NetworksCommandManager;
import de.kwantux.networks.component.util.FilterTranslator;
import de.kwantux.networks.event.NoticeListener;
import de.kwantux.networks.utils.DoubleChestUtils;
import de.kwantux.networks.utils.FoliaUtils;
import de.kwantux.networks.utils.Metrics;
Expand Down Expand Up @@ -127,6 +128,7 @@ public void onEnable() {
new BlockBreakListener(this);
new WandListener(this);
new PlayerJoinListener(this);
new NoticeListener(this);

if (FoliaUtils.folia) {
logger.warning("Folia support on Networks is still in beta, please report any bugs.");
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/de/kwantux/networks/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ public Config(Main main) throws SerializationException {
}

public static boolean blastProofComponents; // TODO: Blast proof components
public static boolean noticeEnabled; // TODO: Notice message
/**
* Whether players that don't have a network should get a notification when opening a full chest
*/
public static boolean noticeEnabled;
public static boolean humanReadableJson;
public static boolean archiveNetworksOnDelete;
public static boolean requestOwnershipTransfers;
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/de/kwantux/networks/event/NoticeListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package de.kwantux.networks.event;

import de.kwantux.networks.Main;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import static de.kwantux.networks.Main.mgr;
import static de.kwantux.networks.Main.lang;

public class NoticeListener implements Listener {

private List<UUID> notices = new ArrayList<>();

public NoticeListener(Main plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

@EventHandler
public void onInventoryOpen(InventoryCloseEvent event) {
if (event.getInventory().firstEmpty() != -1) return;
if (notices.contains(event.getPlayer().getUniqueId())) return;
if (mgr.withUser(event.getPlayer().getUniqueId()).isEmpty()) {
notices.add(event.getPlayer().getUniqueId());
lang.message(event.getPlayer(), "notice");
}
}
}

0 comments on commit 4d4056e

Please sign in to comment.