Skip to content

Commit

Permalink
Divided chat by arena (Including lobby)
Browse files Browse the repository at this point in the history
  • Loading branch information
sammwyy committed Oct 29, 2021
1 parent c9535e4 commit 6ab7f5e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Games are now deactivatable by setting their game time to -1
- Added an option to send the user to the lobby when they join the server.
- Added fireworks for the arena winner.
- Divided chat by arena (Including lobby)

### Fixed

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/dev/_2lstudios/jelly/utils/ObjectUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dev._2lstudios.jelly.utils;

public class ObjectUtils {
public static boolean checkEquals(final Object obj1, final Object obj2) {
if (obj1 == null && obj2 == null) {
return true;
}

if (obj1 == null || obj2 == null) {
return false;
}

return obj1.equals(obj2);
}
}
2 changes: 2 additions & 0 deletions src/main/java/dev/_2lstudios/squidgame/SquidGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import dev._2lstudios.squidgame.commands.SquidGameCommand;
import dev._2lstudios.squidgame.hooks.PlaceholderAPIHook;
import dev._2lstudios.squidgame.hooks.ScoreboardHook;
import dev._2lstudios.squidgame.listeners.AsyncPlayerChatListener;
import dev._2lstudios.squidgame.listeners.BlockBreakListener;
import dev._2lstudios.squidgame.listeners.BlockPlaceListener;
import dev._2lstudios.squidgame.listeners.EntityDamageListener;
Expand Down Expand Up @@ -57,6 +58,7 @@ public void onEnable() {
this.addCommand(new SquidGameCommand());

// Register listeners
this.addEventListener(new AsyncPlayerChatListener(this));
this.addEventListener(new BlockBreakListener(this));
this.addEventListener(new BlockPlaceListener(this));
this.addEventListener(new EntityDamageListener(this));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dev._2lstudios.squidgame.listeners;

import java.util.Iterator;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;

import dev._2lstudios.jelly.utils.ObjectUtils;
import dev._2lstudios.squidgame.SquidGame;
import dev._2lstudios.squidgame.player.SquidPlayer;

public class AsyncPlayerChatListener implements Listener {

private final SquidGame plugin;

public AsyncPlayerChatListener(final SquidGame plugin) {
this.plugin = plugin;
}

@EventHandler
public void onAsyncPlayerChat(final AsyncPlayerChatEvent e) {
if (this.plugin.getMainConfig().getBoolean("game-settings.per-arena-chat", true)) {
final SquidPlayer thisPlayer = (SquidPlayer) this.plugin.getPlayerManager().getPlayer(e.getPlayer());
final Iterator<Player> players = e.getRecipients().iterator();

if (thisPlayer == null) {
return;
}

while (players.hasNext()) {
final Player bukkitPlayer = players.next();
final SquidPlayer recipient = (SquidPlayer) this.plugin.getPlayerManager().getPlayer(bukkitPlayer);

if (!ObjectUtils.checkEquals(recipient.getArena(), thisPlayer.getArena())) {
players.remove();
}
}
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
game-settings:
allow-victory-before-completing-game: false
give-blindness-in-game-3: true
per-arena-chat: true
send-player-to-lobby-on-join: true
spawn-fireworks-on-win: true
min-players: 2
Expand Down

0 comments on commit 6ab7f5e

Please sign in to comment.