Skip to content

Commit

Permalink
Merge pull request #43 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Release 1.3.0
  • Loading branch information
tastybento authored Nov 17, 2024
2 parents 093ac15 + a672d3d commit d9403fa
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 37 deletions.
99 changes: 84 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,27 @@
</issueManagement>

<distributionManagement>
<snapshotRepository>
<id>codemc-snapshots</id>
<url>https://repo.codemc.org/repository/maven-snapshots</url>
</snapshotRepository>
<repository>
<id>codemc-releases</id>
<url>https://repo.codemc.org/repository/maven-releases</url>
<id>bentoboxworld</id>
<url>https://repo.codemc.org/repository/bentoboxworld/</url>
</repository>
</distributionManagement>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<java.version>21</java.version>
<!-- Non-minecraft related dependencies -->
<powermock.version>2.0.2</powermock.version>
<powermock.version>2.0.9</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.16.3-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.15.4-SNAPSHOT</bentobox.version>
<spigot.version>1.21.3-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>2.7.1-SNAPSHOT</bentobox.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>1.2.0</build.version>
<build.version>1.3.0</build.version>
</properties>

<!-- Profiles will allow to automatically change build version. -->
Expand Down Expand Up @@ -123,6 +119,10 @@
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots</url>
</repository>
<repository>
<id>bentoboxworld</id>
<url>https://repo.codemc.org/repository/bentoboxworld</url>
</repository>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
Expand All @@ -145,7 +145,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.0.0</version>
<version>3.11.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -209,26 +209,61 @@
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<version>3.0.0-M5</version>
<configuration>
<argLine>
${argLine}
--add-opens java.base/java.lang=ALL-UNNAMED
--add-opens java.base/java.math=ALL-UNNAMED
--add-opens java.base/java.io=ALL-UNNAMED
--add-opens java.base/java.util=ALL-UNNAMED
--add-opens
java.base/java.util.stream=ALL-UNNAMED
--add-opens java.base/java.text=ALL-UNNAMED
--add-opens
java.base/java.util.regex=ALL-UNNAMED
--add-opens
java.base/java.nio.channels.spi=ALL-UNNAMED
--add-opens java.base/sun.nio.ch=ALL-UNNAMED
--add-opens java.base/java.net=ALL-UNNAMED
--add-opens
java.base/java.util.concurrent=ALL-UNNAMED
--add-opens java.base/sun.nio.fs=ALL-UNNAMED
--add-opens java.base/sun.nio.cs=ALL-UNNAMED
--add-opens java.base/java.nio.file=ALL-UNNAMED
--add-opens
java.base/java.nio.charset=ALL-UNNAMED
--add-opens
java.base/java.lang.reflect=ALL-UNNAMED
--add-opens
java.logging/java.util.logging=ALL-UNNAMED
--add-opens java.base/java.lang.ref=ALL-UNNAMED
--add-opens java.base/java.util.jar=ALL-UNNAMED
--add-opens java.base/java.util.zip=ALL-UNNAMED
</argLine>

</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<version>3.1.1</version>
<configuration>
<show>public</show>
<failOnError>false</failOnError>
<additionalJOption>-Xdoclint:none</additionalJOption>
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
</configuration>
<executions>
<execution>
Expand Down Expand Up @@ -262,6 +297,40 @@
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<configuration>
<append>true</append>
<excludes>
<!-- This is required to prevent Jacoco from adding
synthetic fields to a JavaBean class (causes errors in testing) -->
<exclude>**/*Names*</exclude>
<!-- Prevents the Material is too large to mock error -->
<exclude>org/bukkit/Material*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
<configuration>
<formats>
<format>XML</format>
</formats>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

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
2 changes: 1 addition & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Configuration file for Chat 1.2.0-SNAPSHOT-LOCAL.
# Configuration file for Chat {$version}.
team-chat:
# Lists the gamemodes in which you want the Team Chat to be effective.
gamemodes:
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 d9403fa

Please sign in to comment.