death system, toggleable pvp, end and nether

This commit is contained in:
Infinityy committed 2024-06-29 01:44:54 +02:00
1 parent 77b896e9a1
commit 4dbdd93918
13 files changed
+226 -1

No files matched your search

@@ -13,9 +13,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class NexiaTeams implements ModInitializer {
public static final String MOD_ID = "nexia-teams";
public static Logger logger = LoggerFactory.getLogger(MOD_ID);
public static boolean pvpEnabled = false;
public static boolean endDisabled = true;
public static boolean netherDisabled = true;
public static boolean hardcoreEnabled = false;
@Override
public void onInitialize() {
@@ -13,5 +13,9 @@ public class CommandLoader {
callbackEvent.register(TeamCommand::register);
callbackEvent.register(MeteorCommand::register);
callbackEvent.register(CalendarCommand::register);
callbackEvent.register(HardcoreCommand::register);
callbackEvent.register(PvpCommand::register);
callbackEvent.register(EndCommand::register);
callbackEvent.register(NetherCommand::register);
}
}
@@ -0,0 +1,22 @@
package com.nexia.teams.commands;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.nexia.teams.NexiaTeams;
import com.nexia.teams.utilities.chat.ChatFormat;
import net.kyori.adventure.text.Component;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
public class EndCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext commandBuildContext, Commands.CommandSelection commandSelection) {
dispatcher.register(Commands.literal("end").requires(commandSourceStack -> commandSourceStack.hasPermission(4)).executes(EndCommand::execute));
}
private static int execute(CommandContext<CommandSourceStack> context) {
NexiaTeams.endDisabled = !NexiaTeams.endDisabled;
context.getSource().sendSystemMessage(ChatFormat.convertComponent(ChatFormat.nexiaMessage.append(Component.text((NexiaTeams.endDisabled ? "Disabled" : "Enabled") + " end."))));
return 0;
}
}
@@ -0,0 +1,22 @@
package com.nexia.teams.commands;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.nexia.teams.NexiaTeams;
import com.nexia.teams.utilities.chat.ChatFormat;
import net.kyori.adventure.text.Component;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
public class HardcoreCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext commandBuildContext, Commands.CommandSelection commandSelection) {
dispatcher.register(Commands.literal("hardcore").requires(commandSourceStack -> commandSourceStack.hasPermission(4)).executes(HardcoreCommand::execute));
}
private static int execute(CommandContext<CommandSourceStack> context) {
NexiaTeams.hardcoreEnabled = !NexiaTeams.hardcoreEnabled;
context.getSource().sendSystemMessage(ChatFormat.convertComponent(ChatFormat.nexiaMessage.append(Component.text((NexiaTeams.hardcoreEnabled ? "Enabled" : "Disabled") + " hardcore death system."))));
return 0;
}
}
@@ -0,0 +1,22 @@
package com.nexia.teams.commands;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.nexia.teams.NexiaTeams;
import com.nexia.teams.utilities.chat.ChatFormat;
import net.kyori.adventure.text.Component;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
public class NetherCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext commandBuildContext, Commands.CommandSelection commandSelection) {
dispatcher.register(Commands.literal("nether").requires(commandSourceStack -> commandSourceStack.hasPermission(4)).executes(NetherCommand::execute));
}
private static int execute(CommandContext<CommandSourceStack> context) {
NexiaTeams.netherDisabled = !NexiaTeams.netherDisabled;
context.getSource().sendSystemMessage(ChatFormat.convertComponent(ChatFormat.nexiaMessage.append(Component.text((NexiaTeams.netherDisabled ? "Disabled" : "Enabled") + " nether."))));
return 0;
}
}
@@ -0,0 +1,22 @@
package com.nexia.teams.commands;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.nexia.teams.NexiaTeams;
import com.nexia.teams.utilities.chat.ChatFormat;
import net.kyori.adventure.text.Component;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
public class PvpCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext commandBuildContext, Commands.CommandSelection commandSelection) {
dispatcher.register(Commands.literal("pvp").requires(commandSourceStack -> commandSourceStack.hasPermission(4)).executes(PvpCommand::execute));
}
private static int execute(CommandContext<CommandSourceStack> context) {
NexiaTeams.pvpEnabled = !NexiaTeams.pvpEnabled;
context.getSource().sendSystemMessage(ChatFormat.convertComponent(ChatFormat.nexiaMessage.append(Component.text((NexiaTeams.hardcoreEnabled ? "Enabled" : "Disabled") + " pvp."))));
return 0;
}
}
@@ -0,0 +1,22 @@
package com.nexia.teams.mixin;
import com.nexia.teams.NexiaTeams;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.EndPortalBlock;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(EndPortalBlock.class)
public abstract class EndPortalBlockMixin {
@Inject(method = "entityInside", at = @At("HEAD"), cancellable = true)
private void disableEnd(BlockState blockState, Level level, BlockPos blockPos, Entity entity, CallbackInfo ci) {
if (NexiaTeams.endDisabled) {
ci.cancel();
}
}
}
@@ -0,0 +1,22 @@
package com.nexia.teams.mixin;
import com.nexia.teams.NexiaTeams;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.NetherPortalBlock;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(NetherPortalBlock.class)
public abstract class NetherPortalBlockMixin {
@Inject(method = "entityInside", at = @At("HEAD"), cancellable = true)
private void disableNetherPortal(BlockState blockState, Level level, BlockPos blockPos, Entity entity, CallbackInfo ci) {
if (NexiaTeams.netherDisabled) {
ci.cancel();
}
}
}
@@ -1,18 +1,24 @@
package com.nexia.teams.mixin;
import com.nexia.teams.NexiaTeams;
import com.nexia.teams.utilities.chat.ChatFormat;
import net.kyori.adventure.text.Component;
import net.minecraft.network.protocol.game.ServerboundClientCommandPacket;
import net.minecraft.network.protocol.game.ServerboundInteractPacket;
import net.minecraft.network.protocol.game.ServerboundTeleportToEntityPacket;
import net.minecraft.network.protocol.game.ServerboundUseItemPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.GameType;
import org.spongepowered.asm.mixin.Mixin;
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.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ServerGamePacketListenerImpl.class)
@@ -37,4 +43,15 @@ public class ServerGamePacketListenerMixin {
public void disableSpectatorsTeleporting(ServerboundTeleportToEntityPacket serverboundTeleportToEntityPacket, CallbackInfo ci) {
if (this.player.isSpectator()) ci.cancel();
}
@Inject(method = "handleInteract", at = @At("HEAD"), cancellable = true)
public void disableOrEnablePvp(ServerboundInteractPacket serverboundInteractPacket, CallbackInfo ci) {
final Entity entity = serverboundInteractPacket.getTarget(this.player.serverLevel());
if (!NexiaTeams.pvpEnabled && entity instanceof ServerPlayer) ci.cancel();
}
@ModifyArg(method = "handleClientCommand", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;setGameMode(Lnet/minecraft/world/level/GameType;)Z"))
public GameType deathSystem(GameType gameType) {
return NexiaTeams.hardcoreEnabled ? GameType.SPECTATOR : GameType.SURVIVAL;
}
}
@@ -0,0 +1,49 @@
package com.nexia.teams.utilities.data;
import com.google.gson.Gson;
import com.nexia.teams.NexiaTeams;
import net.fabricmc.loader.api.FabricLoader;
import java.io.File;
import java.io.FileWriter;
import java.nio.file.Files;
public class NexiaDataManager {
public static String dataDirectory = FabricLoader.getInstance().getConfigDir().toString() + "/nexia";
public static void saveNexiaData() {
try {
Gson gson = new Gson();
SavedNexiaData savedNexiaData = new SavedNexiaData(NexiaTeams.pvpEnabled, NexiaTeams.endDisabled, NexiaTeams.netherDisabled, NexiaTeams.hardcoreEnabled);
String json = gson.toJson(savedNexiaData);
String directory = getDataDir();
FileWriter fileWriter = new FileWriter(directory + "/nexia.json");
fileWriter.write(json);
fileWriter.close();
} catch (Exception exception) {
exception.printStackTrace();
}
}
public static void loadNexiaData() {
try {
String directory = getDataDir();
File file = new File(directory + "/nexia.json");
String json = Files.readString(file.toPath());
Gson gson = new Gson();
SavedNexiaData savedNexiaData = gson.fromJson(json, SavedNexiaData.class);
NexiaTeams.pvpEnabled = savedNexiaData.pvpEnabled;
NexiaTeams.endDisabled = savedNexiaData.endDisabled;
NexiaTeams.netherDisabled = savedNexiaData.netherDisabled;
NexiaTeams.hardcoreEnabled = savedNexiaData.hardcoreEnabled;
} catch (Exception exception) {
exception.printStackTrace();
}
}
private static String getDataDir() {
(new File(dataDirectory)).mkdirs();
return dataDirectory;
}
}
@@ -0,0 +1,15 @@
package com.nexia.teams.utilities.data;
public class SavedNexiaData {
public boolean pvpEnabled;
public boolean endDisabled;
public boolean netherDisabled;
public boolean hardcoreEnabled;
public SavedNexiaData(boolean pvpEnabled, boolean endDisabled, boolean netherDisabled, boolean hardcoreEnabled) {
this.pvpEnabled = pvpEnabled;
this.endDisabled = endDisabled;
this.netherDisabled = netherDisabled;
this.hardcoreEnabled = hardcoreEnabled;
}
}
@@ -6,6 +6,7 @@ import com.nexia.teams.events.koth.KothGameHandler;
import com.nexia.teams.events.meteor.Meteor;
import com.nexia.teams.utilities.chat.ChatFormat;
import com.nexia.teams.utilities.data.KothDataManager;
import com.nexia.teams.utilities.data.NexiaDataManager;
import com.nexia.teams.utilities.teams.TeamUtil;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.minecraft.core.RegistryAccess;
@@ -23,10 +24,12 @@ public abstract class ServerTime {
public static void firstTick(MinecraftServer server) {
ServerTime.minecraftServer = server;
ChatFormat.provider = Suppliers.ofInstance(RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY)).get();
NexiaDataManager.loadNexiaData();
KothDataManager.loadKothGamesData();
}
public static void stopServer(MinecraftServer server) {
NexiaDataManager.saveNexiaData();
KothGameHandler.stopAllKothGames();
KothDataManager.saveKothGamesData();
@@ -6,7 +6,9 @@
"mixins": [
"AxeItemMixin",
"EnderPearlMixin",
"EndPortalBlockMixin",
"MinecraftServerMixin",
"NetherPortalBlockMixin",
"ServerGamePacketListenerMixin",
"mace.MaceItemMixin"
],