Semmel
📎 1 file 3,794 chars
📄
pasted-code-1792955292116.txt
txt 56 lines
▶
Create a Minecraft Fabric mod for a multiplayer SMP server with a simple, 

Bounty System
- Every player starts with 0 kills and no bounty.
- When a player gets 5 player kills, they automatically receive a bounty.
- The bounty target should be announced to the entire server with a message such as: "[BOUNTY] Steve now has a bounty! Hunt them down!"
- Display the bounty target's name and kill count clearly.
- When another player kills a bounty target, the killer claims the bounty and receives a permanent reward.
Permanent Rewards
- Each claimed bounty grants the killer one permanent status effect, such as Speed I or Strength I.
- The effect must never expire, even after reconnecting or restarting the server.
- Each additional bounty claimed grants another permanent effect or increases the reward level.
- Effects must be saved persistently and restored when a player rejoins.
Death Penalty
- Whenever a player dies, they lose exactly ONE permanent bounty reward.
- Remove one previously earned permanent effect at random, or remove the most recently earned effect.
- If the player has no bounty rewards, nothing happens.
- Announce the lost reward to the player.
Multiplayer & Anti-Exploit
- The system must work correctly on a dedicated Fabric server.
- Only player kills count; mob kills do not.
- Prevent players from farming kills by repeatedly killing the same friend.
- Prevent players from claiming their own bounty.
- Ensure rewards and kill counts are saved across server restarts.
- All bounty announcements should be visible to every online player.
Commands
- /bounty — view the current bounty targets.
- /bounty stats [player] — view a player's kills and rewards.
- /bounty top — show the players with the most kills.
- /bounty reload — reload configuration (admin only).
Configuration
- Allow server admins to configure the number of kills needed for a bounty, starting at 5.
- Allow admins to configure which permanent effects can be earned and their levels.
- Allow admins to enable or disable the death penalty.
- Make all settings configurable through a simple config file.
Technical Requirements
- Use Fabric API and support my Minecraft version.
- Keep the mod lightweight and compatible with other common SMP mods.
- Make it server-side if possible, so players do not need to install it on their clients.
- Include clear installation instructions and a README.
- Generate complete, working source code and a compiled JAR file, not just example code or pseudocode.
The final result should be a balanced, reliable bounty system suitable for a private SMP with 15–20 friends.

Automatic Bounty Coordinate Leaks
- Every 15 minutes, automatically broadcast the current coordinates of every active bounty target in the server chat.
- Use the format: [BOUNTY LEAK] Steve was spotted at X: 245, Y: 72, Z: -130! Hunt them down!
- Coordinates must update dynamically to show the target's current location at the time of the leak.
- Only broadcast coordinates for players who currently have an active bounty.
- Include the target's Minecraft dimension (Overworld, Nether, or End) so players know where to hunt.
- If multiple players have active bounties, announce each target separately.
- If a target is offline, skip their coordinate leak until they return.
- The 15-minute timer must run continuously and reliably on a dedicated server.
- Make the leak interval configurable in the server config, with 15 minutes as the default.
- Broadcast the leak to all online players, even if they are far away from the bounty target.
- Use server-side coordinates and ensure the feature works without requiring client-side mods.
- aslo add so the kill always counts and i dont have to wait, and make it 26.3 so the newest version
Kodari AI
KodariOct 25 at 7:22 pm 3
BountyHunterSystem
A server-side Fabric mod for SMP servers that implements a dynamic bounty hunting system. Players earn bounties after reaching a configurable kill threshold (default 5 player kills), with automatic server-wide announcements. Killing a bounty target grants the killer a permanent status effect that persists across reconnects and server restarts. Death removes one earned reward. Includes anti-exploit measures preventing kill farming and self-bounty claiming. Features automatic 15-minute coordinate leaks broadcasting active bounty targets' current positions and dimensions to all online players. Commands include /bounty, /bounty stats, /bounty top, and /bounty reload for admins. All settings configurable through a simple config file, with persistent storage for kills and rewards.
  1. Wire a server-only Fabric 26.3 mod and persistent bounty/reward storage.

  2. Add kill tracking, anti-farm rules, death penalties, live coordinate leaks, and admin config.

  3. Register /bounty commands and include setup/usage documentation.

Implemented the server-side Fabric 26.3 bounty mod and added installation/configuration instructions in README.md.

  • Eligible player kills count immediately; reaching the configured threshold activates a bounty. Repeated kills of the same player are blocked for 24 hours by default, configurable in config/smpbounty.properties.

  • Claiming another player’s active bounty grants a permanent effect. Effects are saved across restarts and restored on join or respawn; deaths remove the most recently earned reward when the penalty is enabled.

  • Every configured interval, online bounty targets’ current coordinates and dimension are broadcast server-wide. The mod also adds /bounty, /bounty stats [player], /bounty top, and moderator-only /bounty reload.

To get the jar: click Compile in the desktop top bar, or ⋮ → Compile Project on phone; click Compile in the window, then Download on the successful build. Install the jar in the server’s mods folder; players do not need the mod client-side.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
README.md
settings.gradle
Code
9 668
src/main/java/com/kodari/smpbounty/SmpBountyMod.java
package com.kodari.smpbounty;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents;
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;

public final class SmpBountyMod implements ModInitializer {
	public static final String MOD_ID = "smpbounty";
	private static final long TICKS_PER_MINUTE = 1_200L;
	private static final long TICKS_PER_HOUR = 72_000L;

	@Override
	public void onInitialize() {
		BountyConfig.load();
		CommandRegistrationCallback.EVENT.register((dispatcher, buildContext, selection) -> BountyCommands.register(dispatcher));
		ServerTickEvents.END_SERVER_TICK.register(SmpBountyMod::onServerTick);
		ServerPlayerEvents.JOIN.register(SmpBountyMod::restoreRewards);
		ServerPlayerEvents.AFTER_RESPAWN.register((oldPlayer, newPlayer, alive) -> restoreRewards(newPlayer));
		ServerLivingEntityEvents.AFTER_DEATH.register(SmpBountyMod::onDeath);
	}

	private static void onServerTick(MinecraftServer server) {
		BountyData data = BountyData.get(server);
		long now = server.overworld().getGameTime();
		if (data.lastLeakGameTime() < 0) {
			data.setLastLeakGameTime(now);
			return;
		}

		long interval = BountyConfig.leakIntervalMinutes() * TICKS_PER_MINUTE;
		if (now - data.lastLeakGameTime() < interval) {
			return;
		}

		data.setLastLeakGameTime(now);
		for (ServerPlayer player : server.getPlayerList().getPlayers()) {
			BountyData.PlayerStats stats = data.getOrCreate(player.getUUID(), player.getName().getString());
			if (!stats.bountyActive()) {
				continue;
			}

			String dimension = dimensionName(player.level());
			String message = "[BOUNTY LEAK] " + player.getName().getString() + " was spotted at X: "
				+ (int) Math.floor(player.getX()) + ", Y: " + (int) Math.floor(player.getY()) + ", Z: "
				+ (int) Math.floor(player.getZ()) + " in the " + dimension + "! Hunt them down!";
			broadcast(server, message);
		}
	}

	private static void onDeath(LivingEntity entity, DamageSource damageSource) {
		if (!(entity instanceof ServerPlayer victim)) {
			return;
		}

		MinecraftServer server = victim.level().getServer();
		if (server == null) {
			return;
		}

		BountyData data = BountyData.get(server);
		BountyData.PlayerStats victimStats = data.getOrCreate(victim.getUUID(), victim.getName().getString());
		boolean wasBountyTarget = victimStats.bountyActive();
		if (wasBountyTarget) {
			victimStats = copyStats(victimStats, victimStats.kills(), victimStats.lastBountyAtKills(), false,
				victimStats.rewards(), victimStats.managedEffects(), victimStats.lastVictimKills());
			data.update(victim.getUUID(), victimStats);
		}

		ServerPlayer killer = damageSource.getEntity() instanceof ServerPlayer player ? player : null;
		if (killer != null && killer.getUUID().equals(victim.getUUID())) {
			killer = null;
		}

		boolean eligibleKill = false;
		BountyData.PlayerStats killerStats = null;
		if (killer != null) {
			killerStats = data.getOrCreate(killer.getUUID(), killer.getName().getString());
			Map<String, Long> recentVictims = new HashMap<>(killerStats.lastVictimKills());
			String victimId = victim.getUUID().toString();
			Long previousKill = recentVictims.get(victimId);
			long cooldown = BountyConfig.sameVictimCooldownHours() * TICKS_PER_HOUR;
			long now = server.overworld().getGameTime();
			eligibleKill = cooldown == 0 || previousKill == null || now - previousKill >= cooldown;
			recentVictims.put(victimId, now);

			int kills = killerStats.kills();
			int lastBountyAtKills = killerStats.lastBountyAtKills();
			boolean bountyActive = killerStats.bountyActive();
			if (eligibleKill) {
				kills++;
				int progressSinceMilestone = kills - lastBountyAtKills;
				int requiredKills = BountyConfig.killsPerBounty();
				if (progressSinceMilestone >= requiredKills) {
					lastBountyAtKills += (progressSinceMilestone / requiredKills) * requiredKills;
					if (!bountyActive) {
						bountyActive = true;
						broadcast(server, "[BOUNTY] " + killer.getName().getString()
							+ " now has a bounty! Hunt them down! (" + kills + " kills)");
					}
				}
			}

			killerStats = copyStats(killerStats, kills, lastBountyAtKills, bountyActive,
				killerStats.rewards(), killerStats.managedEffects(), recentVictims);
			data.update(killer.getUUID(), killerStats);
		}

		if (wasBountyTarget && killer != null && eligibleKill && killerStats != null) {
			killerStats = grantReward(killerStats);
			data.update(killer.getUUID(), killerStats);
			reconcileRewards(killer, killerStats);
			broadcast(server, "[BOUNTY] " + killer.getName().getString() + " claimed "
				+ victim.getName().getString() + "'s bounty and earned a permanent reward!");
		} else if (wasBountyTarget && killer != null && !eligibleKill) {
			killer.sendSystemMessage(Component.literal("That bounty kill did not count because you recently killed this player."));
		}

		if (BountyConfig.deathPenalty() && !victimStats.rewards().isEmpty()) {
			List<BountyData.Reward> rewards = new ArrayList<>(victimStats.rewards());
			BountyData.Reward lostReward = rewards.remove(rewards.size() - 1);
			victimStats = copyStats(victimStats, victimStats.kills(), victimStats.lastBountyAtKills(),
				victimStats.bountyActive(), rewards, victimStats.managedEffects(), victimStats.lastVictimKills());
			data.update(victim.getUUID(), victimStats);
			reconcileRewards(victim, victimStats);
			victim.sendSystemMessage(Component.literal("You lost one permanent bounty reward: "
				+ lostReward.effectId() + " level " + lostReward.level() + "."));
		}
	}

	private static BountyData.PlayerStats grantReward(BountyData.PlayerStats stats) {
		List<BountyConfig.EffectOption> options = validRewardOptions();
		BountyConfig.EffectOption selected = options.get(stats.rewards().size() % options.size());
		int existingRewardsForEffect = (int) stats.rewards().stream()
			.filter(reward -> reward.effectId().equals(selected.effectId())).count();
		BountyData.Reward reward = new BountyData.Reward(selected.effectId(), selected.level() + existingRewardsForEffect);
		List<BountyData.Reward> rewards = new ArrayList<>(stats.rewards());
		rewards.add(reward);
		List<String> managedEffects = new ArrayList<>(stats.managedEffects());
		if (!managedEffects.contains(reward.effectId())) {
			managedEffects.add(reward.effectId());
		}
		return copyStats(stats, stats.kills(), stats.lastBountyAtKills(), stats.bountyActive(), rewards,
			managedEffects, stats.lastVictimKills());
	}

	private static List<BountyConfig.EffectOption> validRewardOptions() {
		List<BountyConfig.EffectOption> valid = BountyConfig.effects().stream()
			.filter(option -> effectHolderExists(option.effectId())).toList();
		return valid.isEmpty() ? List.of(new BountyConfig.EffectOption("minecraft:speed", 1)) : valid;
	}

	private static boolean effectHolderExists(String effectId) {
		Identifier identifier = Identifier.tryParse(effectId);
		return identifier != null && BuiltInRegistries.MOB_EFFECT.get(identifier).isPresent();
	}

	private static void restoreRewards(ServerPlayer player) {
		BountyData data = BountyData.get(player.level().getServer());
		BountyData.PlayerStats stats = data.getOrCreate(player.getUUID(), player.getName().getString());
		reconcileRewards(player, stats);
	}

	private static void reconcileRewards(ServerPlayer player, BountyData.PlayerStats stats) {
		Set<String> managedEffects = new HashSet<>(stats.managedEffects());
		for (BountyData.Reward reward : stats.rewards()) {
			managedEffects.add(reward.effectId());
		}
		for (String effectId : managedEffects) {
			Identifier identifier = Identifier.tryParse(effectId);
			if (identifier != null) {
				BuiltInRegistries.MOB_EFFECT.get(identifier).ifPresent(player::removeEffect);
			}
		}

		Map<String, Integer> highestLevels = new HashMap<>();
		for (BountyData.Reward reward : stats.rewards()) {
			highestLevels.merge(reward.effectId(), reward.level(), Math::max);
		}
		for (Map.Entry<String, Integer> entry : highestLevels.entrySet()) {
			Identifier identifier = Identifier.tryParse(entry.getKey());
			if (identifier == null) {
				continue;