-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Divided chat by arena (Including lobby)
- Loading branch information
Showing
5 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/dev/_2lstudios/squidgame/listeners/AsyncPlayerChatListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters