Skip to content

Commit

Permalink
fix infinite kill hopefully pt 2 & remove ffa tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandra-Myers committed Jul 26, 2024
1 parent 45f9e66 commit 04b495f
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 165 deletions.
85 changes: 19 additions & 66 deletions src/main/java/com/nexia/core/games/util/LobbyUtil.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
package com.nexia.core.games.util;

import com.nexia.base.player.NexiaPlayer;
import com.nexia.base.player.PlayerDataManager;
import com.nexia.core.NexiaCore;
import com.nexia.core.utilities.chat.ChatFormat;
import com.nexia.core.utilities.player.BanHandler;
import com.nexia.core.utilities.player.CorePlayerData;
import com.nexia.core.utilities.player.GamemodeBanHandler;
import com.nexia.base.player.NexiaPlayer;
import com.nexia.core.utilities.pos.EntityPos;
import com.nexia.core.utilities.world.WorldUtil;
import com.nexia.ffa.FfaGameMode;
import com.nexia.ffa.FfaUtil;
import com.nexia.ffa.classic.utilities.FfaAreas;
import com.nexia.ffa.base.BaseFfaUtil;
import com.nexia.ffa.classic.utilities.FfaClassicUtil;
import com.nexia.ffa.kits.utilities.FfaKitsUtil;
import com.nexia.ffa.sky.utilities.FfaSkyUtil;
import com.nexia.ffa.uhc.utilities.FfaUhcUtil;
import com.nexia.minigames.games.bedwars.players.BwPlayerEvents;
import com.nexia.minigames.games.duels.DuelGameHandler;
import com.nexia.minigames.games.football.FootballGame;
Expand Down Expand Up @@ -88,11 +82,6 @@ public static void setLobbyWorld(MinecraftServer server) {
public static String[] removedTags = {
PlayerGameMode.BEDWARS.tag,
"bedwars",
PlayerGameMode.FFA.tag,
"ffa_classic",
"ffa_kits",
"ffa_sky",
"ffa_uhc",
PlayerGameMode.FOOTBALL.tag,
"in_football_game",
"duels",
Expand Down Expand Up @@ -238,93 +227,57 @@ public static boolean checkGameModeBan(NexiaPlayer player, String game) {

public static void sendGame(NexiaPlayer player, String game, boolean message, boolean tp) {

if(checkGameModeBan(player, game)) {
if (checkGameModeBan(player, game)) {
return;
}

for (BaseFfaUtil util : BaseFfaUtil.ffaUtils){
for (BaseFfaUtil util : BaseFfaUtil.ffaUtils) {
if (game.equalsIgnoreCase(util.getNameLowercase() + " ffa") && !util.canGoToSpawn(player)) {
player.sendMessage(Component.text("You must be fully healed to go to spawn!").color(ChatFormat.failColor));
return;
}
}

if(player.hasTag("duels")) {
if (player.hasTag("duels")) {
player.removeTag("duels");
DuelGameHandler.leave(player, true);
}

player.reset(true, Minecraft.GameMode.ADVENTURE);
player.leaveAllGames();

if(game.equalsIgnoreCase("classic ffa") ||
if (game.equalsIgnoreCase("classic ffa") ||
game.equalsIgnoreCase("kits ffa") ||
game.equalsIgnoreCase("sky ffa") ||
game.equalsIgnoreCase("uhc ffa")) {
player.addTag(FfaUtil.FFA_TAG);
((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).gameMode = PlayerGameMode.FFA;
if (message) { player.sendActionBarMessage(Component.text("You have joined §8🗡 §7§lFFA §b🔱")); }
}

if(game.equalsIgnoreCase("classic ffa")){
player.addTag("ffa_classic");
FfaClassicUtil.INSTANCE.wasInSpawn.add(player.getUUID());
((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).ffaGameMode = FfaGameMode.CLASSIC;
if (tp) {
FfaClassicUtil.INSTANCE.sendToSpawn(player);
player.setRespawnPosition(FfaAreas.nexusFfaLocation, FfaAreas.spawn.yaw, true, false);
}

FfaClassicUtil.INSTANCE.joinOrRespawn(player, false);
FfaClassicUtil.INSTANCE.clearProjectiles(player);
FfaClassicUtil.INSTANCE.setInventory(player);
}

if(game.equalsIgnoreCase("sky ffa")){
player.addTag("ffa_sky");
FfaSkyUtil.INSTANCE.wasInSpawn.add(player.getUUID());
((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).ffaGameMode = FfaGameMode.SKY;
if (tp) {
FfaSkyUtil.INSTANCE.sendToSpawn(player);
player.setRespawnPosition(com.nexia.ffa.sky.utilities.FfaAreas.nexusFfaLocation, com.nexia.ffa.sky.utilities.FfaAreas.spawn.yaw, true, false);
}

FfaSkyUtil.INSTANCE.joinOrRespawn(player, false);
FfaSkyUtil.INSTANCE.clearProjectiles(player);
}
for (BaseFfaUtil util : BaseFfaUtil.ffaUtils) {
if (game.equalsIgnoreCase(util.getNameLowercase() + " ffa")) {
util.wasInSpawn.add(player.getUUID());
((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).ffaGameMode = util.getGameMode();
if (tp) {
util.sendToSpawn(player);
player.setRespawnPosition(util.getRespawnLocation(), util.getSpawn().yaw, true, false);
}

if(game.equalsIgnoreCase("uhc ffa")){
player.addTag("ffa_uhc");
FfaUhcUtil.INSTANCE.wasInSpawn.add(player.getUUID());
((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).ffaGameMode = FfaGameMode.UHC;
if (tp) {
FfaUhcUtil.INSTANCE.sendToSpawn(player);
player.setRespawnPosition(com.nexia.ffa.uhc.utilities.FfaAreas.nexusFfaLocation, com.nexia.ffa.uhc.utilities.FfaAreas.spawn.yaw, true, false);
util.joinOrRespawn(player, false);
util.clearProjectiles(player);
}

FfaUhcUtil.INSTANCE.joinOrRespawn(player, false);
FfaUhcUtil.INSTANCE.clearProjectiles(player);
}

if(game.equalsIgnoreCase("kits ffa")){
player.addTag("ffa_kits");
FfaKitsUtil.INSTANCE.wasInSpawn.add(player.getUUID());
((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).ffaGameMode = FfaGameMode.KITS;
if (tp) {
FfaKitsUtil.INSTANCE.sendToSpawn(player);
player.setRespawnPosition(com.nexia.ffa.kits.utilities.FfaAreas.nexusFfaLocation, com.nexia.ffa.kits.utilities.FfaAreas.spawn.yaw, true, false);
}

FfaKitsUtil.INSTANCE.joinOrRespawn(player, false);
FfaKitsUtil.INSTANCE.clearProjectiles(player);
if (game.equalsIgnoreCase("classic ffa")) {
FfaClassicUtil.INSTANCE.setInventory(player);
}

if(game.equalsIgnoreCase("bedwars")){
if (game.equalsIgnoreCase("bedwars")) {
if(message){ player.sendActionBarMessage(Component.text("You have joined §b\uD83E\uDE93 §c§lBedwars §e⚡"));}
BwPlayerEvents.tryToJoin(player, false);
}

if(game.equalsIgnoreCase("duels")){
if (game.equalsIgnoreCase("duels")) {
LobbyUtil.returnToLobby(player, tp);

if(message){
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/nexia/core/games/util/PlayerGameMode.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.nexia.core.games.util;

import com.nexia.ffa.FfaUtil;
import com.nexia.minigames.games.bedwars.players.BwPlayers;
import com.nexia.minigames.games.football.FootballGame;
import com.nexia.minigames.games.oitc.OitcGame;
Expand All @@ -26,7 +25,7 @@ public class PlayerGameMode {

public static final PlayerGameMode SKYWARS = new PlayerGameMode("skywars", "Skywars", SkywarsGame.SKYWARS_TAG);
public static final PlayerGameMode OITC = new PlayerGameMode("oitc", "OITC", OitcGame.OITC_TAG);
public static final PlayerGameMode FFA = new PlayerGameMode("ffa", "FFA", FfaUtil.FFA_TAG);
public static final PlayerGameMode FFA = new PlayerGameMode("ffa", "FFA", "ffa");
public static final PlayerGameMode FOOTBALL = new PlayerGameMode("football", "Football", FootballGame.FOOTBALL_TAG);

//public static final PlayerGameMode DUELS = new PlayerGameMode("duels");
Expand Down
34 changes: 10 additions & 24 deletions src/main/java/com/nexia/core/mixin/entity/LivingEntityMixin.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.nexia.core.mixin.entity;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
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.util.BwUtil;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.stats.Stats;
import net.minecraft.world.CombatRules;
import net.minecraft.world.damagesource.CombatTracker;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
Expand All @@ -25,9 +25,7 @@
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin extends Entity {
Expand All @@ -41,30 +39,18 @@ public LivingEntityMixin(EntityType<?> entityType, Level level) {

@Shadow public abstract ItemStack getBlockingItem();

@Shadow public abstract CombatTracker getCombatTracker();

@Shadow public abstract float getHealth();

@Shadow public abstract void setHealth(float f);

@Shadow public abstract float getAbsorptionAmount();

@Shadow public abstract void setAbsorptionAmount(float f);
@Shadow public abstract void kill();

// Make void death instant
@Inject(method = "actuallyHurt", at = @At(value = "HEAD"), cancellable = true)
protected void killInVoid(DamageSource damageSource, float f, CallbackInfo ci) {
if (!isInvulnerableTo(damageSource)) {
if (damageSource == DamageSource.OUT_OF_WORLD) {
if (getAbsorptionAmount() > 0.0F && getAbsorptionAmount() < 3.4028235E37F && damageSource.getEntity() instanceof ServerPlayer attacker) {
attacker.awardStat(Stats.DAMAGE_DEALT_ABSORBED, Math.round(getAbsorptionAmount() * 10));
}
setHealth(0);
getCombatTracker().recordDamage(damageSource, getHealth(), getHealth() + getAbsorptionAmount());
setAbsorptionAmount(0);
ci.cancel();
@WrapOperation(method = "outOfWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z"))
protected boolean killInVoid(LivingEntity instance, DamageSource damageSource, float f, Operation<Boolean> original) {
if ((Object)this instanceof ServerPlayer serverPlayer) {
if (((CorePlayerData) PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(serverPlayer.getUUID())).gameMode == PlayerGameMode.LOBBY) {
return original.call(instance, damageSource, f);
}
}
kill();
return true;
}

/**
Expand Down
25 changes: 0 additions & 25 deletions src/main/java/com/nexia/core/mixin/player/PlayerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.stats.Stats;
import net.minecraft.world.CombatRules;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.EntityType;
Expand All @@ -46,34 +45,10 @@ public abstract class PlayerMixin extends LivingEntity {

@Shadow public abstract ItemCooldowns getCooldowns();

@Shadow public abstract void awardStat(ResourceLocation resourceLocation, int i);

protected PlayerMixin(EntityType<? extends LivingEntity> entityType, Level level) {
super(entityType, level);
}

@Inject(method = "actuallyHurt", at = @At(value = "HEAD"), cancellable = true)
protected void killInVoid(DamageSource damageSource, float f, CallbackInfo ci) {
if (((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(getUUID())).gameMode == PlayerGameMode.LOBBY) {
return;
}
if (!isInvulnerableTo(damageSource)) {
if (damageSource == DamageSource.OUT_OF_WORLD) {
if (getAbsorptionAmount() > 0.0F && getAbsorptionAmount() < 3.4028235E37F) {
awardStat(Stats.DAMAGE_ABSORBED, Math.round(getAbsorptionAmount() * 10));
}
setHealth(0);
float totalHarm = getHealth() + getAbsorptionAmount();
getCombatTracker().recordDamage(damageSource, getHealth(), totalHarm);
setAbsorptionAmount(0);
if (totalHarm < 3.4028235E37F) {
awardStat(Stats.DAMAGE_TAKEN, Math.round(totalHarm * 10.0F));
}
ci.cancel();
}
}
}


/**
* @author NotCoded
Expand Down
9 changes: 1 addition & 8 deletions src/main/java/com/nexia/ffa/FfaUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,8 @@

public class FfaUtil {

public static final String FFA_TAG = "ffa";

public static boolean isFfaPlayer(NexiaPlayer player) {
return (player.hasTag(FFA_TAG)
|| player.hasTag("ffa_classic")
|| player.hasTag("ffa_kits")
|| player.hasTag("ffa_sky")
|| player.hasTag("ffa_uhc"))
&& ((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).gameMode == PlayerGameMode.FFA;
return ((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).gameMode == PlayerGameMode.FFA;
}

public static float calculateHealth(float health){
Expand Down
38 changes: 4 additions & 34 deletions src/main/java/com/nexia/ffa/base/BaseFfaUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.nexia.nexus.api.world.entity.player.Player;
import com.nexia.nexus.api.world.types.Minecraft;
import com.nexia.nexus.api.world.util.BoundingBox;
import com.nexia.nexus.api.world.util.Location;
import com.nexia.nexus.api.world.util.Vector3D;
import com.nexia.nexus.builder.implementation.world.entity.projectile.WrappedProjectile;
import io.github.blumbo.inventorymerger.InventoryMerger;
Expand All @@ -28,11 +29,6 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.projectile.Arrow;
import net.minecraft.world.entity.projectile.SpectralArrow;
import net.minecraft.world.entity.projectile.ThrownEnderpearl;
import net.minecraft.world.entity.projectile.ThrownTrident;
import net.minecraft.world.phys.AABB;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -70,13 +66,15 @@ public String getNameLowercase() {

public abstract EntityPos getSpawn();

public abstract Location getRespawnLocation();

public KillTracker getKillTracker() {
return killTracker;
}

public boolean isFfaPlayer(NexiaPlayer player) {
CorePlayerData data = (CorePlayerData) PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player);
return player.hasTag("ffa_" + getNameLowercase()) && data.gameMode == PlayerGameMode.FFA && data.ffaGameMode == getGameMode();
return data.gameMode == PlayerGameMode.FFA && data.ffaGameMode == getGameMode();
}

public boolean canGoToSpawn(NexiaPlayer player) {
Expand Down Expand Up @@ -304,34 +302,6 @@ public void clearProjectiles(NexiaPlayer player) {
}
}

public void clearThrownTridents(NexiaPlayer player) {
AABB aabb = getFfaCorners().contract(-10, -getFfaCorners().minY, -10).expandTowards(10, 319 - getFfaCorners().maxY, 10);
for (ThrownTrident trident : getFfaWorld().getEntities(EntityType.TRIDENT, aabb, trident -> trident.getOwner() != null && trident.getOwner().getUUID().equals(player.getUUID()))) {
trident.remove();
}
}

public void clearArrows(NexiaPlayer player) {
AABB aabb = getFfaCorners().contract(-10, -getFfaCorners().minY, -10).expandTowards(10, 319 - getFfaCorners().maxY, 10);
for (Arrow arrow : getFfaWorld().getEntities(EntityType.ARROW, aabb, arrow -> arrow.getOwner() != null && arrow.getOwner().getUUID().equals(player.getUUID()))) {
arrow.remove();
}
}

public void clearSpectralArrows(NexiaPlayer player) {
AABB aabb = getFfaCorners().contract(-10, -getFfaCorners().minY, -10).expandTowards(10, 319 - getFfaCorners().maxY, 10);
for (SpectralArrow arrow : getFfaWorld().getEntities(EntityType.SPECTRAL_ARROW, aabb, arrow -> arrow.getOwner() != null && arrow.getOwner().getUUID().equals(player.getUUID()))) {
arrow.remove();
}
}

public void clearEnderpearls(NexiaPlayer player) {
AABB aabb = getFfaCorners().contract(-10, -getFfaCorners().minY, -10).expandTowards(10, 319 - getFfaCorners().maxY, 10);
for (ThrownEnderpearl enderpearl : getFfaWorld().getEntities(EntityType.ENDER_PEARL, aabb, enderpearl -> enderpearl.getOwner() != null && enderpearl.getOwner().getUUID().equals(player.getUUID()))) {
enderpearl.remove();
}
}

public void leaveOrDie(@NotNull NexiaPlayer player, @Nullable DamageSource source, boolean leaving) {
ServerPlayer attacker = PlayerUtil.getPlayerAttacker(player.unwrap());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.nexia.ffa.FfaGameMode;
import com.nexia.ffa.base.BaseFfaUtil;
import com.nexia.nexus.api.world.World;
import com.nexia.nexus.api.world.util.Location;
import net.kyori.adventure.text.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -74,6 +75,11 @@ public EntityPos getSpawn() {
return spawn;
}

@Override
public Location getRespawnLocation() {
return nexusFfaLocation;
}

@Override
public void completeFiveTick(NexiaPlayer player) {
if(wasInSpawn.contains(player.getUUID()) && !isInFfaSpawn(player)){
Expand Down
Loading

0 comments on commit 04b495f

Please sign in to comment.