📄
pasted-code-1786876941695.txt
txt
16 lines
▶
Create a Minecraft server plugin with the following behavior:
Whenever a player kills another player, the killer should be automatically and permanently banned from the server.
Detect all player-versus-player kills reliably.
Immediately ban the killer when the kill occurs.
Send the banned player a clear message explaining that they were banned for killing another player.
Broadcast a configurable message to the server announcing the ban.
Add a configuration file where the server owner can customize:
Ban message
Broadcast message
Whether the ban is permanent or temporary
Ban duration, if temporary
Make sure the plugin does not ban players for deaths caused by mobs, fall damage, fire, commands, or other non-player causes.
Include proper event handling, permissions, logging, and error handling.
Provide the complete source code, plugin configuration, plugin.yml, installation instructions, and build instructions.
Target the latest stable Paper/Spigot API and keep the code clean, lightweight, and production-ready.
Create the Paper/Spigot plugin structure and Gradle build.
Implement PvP kill detection and configurable permanent/temporary bans.
Add default configuration, plugin metadata, and installation/build documentation.
Implemented the complete PvPAutoBan plugin with configurable permanent or temporary bans, reliable player-kill detection, bypass permission, logging, messages, Gradle build setup, plugin.yml, config.yml, and installation/build instructions in README.md.
📄
pasted-code-1786877463590.txt
txt
226 lines
▶
Create a production-ready Minecraft server plugin for **Paper/Spigot** with a strict **“Kill = Automatic Ban”** system.
### Core Requirement
Whenever one player directly kills another player, the player responsible for the kill must be **automatically banned from the server immediately after the kill**.
Example:
* Player `Steve` kills player `Alex`.
* The plugin detects that `Steve` was the killer.
* `Steve` is immediately banned.
* `Steve` is kicked from the server.
* The configured ban message is shown to Steve.
* A configurable broadcast is sent to the server.
* The action is recorded in the plugin log.
### Kill Detection
Use the appropriate Bukkit/Paper player damage/death events to reliably determine PvP kills.
The plugin should:
* Detect direct player-versus-player kills.
* Identify the actual killer correctly.
* Handle melee attacks.
* Handle projectile kills such as bows.
* Handle other player-caused damage where the server API can reliably identify the responsible player.
* Avoid banning players for deaths caused by:
* Mobs
* Fall damage
* Fire/lava
* Drowning
* Suffocation
* Void
* Environmental damage
* Other non-player causes
Make sure the plugin does not accidentally ban the victim instead of the killer.
### Ban System
When a valid PvP kill occurs:
1. Identify the killer.
2. Verify that the victim is a player.
3. Determine that the death was actually caused by the killer.
4. Ban the killer immediately.
5. Kick the killer if necessary.
6. Record the ban reason.
7. Send the configured messages.
The default ban reason should be:
`You have been banned for killing another player.`
Use the server's native ban system where possible so the ban persists across restarts.
### Configuration
Create a fully configurable `config.yml`.
Include options such as:
```yaml
ban:
enabled: true
permanent: true
duration: "7d"
reason: "&cYou have been banned for killing another player."
messages:
killer: "&cYou have been banned for killing another player."
broadcast: "&e{killer} &chas been banned for killing &e{victim}&c."
console: "&7[AUTO-BAN] {killer} killed {victim} and was automatically banned."
settings:
announce-ban: true
log-kills: true
log-bans: true
```
Support placeholders such as:
* `{killer}`
* `{victim}`
* `{reason}`
* `{duration}`
Use Minecraft color-code support such as `&c`, `&e`, etc.
### Commands
Add useful administrative commands.
For example:
`/autoban reload`
Reload the configuration without restarting the server.
`/autoban status`
Display whether the automatic ban system is enabled.
Add appropriate permissions:
* `autoban.admin`
* `autoban.reload`
* `autoban.status`
The plugin should never require ordinary players to have permissions for the automatic ban functionality.
### Bypass System
Add an optional permission allowing trusted players to bypass the automatic ban system:
`autoban.bypass`
If a player has this permission, killing another player should not automatically ban them.
Make this configurable:
```yaml
settings:
bypass-permission: "autoban.bypass"
bypass-enabled: true
```
### Edge Cases
Handle important edge cases correctly.
For example:
* A player damages another player, but a mob gets the final hit → do not ban the player unless the plugin can confidently determine they caused the kill.
* A player shoots another player with a bow and the victim dies later → correctly identify the shooter when possible.
* A player dies from environmental damage after being attacked → do not incorrectly assign the kill unless the server API confirms the attacker caused the death.
* Ignore self-inflicted deaths.
* Ignore non-player entities as victims.
* Avoid duplicate bans/events for the same death.
* Prevent errors if a player disconnects immediately after the kill.
* Ensure the plugin works correctly after server restarts.
### Logging
Create useful console logs.
Example:
`[AutoBan] Steve killed Alex. Steve has been automatically banned.`
Include:
* Killer name
* Victim name
* Time
* World
* Location
* Kill method, when available
* Ban duration
* Ban reason
Optionally store records in a local file such as:
`plugins/AutoBan/kills.log`
### Performance
The plugin must be lightweight.
* Do not continuously scan all players.
* Do not use unnecessary repeating tasks.
* Use Bukkit/Paper events efficiently.
* Avoid blocking the main server thread with unnecessary database or file operations.
* Clean up temporary data when it is no longer needed.
### Compatibility
Target the latest stable **Paper API** and structure the code so it can be updated easily for future Minecraft versions.
Clearly specify the required Java version and API version.
Provide:
* Complete Java source code
* `plugin.yml`
* `config.yml`
* Maven or Gradle build configuration
* Project folder structure
* Installation instructions
* Compilation/build instructions
* Server installation instructions
* Permission documentation
* Configuration documentation
### Code Quality
Use clean, maintainable, well-commented code.
Separate responsibilities into appropriate classes, for example:
* Main plugin class
* Kill/PvP event listener
* Ban manager
* Configuration manager
* Command handler
* Logging manager
Use proper Bukkit/Paper APIs rather than relying on fragile workarounds.
Before providing the final code, verify that:
1. The project compiles successfully.
2. The plugin loads without errors.
3. PvP kills trigger the automatic ban.
4. Non-PvP deaths do not trigger bans.
5. Configuration values work correctly.
6. Permissions work correctly.
7. `/autoban reload` works.
8. `/autoban status` works.
9. Ban messages and broadcasts display correctly.
10. The implementation does not create unnecessary performance overhead.
Finally, provide the **complete ready-to-build plugin project**, not just a code snippet.
Verify the existing project structure and build setup.
Implement kill attribution, bans, commands, configuration, and logging.
Add plugin metadata and complete operational documentation.
Implemented direct melee, projectile, and owned-tameable kill attribution; only a player-caused final damage event can trigger a ban.
Added the
AutoBancommand, permission model, default config, metadata, and build/server documentation.Implemented the production-ready AutoBan plugin project.
Direct player kills trigger immediate native persistent bans; melee, projectiles, and player-owned tameables are supported.
Environmental, mob, delayed, self-inflicted, and non-player deaths are excluded by final-damage attribution.
Added configurable permanent/temporary bans, duration parsing, messages, placeholders, broadcasts, logs, bypass permission, and duplicate-event protection.
Added
/autoban reloadand/autoban statuswithautoban.admin,autoban.reload,autoban.status, andautoban.bypass.Updated Gradle setup,
plugin.yml,config.yml, and comprehensive build/install/configuration documentation.
package com.kodari.pvpautoban;
import com.kodari.pvpautoban.command.AutoBanCommand;
import com.kodari.pvpautoban.config.ConfigManager;
import com.kodari.pvpautoban.listener.PvPKillListener;
import com.kodari.pvpautoban.service.AutoBanService;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
public final class PvPAutoBanPlugin extends JavaPlugin {
private ConfigManager configManager;
private AutoBanService autoBanService;
@Override
public void onEnable() {
saveDefaultConfig();
configManager = new ConfigManager(this);
configManager.load();
autoBanService = new AutoBanService(this, configManager);
getServer().getPluginManager().registerEvents(new PvPKillListener(this, configManager, autoBanService), this);
PluginCommand command = getCommand("autoban");
if (command == null) {
getLogger().severe("Could not register /autoban because it is missing from plugin.yml.");
} else {
AutoBanCommand autoBanCommand = new AutoBanCommand(this, configManager);
command.setExecutor(autoBanCommand);
command.setTabCompleter(autoBanCommand);
}
getLogger().info("AutoBan enabled. Direct player kills are handled according to config.yml.");
}
public void reloadPluginConfiguration() {
reloadConfig();
configManager.load();
}
}