first commit
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.bitnix</groupId>
|
||||
<artifactId>AntiFLY-PVP</artifactId>
|
||||
<version>1.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>AntiFLY-PVP</name>
|
||||
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.21.8-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>AntiFLY-PVP</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<release>21</release>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,269 @@
|
||||
package com.bitnix.antiflypvp;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class AntiFlyPVPPlugin extends JavaPlugin implements Listener {
|
||||
|
||||
private final Map<UUID, Long> combatUntil = new HashMap<>();
|
||||
private final Map<UUID, BukkitTask> expiryTasks = new HashMap<>();
|
||||
|
||||
private long combatDurationTicks;
|
||||
private long combatDurationMillis;
|
||||
private boolean disableFlightOnAnyDamage;
|
||||
private boolean disableFlightOnDamagingAnyEntity;
|
||||
private boolean opBypass;
|
||||
|
||||
private String msgCombatStartDamaged;
|
||||
private String msgCombatStartAttack;
|
||||
private String msgCombatFlyBlocked;
|
||||
private String msgCombatEnded;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
loadPluginSettings();
|
||||
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
getLogger().info("AntiFLY-PVP enabled.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
for (BukkitTask task : expiryTasks.values()) {
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
expiryTasks.clear();
|
||||
combatUntil.clear();
|
||||
}
|
||||
|
||||
private void loadPluginSettings() {
|
||||
reloadConfig();
|
||||
FileConfiguration config = getConfig();
|
||||
|
||||
int seconds = config.getInt("combat-duration-seconds", 300);
|
||||
if (seconds < 1) {
|
||||
seconds = 300;
|
||||
}
|
||||
|
||||
this.combatDurationMillis = seconds * 1000L;
|
||||
this.combatDurationTicks = seconds * 20L;
|
||||
|
||||
this.disableFlightOnAnyDamage = config.getBoolean("disable-flight-on-any-damage", true);
|
||||
this.disableFlightOnDamagingAnyEntity = config.getBoolean("disable-flight-on-damaging-any-entity", true);
|
||||
this.opBypass = config.getBoolean("op-bypass", true);
|
||||
|
||||
this.msgCombatStartDamaged = color(config.getString(
|
||||
"messages.combat-start-damaged",
|
||||
"&cFlight disabled: you were damaged and are now in combat for &e%time%&c seconds."
|
||||
));
|
||||
|
||||
this.msgCombatStartAttack = color(config.getString(
|
||||
"messages.combat-start-attack",
|
||||
"&cFlight disabled: you attacked something and are now in combat for &e%time%&c seconds."
|
||||
));
|
||||
|
||||
this.msgCombatFlyBlocked = color(config.getString(
|
||||
"messages.combat-fly-blocked",
|
||||
"&cYou cannot fly while in combat. Time left: &e%time%&c seconds."
|
||||
));
|
||||
|
||||
this.msgCombatEnded = color(config.getString(
|
||||
"messages.combat-ended",
|
||||
"&aYour combat timer ended. You may fly again if you still have permission."
|
||||
));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerDamaged(EntityDamageEvent event) {
|
||||
if (!disableFlightOnAnyDamage) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof Player player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldIgnore(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
enterCombat(player, msgCombatStartDamaged);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEntityDamagedByPlayer(EntityDamageByEntityEvent event) {
|
||||
if (!disableFlightOnDamagingAnyEntity) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player attacker = getResponsiblePlayer(event.getDamager());
|
||||
if (attacker == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldIgnore(attacker)) {
|
||||
return;
|
||||
}
|
||||
|
||||
enterCombat(attacker, msgCombatStartAttack);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onFlightToggle(PlayerToggleFlightEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (shouldIgnore(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isInCombat(player.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
disableFlightNow(player);
|
||||
player.sendMessage(replaceTime(msgCombatFlyBlocked, getRemainingSeconds(player.getUniqueId())));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (shouldIgnore(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isInCombat(player.getUniqueId())) {
|
||||
disableFlightNow(player);
|
||||
}
|
||||
}
|
||||
|
||||
private Player getResponsiblePlayer(Entity damager) {
|
||||
if (damager instanceof Player player) {
|
||||
return player;
|
||||
}
|
||||
|
||||
if (damager instanceof Projectile projectile) {
|
||||
Object shooter = projectile.getShooter();
|
||||
if (shooter instanceof Player player) {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean shouldIgnore(Player player) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return opBypass && player.isOp();
|
||||
}
|
||||
|
||||
private void enterCombat(Player player, String startMessage) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
boolean alreadyInCombat = isInCombat(uuid);
|
||||
|
||||
disableFlightNow(player);
|
||||
|
||||
long expiresAt = System.currentTimeMillis() + combatDurationMillis;
|
||||
combatUntil.put(uuid, expiresAt);
|
||||
|
||||
BukkitTask oldTask = expiryTasks.remove(uuid);
|
||||
if (oldTask != null) {
|
||||
oldTask.cancel();
|
||||
}
|
||||
|
||||
BukkitTask newTask = Bukkit.getScheduler().runTaskLater(this, () -> {
|
||||
Long stored = combatUntil.get(uuid);
|
||||
if (stored != null && stored <= System.currentTimeMillis()) {
|
||||
combatUntil.remove(uuid);
|
||||
expiryTasks.remove(uuid);
|
||||
|
||||
Player online = Bukkit.getPlayer(uuid);
|
||||
if (online != null && online.isOnline()) {
|
||||
online.sendMessage(msgCombatEnded);
|
||||
}
|
||||
}
|
||||
}, combatDurationTicks);
|
||||
|
||||
expiryTasks.put(uuid, newTask);
|
||||
|
||||
if (!alreadyInCombat) {
|
||||
player.sendMessage(replaceTime(startMessage, combatDurationMillis / 1000L));
|
||||
}
|
||||
}
|
||||
|
||||
private void disableFlightNow(Player player) {
|
||||
if (player.isFlying()) {
|
||||
player.setFlying(false);
|
||||
}
|
||||
|
||||
if (player.getAllowFlight()) {
|
||||
player.setAllowFlight(false);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isInCombat(UUID uuid) {
|
||||
Long expiresAt = combatUntil.get(uuid);
|
||||
if (expiresAt == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (expiresAt <= System.currentTimeMillis()) {
|
||||
combatUntil.remove(uuid);
|
||||
|
||||
BukkitTask task = expiryTasks.remove(uuid);
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private long getRemainingSeconds(UUID uuid) {
|
||||
Long expiresAt = combatUntil.get(uuid);
|
||||
if (expiresAt == null) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
long remaining = expiresAt - System.currentTimeMillis();
|
||||
if (remaining <= 0L) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
return (remaining + 999L) / 1000L;
|
||||
}
|
||||
|
||||
private String replaceTime(String message, long seconds) {
|
||||
return message.replace("%time%", String.valueOf(seconds));
|
||||
}
|
||||
|
||||
private String color(String input) {
|
||||
return input == null ? "" : input.replace("&", "§");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
combat-duration-seconds: 300
|
||||
|
||||
disable-flight-on-any-damage: true
|
||||
disable-flight-on-damaging-any-entity: true
|
||||
|
||||
op-bypass: true
|
||||
|
||||
messages:
|
||||
combat-start-damaged: "&cFlight disabled: you were damaged and are now in combat for &e%time%&c seconds."
|
||||
combat-start-attack: "&cFlight disabled: you attacked something and are now in combat for &e%time%&c seconds."
|
||||
combat-fly-blocked: "&cYou cannot fly while in combat. Time left: &e%time%&c seconds."
|
||||
combat-ended: "&aYour combat timer ended. You may fly again if you still have permission."
|
||||
@@ -0,0 +1,6 @@
|
||||
name: AntiFLY-PVP
|
||||
version: 1.1
|
||||
main: com.bitnix.antiflypvp.AntiFlyPVPPlugin
|
||||
api-version: '1.21'
|
||||
author: bitnix
|
||||
description: Disables player flight during combat.
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,12 @@
|
||||
combat-duration-seconds: 300
|
||||
|
||||
disable-flight-on-any-damage: true
|
||||
disable-flight-on-damaging-any-entity: true
|
||||
|
||||
op-bypass: true
|
||||
|
||||
messages:
|
||||
combat-start-damaged: "&cFlight disabled: you were damaged and are now in combat for &e%time%&c seconds."
|
||||
combat-start-attack: "&cFlight disabled: you attacked something and are now in combat for &e%time%&c seconds."
|
||||
combat-fly-blocked: "&cYou cannot fly while in combat. Time left: &e%time%&c seconds."
|
||||
combat-ended: "&aYour combat timer ended. You may fly again if you still have permission."
|
||||
@@ -0,0 +1,6 @@
|
||||
name: AntiFLY-PVP
|
||||
version: 1.1
|
||||
main: com.bitnix.antiflypvp.AntiFlyPVPPlugin
|
||||
api-version: '1.21'
|
||||
author: bitnix
|
||||
description: Disables player flight during combat.
|
||||
@@ -0,0 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Sun Jun 07 20:39:31 EDT 2026
|
||||
artifactId=AntiFLY-PVP
|
||||
groupId=com.bitnix
|
||||
version=1.1
|
||||
@@ -0,0 +1 @@
|
||||
com/bitnix/antiflypvp/AntiFlyPVPPlugin.class
|
||||
@@ -0,0 +1 @@
|
||||
/home/bitnix/Desktop/AntiFLY-PVP/src/main/java/com/bitnix/antiflypvp/AntiFlyPVPPlugin.java
|
||||
Reference in New Issue
Block a user