Skip to content

Commit

Permalink
Merge pull request #44 from BentoBoxWorld/pladdon
Browse files Browse the repository at this point in the history
Make Pladdon
  • Loading branch information
tastybento authored Sep 26, 2024
2 parents dc52303 + bcfe093 commit 790912b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version>
<java.version>21</java.version>
<!-- Non-minecraft related dependencies -->
<powermock.version>2.0.9</powermock.version>
<!-- More visible way how to change dependency versions -->
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/world/bentobox/chat/ChatPladdon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package world.bentobox.chat;


import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.addons.Pladdon;

/**
* @author tastybento
*
*/
public class ChatPladdon extends Pladdon {
private Addon addon;

@Override
public Addon getAddon() {
if (addon == null) {
addon = new Chat();
}
return addon;
}
}
49 changes: 28 additions & 21 deletions src/main/java/world/bentobox/chat/listeners/ChatListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public class ChatListener implements Listener, EventExecutor {
private static final String MESSAGE = "[message]";
private final Chat addon;
private final Set<UUID> teamChatUsers;
private final Map<Island, Set<Player>> islands;
private final Map<Island, Set<Player>> islandChatters;
// List of which users are spying or not on team and island chat
private final Set<UUID> spies;
private final Set<UUID> islandSpies;

public ChatListener(Chat addon) {
this.teamChatUsers = new HashSet<>();
this.islands = new HashMap<>();
this.islandChatters = new HashMap<>();
this.addon = addon;
// Initialize spies
spies = new HashSet<>();
Expand Down Expand Up @@ -83,8 +83,8 @@ public void onChat(final AsyncPlayerChatEvent e) {
}
}
addon.getIslands().getIslandAt(p.getLocation())
.filter(islands.keySet()::contains)
.filter(i -> islands.get(i).contains(p))
.filter(islandChatters.keySet()::contains)
.filter(i -> islandChatters.get(i).contains(p))
.ifPresent(i -> {
// Cancel the event
e.setCancelled(true);
Expand All @@ -99,17 +99,13 @@ public void onChat(final AsyncPlayerChatEvent e) {
// Removes player from TeamChat set if he left the island
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onLeave(TeamLeaveEvent e) {

if (teamChatUsers.contains(e.getPlayerUUID()))
teamChatUsers.remove(e.getPlayerUUID());
teamChatUsers.remove(e.getPlayerUUID());
}

// Removes player from TeamChat set if he was kicked from the island
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onKick(TeamKickEvent e) {

if (teamChatUsers.contains(e.getPlayerUUID()))
teamChatUsers.remove(e.getPlayerUUID());
teamChatUsers.remove(e.getPlayerUUID());
}

public void islandChat(Island i, Player player, String message) {
Expand Down Expand Up @@ -157,6 +153,20 @@ public boolean isTeamChat(UUID playerUUID) {
return this.teamChatUsers.contains(playerUUID);
}

/**
* Whether the player has chat on or not. Note that with multiple islands the response is true
* if *any* chat is enabled
* @param playerUUID - player's UUID
* @return true if chat is active on any island
*/
public boolean isChat(UUID playerUUID) {
Player p = Bukkit.getPlayer(playerUUID);
if (p == null) {
return false;
}
return this.islandChatters.values().stream().anyMatch(playerSet -> playerSet.contains(p));
}

/**
* Toggles team chat spy. Spy must also have the spy permission to see chats
* @param playerUUID - the player's UUID
Expand Down Expand Up @@ -206,20 +216,17 @@ public boolean togglePlayerTeamChat(UUID playerUUID) {
/**
* Toggle island chat state
* @param island - island
* @param player - player
* @return true if island chat is now on, otherwise false
*/
public boolean toggleIslandChat(Island island, Player player) {
if (islands.containsKey(island)) {
if (islands.get(island).contains(player)) {
islands.get(island).remove(player);
return false;
}
islands.get(island).add(player);
return true;
}
else {
islands.put(island, new HashSet<>());
islands.get(island).add(player);
var chatters = islandChatters.computeIfAbsent(island, k -> new HashSet<>());

if (chatters.contains(player)) {
chatters.remove(player);
return false;
} else {
chatters.add(player);
return true;
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: BentoBox-Chat
main: world.bentobox.chat.ChatPladdon
version: ${project.version}${build.number}
api-version: "1.16"

authors: [tastybento]
contributors: ["The BentoBoxWorld Community"]
website: https://bentobox.world
description: ${project.description}

0 comments on commit 790912b

Please sign in to comment.