Skip to content

Commit

Permalink
add golden heads, enable crafting in uhc ffa and disable natural rege…
Browse files Browse the repository at this point in the history
…n in only uhc ffa
  • Loading branch information
Inf1nityy committed Dec 26, 2024
1 parent 462399b commit adaa25d
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.nexia.core.commands.staff.dev;

import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
Expand All @@ -11,21 +13,30 @@
import com.nexia.ffa.uhc.utilities.UhcFfaAreas;
import com.nexia.minigames.games.skywars.SkywarsGame;
import com.nexia.minigames.games.skywars.SkywarsMap;
import com.nexia.nexus.builder.implementation.util.ObjectMappings;
import io.github.blumbo.inventorymerger.saving.SavableInventory;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.loader.api.FabricLoader;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.minecraft.Util;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;

import java.io.FileWriter;
import java.util.UUID;

public class DevExperimentalCommandsCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
Expand All @@ -38,7 +49,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, bo
}
})
.then(Commands.argument("argument", StringArgumentType.string())
.suggests(((context, builder) -> SharedSuggestionProvider.suggest((new String[]{"cffa", "rluhc", "swmap", "saveinventory"}), builder)))
.suggests(((context, builder) -> SharedSuggestionProvider.suggest((new String[]{"cffa", "rluhc", "swmap", "saveinventory", "ghead"}), builder)))
.executes(DevExperimentalCommandsCommand::run))
)
);
Expand Down Expand Up @@ -84,6 +95,16 @@ private static int run(CommandContext<CommandSourceStack> context) throws Comman
}


} else if (argument.equalsIgnoreCase("ghead")) {
ItemStack itemStack = new ItemStack(Items.PLAYER_HEAD);
itemStack.setHoverName(ObjectMappings.convertComponent(Component.text("Golden head").decoration(TextDecoration.ITALIC, false).decorate(TextDecoration.BOLD).color(NamedTextColor.GOLD)));

GameProfile gameProfile = new GameProfile(UUID.fromString("70e06280-13c1-4c9d-8ca8-0d3ce118a534"), "NotInfinityy");
gameProfile.getProperties().get("textures").add(new Property("value", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvM2JiNjEyZWI0OTVlZGUyYzVjYTUxNzhkMmQxZWNmMWNhNWEyNTVkMjVkZmMzYzI1NGJjNDdmNjg0ODc5MWQ4In19fQ=="));

itemStack.getOrCreateTag().put("SkullOwner", NbtUtils.writeGameProfile(new CompoundTag(), gameProfile));

player.addItem(itemStack);
}

return 1;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/nexia/core/listeners/ListenerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public class ListenerHelper {
public static void registerListeners() {
// Nexus Listeners
new LivingEntityHealListener().registerListener();
new PlayerJoinListener().registerListener();
new PlayerDamageListener().registerListener();
new PlayerDeathListener().registerListener();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.nexia.core.listeners.nexus;

import com.nexia.base.player.NexiaPlayer;
import com.nexia.ffa.uhc.utilities.FfaUhcUtil;
import com.nexia.nexus.api.event.entity.LivingEntityHealEvent;

public class LivingEntityHealListener {
public void registerListener() {
LivingEntityHealEvent.BACKEND.register(livingEntityHealEvent -> {
if (!(livingEntityHealEvent.getEntity() instanceof NexiaPlayer nexiaPlayer)) return;

if (FfaUhcUtil.INSTANCE.isFfaPlayer(nexiaPlayer) && livingEntityHealEvent.getCause() == LivingEntityHealEvent.HealCause.NATURAL_REGENERATION) {
livingEntityHealEvent.setCancelled(true);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,86 @@
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.ffa.uhc.utilities.FfaUhcUtil;
import com.nexia.nexus.api.event.player.PlayerPlaceBlockEvent;
import com.nexia.nexus.api.event.player.PlayerUseItemEvent;
import com.nexia.nexus.api.world.item.ItemStack;
import com.nexia.core.games.util.PlayerGameMode;
import com.nexia.base.player.NexiaPlayer;
import net.kyori.adventure.text.Component;
import com.nexia.nexus.api.world.types.Minecraft;
import com.nexia.nexus.builder.implementation.world.effect.WrappedStatusEffectInstance;
import com.nexia.nexus.builder.implementation.world.item.WrappedItemStack;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;

import java.util.Random;

public class PlayerUseItemListener {
private void eatGoldenHead(NexiaPlayer player, ItemStack itemStack) {
player.addEffectInstance(new WrappedStatusEffectInstance(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 100)));
player.addEffectInstance(new WrappedStatusEffectInstance(new MobEffectInstance(MobEffects.ABSORPTION, 2400, 1)));
player.addEffectInstance(new WrappedStatusEffectInstance(new MobEffectInstance(MobEffects.REGENERATION, 100, 2)));
player.unwrap().playNotifySound(SoundEvents.PLAYER_BURP, SoundSource.PLAYERS, 0.5F, new Random().nextFloat() * 0.1F + 0.9F);

player.unwrap().getCooldowns().addCooldown(((WrappedItemStack) itemStack).unwrap().getItem(), 240);
itemStack.decrementCount();
player.refreshInventory();
}

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

NexiaPlayer player = new NexiaPlayer(playerUseItemEvent.getPlayer());

ItemStack itemStack = playerUseItemEvent.getItemStack();

Component name = itemStack.getDisplayName();
String name = itemStack.getDisplayName().toString().toLowerCase();

PlayerGameMode gameMode = ((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).gameMode;
String sName = name.toString().toLowerCase();

if(gameMode == PlayerGameMode.LOBBY) {
if(sName.contains("gamemode selector")){
if (name.contains("gamemode selector")) {
//PlayGUI.openMainGUI(minecraftPlayer);
player.runCommand("/play", 0, false);
return;
}

if(sName.contains("prefix selector")){
if (name.contains("prefix selector")) {
//PrefixGUI.openRankGUI(minecraftPlayer);
player.runCommand("/prefix", 0, false);
return;
}

if(sName.contains("duel sword") && !sName.contains("custom duel sword")) {
if (name.contains("duel sword") && !name.contains("custom duel sword")) {
//QueueGUI.openQueueGUI(minecraftPlayer);
player.runCommand("/queue", 0, false);
return;
}

if(sName.contains("team axe")) {
if (name.contains("team axe")) {
player.runCommand("/party list");
}
}

if (name.contains("golden head") && itemStack.getItem() == Minecraft.Item.PLAYER_HEAD && !FfaUhcUtil.INSTANCE.isInFfaSpawn(player)) {
eatGoldenHead(player, itemStack);
playerUseItemEvent.setCancelled(true);

}
});

PlayerPlaceBlockEvent.BACKEND.register(playerPlaceBlockEvent -> {
NexiaPlayer player = new NexiaPlayer(playerPlaceBlockEvent.getPlayer());

ItemStack itemStack = playerPlaceBlockEvent.getBlockStack();
if (itemStack.getDisplayName().toString().toLowerCase().contains("golden head") && itemStack.getItem() == Minecraft.Item.PLAYER_HEAD && !FfaUhcUtil.INSTANCE.isInFfaSpawn(player)) {
eatGoldenHead(player, itemStack);
playerPlaceBlockEvent.setCancelled(true);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.nexia.core.utilities.misc.EventUtil;
import com.nexia.core.utilities.player.CorePlayerData;
import com.nexia.core.utilities.time.ServerTime;
import com.nexia.ffa.FfaUtil;
import com.nexia.ffa.classic.utilities.FfaClassicUtil;
import com.nexia.ffa.kits.utilities.FfaKitsUtil;
import com.nexia.ffa.pot.utilities.FfaPotUtil;
Expand Down Expand Up @@ -136,7 +135,7 @@ private void handleContainerClick(ServerboundContainerClickPacket clickPacket, C
}
}

if (FfaUtil.isFfaPlayer(nexiaPlayer) || BwUtil.isBedWarsPlayer(nexiaPlayer)) {
if (BwUtil.isBedWarsPlayer(nexiaPlayer)) {
// If clicks on crafting slot
if (containerId == 0 && slot >= 1 && slot <= 4) {
ci.cancel();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/nexia/core/utilities/misc/EventUtil.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.nexia.core.utilities.misc;

import com.nexia.base.player.NexiaPlayer;
import com.nexia.core.games.util.LobbyUtil;
import com.nexia.core.gui.ffa.KitGUI;
import com.nexia.base.player.NexiaPlayer;
import com.nexia.ffa.FfaUtil;
import com.nexia.ffa.kits.utilities.KitFfaAreas;
import com.nexia.minigames.games.bedwars.util.BwUtil;
Expand Down Expand Up @@ -48,7 +48,7 @@ public static boolean dropItem(NexiaPlayer player, com.nexia.nexus.api.world.ite
}

public static boolean craftItem(NexiaPlayer player) {
if(FfaUtil.isFfaPlayer(player)) return false;
if (FfaUtil.isFfaPlayer(player)) return true;
if(LobbyUtil.isLobbyWorld(player.getWorld())) return false;
if(OitcGame.isOITCPlayer(player)) return false;
if(FootballGame.isFootballPlayer(player)) return false;
Expand Down

0 comments on commit adaa25d

Please sign in to comment.