Skip to content

Commit

Permalink
chat, is this nexus listening? (probably untested?)
Browse files Browse the repository at this point in the history
  • Loading branch information
not-coded committed Aug 7, 2024
1 parent 408425e commit 19877b2
Show file tree
Hide file tree
Showing 22 changed files with 264 additions and 249 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/nexia/core/games/util/LobbyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public static void sendGame(NexiaPlayer player, String game, boolean message, bo
if(game.equalsIgnoreCase("oitc")){
player.addTag(OitcGame.OITC_TAG);
((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).gameMode = PlayerGameMode.OITC;
OitcGame.death(player, player.unwrap().getLastDamageSource());
OitcGame.death(player, null);

((OITCPlayerData)PlayerDataManager.getDataManager(NexiaCore.OITC_DATA_MANAGER).get(player)).gameMode = OitcGameMode.LOBBY;

Expand All @@ -311,7 +311,7 @@ public static void sendGame(NexiaPlayer player, String game, boolean message, bo
if(game.equalsIgnoreCase("skywars")){
player.addTag(PlayerGameMode.SKYWARS.tag);
((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).gameMode = PlayerGameMode.SKYWARS;
SkywarsGame.death(player, player.unwrap().getLastDamageSource());
SkywarsGame.death(player, null);

((SkywarsPlayerData)PlayerDataManager.getDataManager(NexiaCore.SKYWARS_DATA_MANAGER).get(player)).gameMode = SkywarsGameMode.LOBBY;

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/nexia/core/listeners/ListenerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ public class ListenerHelper {
public static void registerListeners() {
// Nexus Listeners
new PlayerJoinListener().registerListener();
new PlayerDamageListener().registerListener();
new PlayerDeathListener().registerListener();
new PlayerHungerListener().registerListener();
new PlayerLeaveListener().registerListener();
new PlayerSwapHandItemsListener().registerListener();
new UseItemListener().registerListener();
new PlayerUseItemListener().registerListener();
new PlayerDropItemListener().registerListener();
new PlayerRespawnListener().registerListener();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.nexia.core.listeners.nexus;

import com.nexia.base.player.NexiaPlayer;
import com.nexia.core.games.util.LobbyUtil;
import com.nexia.core.games.util.PlayerGameMode;
import com.nexia.core.utilities.player.PlayerUtil;
import com.nexia.ffa.base.BaseFfaUtil;
import com.nexia.nexus.api.event.entity.LivingEntityDamageEvent;
import com.nexia.nexus.api.world.damage.DamageData;
import com.nexia.nexus.api.world.entity.player.Player;

public class PlayerDamageListener {
public void registerListener() {
LivingEntityDamageEvent.BACKEND.register(livingEntityDamageEvent -> {
if(!(livingEntityDamageEvent.getLivingEntity() instanceof Player nexusPlayer)) return;
NexiaPlayer player = new NexiaPlayer(nexusPlayer);
DamageData damageData = livingEntityDamageEvent.getCause();

for (BaseFfaUtil util : BaseFfaUtil.ffaUtils) {
if (util.isFfaPlayer(player) && !util.beforeDamage(player, damageData)) {
livingEntityDamageEvent.setCancelled(true);
return;
}
}

if(LobbyUtil.isLobbyWorld(player.getWorld()) && damageData.getType().equals(DamageData.Type.VOID)) {
LobbyUtil.lobbySpawn.teleportPlayer(LobbyUtil.nexusLobbyWorld, player);
player.teleport(LobbyUtil.nexusLobbyLocation);
livingEntityDamageEvent.setCancelled(true);
return;
}

if (player.hasTag(LobbyUtil.NO_DAMAGE_TAG)) {
livingEntityDamageEvent.setCancelled(true);
return;
}

Player attacker = PlayerUtil.getPlayerAttacker(damageData);

if(attacker != null) {
if(attacker.hasTag(LobbyUtil.NO_DAMAGE_TAG)) {
livingEntityDamageEvent.setCancelled(true);
return;
}
}

if(damageData.getType().equals(DamageData.Type.VOID) && (!player.isInGameMode(PlayerGameMode.LOBBY) || player.isInGameMode(PlayerGameMode.FFA))) {
livingEntityDamageEvent.setDamage(1000);
return;
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.nexia.core.listeners.nexus;

import com.nexia.base.player.NexiaPlayer;
import com.nexia.base.player.PlayerDataManager;
import com.nexia.core.NexiaCore;
import com.nexia.core.games.util.PlayerGameMode;
import com.nexia.core.utilities.player.CorePlayerData;
import com.nexia.minigames.games.bedwars.areas.BwAreas;
import com.nexia.minigames.games.bedwars.players.BwPlayerEvents;
import com.nexia.minigames.games.duels.util.player.DuelsPlayerData;
import com.nexia.minigames.games.oitc.OitcGame;
import com.nexia.minigames.games.skywars.SkywarsGame;
import com.nexia.nexus.api.event.player.PlayerDeathEvent;

public class PlayerDeathListener {
public void registerListener() {
PlayerDeathEvent.BACKEND.register(playerDeathEvent -> {
NexiaPlayer nexiaPlayer = new NexiaPlayer(playerDeathEvent.getPlayer());

PlayerGameMode gameMode = ((CorePlayerData) PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(nexiaPlayer)).gameMode;
DuelsPlayerData duelsData = (DuelsPlayerData) PlayerDataManager.getDataManager(NexiaCore.DUELS_DATA_MANAGER).get(nexiaPlayer);

/*
if(FfaUtil.isFfaPlayer(nexiaPlayer)) {
FfaUtil.leaveOrDie(nexiaPlayer, playerDeathEvent, false);
}
*/

if (BwAreas.isBedWarsWorld(nexiaPlayer.getWorld())) {
BwPlayerEvents.death(nexiaPlayer);
return;
}

if(gameMode == PlayerGameMode.OITC){
OitcGame.death(nexiaPlayer, playerDeathEvent);
return;
}

if(gameMode == PlayerGameMode.SKYWARS) {
SkywarsGame.death(nexiaPlayer, playerDeathEvent);
return;
}

/*
if(gameMode == PlayerGameMode.LOBBY && duelsData.gameOptions != null) {
if(duelsData.gameOptions.duelsGame != null) {
duelsData.gameOptions.duelsGame.death(nexiaPlayer, playerDeathEvent);
return;
}
if(duelsData.gameOptions.teamDuelsGame != null) {
duelsData.gameOptions.teamDuelsGame.death(nexiaPlayer, playerDeathEvent);
return;
}
}
*/
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.nexia.core.listeners.nexus;

import com.nexia.base.player.NexiaPlayer;
import com.nexia.base.player.PlayerDataManager;
import com.nexia.core.NexiaCore;
import com.nexia.core.games.util.PlayerGameMode;
import com.nexia.core.utilities.player.CorePlayerData;
import com.nexia.minigames.games.duels.DuelGameMode;
import com.nexia.minigames.games.duels.util.player.DuelsPlayerData;
import com.nexia.minigames.games.skywars.SkywarsGame;
import com.nexia.minigames.games.skywars.SkywarsGameMode;
import com.nexia.minigames.games.skywars.util.player.SkywarsPlayerData;
import com.nexia.nexus.api.event.player.PlayerFoodLevelsChangeEvent;

public class PlayerHungerListener {
public void registerListener(){
PlayerFoodLevelsChangeEvent.BACKEND.register(playerFoodLevelsChangeEvent -> {
NexiaPlayer player = new NexiaPlayer(playerFoodLevelsChangeEvent.getPlayer());

// SkyWars
SkywarsPlayerData playerData = (SkywarsPlayerData) PlayerDataManager.getDataManager(NexiaCore.SKYWARS_DATA_MANAGER).get(player);
if(SkywarsGame.isSkywarsPlayer(player) && playerData.gameMode.equals(SkywarsGameMode.PLAYING)) return;

// Duels
DuelGameMode duelGameMode = ((DuelsPlayerData)PlayerDataManager.getDataManager(NexiaCore.DUELS_DATA_MANAGER).get(player)).gameMode;
PlayerGameMode gameMode = ((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).gameMode;
if(gameMode.equals(PlayerGameMode.LOBBY) && (duelGameMode != null && !duelGameMode.hasSaturation)) return;

playerFoodLevelsChangeEvent.setFoodLevel(20);
playerFoodLevelsChangeEvent.setCancelled(true);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import com.nexia.core.utilities.time.ServerTime;
import com.nexia.discord.NexiaDiscord;
import com.nexia.nexus.api.event.player.PlayerJoinEvent;
import com.nexia.nexus.api.world.entity.player.Player;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
import net.minecraft.stats.Stats;

import java.util.Objects;

Expand All @@ -27,30 +27,42 @@ public void registerListener() {
PlayerJoinEvent.BACKEND.register(playerJoinEvent -> {

NexiaPlayer player = new NexiaPlayer(playerJoinEvent.getPlayer());
processJoin(player);

/*
if(minecraftPlayer.getStats().getValue(Stats.CUSTOM.get(Stats.LEAVE_GAME)) <= 1) {
playerJoinEvent.setJoinMessage(
Component.text("[").color(ChatFormat.lineColor)
.append(Component.text("!").color(TextColor.fromHexString("#ff9940")))
.append(Component.text("] ").color(ChatFormat.lineColor))
.append(Component.text(player.getRawName()).color(TextColor.fromHexString("#ff9940")))
);
} else {
playerJoinEvent.setJoinMessage(
Component.text("[").color(ChatFormat.lineColor)
.append(Component.text("+").color(ChatFormat.greenColor))
.append(Component.text("] ").color(ChatFormat.lineColor))
.append(Component.text(player.getRawName()).color(ChatFormat.greenColor))
);
}
*/
if(((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).clientType.equals(CorePlayerData.ClientType.VIAFABRICPLUS)) return;

//setJoinMessage(player, playerJoinEvent);

PlayerDataManager.dataManagerMap.forEach((resourceLocation, playerDataManager) -> playerDataManager.addPlayerData(player));

LobbyUtil.returnToLobby(player, true);
checkBooster(player);

ServerTime.scheduler.schedule(() -> {
sendJoinMessage(player);
}, 10);


});
}

private static void setJoinMessage(NexiaPlayer player, PlayerJoinEvent playerJoinEvent) {
if(player.unwrap().getStats().getValue(Stats.CUSTOM.get(Stats.LEAVE_GAME)) < 1) {
playerJoinEvent.setJoinMessage(
net.kyori.adventure.text.Component.text("[").color(ChatFormat.lineColor)
.append(net.kyori.adventure.text.Component.text("!").color(ChatFormat.goldColor)
.append(net.kyori.adventure.text.Component.text("] ").color(ChatFormat.lineColor))
.append(net.kyori.adventure.text.Component.text(player.getRawName()).color(ChatFormat.goldColor)))
);
} else {
playerJoinEvent.setJoinMessage(
net.kyori.adventure.text.Component.text("[").color(ChatFormat.lineColor)
.append(net.kyori.adventure.text.Component.text("+").color(ChatFormat.greenColor))
.append(net.kyori.adventure.text.Component.text("] ").color(ChatFormat.lineColor))
.append(net.kyori.adventure.text.Component.text(player.getRawName()).color(ChatFormat.greenColor))
);
}
}

private static void sendJoinMessage(Player player){
private static void sendJoinMessage(NexiaPlayer player){
player.sendMessage(ChatFormat.separatorLine("Welcome"));
player.sendMessage(
Component.text(" » ", ChatFormat.brandColor2)
Expand Down Expand Up @@ -124,15 +136,4 @@ private static void checkBooster(NexiaPlayer player) {
NexiaRank.setRank(NexiaRank.DEFAULT, player);
}
}

private static void processJoin(NexiaPlayer player) {
if(((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).clientType.equals(CorePlayerData.ClientType.VIAFABRICPLUS)) return;

PlayerDataManager.dataManagerMap.forEach((resourceLocation, playerDataManager) -> playerDataManager.addPlayerData(player));

LobbyUtil.returnToLobby(player, true);

checkBooster(player);
sendJoinMessage(player);
}
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,31 @@
package com.nexia.core.listeners.nexus;

import com.nexia.base.player.PlayerDataManager;
import com.nexia.base.player.NexiaPlayer;
import com.nexia.base.player.PlayerDataManager;
import com.nexia.core.utilities.chat.ChatFormat;
import com.nexia.nexus.api.event.player.PlayerDisconnectEvent;
import net.kyori.adventure.text.Component;

public class PlayerLeaveListener {
public void registerListener() {
PlayerDisconnectEvent.BACKEND.register(playerDisconnectEvent -> {

NexiaPlayer player = new NexiaPlayer(playerDisconnectEvent.getPlayer());
processDisconnect(player);
player.leaveAllGames();

/*
if(NexiaCore.config.events.statusMessages){
playerDisconnectEvent.setLeaveMessage(
Component.text("[").color(ChatFormat.lineColor)
.append(Component.text("-", ChatFormat.failColor)
.append(Component.text("] ").color(ChatFormat.lineColor))
.append(Component.text(player.getRawName(), ChatFormat.failColor)))
);
}
//setLeaveMessage(player, playerDisconnectEvent);

*/
PlayerDataManager.dataManagerMap.forEach((resourceLocation, playerDataManager) -> playerDataManager.removePlayerData(player));
});
}



private static void processDisconnect(NexiaPlayer player){
/*
if (BwUtil.isInBedWars(player)) BwPlayerEvents.leaveInBedWars(player);
else if (FfaUtil.isFfaPlayer(player)) {
FfaUtil.leaveOrDie(player, player.getLastDamageSource(), true);
}
else if (PlayerDataManager.get(player).gameMode == PlayerGameMode.LOBBY) DuelGameHandler.leave(player, true);
else if (PlayerDataManager.get(player).gameMode == PlayerGameMode.SKYWARS) SkywarsGame.leave(player);
else if (PlayerDataManager.get(player).gameMode == PlayerGameMode.OITC) OitcGame.leave(player);
else if (PlayerDataManager.get(player).gameMode == PlayerGameMode.FOOTBALL) FootballGame.leave(player);
else if (player.hasTag("duels")) DuelGameHandler.leave(player, true);
*/

player.leaveAllGames();

PlayerDataManager.dataManagerMap.forEach((resourceLocation, playerDataManager) -> playerDataManager.removePlayerData(player));
private static void setLeaveMessage(NexiaPlayer player, PlayerDisconnectEvent playerDisconnectEvent){
playerDisconnectEvent.setLeaveMessage(
Component.text("[").color(ChatFormat.lineColor)
.append(Component.text("-", ChatFormat.failColor))
.append(Component.text("] ").color(ChatFormat.lineColor))
.append(Component.text(player.getRawName(), ChatFormat.failColor))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public void registerListener() {
if (ffaUtil != null) {
respawnEvent.setRespawnMode(ffaUtil.getMinecraftGameMode());
respawnEvent.setSpawnpoint(ffaUtil.getRespawnLocation());
respawnEvent.runAfterwards(() -> ffaUtil.respawn(new NexiaPlayer(respawnEvent.getPlayer())));
respawnEvent.runAfterwards(() -> {
ffaUtil.respawn(player.refreshPlayer());
player.setInvulnerabilityTime(0);
});
}
return;
case "skywars":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

public class PlayerSwapHandItemsListener {
public void registerListener(){
PlayerSwapHandItemsEvent.BACKEND.register(playerDropItemEvent -> {

NexiaPlayer player = new NexiaPlayer(playerDropItemEvent.getPlayer());
PlayerSwapHandItemsEvent.BACKEND.register(playerSwapHandItemsEvent -> {
NexiaPlayer player = new NexiaPlayer(playerSwapHandItemsEvent.getPlayer());

if(LobbyUtil.isLobbyWorld(player.getWorld())) {
playerDropItemEvent.setCancelled(true);
playerSwapHandItemsEvent.setCancelled(true);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.nexia.base.player.NexiaPlayer;
import net.kyori.adventure.text.Component;

public class UseItemListener {
public class PlayerUseItemListener {
public void registerListener() {
PlayerUseItemEvent.BACKEND.register(playerUseItemEvent -> {

Expand Down
Loading

0 comments on commit 19877b2

Please sign in to comment.