-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
188 additions
and
150 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
64 changes: 32 additions & 32 deletions
64
...nchat/bukkit/listeners/LoginListener.java → ...chat/bukkit/listeners/PlayerListener.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 |
---|---|---|
@@ -1,32 +1,32 @@ | ||
package com.mineaurion.aurionchat.bukkit.listeners; | ||
|
||
import com.mineaurion.aurionchat.bukkit.AurionChat; | ||
import com.mineaurion.aurionchat.common.listeners.LoginListenerCommon; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerJoinEvent; | ||
import org.bukkit.event.player.PlayerKickEvent; | ||
import org.bukkit.event.player.PlayerQuitEvent; | ||
|
||
public class LoginListener extends LoginListenerCommon<AurionChat> implements Listener { | ||
|
||
public LoginListener(AurionChat plugin){ | ||
super(plugin); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.LOW) | ||
public void onPlayerKick(PlayerKickEvent event){ | ||
playerLeaving(plugin.getPlayerFactory().wrap(event.getPlayer())); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.LOW) | ||
public void onPlayerQuit(PlayerQuitEvent event){ | ||
playerLeaving(plugin.getPlayerFactory().wrap(event.getPlayer())); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.LOW) | ||
public void onPlayerJoin(PlayerJoinEvent event){ | ||
playerJoin(plugin.getPlayerFactory().wrap(event.getPlayer())); | ||
} | ||
} | ||
package com.mineaurion.aurionchat.bukkit.listeners; | ||
|
||
import com.mineaurion.aurionchat.bukkit.AurionChat; | ||
import com.mineaurion.aurionchat.common.listeners.PlayerListenerCommon; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerJoinEvent; | ||
import org.bukkit.event.player.PlayerKickEvent; | ||
import org.bukkit.event.player.PlayerQuitEvent; | ||
|
||
public class PlayerListener extends PlayerListenerCommon<AurionChat> implements Listener { | ||
|
||
public PlayerListener(AurionChat plugin){ | ||
super(plugin); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.LOW) | ||
public void onPlayerKick(PlayerKickEvent event){ | ||
playerLeaving(plugin.getPlayerFactory().wrap(event.getPlayer())); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.LOW) | ||
public void onPlayerQuit(PlayerQuitEvent event){ | ||
playerLeaving(plugin.getPlayerFactory().wrap(event.getPlayer())); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.LOW) | ||
public void onPlayerJoin(PlayerJoinEvent event){ | ||
playerJoin(plugin.getPlayerFactory().wrap(event.getPlayer())); | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
common/src/main/java/com/mineaurion/aurionchat/common/listeners/LoginListenerCommon.java
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
common/src/main/java/com/mineaurion/aurionchat/common/listeners/PlayerListenerCommon.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,74 @@ | ||
package com.mineaurion.aurionchat.common.listeners; | ||
|
||
import com.mineaurion.aurionchat.api.AurionPacket; | ||
import com.mineaurion.aurionchat.common.AbstractAurionChat; | ||
import com.mineaurion.aurionchat.common.AurionChatPlayer; | ||
import com.mineaurion.aurionchat.common.player.Player; | ||
import net.kyori.adventure.text.Component; | ||
|
||
import static com.mineaurion.aurionchat.api.AurionPacket.Type.*; | ||
|
||
public abstract class PlayerListenerCommon<T extends AbstractAurionChat> { | ||
public T plugin; | ||
|
||
public PlayerListenerCommon(T plugin){ | ||
this.plugin = plugin; | ||
} | ||
|
||
protected void playerJoin(Player player){ | ||
AurionChatPlayer plr = new AurionChatPlayer(player, plugin); | ||
this.plugin.getAurionChatPlayers().putIfAbsent(player.getUUID(), plr); | ||
//todo: needs join/leave message pattern | ||
String txt = plr.getBestName() + " joined the game"; | ||
Component component = Component.text(txt); | ||
AurionPacket.Builder packet = AurionPacket.event(plr, JOIN, component) | ||
.detail(txt); | ||
try { | ||
this.plugin.getChatService().send(packet); | ||
} catch (Throwable e) { | ||
plugin.getlogger().severe("Failed to send PlayerJoin event", e); | ||
} | ||
} | ||
|
||
protected void playerLeaving(Player player){ | ||
AurionChatPlayer plr = this.plugin.getAurionChatPlayers().remove(player.getUUID()); | ||
//todo: needs join/leave message pattern | ||
String txt = plr.getBestName() + " left the game"; | ||
Component component = Component.text(txt); | ||
AurionPacket.Builder packet = AurionPacket.event(plr, LEAVE, component) | ||
.detail(txt); | ||
try { | ||
this.plugin.getChatService().send(packet); | ||
} catch (Throwable e) { | ||
plugin.getlogger().severe("Failed to send PlayerLeave event", e); | ||
} | ||
} | ||
|
||
protected void playerAdvancement(Player player, String sanitizedAdvancementMessage){ | ||
AurionChatPlayer plr = this.plugin.getAurionChatPlayers().remove(player.getUUID()); | ||
Component component = Component.text(sanitizedAdvancementMessage); | ||
AurionPacket.Builder packet = AurionPacket.event(plr, ADVANCEMENT, component) | ||
.detail(sanitizedAdvancementMessage); | ||
try { | ||
this.plugin.getChatService().send(packet); | ||
} catch (Throwable e) { | ||
plugin.getlogger().severe("Failed to send PlayerAdvancement event", e); | ||
} | ||
} | ||
|
||
protected void playerDeath(Player player, String sanitizedDeathMessage){ | ||
AurionChatPlayer plr = this.plugin.getAurionChatPlayers().remove(player.getUUID()); | ||
Component component = Component.text(sanitizedDeathMessage); | ||
AurionPacket.Builder packet = AurionPacket.event(plr, DEATH, component) | ||
.detail(sanitizedDeathMessage); | ||
try { | ||
this.plugin.getChatService().send(packet); | ||
} catch (Throwable e) { | ||
plugin.getlogger().severe("Failed to send PlayerDeath event", e); | ||
} | ||
} | ||
|
||
public T getPlugin(){ | ||
return this.plugin; | ||
} | ||
} |
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
38 changes: 19 additions & 19 deletions
38
...nchat/fabric/listeners/LoginListener.java → ...chat/fabric/listeners/PlayerListener.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 |
---|---|---|
@@ -1,19 +1,19 @@ | ||
package com.mineaurion.aurionchat.fabric.listeners; | ||
|
||
import com.mineaurion.aurionchat.common.listeners.LoginListenerCommon; | ||
import com.mineaurion.aurionchat.fabric.AurionChat; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
|
||
public class LoginListener extends LoginListenerCommon<AurionChat> { | ||
public LoginListener(AurionChat plugin){ | ||
super(plugin); | ||
} | ||
|
||
public void onPlayerJoin(ServerPlayerEntity player){ | ||
playerJoin(plugin.getPlayerFactory().wrap(player)); | ||
} | ||
|
||
public void onPlayerQuit(ServerPlayerEntity player){ | ||
this.playerLeaving(plugin.getPlayerFactory().wrap(player)); | ||
} | ||
} | ||
package com.mineaurion.aurionchat.fabric.listeners; | ||
|
||
import com.mineaurion.aurionchat.common.listeners.PlayerListenerCommon; | ||
import com.mineaurion.aurionchat.fabric.AurionChat; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
|
||
public class PlayerListener extends PlayerListenerCommon<AurionChat> { | ||
public PlayerListener(AurionChat plugin){ | ||
super(plugin); | ||
} | ||
|
||
public void onPlayerJoin(ServerPlayerEntity player){ | ||
playerJoin(plugin.getPlayerFactory().wrap(player)); | ||
} | ||
|
||
public void onPlayerQuit(ServerPlayerEntity player){ | ||
this.playerLeaving(plugin.getPlayerFactory().wrap(player)); | ||
} | ||
} |
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
50 changes: 25 additions & 25 deletions
50
...onchat/forge/listeners/LoginListener.java → ...nchat/forge/listeners/PlayerListener.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 |
---|---|---|
@@ -1,25 +1,25 @@ | ||
package com.mineaurion.aurionchat.forge.listeners; | ||
|
||
import com.mineaurion.aurionchat.common.listeners.LoginListenerCommon; | ||
import com.mineaurion.aurionchat.forge.AurionChat; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraftforge.event.entity.player.PlayerEvent; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
|
||
|
||
public class LoginListener extends LoginListenerCommon<AurionChat> { | ||
|
||
public LoginListener(AurionChat plugin){ | ||
super(plugin); | ||
} | ||
|
||
@SubscribeEvent | ||
public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) { | ||
playerJoin(plugin.getPlayerFactory().wrap((ServerPlayer) event.getEntity())); | ||
} | ||
|
||
@SubscribeEvent | ||
public void onPlayerQuit(PlayerEvent.PlayerLoggedOutEvent event){ | ||
playerLeaving(plugin.getPlayerFactory().wrap((ServerPlayer) event.getEntity())); | ||
} | ||
} | ||
package com.mineaurion.aurionchat.forge.listeners; | ||
|
||
import com.mineaurion.aurionchat.common.listeners.PlayerListenerCommon; | ||
import com.mineaurion.aurionchat.forge.AurionChat; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraftforge.event.entity.player.PlayerEvent; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
|
||
|
||
public class PlayerListener extends PlayerListenerCommon<AurionChat> { | ||
|
||
public PlayerListener(AurionChat plugin){ | ||
super(plugin); | ||
} | ||
|
||
@SubscribeEvent | ||
public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) { | ||
playerJoin(plugin.getPlayerFactory().wrap((ServerPlayer) event.getEntity())); | ||
} | ||
|
||
@SubscribeEvent | ||
public void onPlayerQuit(PlayerEvent.PlayerLoggedOutEvent event){ | ||
playerLeaving(plugin.getPlayerFactory().wrap((ServerPlayer) event.getEntity())); | ||
} | ||
} |
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
Oops, something went wrong.