mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-12 13:26:56 +00:00
Compare commits
50 Commits
v1.6.0
...
2.0.0-pre-1
| Author | SHA1 | Date | |
|---|---|---|---|
| 42f8f92a6a | |||
| d3e8b590cb | |||
| 88917d65c3 | |||
| 4096cfe152 | |||
| 7f74826e2c | |||
| c369c110e5 | |||
| 375ef3de4e | |||
| 292b7b1b77 | |||
| 47ade3e0c0 | |||
| 7d8d27b1ef | |||
| 096599081b | |||
| 7b155d0b3e | |||
| 58a4a9f25d | |||
| 3c7904786e | |||
| 1aeb245666 | |||
| b9e2aefc40 | |||
| 8df1fe54e4 | |||
| b414f96257 | |||
| c11c455c53 | |||
| d859fd0aaa | |||
| 3919b0f44b | |||
| 0290629d27 | |||
| 4590b1d532 | |||
| 8ae6e9212c | |||
| fec1dd2ab6 | |||
| fba2f03aab | |||
| e30437694c | |||
| 8fcf34e310 | |||
| aac1f99374 | |||
| 7f1da79444 | |||
| 244ceb4dcc | |||
| ac1cafe0d9 | |||
| b3ce1913fd | |||
| 9a707b34a3 | |||
| d52648b4ff | |||
| 7d2c41646e | |||
| 61908b8fab | |||
| 5abf99cd6c | |||
| 3c014304ba | |||
| b361681600 | |||
| 7ada9eab29 | |||
| 78504ee097 | |||
| 7da6ff0ac9 | |||
| c83888837b | |||
| 4052afe4d3 | |||
| 93efa37e77 | |||
| 44a5c6d800 | |||
| 2ee577a08c | |||
| f5d38eefc3 | |||
| e5b566db67 |
@@ -6,14 +6,14 @@
|
||||
|
||||
<groupId>me.youhavetrouble</groupId>
|
||||
<artifactId>PreventStabby</artifactId>
|
||||
<version>1.6.0</version>
|
||||
<version>2.0.0-pre-1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>PreventStabby</name>
|
||||
|
||||
<description>Stop people from getting stabbed!</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<java.version>17</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<version>3.3.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -41,13 +41,9 @@
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>io.github.thatsmusic99</pattern>
|
||||
<shadedPattern>configurationmaster</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>bstats</shadedPattern>
|
||||
<shadedPattern>me.youhavetrouble.preventstabby.bstats</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
@@ -65,16 +61,8 @@
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>bs-repo</id>
|
||||
<url>https://ci.pluginwiki.us/plugin/repository/everything/</url>
|
||||
<id>papermc-repo</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sk89q-repo</id>
|
||||
@@ -88,37 +76,22 @@
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.16.5-R0.1-SNAPSHOT</version>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.20.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.24</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.10.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.thatsmusic99</groupId>
|
||||
<artifactId>ConfigurationMaster</artifactId>
|
||||
<version>v1.0.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-bukkit</artifactId>
|
||||
<version>7.0.4-SNAPSHOT</version>
|
||||
<version>7.0.9-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -127,28 +100,5 @@
|
||||
<version>2.11.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-api</artifactId>
|
||||
<version>4.11.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
<version>4.1.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>4.11.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-serializer-legacy</artifactId>
|
||||
<version>4.11.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -1,43 +1,34 @@
|
||||
<h2>PreventStabby ⚔</h2>
|
||||
<h1>PreventStabby ⚔</h1>
|
||||
|
||||
Use Issues section to report bugs or submit suggestions.
|
||||
|
||||
<h3>Commands</h3>
|
||||
Permission: <code>preventstabby.command</code> (given by default to everyone) :
|
||||
You can find available commands <a href="https://github.com/YouHaveTrouble/PreventStabby/wiki/Commands">HERE</a>.
|
||||
|
||||
<h3>Configuration</h3>
|
||||
Explanation of all available config options is <a href="https://github.com/YouHaveTrouble/PreventStabby/wiki/Config">HERE</a>.
|
||||
|
||||
<h3>Placeholders</h3>
|
||||
List of all PlaceholderAPI placeholders can be found <a href="https://github.com/YouHaveTrouble/PreventStabby/wiki/Placeholders">HERE</a>.
|
||||
|
||||
<h3>Developer API</h3>
|
||||
Developer API documetation is <a href="https://github.com/YouHaveTrouble/PreventStabby/wiki/Developer-API">HERE</a>!
|
||||
|
||||
<h2>Features</h2>
|
||||
<ul>
|
||||
<li>/pvp help- displays help message</li>
|
||||
<li>Per-player PvP Toggle</li>
|
||||
<li>Global PvP override, allowing to ignore personal toggles temporarily</li>
|
||||
<li>Block all forms of player-induced damage when PvP off</li>
|
||||
<li>Block damage done to pets and mounts when PvP off</li>
|
||||
<li>Block the ability to pour lava and set fire under player's feet</li>
|
||||
<li>Block channeling tridents spawning fire under players with PvP off</li>
|
||||
<li>Block fishing pole pulling for players with PvP off</li>
|
||||
<li>Pets do not attack players with PvP off</li>
|
||||
<li>Configurable PvP protection after login</li>
|
||||
<li>Configurable PvP protection after teleport</li>
|
||||
<li>Kill players that logged out during combat</li>
|
||||
<li>Block specific commands while in combat</li>
|
||||
<li>Block teleports in combat (might cause issues with some plugins)</li>
|
||||
<li>Toggles for eggs and snowballs applying knockback</li>
|
||||
<li>Extensive developer API</li>
|
||||
</ul>
|
||||
|
||||
Permission: <code>preventstabby.command.toggle</code> (given by default to everyone) :
|
||||
<ul>
|
||||
<li>/pvp toggle - toggles PvP</li>
|
||||
<li>/pvp on - enables PvP (aliases: enable)</li>
|
||||
<li>/pvp off - disables PvP (aliases: disable)</li>
|
||||
</ul>
|
||||
|
||||
Permission: <code>preventstabby.command.toggle.others</code> (given by default to ops) :
|
||||
<ul>
|
||||
<li>/pvp toggle [player] - toggles other player's PvP</li>
|
||||
<li>/pvp on [player] - enables other player's PvP (aliases: enable)</li>
|
||||
<li>/pvp off [player] - disables other player's PvP (aliases: disable)</li>
|
||||
</ul>
|
||||
|
||||
<h3>Features</h3>
|
||||
Player who disables PvP cannot get hurt by any player induced damage.
|
||||
They also can't deal any damage to other players.
|
||||
This includes basic attacks, projectiles, splash potions,
|
||||
lingering potions and lightning strikes from channeling trident enchant.
|
||||
Additionally lightning strikes from channeling cannot spawn fire under
|
||||
players, who have pvp disabled and it's impossible to use
|
||||
fishing rod on players who have pvp disabled.
|
||||
|
||||
There is also a feature that disallows pouring lava or using
|
||||
flint and steel nearby players with disabled pvp. You can
|
||||
either disable it in config or set its radius.
|
||||
|
||||
All the protections are extended to tameable entities (pets) that set player's uuid as their owner on tame.
|
||||
|
||||
Pets will not attack players with pvp off or if their owner has pvp off.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,68 +2,43 @@ package me.youhavetrouble.preventstabby;
|
||||
|
||||
import me.youhavetrouble.preventstabby.commands.MainCommand;
|
||||
import me.youhavetrouble.preventstabby.config.ConfigCache;
|
||||
import me.youhavetrouble.preventstabby.hooks.PlacoholderApiHook;
|
||||
import me.youhavetrouble.preventstabby.hooks.PlaceholderApiHook;
|
||||
import me.youhavetrouble.preventstabby.hooks.WorldGuardHook;
|
||||
import me.youhavetrouble.preventstabby.players.PlayerManager;
|
||||
import me.youhavetrouble.preventstabby.players.SmartCache;
|
||||
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import me.youhavetrouble.preventstabby.util.DatabaseSQLite;
|
||||
import lombok.Getter;
|
||||
import me.youhavetrouble.preventstabby.util.Util;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import me.youhavetrouble.preventstabby.data.PlayerListener;
|
||||
import me.youhavetrouble.preventstabby.data.PlayerManager;
|
||||
import me.youhavetrouble.preventstabby.listeners.EnvironmentalListener;
|
||||
import me.youhavetrouble.preventstabby.listeners.PvpListener;
|
||||
import me.youhavetrouble.preventstabby.listeners.UtilListener;
|
||||
import me.youhavetrouble.preventstabby.util.*;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Set;
|
||||
|
||||
public final class PreventStabby extends JavaPlugin {
|
||||
|
||||
@Getter private static PreventStabby plugin;
|
||||
private static PreventStabby plugin;
|
||||
private ConfigCache configCache;
|
||||
private PlayerManager playerManager;
|
||||
private DatabaseSQLite sqLite;
|
||||
private SmartCache smartCache;
|
||||
private static boolean worldGuardHook;
|
||||
|
||||
private static BukkitAudiences adventure;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
Util.initData();
|
||||
reloadPluginConfig();
|
||||
File dbFile = new File("plugins/PreventStabby");
|
||||
sqLite = new DatabaseSQLite("jdbc:sqlite:plugins/PreventStabby/database.db", dbFile);
|
||||
sqLite.createDatabaseFile();
|
||||
if (!sqLite.testConnection()) {
|
||||
getLogger().severe("Error with accessing database. Check if server has write rights.");
|
||||
getLogger().severe("Plugin will now disable.");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
adventure = BukkitAudiences.create(this);
|
||||
playerManager = new PlayerManager();
|
||||
smartCache = new SmartCache();
|
||||
smartCache.runSmartCache();
|
||||
sqLite = new DatabaseSQLite("jdbc:sqlite:plugins/PreventStabby/database.db", dbFile, getLogger());
|
||||
playerManager = new PlayerManager(this);
|
||||
|
||||
// Register listeners
|
||||
Reflections reflections = new Reflections((Object[]) new String[]{"me.youhavetrouble.preventstabby"});
|
||||
Set<Class<?>> listenerClasses = reflections.getTypesAnnotatedWith(PreventStabbyListener.class);
|
||||
listenerClasses.forEach((listener)-> {
|
||||
try {
|
||||
getServer().getPluginManager().registerEvents((org.bukkit.event.Listener) listener.getConstructor().newInstance(), this);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
getLogger().severe("Error with registering listeners.");
|
||||
getLogger().severe("Plugin will now disable.");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
});
|
||||
getServer().getPluginManager().registerEvents(new UtilListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new EnvironmentalListener(this), this);
|
||||
|
||||
getServer().getPluginManager().registerEvents(new PvpListener(this), this);
|
||||
|
||||
// Register command
|
||||
PluginCommand pvpCommand = getCommand("pvp");
|
||||
@@ -71,23 +46,29 @@ public final class PreventStabby extends JavaPlugin {
|
||||
getLogger().severe("Error with registering commands.");
|
||||
getLogger().severe("Plugin will now disable.");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
MainCommand mainCommand = new MainCommand();
|
||||
pvpCommand.setExecutor(mainCommand);
|
||||
pvpCommand.setTabCompleter(mainCommand);
|
||||
|
||||
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
new PlaceholderApiHook(this).register();
|
||||
}
|
||||
|
||||
Metrics metrics = new Metrics(this, 14074);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
if (getServer().getPluginManager().getPlugin("WorldGuard") != null) {
|
||||
try {
|
||||
WorldGuardHook.init();
|
||||
worldGuardHook = true;
|
||||
} catch (NoClassDefFoundError e) {
|
||||
worldGuardHook = false;
|
||||
}
|
||||
|
||||
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
new PlacoholderApiHook(this).register();
|
||||
}
|
||||
|
||||
Metrics metrics = new Metrics(this, 14074);
|
||||
}
|
||||
|
||||
public static boolean worldGuardHookEnabled() {
|
||||
@@ -95,11 +76,11 @@ public final class PreventStabby extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void reloadPluginConfig() {
|
||||
configCache = new ConfigCache();
|
||||
configCache = new ConfigCache(this);
|
||||
}
|
||||
|
||||
public void reloadPluginConfig(CommandSender commandSender) {
|
||||
getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
||||
getServer().getAsyncScheduler().runNow(this, (task) -> {
|
||||
reloadPluginConfig();
|
||||
PluginMessages.sendMessage(commandSender, "PreventStabby configuration reloaded.");
|
||||
});
|
||||
@@ -115,11 +96,8 @@ public final class PreventStabby extends JavaPlugin {
|
||||
|
||||
public DatabaseSQLite getSqLite() {return sqLite;}
|
||||
|
||||
public SmartCache getSmartCache() {
|
||||
return smartCache;
|
||||
public static PreventStabby getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public static BukkitAudiences getAudiences() {
|
||||
return adventure;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,147 +1,12 @@
|
||||
package me.youhavetrouble.preventstabby.api;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.data.DamageCheckResult;
|
||||
import me.youhavetrouble.preventstabby.util.PvpState;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public class PreventStabbyAPI {
|
||||
|
||||
/**
|
||||
* Sets players PvP state. This will always save to database.
|
||||
* @param player Player to set pvp state to
|
||||
* @param newState State to set
|
||||
*/
|
||||
public static void setPvpEnabled(Player player, boolean newState) {
|
||||
PreventStabby.getPlugin().getSmartCache().setPlayerPvpState(player.getUniqueId(), newState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets players PvP state. This will always save to database.
|
||||
* @param uuid UUID of player to set pvp state to
|
||||
* @param newState State to set
|
||||
*/
|
||||
public static void setPvpEnabled(UUID uuid, boolean newState) {
|
||||
PreventStabby.getPlugin().getSmartCache().setPlayerPvpState(uuid, newState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets player's PvP state. If player is not cached this will query the database.
|
||||
* @param uuid UUID of the player to get data from.
|
||||
* @return True if enabled, false if disabled
|
||||
*/
|
||||
public static boolean getPvpEnabled(UUID uuid) {
|
||||
return PreventStabby.getPlugin().getSmartCache().getPlayerData(uuid).isPvpEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets player's PvP state. If player is not cached this will query the database.
|
||||
* @param player Player to get data from.
|
||||
* @return True if enabled, false if disabled
|
||||
*/
|
||||
public static boolean getPvpEnabled(Player player) {
|
||||
return PreventStabby.getPlugin().getSmartCache().getPlayerData(player.getUniqueId()).isPvpEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player can be damaged by another. Providing UUID of entity other than player may result in exceptions
|
||||
* @param attackerUuid Attacker's UUID
|
||||
* @param victimUuid Victim's UUID
|
||||
* @param sendDenyMessage True if check should send deny message to attacker
|
||||
* @return True if victim can be attacked by attacker, false if not
|
||||
*/
|
||||
public static boolean canDamage(UUID attackerUuid, UUID victimUuid, boolean sendDenyMessage) {
|
||||
return PreventStabby.getPlugin().getPlayerManager().canDamage(attackerUuid, victimUuid, sendDenyMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player can be damaged by another.
|
||||
* @param attacker Attacker
|
||||
* @param victim Victim
|
||||
* @param sendDenyMessage True if check should send deny message to attacker
|
||||
* @return True if victim can be attacked by attacker, false if not
|
||||
*/
|
||||
public static boolean canDamage(Player attacker, Player victim, boolean sendDenyMessage) {
|
||||
return PreventStabby.getPlugin().getPlayerManager().canDamage(attacker.getUniqueId(), victim.getUniqueId(), sendDenyMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player can be damaged by another. Providing UUID of entity other than player may result in exceptions
|
||||
* @param attackerUuid Attacker's UUID
|
||||
* @param victimUuid Victim's UUID
|
||||
* @return True if victim can be attacked by attacker, false if not
|
||||
*/
|
||||
public static boolean canDamage(UUID attackerUuid, UUID victimUuid) {
|
||||
return PreventStabby.getPlugin().getPlayerManager().canDamage(attackerUuid, victimUuid, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player can be damaged by another.
|
||||
* @param attacker Attacker
|
||||
* @param victim Victim
|
||||
* @return True if victim can be attacked by attacker, false if not
|
||||
*/
|
||||
public static boolean canDamage(Player attacker, Player victim) {
|
||||
return PreventStabby.getPlugin().getPlayerManager().canDamage(attacker.getUniqueId(), victim.getUniqueId(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player has login protection.
|
||||
* @param uuid UUID of player to check
|
||||
* @return True if player has login protection, false if not
|
||||
*/
|
||||
public static boolean hasLoginProtection(UUID uuid) {
|
||||
return PreventStabby.getPlugin().getPlayerManager().hasLoginProtection(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player has teleport protection.
|
||||
* @param player Player to check
|
||||
* @return True if player has teleport protection, false if not
|
||||
*/
|
||||
public static boolean hasTeleportProtection(Player player) {
|
||||
return PreventStabby.getPlugin().getPlayerManager().hasLoginProtection(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player has teleport protection.
|
||||
* @param uuid UUID of player to check
|
||||
* @return True if player has teleport protection, false if not
|
||||
*/
|
||||
public static boolean hasTeleportProtection(UUID uuid) {
|
||||
return PreventStabby.getPlugin().getPlayerManager().hasLoginProtection(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player has login protection.
|
||||
* @param player Player to check
|
||||
* @return True if player has login protection, false if not
|
||||
*/
|
||||
public static boolean hasLoginProtection(Player player) {
|
||||
return PreventStabby.getPlugin().getPlayerManager().hasLoginProtection(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player is in combat.
|
||||
* @param uuid UUID of player to check
|
||||
* @return True if player is in combat, false if they are not or if they are offline
|
||||
*/
|
||||
public static boolean isInCombat(UUID uuid) {
|
||||
return CombatTimer.isInCombat(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player is in combat.
|
||||
* @param player Player to check
|
||||
* @return True if player is in combat, false if they are not or if they are offline
|
||||
*/
|
||||
public static boolean isInCombat(Player player) {
|
||||
return CombatTimer.isInCombat(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Current state of forced PvP
|
||||
*/
|
||||
@@ -150,15 +15,15 @@ public class PreventStabbyAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param newForcedPvpState<br>
|
||||
* true - force enable PvP for every player<br>
|
||||
* false - force disable PvP for every player<br>
|
||||
* null - don't force PvP state<br>
|
||||
* Sets forced PvP state until server restart or changed with override command or this method.
|
||||
*/
|
||||
public static void setForcedPvpState(PvpState newForcedPvpState) {
|
||||
PreventStabby.getPlugin().getPlayerManager().setForcedPvpState(newForcedPvpState);
|
||||
}
|
||||
|
||||
public static DamageCheckResult canDamage(Entity attacker, Entity victim) {
|
||||
return PreventStabby.getPlugin().getPlayerManager().canDamage(attacker, victim);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.youhavetrouble.preventstabby.api.event;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.players.PlayerData;
|
||||
import me.youhavetrouble.preventstabby.data.PlayerData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
@@ -45,4 +45,9 @@ public class PlayerEnterCombatEvent extends Event implements Cancellable {
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.youhavetrouble.preventstabby.api.event;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.players.PlayerData;
|
||||
import me.youhavetrouble.preventstabby.data.PlayerData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
@@ -45,4 +45,10 @@ public class PlayerLeaveCombatEvent extends Event implements Cancellable {
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,42 +1,55 @@
|
||||
package me.youhavetrouble.preventstabby.api.event;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.data.PlayerData;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* NOT IMPLEMENTED YET
|
||||
* Fired when player gets their personal pvp state toggled.
|
||||
*/
|
||||
@Deprecated
|
||||
public class PlayerTogglePvpEvent extends Event {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
private final Player player;
|
||||
private boolean newState, sendMessage;
|
||||
private final OfflinePlayer player;
|
||||
private final boolean newState;
|
||||
private boolean sendMessage;
|
||||
|
||||
public PlayerTogglePvpEvent(Player player, boolean newState, boolean sendMessage) {
|
||||
public PlayerTogglePvpEvent(OfflinePlayer player, boolean newState, boolean sendMessage) {
|
||||
this.player = player;
|
||||
this.newState = newState;
|
||||
this.sendMessage = sendMessage;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
public OfflinePlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public PlayerData getPlayerData() {
|
||||
return PreventStabby.getPlugin().getPlayerManager().getPlayer(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the state player's pvp state was toggled to.
|
||||
* @return The state player's pvp state was toggled to.
|
||||
*/
|
||||
public boolean newState() {
|
||||
return newState;
|
||||
}
|
||||
|
||||
public void setNewState(boolean newState) {
|
||||
this.newState = newState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the state message will be sent to the player, false otherwise
|
||||
* @return True if the state message will be sent to the player, false otherwise
|
||||
*/
|
||||
public boolean isSendMessage() {
|
||||
return sendMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this is true at the end of event pipeline, message with the current state will be sent to player.
|
||||
*/
|
||||
public void setSendMessage(boolean sendMessage) {
|
||||
this.sendMessage = sendMessage;
|
||||
}
|
||||
@@ -46,4 +59,10 @@ public class PlayerTogglePvpEvent extends Event {
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ import java.util.Locale;
|
||||
|
||||
public class GlobalToggleCommand {
|
||||
public static void globalToggle(CommandSender sender, String[] args) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(PreventStabby.getPlugin(), () -> {
|
||||
Bukkit.getAsyncScheduler().runNow(PreventStabby.getPlugin(), (task) -> {
|
||||
if (!PreventStabbyPermission.COMMAND_GLOBAL_TOGGLE.doesCommandSenderHave(sender)) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getNo_permission());
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().no_permission);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -27,15 +27,15 @@ public class GlobalToggleCommand {
|
||||
switch (pvpState) {
|
||||
case ENABLED:
|
||||
PreventStabby.getPlugin().getPlayerManager().setForcedPvpState(PvpState.ENABLED);
|
||||
PluginMessages.broadcastMessage(PreventStabby.getPlugin().getConfigCache().getForce_pvp_on());
|
||||
PluginMessages.broadcastMessage(PreventStabby.getPlugin().getConfigCache().force_pvp_on);
|
||||
break;
|
||||
case DISABLED:
|
||||
PreventStabby.getPlugin().getPlayerManager().setForcedPvpState(PvpState.DISABLED);
|
||||
PluginMessages.broadcastMessage(PreventStabby.getPlugin().getConfigCache().getForce_pvp_off());
|
||||
PluginMessages.broadcastMessage(PreventStabby.getPlugin().getConfigCache().force_pvp_off);
|
||||
break;
|
||||
case NONE:
|
||||
PreventStabby.getPlugin().getPlayerManager().setForcedPvpState(PvpState.NONE);
|
||||
PluginMessages.broadcastMessage(PreventStabby.getPlugin().getConfigCache().getForce_pvp_none());
|
||||
PluginMessages.broadcastMessage(PreventStabby.getPlugin().getConfigCache().force_pvp_none);
|
||||
break;
|
||||
default:
|
||||
PluginMessages.sendMessage(sender, "Try /pvp override <enabled/disabled/none>");
|
||||
|
||||
@@ -3,14 +3,19 @@ package me.youhavetrouble.preventstabby.commands;
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.config.PreventStabbyPermission;
|
||||
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
||||
import net.kyori.adventure.audience.MessageType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class HelpCommand {
|
||||
public static void help(CommandSender sender, String[] args) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(PreventStabby.getPlugin(), () -> {
|
||||
Bukkit.getAsyncScheduler().runNow(PreventStabby.getPlugin(), (task) -> {
|
||||
|
||||
if (!PreventStabbyPermission.COMMAND_HELP.doesCommandSenderHave(sender)) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().no_permission);
|
||||
return;
|
||||
}
|
||||
|
||||
Component helpComponent = PluginMessages.MINIMESSAGE
|
||||
.deserialize("<aqua><strikethrough> </strikethrough> PreventStabby Help <strikethrough> </strikethrough>")
|
||||
.append(Component.newline())
|
||||
@@ -23,7 +28,7 @@ public class HelpCommand {
|
||||
.append(Component.newline())
|
||||
.append(PluginMessages.MINIMESSAGE.deserialize("<blue>/pvp <aqua><bold>toggle</bold> <white>- toggles PvP status"));
|
||||
}
|
||||
PreventStabby.getAudiences().sender(sender).sendMessage(helpComponent, MessageType.SYSTEM);
|
||||
sender.sendMessage(helpComponent);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public class MainCommand implements TabExecutor {
|
||||
private final HashMap<String, PreventStabbyPermission> subCommands = new HashMap<>();
|
||||
|
||||
public MainCommand() {
|
||||
subCommands.put("help", PreventStabbyPermission.COMMAND);
|
||||
subCommands.put("help", PreventStabbyPermission.COMMAND_HELP);
|
||||
subCommands.put("toggle", PreventStabbyPermission.COMMAND_TOGGLE);
|
||||
subCommands.put("on", PreventStabbyPermission.COMMAND_TOGGLE);
|
||||
subCommands.put("enable", PreventStabbyPermission.COMMAND_TOGGLE);
|
||||
@@ -33,10 +33,14 @@ public class MainCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!sender.hasPermission("preventstabby.command")) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getNo_permission());
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().no_permission);
|
||||
return true;
|
||||
}
|
||||
if (args.length >= 1) {
|
||||
if (args.length == 0) {
|
||||
PvpToggleCommand.toggle(sender, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "help":
|
||||
HelpCommand.help(sender, args);
|
||||
@@ -59,12 +63,9 @@ public class MainCommand implements TabExecutor {
|
||||
GlobalToggleCommand.globalToggle(sender, args);
|
||||
break;
|
||||
default:
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getNo_such_command());
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().no_such_command);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
HelpCommand.help(sender, args);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package me.youhavetrouble.preventstabby.commands;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.api.event.PlayerTogglePvpEvent;
|
||||
import me.youhavetrouble.preventstabby.config.PreventStabbyPermission;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.data.PlayerManager;
|
||||
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -10,39 +11,47 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class PvpToggleCommand {
|
||||
|
||||
private static final PlayerManager playerManager = PreventStabby.getPlugin().getPlayerManager();
|
||||
|
||||
public static void toggle(CommandSender sender, String[] args) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(PreventStabby.getPlugin(), () -> {
|
||||
Bukkit.getAsyncScheduler().runNow(PreventStabby.getPlugin(), (task) -> {
|
||||
if (!PreventStabbyPermission.COMMAND_TOGGLE.doesCommandSenderHave(sender)) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getNo_permission());
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().no_permission);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if (CombatTimer.isInCombat(player.getUniqueId())) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getCant_do_that_during_combat());
|
||||
return;
|
||||
}
|
||||
boolean currentState = PreventStabby.getPlugin().getPlayerManager().togglePlayerPvpState(player.getUniqueId());
|
||||
|
||||
if (currentState) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getPvp_enabled());
|
||||
} else {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getPvp_disabled());
|
||||
}
|
||||
} else {
|
||||
if (args.length <= 1) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
PluginMessages.sendMessage(sender, "Try /pvp toggle <player>");
|
||||
return;
|
||||
}
|
||||
if (playerManager.getPlayer(player.getUniqueId()).isInCombat()) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().cant_do_that_during_combat);
|
||||
return;
|
||||
}
|
||||
playerManager.togglePlayerPvpState(player.getUniqueId()).thenAccept(newState -> {
|
||||
PlayerTogglePvpEvent toggleEvent = new PlayerTogglePvpEvent(player, newState, true);
|
||||
Bukkit.getGlobalRegionScheduler().run(PreventStabby.getPlugin(), (task1) -> {
|
||||
if (PlayerTogglePvpEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
Bukkit.getPluginManager().callEvent(toggleEvent);
|
||||
}
|
||||
if (!toggleEvent.isSendMessage()) return;
|
||||
if (newState) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().pvp_enabled);
|
||||
} else {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().pvp_disabled);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
} else if (args.length == 2) {
|
||||
if (!PreventStabbyPermission.COMMAND_TOGGLE_OTHERS.doesCommandSenderHave(sender)) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getNo_permission());
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().no_permission);
|
||||
return;
|
||||
}
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if (CombatTimer.isInCombat(player.getUniqueId())) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getCant_do_that_during_combat());
|
||||
if (sender instanceof Player player) {
|
||||
if (playerManager.getPlayer(player.getUniqueId()).isInCombat()) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().cant_do_that_during_combat);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -52,50 +61,65 @@ public class PvpToggleCommand {
|
||||
PluginMessages.sendMessage(sender, "<red>Player offline.");
|
||||
return;
|
||||
}
|
||||
boolean currentState = PreventStabby.getPlugin().getPlayerManager().togglePlayerPvpState(player.getUniqueId());
|
||||
String message;
|
||||
if (currentState) {
|
||||
message = PreventStabby.getPlugin().getConfigCache().getPvp_enabled_other();
|
||||
playerManager.togglePlayerPvpState(player.getUniqueId()).thenAccept(newState -> {
|
||||
PlayerTogglePvpEvent toggleEvent = new PlayerTogglePvpEvent(player, newState, false);
|
||||
Bukkit.getGlobalRegionScheduler().run(PreventStabby.getPlugin(), (task1) -> {
|
||||
if (PlayerTogglePvpEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
Bukkit.getPluginManager().callEvent(toggleEvent);
|
||||
}
|
||||
if (toggleEvent.isSendMessage()) {
|
||||
if (newState) {
|
||||
PluginMessages.sendMessage(player, PreventStabby.getPlugin().getConfigCache().pvp_enabled);
|
||||
} else {
|
||||
message = PreventStabby.getPlugin().getConfigCache().getPvp_disabled_other();
|
||||
PluginMessages.sendMessage(player, PreventStabby.getPlugin().getConfigCache().pvp_disabled);
|
||||
}
|
||||
}
|
||||
String message;
|
||||
if (newState) {
|
||||
message = PreventStabby.getPlugin().getConfigCache().pvp_enabled_other;
|
||||
} else {
|
||||
message = PreventStabby.getPlugin().getConfigCache().pvp_disabled_other;
|
||||
}
|
||||
PluginMessages.sendMessage(sender, PluginMessages.parsePlayerName(player, message));
|
||||
} else {
|
||||
if (PreventStabbyPermission.COMMAND_TOGGLE_OTHERS.doesCommandSenderHave(sender)) {
|
||||
PluginMessages.sendMessage(sender, "Try /pvp toggle <player>");
|
||||
} else {
|
||||
PluginMessages.sendMessage(sender, "Try /pvp toggle");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void enable(CommandSender sender, String[] args) {
|
||||
if (!PreventStabbyPermission.COMMAND_TOGGLE.doesCommandSenderHave(sender)) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getNo_permission());
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().no_permission);
|
||||
return;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if (CombatTimer.isInCombat(player.getUniqueId())) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getCant_do_that_during_combat());
|
||||
if (!(sender instanceof Player player)) {
|
||||
PluginMessages.sendMessage(sender, "Try /pvp enable <player>");
|
||||
return;
|
||||
}
|
||||
PreventStabby.getPlugin().getPlayerManager().setPlayerPvpState(player.getUniqueId(), true);
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getPvp_enabled());
|
||||
} else {
|
||||
PluginMessages.sendMessage(sender, "Try /pvp enable <player>");
|
||||
if (playerManager.getPlayer(player.getUniqueId()).isInCombat()) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().cant_do_that_during_combat);
|
||||
return;
|
||||
}
|
||||
playerManager.setPlayerPvpState(player.getUniqueId(), true);
|
||||
PlayerTogglePvpEvent toggleEvent = new PlayerTogglePvpEvent(player, true, true);
|
||||
Bukkit.getGlobalRegionScheduler().run(PreventStabby.getPlugin(), (task) -> {
|
||||
if (PlayerTogglePvpEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
Bukkit.getPluginManager().callEvent(toggleEvent);
|
||||
}
|
||||
if (toggleEvent.isSendMessage()) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().pvp_enabled);
|
||||
}
|
||||
});
|
||||
|
||||
} else if (args.length == 2) {
|
||||
if (!PreventStabbyPermission.COMMAND_TOGGLE_OTHERS.doesCommandSenderHave(sender)) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getNo_permission());
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().no_permission);
|
||||
return;
|
||||
}
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if (CombatTimer.isInCombat(player.getUniqueId())) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getCant_do_that_during_combat());
|
||||
if (sender instanceof Player player) {
|
||||
if (playerManager.getPlayer(player.getUniqueId()).isInCombat()) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().cant_do_that_during_combat);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -104,9 +128,18 @@ public class PvpToggleCommand {
|
||||
PluginMessages.sendMessage(sender, "<red>Player offline.");
|
||||
return;
|
||||
}
|
||||
String message = PreventStabby.getPlugin().getConfigCache().getPvp_enabled_other();
|
||||
String message = PreventStabby.getPlugin().getConfigCache().pvp_enabled_other;
|
||||
PluginMessages.sendMessage(sender, PluginMessages.parsePlayerName(player, message));
|
||||
PreventStabby.getPlugin().getPlayerManager().setPlayerPvpState(player.getUniqueId(), true);
|
||||
playerManager.setPlayerPvpState(player.getUniqueId(), true);
|
||||
PlayerTogglePvpEvent toggleEvent = new PlayerTogglePvpEvent(player, true, false);
|
||||
Bukkit.getGlobalRegionScheduler().run(PreventStabby.getPlugin(), (task) -> {
|
||||
if (PlayerTogglePvpEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
Bukkit.getPluginManager().callEvent(toggleEvent);
|
||||
}
|
||||
if (toggleEvent.isSendMessage()) {
|
||||
PluginMessages.sendMessage(player, PreventStabby.getPlugin().getConfigCache().pvp_enabled);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (PreventStabbyPermission.COMMAND_TOGGLE_OTHERS.doesCommandSenderHave(sender)) {
|
||||
PluginMessages.sendMessage(sender, "Try /pvp enable <player>");
|
||||
@@ -118,30 +151,36 @@ public class PvpToggleCommand {
|
||||
|
||||
public static void disable(CommandSender sender, String[] args) {
|
||||
if (!PreventStabbyPermission.COMMAND_TOGGLE.doesCommandSenderHave(sender)) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getNo_permission());
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().no_permission);
|
||||
return;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if (CombatTimer.isInCombat(player.getUniqueId())) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getCant_do_that_during_combat());
|
||||
if (sender instanceof Player player) {
|
||||
if (playerManager.getPlayer(player.getUniqueId()).isInCombat()) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().cant_do_that_during_combat);
|
||||
return;
|
||||
}
|
||||
PreventStabby.getPlugin().getPlayerManager().setPlayerPvpState(player.getUniqueId(), false);
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getPvp_disabled());
|
||||
playerManager.setPlayerPvpState(player.getUniqueId(), false);
|
||||
PlayerTogglePvpEvent toggleEvent = new PlayerTogglePvpEvent(player, false, true);
|
||||
Bukkit.getGlobalRegionScheduler().run(PreventStabby.getPlugin(), (task) -> {
|
||||
if (PlayerTogglePvpEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
Bukkit.getPluginManager().callEvent(toggleEvent);
|
||||
}
|
||||
if (toggleEvent.isSendMessage()) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().pvp_disabled);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
PluginMessages.sendMessage(sender, "Try /pvp disable <player>");
|
||||
}
|
||||
} else if (args.length == 2) {
|
||||
if (!PreventStabbyPermission.COMMAND_TOGGLE_OTHERS.doesCommandSenderHave(sender)) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getNo_permission());
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().no_permission);
|
||||
return;
|
||||
}
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if (CombatTimer.isInCombat(player.getUniqueId())) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().getCant_do_that_during_combat());
|
||||
if (sender instanceof Player player) {
|
||||
if (playerManager.getPlayer(player.getUniqueId()).isInCombat()) {
|
||||
PluginMessages.sendMessage(sender, PreventStabby.getPlugin().getConfigCache().cant_do_that_during_combat);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -150,9 +189,18 @@ public class PvpToggleCommand {
|
||||
PluginMessages.sendMessage(sender, "<red>Player offline.");
|
||||
return;
|
||||
}
|
||||
String message = PreventStabby.getPlugin().getConfigCache().getPvp_disabled_other();
|
||||
String message = PreventStabby.getPlugin().getConfigCache().pvp_disabled_other;
|
||||
PluginMessages.sendMessage(sender, PluginMessages.parsePlayerName(player, message));
|
||||
PreventStabby.getPlugin().getPlayerManager().setPlayerPvpState(player.getUniqueId(), true);
|
||||
playerManager.setPlayerPvpState(player.getUniqueId(), false);
|
||||
PlayerTogglePvpEvent toggleEvent = new PlayerTogglePvpEvent(player, false, false);
|
||||
Bukkit.getGlobalRegionScheduler().run(PreventStabby.getPlugin(), (task) -> {
|
||||
if (PlayerTogglePvpEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
Bukkit.getPluginManager().callEvent(toggleEvent);
|
||||
}
|
||||
if (toggleEvent.isSendMessage()) {
|
||||
PluginMessages.sendMessage(player, PreventStabby.getPlugin().getConfigCache().pvp_disabled);
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
if (PreventStabbyPermission.COMMAND_TOGGLE_OTHERS.doesCommandSenderHave(sender)) {
|
||||
|
||||
@@ -9,9 +9,9 @@ import org.bukkit.command.CommandSender;
|
||||
public class ReloadCommand {
|
||||
|
||||
public static void reload(CommandSender sender) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(PreventStabby.getPlugin(), () -> {
|
||||
Bukkit.getAsyncScheduler().runNow(PreventStabby.getPlugin(), (task) -> {
|
||||
if (!PreventStabbyPermission.COMMAND_RELOAD.doesCommandSenderHave(sender)) {
|
||||
PluginMessages.parseMessage(sender, PreventStabby.getPlugin().getConfigCache().getNo_permission());
|
||||
PluginMessages.parseMessage(sender, PreventStabby.getPlugin().getConfigCache().no_permission);
|
||||
return;
|
||||
}
|
||||
PreventStabby.getPlugin().reloadPluginConfig(sender);
|
||||
|
||||
@@ -1,154 +1,220 @@
|
||||
package me.youhavetrouble.preventstabby.config;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import io.github.thatsmusic99.configurationmaster.CMFile;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ConfigCache {
|
||||
|
||||
private final PreventStabby plugin = PreventStabby.getPlugin();
|
||||
|
||||
@Getter private final boolean pvp_enabled_by_default, lava_and_fire_stopper_enabled, channeling_enchant_disabled,
|
||||
punish_for_combat_logout, punish_for_combat_logout_announce, only_owner_can_interact_with_pet,
|
||||
snowballs_knockback, egg_knockback, block_commands_in_combat, block_teleports_in_combat;
|
||||
@Getter private final String pvp_enabled, pvp_disabled, cannot_attack_victim, cannot_attack_attacker,
|
||||
public final boolean pvp_enabled_by_default,
|
||||
bucket_stopper_enabled,
|
||||
fire_stopper_enabled,
|
||||
block_stopper_enabled,
|
||||
punish_for_combat_logout,
|
||||
punish_for_combat_logout_announce,
|
||||
block_teleports_in_combat,
|
||||
allow_fishing_rod_pull;
|
||||
public final String pvp_enabled, pvp_disabled, cannot_attack_victim, cannot_attack_attacker,
|
||||
cannot_attack_pets_victim, cannot_attack_pets_attacker, no_permission, no_such_command, pvp_enabled_other,
|
||||
pvp_disabled_other, punish_for_combat_logout_message, entering_combat, leaving_combat,
|
||||
cant_do_that_during_combat, cannot_attack_mounts_attacker, cannot_attack_mounts_victim, force_pvp_on,
|
||||
force_pvp_off, force_pvp_none, placeholder_combat_time, placeholder_not_in_combat, cannot_attack_pvp_force_off;
|
||||
@Getter private final double lava_and_fire_stopper_radius;
|
||||
@Getter private final long cache_time, combat_time, login_protection_time, teleport_protection_time;
|
||||
@Getter private final Set<String> combatBlockedCommands = new HashSet<>();
|
||||
force_pvp_off, force_pvp_none, placeholder_combat_time, placeholder_not_in_combat, cannot_attack_pvp_force_off,
|
||||
placeholder_pvp_forced_true, placeholder_pvp_forced_false, placeholder_pvp_forced_none;
|
||||
|
||||
public ConfigCache() {
|
||||
public final String cannot_attack_forced_pvp_off, cannot_attack_teleport_or_spawn_protection_attacker,
|
||||
cannot_attack_pets_teleport_or_spawn_protection_attacker, cannot_attack_mounts_teleport_or_spawn_protection_attacker,
|
||||
cannot_attack_teleport_or_spawn_protection_victim;
|
||||
|
||||
CMFile configFile = new CMFile(plugin, "config") {
|
||||
@Override
|
||||
public void loadDefaults() {
|
||||
public final double combat_time, login_protection_time, teleport_protection_time, bucket_stopper_radius,
|
||||
fire_stopper_radius, block_stopper_radius;
|
||||
private final Set<String> combatBlockedCommands = new HashSet<>();
|
||||
|
||||
addDefault("settings.pvp_enabled_by_default", false, "Decides if pvp should be enabled or disabled by default");
|
||||
private final FileConfiguration config;
|
||||
|
||||
addComment("settings.lava_and_fire_stopper", "Prevents dumping lava and pufferfish bucket, placing wither roses and lighting blocks on fire near players with pvp off");
|
||||
addDefault("settings.lava_and_fire_stopper.enabled", true);
|
||||
addDefault("settings.lava_and_fire_stopper.radius", 2.5);
|
||||
|
||||
addDefault("settings.channeling_enchant_disabled", false, "Disables channeling (trident enchant) lightning strike.\nYou may want to keep it disabled because players with pvp off can use it to attack players with pvp on");
|
||||
|
||||
addDefault("settings.only_owner_can_interact_with_pet", false, "Makes it so only pet owner can interact with it. Useful if you don't want people renaming other people's pets.");
|
||||
|
||||
addDefault("settings.combat_time", 25, "Time (in seconds) to keep player in combat");
|
||||
|
||||
addDefault("settings.login_protection_time", 0, "Time (in seconds) that player can't be harmed by other player after logging in");
|
||||
|
||||
addDefault("settings.teleport_protection_time", 0, "Time (in seconds) that player can't be harmed by other player after teleporting");
|
||||
|
||||
addComment("settings.punish_for_combat_logout", "Kill the player if they log out during combat");
|
||||
addDefault("settings.punish_for_combat_logout.enabled", true);
|
||||
addDefault("settings.punish_for_combat_logout.announce", true);
|
||||
addDefault("settings.punish_for_combat_logout.message", "%player%<reset> <white>logged out while in combat. What a loser.");
|
||||
|
||||
addDefault("settings.snowballs_do_knockback", false, "Set to true if snowballs should cause knockback to players");
|
||||
|
||||
addDefault("settings.eggs_do_knockback", false, "Set to true if eggs should cause knockback to players");
|
||||
|
||||
addComment("settings.block_in_combat", "Set what actions should be blocked while in combat");
|
||||
addDefault("settings.block_in_combat.block_commands.enabled", true);
|
||||
List<String> defaultCommandsBlocked = new ArrayList<>();
|
||||
defaultCommandsBlocked.add("spawn");
|
||||
defaultCommandsBlocked.add("tpa");
|
||||
defaultCommandsBlocked.add("home");
|
||||
addDefault("settings.block_in_combat.block_commands.commands", defaultCommandsBlocked);
|
||||
addDefault("settings.block_in_combat.block_teleports", true, "Set if players should be denied teleportation attempts while in combat");
|
||||
|
||||
addDefault("settings.cache_time", 30, "Time (in seconds) to keep player data in memory when players goes offline.\nThis is used for checking if offline players pvp state.\nAdjust only if you know what you're doing. NEVER set to less than 6.");
|
||||
|
||||
addDefault("messages.pvp_enabled", "<red>You enabled PvP!");
|
||||
addDefault("messages.pvp_disabled", "<red>You disabled PvP!");
|
||||
addDefault("messages.cannot_attack_victim", "<red>You can't attack players that have PvP turned off!");
|
||||
addDefault("messages.cannot_attack_attacker", "<red>You can't attack players while you have PvP turned off!");
|
||||
addDefault("messages.cannot_attack_pets_victim", "<red>You can't attack pets of players that have PvP turned off");
|
||||
addDefault("messages.cannot_attack_pets_attacker", "<red>You can't attack pets while you have PvP turned off");
|
||||
addDefault("messages.cannot_attack_mounts_victim", "<red>You can't attack mounts of players that have PvP turned off");
|
||||
addDefault("messages.cannot_attack_mounts_attacker", "<red>You can't attack mounts while you have PvP turned off");
|
||||
addDefault("messages.cannot_attack_pvp_force_off", "<red>PvP is forcibly disabled");
|
||||
addDefault("messages.no_permission", "<red>You don't have permission to use that.");
|
||||
addDefault("messages.no_such_command", "<red>No such command.");
|
||||
addDefault("messages.pvp_enabled_others", "<red>You've enabled %player%'s PvP.");
|
||||
addDefault("messages.pvp_disabled_others", "<red>You've disabled %player%'s PvP.");
|
||||
addDefault("messages.entering_combat", "<red>Entering combat");
|
||||
addDefault("messages.leaving_combat", "<red>Leaving combat");
|
||||
addDefault("messages.cant_do_that_during_combat", "<red>You can't do that while in combat!");
|
||||
addDefault("messages.force_pvp_on", "PvP is now force enabled");
|
||||
addDefault("messages.force_pvp_off", "PvP is now force disabled");
|
||||
addDefault("messages.force_pvp_none", "PvP state is not forced now");
|
||||
addDefault("placeholder.placeholder_combat_time", "Combat time: %time%");
|
||||
addDefault("placeholder.not_in_combat", "Not in combat");
|
||||
}
|
||||
};
|
||||
|
||||
configFile.setDescription("Prevent people from getting stabbed!");
|
||||
configFile.addLink("Spigot", "https://www.spigotmc.org/resources/89376/");
|
||||
configFile.addLink("Source", "https://github.com/YouHaveTrouble/PreventStabby");
|
||||
|
||||
configFile.load();
|
||||
FileConfiguration config = configFile.getConfig();
|
||||
public ConfigCache(PreventStabby plugin) {
|
||||
plugin.reloadConfig();
|
||||
config = plugin.getConfig();
|
||||
|
||||
// Settings
|
||||
this.pvp_enabled_by_default = config.getBoolean("settings.pvp_enabled_by_default", false);
|
||||
this.pvp_enabled_by_default = getBoolean(
|
||||
"settings.pvp_enabled_by_default",
|
||||
false,
|
||||
List.of("Should pvp be enabled by default when the player first joins?")
|
||||
);
|
||||
|
||||
this.lava_and_fire_stopper_enabled = config.getBoolean("settings.lava_and_fire_stopper.enabled", true);
|
||||
this.lava_and_fire_stopper_radius = config.getDouble("settings.lava_and_fire_stopper.radius", 2.5);
|
||||
this.combat_time = getDouble(
|
||||
"settings.combat_time",
|
||||
25,
|
||||
List.of("How long in seconds should combat last since the last hit")
|
||||
);
|
||||
this.punish_for_combat_logout = getBoolean(
|
||||
"settings.punish_for_combat_logout.enabled",
|
||||
true,
|
||||
List.of("Should players be killed if they log out during combat?")
|
||||
);
|
||||
this.punish_for_combat_logout_announce = getBoolean(
|
||||
"settings.punish_for_combat_logout.announce",
|
||||
true,
|
||||
List.of("Should killing of a player that logged out of combat be announced?")
|
||||
);
|
||||
|
||||
this.channeling_enchant_disabled = config.getBoolean("settings.channeling_enchant_disabled", true);
|
||||
this.combatBlockedCommands.addAll(getList(
|
||||
"settings.block_in_combat.commands",
|
||||
List.of("spawn", "tpa", "home"),
|
||||
List.of("Commands to block when player is in combat")
|
||||
)
|
||||
);
|
||||
|
||||
this.combat_time = config.getLong("settings.combat_time", 25L);
|
||||
this.punish_for_combat_logout = config.getBoolean("settings.punish_for_combat_logout.enabled", true);
|
||||
this.punish_for_combat_logout_announce = config.getBoolean("settings.punish_for_combat_logout.announce", true);
|
||||
this.punish_for_combat_logout_message = config.getString("settings.punish_for_combat_logout.message", "%player%<reset><white> logged out while in combat. What a loser.");
|
||||
this.only_owner_can_interact_with_pet = config.getBoolean("settings.only_owner_can_interact_with_pet", false);
|
||||
this.block_teleports_in_combat = getBoolean(
|
||||
"settings.block_in_combat.teleports",
|
||||
false,
|
||||
List.of("Block teleportation triggered by plugins while in combat")
|
||||
);
|
||||
|
||||
this.snowballs_knockback = config.getBoolean("settings.snowballs_do_knockback", false);
|
||||
this.egg_knockback = config.getBoolean("settings.eggs_do_knockback", false);
|
||||
this.block_commands_in_combat = config.getBoolean("settings.block_in_combat.block_commands", true);
|
||||
if (block_commands_in_combat) {
|
||||
this.combatBlockedCommands.addAll(config.getStringList("settings.block_in_combat.block_commands.commands"));
|
||||
}
|
||||
this.block_teleports_in_combat = config.getBoolean("settings.block_in_combat.block_teleports", false);
|
||||
this.login_protection_time = getDouble(
|
||||
"settings.login_protection_time",
|
||||
0,
|
||||
List.of("Protection time after player logs in in seconds")
|
||||
);
|
||||
this.teleport_protection_time = getDouble(
|
||||
"settings.teleport_protection_time",
|
||||
0,
|
||||
List.of("Protection time after player is teleported in seconds")
|
||||
);
|
||||
|
||||
this.cache_time = config.getLong("settings.cache_time", 30L);
|
||||
|
||||
this.login_protection_time = config.getLong("settings.login_protection_time", 0);
|
||||
this.teleport_protection_time = config.getLong("settings.teleport_protection_time", 0);
|
||||
this.allow_fishing_rod_pull = getBoolean(
|
||||
"settings.allow_fishing_rod_pull",
|
||||
false,
|
||||
List.of("Should fishing rod pulling be allowed regardless of players pvp state?")
|
||||
);
|
||||
this.bucket_stopper_enabled = getBoolean(
|
||||
"settings.environmental.bucket_stopper.enabled",
|
||||
true,
|
||||
List.of("Should plugin block dumping buckets with dangers near players with pvp off?")
|
||||
);
|
||||
this.bucket_stopper_radius = getDouble(
|
||||
"settings.environmental.bucket_stopper.radius",
|
||||
2.5,
|
||||
List.of("Distance from the player where dumping buckets will be disallowed")
|
||||
);
|
||||
this.fire_stopper_enabled = getBoolean(
|
||||
"settings.environmental.fire_stopper.enabled",
|
||||
true,
|
||||
List.of("Should plugin block igniting blocks near players with pvp off?")
|
||||
);
|
||||
this.fire_stopper_radius = getDouble(
|
||||
"settings.environmental.fire_stopper.radius",
|
||||
2.5,
|
||||
List.of("Distance from the player where igniting blocks will be disallowed")
|
||||
);
|
||||
this.block_stopper_enabled = getBoolean(
|
||||
"settings.environmental.block_stopper.enabled",
|
||||
true,
|
||||
List.of("Should plugin block placing dangerous blocks near players with pvp off?")
|
||||
);
|
||||
this.block_stopper_radius = getDouble(
|
||||
"settings.environmental.block_stopper.radius",
|
||||
2.5,
|
||||
List.of("Distance from the player where placing dangerous blocks will be disallowed")
|
||||
);
|
||||
|
||||
// Messages
|
||||
this.pvp_enabled = config.getString("messages.pvp_enabled", "<red>You enabled PvP!");
|
||||
this.pvp_disabled = config.getString("messages.pvp_disabled", "<red>You disabled PvP!");
|
||||
this.cannot_attack_victim = config.getString("messages.cannot_attack_victim", "<red>You can't attack players that have PvP turned off!");
|
||||
this.cannot_attack_attacker = config.getString("messages.cannot_attack_attacker", "<red>You can't attack players while you have PvP turned off!");
|
||||
this.cannot_attack_pets_victim = config.getString("messages.cannot_attack_pets_victim", "<red>You can't attack pets while you have PvP turned off");
|
||||
this.cannot_attack_pets_attacker = config.getString("messages.cannot_attack_pets_attacker", "<red>You can't attack pets of players that have PvP turned off");
|
||||
this.cannot_attack_mounts_victim = config.getString("messages.cannot_attack_mounts_victim", "<red>You can't attack mounts of players that have PvP turned off");
|
||||
this.cannot_attack_mounts_attacker = config.getString("messages.cannot_attack_mounts_attacker", "<red>You can't attack mounts while you have PvP turned off");
|
||||
this.cannot_attack_pvp_force_off = config.getString("messages.cannot_attack_pvp_force_off", "<red>PvP is forcibly disabled");
|
||||
this.no_permission = config.getString("messages.no_permission", "<red>You don't have permission to use that.");
|
||||
this.no_such_command = config.getString("messages.no_such_command", "<red>No such command.");
|
||||
this.pvp_enabled_other = config.getString("messages.pvp_enabled_others", "<red>You've enabled %player%'s PvP.");
|
||||
this.pvp_disabled_other = config.getString("messages.pvp_disabled_others", "<red>You've disabled %player%'s PvP.");
|
||||
this.entering_combat = config.getString("messages.entering_combat", "<red>Entering combat");
|
||||
this.leaving_combat = config.getString("messages.leaving_combat", "<red>Leaving combat");
|
||||
this.cant_do_that_during_combat = config.getString("messages.cant_do_that_during_combat", "<red>You can't do that while in combat!");
|
||||
this.force_pvp_on = config.getString("messages.force_pvp_on", "PvP is now force enabled");
|
||||
this.force_pvp_off = config.getString("messages.force_pvp_off", "PvP is now force disabled");
|
||||
this.force_pvp_none = config.getString("messages.force_pvp_none", "PvP state is not forced now");
|
||||
this.pvp_enabled = getString("messages.pvp_enabled", "<red>You enabled PvP!");
|
||||
this.pvp_disabled = getString("messages.pvp_disabled", "<red>You disabled PvP!");
|
||||
this.cannot_attack_victim = getString("messages.cannot_attack_victim", "<red>You can't attack players that have PvP turned off!");
|
||||
this.cannot_attack_attacker = getString("messages.cannot_attack_attacker", "<red>You can't attack players while you have PvP turned off!");
|
||||
this.cannot_attack_pets_victim = getString("messages.cannot_attack_pets_victim", "<red>You can't attack pets while you have PvP turned off");
|
||||
this.cannot_attack_pets_attacker = getString("messages.cannot_attack_pets_attacker", "<red>You can't attack pets of players that have PvP turned off");
|
||||
this.cannot_attack_mounts_victim = getString("messages.cannot_attack_mounts_victim", "<red>You can't attack mounts of players that have PvP turned off");
|
||||
this.cannot_attack_mounts_attacker = getString("messages.cannot_attack_mounts_attacker", "<red>You can't attack mounts while you have PvP turned off");
|
||||
this.cannot_attack_pvp_force_off = getString("messages.cannot_attack_pvp_force_off", "<red>PvP is forcibly disabled");
|
||||
|
||||
this.placeholder_combat_time = config.getString("placeholder.placeholder_combat_time", "Combat time: %time%");
|
||||
this.placeholder_not_in_combat = config.getString("placeholder.not_in_combat", "Not in combat");
|
||||
this.no_permission = getString("messages.no_permission", "<red>You don't have permission to use that.");
|
||||
this.no_such_command = getString("messages.no_such_command", "<red>No such command.");
|
||||
this.pvp_enabled_other = getString("messages.pvp_enabled_others", "<red>You've enabled %player%'s PvP.");
|
||||
this.pvp_disabled_other = getString("messages.pvp_disabled_others", "<red>You've disabled %player%'s PvP.");
|
||||
this.entering_combat = getString("messages.entering_combat", "<red>Entering combat");
|
||||
this.leaving_combat = getString("messages.leaving_combat", "<red>Leaving combat");
|
||||
this.cant_do_that_during_combat = getString("messages.cant_do_that_during_combat", "<red>You can't do that while in combat!");
|
||||
this.force_pvp_on = getString("messages.force_pvp_on", "PvP is now force enabled");
|
||||
this.force_pvp_off = getString("messages.force_pvp_off", "PvP is now force disabled");
|
||||
this.force_pvp_none = getString("messages.force_pvp_none", "PvP state is not forced now");
|
||||
|
||||
this.punish_for_combat_logout_message = getString("messages.punish_for_combat_logout.message", "%player%<reset><white> logged out while in combat. What a loser.");
|
||||
|
||||
this.placeholder_combat_time = getString("placeholder.placeholder_combat_time", "Combat time: %time%");
|
||||
this.placeholder_not_in_combat = getString("placeholder.not_in_combat", "Not in combat");
|
||||
|
||||
this.placeholder_pvp_forced_true = getString("placeholder.pvp_forced_true", "PvP is forced on");
|
||||
this.placeholder_pvp_forced_false = getString("placeholder.pvp_forced_false", "PvP is forced off");
|
||||
this.placeholder_pvp_forced_none = getString("placeholder.pvp_forced_none", "PvP is not forced");
|
||||
|
||||
this.cannot_attack_forced_pvp_off = getString("messages.cannot_attack_pvp_force_off", "<red>PvP is forcibly disabled");
|
||||
this.cannot_attack_teleport_or_spawn_protection_attacker = getString("messages.cannot_attack_teleport_or_spawn_protection_attacker", "<red>You can't attack players while they have teleport or spawn protection");
|
||||
this.cannot_attack_pets_teleport_or_spawn_protection_attacker = getString("messages.cannot_attack_pets_teleport_or_spawn_protection_attacker", "<red>You can't attack pets while you have teleport or spawn protection");
|
||||
this.cannot_attack_mounts_teleport_or_spawn_protection_attacker = getString("messages.cannot_attack_mounts_teleport_or_spawn_protection_attacker", "<red>You can't attack mounts while you have teleport or spawn protection");
|
||||
this.cannot_attack_teleport_or_spawn_protection_victim = getString("messages.cannot_attack_teleport_or_spawn_protection_victim", "<red>You can't attack players while you have teleport or spawn protection");
|
||||
try {
|
||||
config.save(new File(plugin.getDataFolder(), "config.yml"));
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().severe("Failed to save configuration file! - " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Set<String> getCombatBlockedCommands() {
|
||||
return Collections.unmodifiableSet(combatBlockedCommands);
|
||||
}
|
||||
|
||||
private String getString(String path, @NotNull String def) {
|
||||
return getString(path, def, null);
|
||||
}
|
||||
|
||||
private String getString(String path, @NotNull String def, @Nullable List<String> comments) {
|
||||
if (config.isSet(path)) return config.getString(path, def);
|
||||
config.set(path, def);
|
||||
if (comments != null) config.setComments(path, comments);
|
||||
return def;
|
||||
}
|
||||
|
||||
private boolean getBoolean(String path, boolean def, @Nullable List<String> comments) {
|
||||
if (config.isSet(path)) return config.getBoolean(path, def);
|
||||
config.set(path, def);
|
||||
if (comments != null) config.setComments(path, comments);
|
||||
return def;
|
||||
}
|
||||
|
||||
private double getDouble(String path, double def, @Nullable List<String> comments) {
|
||||
if (config.isSet(path)) return config.getDouble(path, def);
|
||||
config.set(path, def);
|
||||
if (comments != null) config.setComments(path, comments);
|
||||
return def;
|
||||
}
|
||||
|
||||
private long getLong(String path, long def, @Nullable List<String> comments) {
|
||||
if (config.isSet(path)) return config.getLong(path, def);
|
||||
config.set(path, def);
|
||||
if (comments != null) config.setComments(path, comments);
|
||||
return def;
|
||||
}
|
||||
|
||||
private List<String> getList(String path, List<String> def, @Nullable List<String> comments) {
|
||||
if (config.isSet(path)) return config.getStringList(path);
|
||||
config.set(path, def);
|
||||
if (comments != null) config.setComments(path, comments);
|
||||
return def;
|
||||
}
|
||||
|
||||
private List<String> getList(String path, List<String> def) {
|
||||
return getList(path, def, null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ public enum PreventStabbyPermission {
|
||||
COMMAND_TOGGLE("command.toggle"),
|
||||
COMMAND_TOGGLE_OTHERS("command.toggle.others"),
|
||||
COMMAND_RELOAD("command.reload"),
|
||||
COMMAND_GLOBAL_TOGGLE("command.toggle.global");
|
||||
COMMAND_GLOBAL_TOGGLE("command.toggle.global"),
|
||||
COMMAND_HELP("command.help");
|
||||
|
||||
private final String permission;
|
||||
PreventStabbyPermission(String permission) {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package me.youhavetrouble.preventstabby.data;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @param ableToDamage Result of the damage check
|
||||
* @param feedbackForAttacker Feedback to send to the attacker
|
||||
* @param attackerId UUID of attacker player
|
||||
* @param victimId UUID of victim player
|
||||
*/
|
||||
public record DamageCheckResult(
|
||||
boolean ableToDamage,
|
||||
@Nullable UUID attackerId,
|
||||
@Nullable UUID victimId,
|
||||
@Nullable String feedbackForAttacker,
|
||||
boolean shouldVictimBePutInCombat
|
||||
) {
|
||||
|
||||
public static DamageCheckResult positive() {
|
||||
return new DamageCheckResult(
|
||||
true,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public static DamageCheckResult positive(UUID attackerId, UUID victimId, boolean shouldVictimBePutInCombat) {
|
||||
return new DamageCheckResult(
|
||||
true,
|
||||
attackerId,
|
||||
victimId,
|
||||
null,
|
||||
shouldVictimBePutInCombat
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
package me.youhavetrouble.preventstabby.data;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* PreventStabby player data keeper.
|
||||
*/
|
||||
public class PlayerData {
|
||||
|
||||
private final UUID playerUuid;
|
||||
private long lastAccessTimestamp;
|
||||
private Long combatStartTimestamp, teleportTimestamp, loginTimestamp;
|
||||
private boolean pvpEnabled, lastCombatCheck;
|
||||
|
||||
public PlayerData(UUID playerUuid, boolean pvpEnabled) {
|
||||
this.playerUuid = playerUuid;
|
||||
this.pvpEnabled = pvpEnabled;
|
||||
this.lastCombatCheck = false;
|
||||
this.combatStartTimestamp = null;
|
||||
this.loginTimestamp = null;
|
||||
this.teleportTimestamp = null;
|
||||
refreshCacheTime();
|
||||
}
|
||||
|
||||
public UUID getPlayerUuid() {
|
||||
return playerUuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if player has personal pvp enabled, false otherwise.
|
||||
* @return True if player has personal pvp enabled, false otherwise.
|
||||
*/
|
||||
public boolean isPvpEnabled() {
|
||||
return pvpEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets player's personal pvp state.
|
||||
* @param pvpEnabled Pvp state to set.
|
||||
*/
|
||||
protected void setPvpEnabled(boolean pvpEnabled) {
|
||||
this.pvpEnabled = pvpEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns player's last access timestamp.
|
||||
* @return Player's last access timestamp.
|
||||
*/
|
||||
protected long getLastAccessTimestamp() {
|
||||
return lastAccessTimestamp;
|
||||
}
|
||||
|
||||
protected boolean isCacheExpired() {
|
||||
return System.currentTimeMillis() - lastAccessTimestamp > 60000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the last access to any of the fields
|
||||
*/
|
||||
protected void refreshCacheTime() {
|
||||
this.lastAccessTimestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the timestamp when combat started.
|
||||
* @return The timestamp when combat started.
|
||||
*/
|
||||
protected long getCombatStartTimestamp() {
|
||||
refreshCacheTime();
|
||||
return combatStartTimestamp;
|
||||
}
|
||||
|
||||
protected boolean getLastCombatCheckState() {
|
||||
return lastCombatCheck;
|
||||
}
|
||||
|
||||
protected void setLastCombatCheckState(boolean state) {
|
||||
this.lastCombatCheck = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the player as in combat.
|
||||
*/
|
||||
public void markInCombat() {
|
||||
refreshCacheTime();
|
||||
if (PreventStabby.getPlugin().getConfigCache().combat_time <= 0) return;
|
||||
this.combatStartTimestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
protected void markNotInCombat() {
|
||||
refreshCacheTime();
|
||||
this.combatStartTimestamp = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the login timestamp for the player.
|
||||
* @param loginTimestamp The login timestamp to set.
|
||||
*/
|
||||
protected void setLoginTimestamp(long loginTimestamp) {
|
||||
this.loginTimestamp = loginTimestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the login timestamp for the player.
|
||||
* @return The login timestamp for the player.
|
||||
*/
|
||||
public Long getLoginTimestamp() {
|
||||
return loginTimestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the timestamp of the player's teleport.
|
||||
* @param teleportTimestamp The timestamp of the player's teleport.
|
||||
*/
|
||||
public void setTeleportTimestamp(long teleportTimestamp) {
|
||||
this.teleportTimestamp = teleportTimestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player is currently in combat.
|
||||
*
|
||||
* @return true if the player is in combat, false otherwise.
|
||||
*/
|
||||
public boolean isInCombat() {
|
||||
if (combatStartTimestamp == null) return false;
|
||||
return System.currentTimeMillis() - (combatStartTimestamp + (PreventStabby.getPlugin().getConfigCache().combat_time * 1000)) < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the number of seconds left until combat ends for the player.
|
||||
* @return The number of seconds left until combat ends. -1 if not in combat
|
||||
*/
|
||||
public long getSecondsLeftUntilCombatEnd() {
|
||||
if (combatStartTimestamp == null) return -1;
|
||||
long timeSinceCombatStart = System.currentTimeMillis() - combatStartTimestamp;
|
||||
long combatTimeConfigured = (long) (PreventStabby.getPlugin().getConfigCache().combat_time * 1000);
|
||||
return (timeSinceCombatStart < combatTimeConfigured) ? (combatTimeConfigured - timeSinceCombatStart) / 1000 : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player has login protection.
|
||||
*
|
||||
* @return true if the player has login protection, false otherwise.
|
||||
*/
|
||||
public boolean hasLoginProtection() {
|
||||
if (loginTimestamp == null) return false;
|
||||
return System.currentTimeMillis() - (loginTimestamp + (PreventStabby.getPlugin().getConfigCache().login_protection_time * 1000)) < 0;
|
||||
}
|
||||
|
||||
public boolean hasTeleportProtection() {
|
||||
if (teleportTimestamp == null) return false;
|
||||
return System.currentTimeMillis() - (teleportTimestamp + (PreventStabby.getPlugin().getConfigCache().teleport_protection_time * 1000)) < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the player has any form of protection enabled, including login and teleport protection.
|
||||
*
|
||||
* @return true if the player has protection enabled, false otherwise.
|
||||
*/
|
||||
public boolean isProtected() {
|
||||
return hasLoginProtection() || hasTeleportProtection();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package me.youhavetrouble.preventstabby.data;
|
||||
|
||||
import com.destroystokyo.paper.event.entity.EntityAddToWorldEvent;
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerLogin(AsyncPlayerPreLoginEvent event) {
|
||||
if (!event.getLoginResult().equals(AsyncPlayerPreLoginEvent.Result.ALLOWED)) return;
|
||||
UUID uuid = event.getUniqueId();
|
||||
try {
|
||||
PreventStabby.getPlugin().getPlayerManager().getPlayerData(uuid).get();
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
PreventStabby.getPlugin().getLogger().severe(e.getMessage());
|
||||
PreventStabby.getPlugin().getLogger().severe("Failed to load data for player %s".formatted(event.getPlayerProfile().getName()));
|
||||
PreventStabby.getPlugin().getPlayerManager().addPlayer(uuid, new PlayerData(uuid, false));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
PlayerData playerData = PreventStabby.getPlugin().getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
|
||||
playerData.setLoginTimestamp(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is here to save player's data to database
|
||||
* Also punishes players who log out during combat
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!PreventStabby.getPlugin().getConfigCache().punish_for_combat_logout) return;
|
||||
PlayerData playerData = PreventStabby.getPlugin().getPlayerManager().getPlayer(player.getUniqueId());
|
||||
if (!playerData.isInCombat()) return;
|
||||
player.setHealth(0);
|
||||
if (!PreventStabby.getPlugin().getConfigCache().punish_for_combat_logout_announce) return;
|
||||
PluginMessages.broadcastMessage(player, PreventStabby.getPlugin().getConfigCache().punish_for_combat_logout_message);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
PlayerData playerData = PreventStabby.getPlugin().getPlayerManager().getPlayer(player.getUniqueId());
|
||||
playerData.setTeleportTimestamp(Instant.now().getEpochSecond());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPlayerDeath(EntityDeathEvent event) {
|
||||
if (!(event.getEntity() instanceof Player player)) return;
|
||||
PlayerData playerData = PreventStabby.getPlugin().getPlayerManager().getPlayer(player.getUniqueId());
|
||||
if (playerData == null) return;
|
||||
playerData.markNotInCombat();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data for owners of loaded tameables
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityLoad(EntityAddToWorldEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
if (!(entity instanceof Tameable tameable)) return;
|
||||
UUID ownerId = tameable.getOwnerUniqueId();
|
||||
if (ownerId == null) return;
|
||||
PreventStabby.getPlugin().getPlayerManager().getPlayerData(ownerId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
package me.youhavetrouble.preventstabby.data;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.api.event.PlayerEnterCombatEvent;
|
||||
import me.youhavetrouble.preventstabby.api.event.PlayerLeaveCombatEvent;
|
||||
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
||||
import me.youhavetrouble.preventstabby.util.PvpState;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class PlayerManager {
|
||||
|
||||
private final PreventStabby plugin;
|
||||
private final ConcurrentHashMap<UUID, PlayerData> playerList = new ConcurrentHashMap<>();
|
||||
private PvpState pvpForcedState = PvpState.NONE;
|
||||
|
||||
public PlayerManager(PreventStabby plugin) {
|
||||
this.plugin = plugin;
|
||||
Bukkit.getAsyncScheduler().runAtFixedRate(plugin, (task) -> {
|
||||
// Check for entries that should be invalidated
|
||||
playerList.values().removeIf(PlayerData::isCacheExpired);
|
||||
}, 250, 250, TimeUnit.MILLISECONDS);
|
||||
|
||||
Bukkit.getGlobalRegionScheduler().runAtFixedRate(plugin, (task) -> Bukkit.getWorlds().forEach((world -> {
|
||||
for (Chunk chunk : world.getLoadedChunks()) {
|
||||
if (!chunk.isEntitiesLoaded()) continue;
|
||||
Bukkit.getRegionScheduler().run(plugin, chunk.getWorld(), chunk.getX(), chunk.getZ(), (task1) -> {
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
if (!(entity instanceof Tameable tameable)) continue;
|
||||
UUID ownerId = tameable.getOwnerUniqueId();
|
||||
if (ownerId == null) continue;
|
||||
getPlayerData(ownerId);
|
||||
}
|
||||
});
|
||||
}
|
||||
})), 5, 20 * 15);
|
||||
|
||||
Bukkit.getGlobalRegionScheduler().runAtFixedRate(plugin, (task) -> {
|
||||
for (PlayerData playerData : playerList.values()) {
|
||||
if (playerData == null) continue;
|
||||
Player player = Bukkit.getPlayer(playerData.getPlayerUuid());
|
||||
if (player == null || !player.isOnline()) continue;
|
||||
playerData.refreshCacheTime(); // Refresh cache timer if player is online
|
||||
// leaving combat logic
|
||||
if (playerData.getLastCombatCheckState() && !playerData.isInCombat()) {
|
||||
PlayerLeaveCombatEvent leaveCombatEvent = null;
|
||||
if (PlayerLeaveCombatEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
leaveCombatEvent = new PlayerLeaveCombatEvent(player);
|
||||
Bukkit.getPluginManager().callEvent(leaveCombatEvent);
|
||||
}
|
||||
if (leaveCombatEvent != null && leaveCombatEvent.isCancelled()) {
|
||||
playerData.markInCombat();
|
||||
playerData.setLastCombatCheckState(playerData.isInCombat());
|
||||
continue;
|
||||
}
|
||||
PluginMessages.sendActionBar(player, plugin.getConfigCache().leaving_combat);
|
||||
playerData.setLastCombatCheckState(playerData.isInCombat());
|
||||
continue;
|
||||
}
|
||||
// entering combat logic
|
||||
if (plugin.getConfigCache().combat_time <= 0) return; // disable combat entering when combat time is <0
|
||||
if (!playerData.getLastCombatCheckState() && playerData.isInCombat()) {
|
||||
PlayerEnterCombatEvent enterCombatEvent = null;
|
||||
if (PlayerEnterCombatEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
enterCombatEvent = new PlayerEnterCombatEvent(player);
|
||||
Bukkit.getPluginManager().callEvent(enterCombatEvent);
|
||||
}
|
||||
if (enterCombatEvent != null && enterCombatEvent.isCancelled()) {
|
||||
playerData.markNotInCombat();
|
||||
playerData.setLastCombatCheckState(playerData.isInCombat());
|
||||
continue;
|
||||
}
|
||||
PluginMessages.sendActionBar(player, plugin.getConfigCache().entering_combat);
|
||||
playerData.setLastCombatCheckState(playerData.isInCombat());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets player's PlayerData object. Returns null when player with provided UUID doesn't exist.
|
||||
*
|
||||
* @param uuid Player's UUID.
|
||||
* @return Player's PlayerData object or null if player doesn't exist.
|
||||
*/
|
||||
public PlayerData getPlayer(UUID uuid) {
|
||||
return playerList.get(uuid);
|
||||
}
|
||||
|
||||
protected void addPlayer(UUID uuid, PlayerData data) {
|
||||
playerList.put(uuid, data);
|
||||
}
|
||||
|
||||
public void handleDamageCheck(@NotNull DamageCheckResult damageCheckResult) {
|
||||
if (damageCheckResult.attackerId() == null) return;
|
||||
if (damageCheckResult.victimId() == null) return;
|
||||
PluginMessages.sendOutMessages(damageCheckResult);
|
||||
PlayerData attacker = getPlayer(damageCheckResult.attackerId());
|
||||
PlayerData victim = getPlayer(damageCheckResult.victimId());
|
||||
if (attacker == null || victim == null) return;
|
||||
if (!damageCheckResult.ableToDamage()) return;
|
||||
attacker.markInCombat();
|
||||
if (!damageCheckResult.shouldVictimBePutInCombat()) return;
|
||||
victim.markInCombat();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the given attacker can damage the victim.
|
||||
*
|
||||
* @param attacker The attacking entity.
|
||||
* @param victim The victim entity.
|
||||
* @return A {@link DamageCheckResult} object containing the result of the damage check.
|
||||
*/
|
||||
public DamageCheckResult canDamage(@NotNull Entity attacker, @NotNull Entity victim) {
|
||||
Target attackerData = Target.getTarget(attacker);
|
||||
Target victimData = Target.getTarget(victim);
|
||||
if (attackerData == null || victimData == null) return DamageCheckResult.positive();
|
||||
return canDamage(attackerData.playerUuid, victimData.playerUuid, victimData.classifier);
|
||||
}
|
||||
|
||||
public DamageCheckResult canDamage(UUID attackerId, UUID victimId, Target.EntityClassifier victimClassifier) {
|
||||
|
||||
if (attackerId == null || victimId == null) return DamageCheckResult.positive();
|
||||
|
||||
PlayerData attackerPlayerData = getPlayer(attackerId);
|
||||
PlayerData victimPlayerData = getPlayer(victimId);
|
||||
|
||||
if (attackerPlayerData == null || victimPlayerData == null) {
|
||||
return DamageCheckResult.positive();
|
||||
}
|
||||
|
||||
if (attackerPlayerData.getPlayerUuid().equals(victimPlayerData.getPlayerUuid())) {
|
||||
return DamageCheckResult.positive(attackerId, victimId, false);
|
||||
}
|
||||
|
||||
if (attackerPlayerData.isProtected()) {
|
||||
String message = switch (victimClassifier) {
|
||||
case PLAYER -> plugin.getConfigCache().cannot_attack_teleport_or_spawn_protection_attacker;
|
||||
case PET -> plugin.getConfigCache().cannot_attack_pets_teleport_or_spawn_protection_attacker;
|
||||
case MOUNT -> plugin.getConfigCache().cannot_attack_mounts_teleport_or_spawn_protection_attacker;
|
||||
default -> null;
|
||||
};
|
||||
return new DamageCheckResult(false, attackerId, victimId, message, false);
|
||||
}
|
||||
if (victimPlayerData.isProtected()) {
|
||||
String message = null;
|
||||
if (victimClassifier == Target.EntityClassifier.PLAYER) {
|
||||
message = plugin.getConfigCache().cannot_attack_teleport_or_spawn_protection_victim;
|
||||
}
|
||||
return new DamageCheckResult(false, attackerId, victimId, message, false);
|
||||
}
|
||||
|
||||
switch (getForcedPvpState()) {
|
||||
case DISABLED -> {
|
||||
return new DamageCheckResult(false, attackerId, victimId, plugin.getConfigCache().cannot_attack_forced_pvp_off, false);
|
||||
}
|
||||
case ENABLED -> {
|
||||
return DamageCheckResult.positive(attackerId, victimId, victimClassifier.equals(Target.EntityClassifier.PLAYER));
|
||||
}
|
||||
}
|
||||
|
||||
if (!attackerPlayerData.isPvpEnabled()) {
|
||||
String message = switch (victimClassifier) {
|
||||
case PLAYER -> plugin.getConfigCache().cannot_attack_attacker;
|
||||
case PET -> plugin.getConfigCache().cannot_attack_pets_victim;
|
||||
case MOUNT -> plugin.getConfigCache().cannot_attack_mounts_attacker;
|
||||
default -> null;
|
||||
};
|
||||
return new DamageCheckResult(false, attackerId, victimId, message, victimClassifier.equals(Target.EntityClassifier.PLAYER));
|
||||
}
|
||||
|
||||
if (!victimPlayerData.isPvpEnabled()) {
|
||||
String message = switch (victimClassifier) {
|
||||
case PLAYER -> plugin.getConfigCache().cannot_attack_victim;
|
||||
case PET -> plugin.getConfigCache().cannot_attack_pets_attacker;
|
||||
case MOUNT -> plugin.getConfigCache().cannot_attack_mounts_victim;
|
||||
default -> null;
|
||||
};
|
||||
return new DamageCheckResult(false, attackerId, victimId, message, victimClassifier.equals(Target.EntityClassifier.PLAYER));
|
||||
}
|
||||
|
||||
return new DamageCheckResult(
|
||||
true,
|
||||
attackerId,
|
||||
victimId,
|
||||
null,
|
||||
victimClassifier.equals(Target.EntityClassifier.PLAYER)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current forced pvp state.
|
||||
* @return Current forced pvp state.
|
||||
*/
|
||||
public PvpState getForcedPvpState() {
|
||||
return pvpForcedState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets current forced pvp state.
|
||||
* @param forcedPvpState New forced pvp state.
|
||||
*/
|
||||
public void setForcedPvpState(PvpState forcedPvpState) {
|
||||
this.pvpForcedState = forcedPvpState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the PlayerData object for the player with the provided UUID. Returns new default if there isn't data.
|
||||
*
|
||||
* @param uuid The UUID of the player.
|
||||
* @return The PlayerData object associated with the player.
|
||||
*/
|
||||
public CompletableFuture<PlayerData> getPlayerData(UUID uuid) {
|
||||
// Try to get data from cache and refresh it
|
||||
PlayerData data = getPlayer(uuid);
|
||||
if (data != null) {
|
||||
data.refreshCacheTime();
|
||||
return CompletableFuture.completedFuture(data);
|
||||
}
|
||||
// Get data from database or provide default
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
PlayerData playerData = plugin.getSqLite().getPlayerInfo(uuid);
|
||||
if (playerData == null) {
|
||||
playerData = new PlayerData(uuid, false);
|
||||
}
|
||||
plugin.getPlayerManager().addPlayer(uuid, playerData);
|
||||
return playerData;
|
||||
});
|
||||
}
|
||||
|
||||
public void setPlayerPvpState(UUID uuid, boolean state) {
|
||||
// If player is in cache update that
|
||||
if (getPlayer(uuid) != null) {
|
||||
getPlayer(uuid).setPvpEnabled(state);
|
||||
}
|
||||
// Update the database aswell
|
||||
plugin.getSqLite().updatePlayerInfo(uuid, new PlayerData(uuid, state));
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> togglePlayerPvpState(UUID uuid) {
|
||||
return getPlayerData(uuid).thenApply(playerData -> {
|
||||
playerData.setPvpEnabled(!playerData.isPvpEnabled());
|
||||
plugin.getSqLite().updatePlayerInfo(uuid, new PlayerData(uuid, playerData.isPvpEnabled()));
|
||||
return playerData.isPvpEnabled();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package me.youhavetrouble.preventstabby.data;
|
||||
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataHolder;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Target {
|
||||
|
||||
public static final NamespacedKey playerSourceIdKey = new NamespacedKey("preventstabby", "playersource");
|
||||
|
||||
/**
|
||||
* The unique identifier for a player.
|
||||
*/
|
||||
public final UUID playerUuid;
|
||||
|
||||
/**
|
||||
* Represents the entity classifier of a target.
|
||||
* This indicates what type of entity player's id was assumed from
|
||||
*/
|
||||
public final EntityClassifier classifier;
|
||||
|
||||
private Target(UUID uuid, EntityClassifier classifier) {
|
||||
this.playerUuid = uuid;
|
||||
this.classifier = classifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the UUID of the actual player, being owner of a pet, shooter of a projectile, etc.
|
||||
*
|
||||
* @param entity Base entity to get the player UUID from
|
||||
* @return UUID of the actual player, null if not found
|
||||
*/
|
||||
@Nullable
|
||||
public static Target getTarget(@NotNull Entity entity) {
|
||||
if (entity instanceof Player) return new Target(entity.getUniqueId(), EntityClassifier.PLAYER);
|
||||
|
||||
// Get shooter of projectile
|
||||
if (entity instanceof Projectile projectile) {
|
||||
if (projectile.getShooter() instanceof Player shooter) {
|
||||
return new Target(shooter.getUniqueId(), EntityClassifier.PLAYER);
|
||||
}
|
||||
}
|
||||
|
||||
// Get player riding mount
|
||||
if (!entity.getPassengers().isEmpty()) {
|
||||
Entity passenger = entity.getPassengers().get(0);
|
||||
if (passenger instanceof Player) {
|
||||
return new Target(passenger.getUniqueId(), EntityClassifier.MOUNT);
|
||||
}
|
||||
}
|
||||
|
||||
// Get owner of tamed entity
|
||||
if (entity instanceof Tameable tameable) {
|
||||
if (tameable.getOwner() != null) {
|
||||
return new Target(tameable.getOwner().getUniqueId(), EntityClassifier.PET);
|
||||
}
|
||||
}
|
||||
|
||||
// Try to get player's id from other various entities
|
||||
PersistentDataContainer pdc = entity.getPersistentDataContainer();
|
||||
if (!pdc.has(playerSourceIdKey)) return null;
|
||||
String id = pdc.get(playerSourceIdKey, PersistentDataType.STRING);
|
||||
if (id == null) return null;
|
||||
try {
|
||||
UUID uuid = UUID.fromString(id);
|
||||
return new Target(uuid, EntityClassifier.OTHER);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns the player source ID to the given data holder.
|
||||
* @param dataHolder The persistent data holder to assign the player source ID to.
|
||||
* @param id The UUID of the player source ID to assign.
|
||||
*/
|
||||
public static void assignPlayerSourceId(@NotNull PersistentDataHolder dataHolder, @NotNull UUID id) {
|
||||
dataHolder.getPersistentDataContainer().set(playerSourceIdKey, PersistentDataType.STRING, id.toString());
|
||||
}
|
||||
|
||||
public enum EntityClassifier {
|
||||
PLAYER,
|
||||
PET,
|
||||
MOUNT,
|
||||
OTHER
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package me.youhavetrouble.preventstabby.hooks;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlaceholderApiHook extends PlaceholderExpansion {
|
||||
|
||||
private final PreventStabby plugin;
|
||||
private final LegacyComponentSerializer legacyComponentSerializer;
|
||||
|
||||
public PlaceholderApiHook(PreventStabby preventStabby) {
|
||||
plugin = preventStabby;
|
||||
this.legacyComponentSerializer = LegacyComponentSerializer.legacyAmpersand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "preventstabby";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return plugin.getDescription().getAuthors().get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
return plugin.getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onRequest(OfflinePlayer player, String params) {
|
||||
return switch (params) {
|
||||
case "pvp" -> {
|
||||
if (!player.isOnline()) yield String.valueOf(false);
|
||||
yield String.valueOf(plugin.getPlayerManager().getPlayer(player.getUniqueId()).isPvpEnabled());
|
||||
}
|
||||
case "combat_time" -> getCombatTimePlaceholder(player.getUniqueId(), player);
|
||||
case "in_combat" -> {
|
||||
if (!player.isOnline()) yield String.valueOf(false);
|
||||
yield String.valueOf(plugin.getPlayerManager().getPlayer(player.getUniqueId()).isInCombat());
|
||||
}
|
||||
case "pvp_forced" -> switch (PreventStabby.getPlugin().getPlayerManager().getForcedPvpState()) {
|
||||
case NONE ->
|
||||
legacyComponentSerializer.serialize(PluginMessages.parseMessage(plugin.getConfigCache().placeholder_pvp_forced_none));
|
||||
case ENABLED ->
|
||||
legacyComponentSerializer.serialize(PluginMessages.parseMessage(plugin.getConfigCache().placeholder_pvp_forced_true));
|
||||
case DISABLED ->
|
||||
legacyComponentSerializer.serialize(PluginMessages.parseMessage(plugin.getConfigCache().placeholder_pvp_forced_false));
|
||||
};
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
private String getCombatTimePlaceholder(UUID uuid, OfflinePlayer player) {
|
||||
if (!player.isOnline()) {
|
||||
return legacyComponentSerializer.serialize(PluginMessages.parseMessage(plugin.getConfigCache().placeholder_not_in_combat));
|
||||
}
|
||||
long seconds = plugin.getPlayerManager().getPlayer(uuid).getSecondsLeftUntilCombatEnd();
|
||||
if (seconds > 0) {
|
||||
String msg = plugin.getConfigCache().placeholder_combat_time;
|
||||
msg = msg.replaceAll("%time%", String.valueOf(seconds));
|
||||
return legacyComponentSerializer.serialize(PluginMessages.parseMessage(msg));
|
||||
}
|
||||
return legacyComponentSerializer.serialize(PluginMessages.parseMessage(plugin.getConfigCache().placeholder_not_in_combat));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.hooks;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlacoholderApiHook extends PlaceholderExpansion {
|
||||
|
||||
private final PreventStabby plugin;
|
||||
private final LegacyComponentSerializer legacyComponentSerializer;
|
||||
|
||||
public PlacoholderApiHook(PreventStabby preventStabby) {
|
||||
plugin = preventStabby;
|
||||
this.legacyComponentSerializer = LegacyComponentSerializer.legacyAmpersand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "preventstabby";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return plugin.getDescription().getAuthors().get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
return plugin.getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onRequest(OfflinePlayer player, String params) {
|
||||
if (params.equalsIgnoreCase("combat_time")) {
|
||||
return getCombatTimePlaceholder(player.getUniqueId());
|
||||
}
|
||||
if (params.equalsIgnoreCase("in_combat")) {
|
||||
return String.valueOf(plugin.getPlayerManager().getPlayer(player.getUniqueId()).isInCombat());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getCombatTimePlaceholder(UUID uuid) {
|
||||
long seconds = plugin.getPlayerManager().getPlayer(uuid).getCombattime() - Instant.now().getEpochSecond();
|
||||
if (seconds > 0) {
|
||||
String msg = plugin.getConfigCache().getPlaceholder_combat_time();
|
||||
msg = msg.replaceAll("%time%", String.valueOf(seconds));
|
||||
return legacyComponentSerializer.serialize(PluginMessages.parseMessage(msg));
|
||||
}
|
||||
return legacyComponentSerializer.serialize(PluginMessages.parseMessage(plugin.getConfigCache().getPlaceholder_not_in_combat()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,6 @@ import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class WorldGuardHook {
|
||||
|
||||
@@ -22,19 +21,18 @@ public class WorldGuardHook {
|
||||
public static StateFlag FORCE_PVP_FLAG;
|
||||
|
||||
public static void init() {
|
||||
PreventStabby plugin = PreventStabby.getPlugin();
|
||||
try {
|
||||
Class.forName("com.sk89q.worldguard.protection.flags.registry.FlagRegistry");
|
||||
WorldGuardPlugin worldGuardPlugin = WorldGuardPlugin.inst();
|
||||
if (WorldGuard.getInstance() == null || worldGuardPlugin == null) return;
|
||||
plugin.getLogger().info("Hooking into WorldGuard");
|
||||
PreventStabby.getPlugin().getLogger().info("[PreventStabby] Hooking into WorldGuard");
|
||||
flagRegistry = WorldGuard.getInstance().getFlagRegistry();
|
||||
createForcePvpFlag(plugin);
|
||||
createForcePvpFlag();
|
||||
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private static void createForcePvpFlag(Plugin plugin) {
|
||||
private static void createForcePvpFlag() {
|
||||
if (flagRegistry == null) return;
|
||||
String flagName = "preventstabby-force-pvp";
|
||||
try {
|
||||
@@ -46,7 +44,7 @@ public class WorldGuardHook {
|
||||
if (existing instanceof StateFlag) {
|
||||
FORCE_PVP_FLAG = (StateFlag) existing;
|
||||
} else {
|
||||
plugin.getLogger().severe("There is a conflict between flag names!");
|
||||
PreventStabby.getPlugin().getLogger().severe("[PreventStabby] There is a conflict between flag names!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
package me.youhavetrouble.preventstabby.listeners;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.config.ConfigCache;
|
||||
import me.youhavetrouble.preventstabby.data.DamageCheckResult;
|
||||
import me.youhavetrouble.preventstabby.data.Target;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class EnvironmentalListener implements Listener {
|
||||
|
||||
private final PreventStabby plugin;
|
||||
private final Set<Material> dangerousBuckets = new HashSet<>();
|
||||
|
||||
public EnvironmentalListener(PreventStabby plugin) {
|
||||
this.plugin = plugin;
|
||||
dangerousBuckets.add(Material.LAVA_BUCKET);
|
||||
dangerousBuckets.add(Material.PUFFERFISH_BUCKET);
|
||||
dangerousBuckets.add(Material.POWDER_SNOW_BUCKET);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onDangerousBucketDump(PlayerBucketEmptyEvent event) {
|
||||
ConfigCache config = plugin.getConfigCache();
|
||||
if (!config.bucket_stopper_enabled) return;
|
||||
if (!dangerousBuckets.contains(event.getBucket())) return;
|
||||
Location location = event.getBlockClicked().getLocation();
|
||||
Player placer = event.getPlayer();
|
||||
double radius = config.bucket_stopper_radius;
|
||||
|
||||
BoundingBox boundingBox = BoundingBox.of(location.toVector(), radius, radius, radius);
|
||||
for (Entity victim : location.getWorld().getNearbyEntities(boundingBox)) {
|
||||
if (victim.getUniqueId() == placer.getUniqueId()) continue;
|
||||
Target victimTarget = Target.getTarget(victim);
|
||||
if (victimTarget == null) continue;
|
||||
DamageCheckResult result = plugin.getPlayerManager().canDamage(placer.getUniqueId(), victim.getUniqueId(), victimTarget.classifier);
|
||||
if (!result.ableToDamage()) {
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
ConfigCache config = plugin.getConfigCache();
|
||||
if (!config.fire_stopper_enabled) return;
|
||||
Entity igniter = event.getIgnitingEntity();
|
||||
if (igniter == null) return;
|
||||
Target igniterTarget = Target.getTarget(igniter);
|
||||
if (igniterTarget == null) return;
|
||||
Location location = event.getBlock().getLocation();
|
||||
double radius = config.fire_stopper_radius;
|
||||
|
||||
BoundingBox boundingBox = BoundingBox.of(location.toVector(), radius, radius, radius);
|
||||
for (Entity victim : location.getWorld().getNearbyEntities(boundingBox)) {
|
||||
if (victim.getUniqueId() == igniterTarget.playerUuid) continue;
|
||||
Target victimTarget = Target.getTarget(victim);
|
||||
if (victimTarget == null) continue;
|
||||
DamageCheckResult result = plugin.getPlayerManager().canDamage(igniterTarget.playerUuid, victim.getUniqueId(), victimTarget.classifier);
|
||||
if (!result.ableToDamage()) {
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockIgnite(BlockPlaceEvent event) {
|
||||
ConfigCache config = plugin.getConfigCache();
|
||||
if (!config.block_stopper_enabled) return;
|
||||
Player player = event.getPlayer();
|
||||
Location location = event.getBlock().getLocation().toCenterLocation();
|
||||
Target target = Target.getTarget(player);
|
||||
if (target == null) return;
|
||||
double radius = config.block_stopper_radius;
|
||||
|
||||
BoundingBox boundingBox = BoundingBox.of(location.toVector(), radius, radius, radius);
|
||||
for (Entity victim : location.getWorld().getNearbyEntities(boundingBox)) {
|
||||
if (victim.getUniqueId() == target.playerUuid) continue;
|
||||
Target victimTarget = Target.getTarget(victim);
|
||||
if (victimTarget == null) continue;
|
||||
DamageCheckResult result = plugin.getPlayerManager().canDamage(target.playerUuid, victim.getUniqueId(), victimTarget.classifier);
|
||||
if (!result.ableToDamage()) {
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package me.youhavetrouble.preventstabby.listeners;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.data.DamageCheckResult;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.PotionSplashEvent;
|
||||
import org.bukkit.event.player.PlayerFishEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public class PvpListener implements Listener {
|
||||
|
||||
private final PreventStabby plugin;
|
||||
|
||||
public PvpListener(PreventStabby plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onEntityDamage(EntityDamageByEntityEvent event) {
|
||||
Entity attacker = event.getDamager();
|
||||
Entity victim = event.getEntity();
|
||||
|
||||
DamageCheckResult result = plugin.getPlayerManager().canDamage(attacker, victim);
|
||||
if (!result.ableToDamage()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
plugin.getPlayerManager().handleDamageCheck(result);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPotionSplash(PotionSplashEvent event) {
|
||||
if (!(event.getEntity().getShooter() instanceof Player thrower)) return;
|
||||
boolean harmful = false;
|
||||
for (PotionEffect effect : event.getPotion().getEffects()) {
|
||||
if (!PotionEffectType.Category.HARMFUL.equals(effect.getType().getEffectCategory())) continue;
|
||||
harmful = true;
|
||||
break;
|
||||
}
|
||||
if (!harmful) return;
|
||||
for (LivingEntity victim : event.getAffectedEntities()) {
|
||||
if (thrower == victim) continue;
|
||||
DamageCheckResult result = plugin.getPlayerManager().canDamage(thrower, victim);
|
||||
if (!result.ableToDamage()) {
|
||||
event.setIntensity(victim, 0);
|
||||
}
|
||||
plugin.getPlayerManager().handleDamageCheck(result);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPotionCloudEffectApply(AreaEffectCloudApplyEvent event) {
|
||||
if (!(event.getEntity().getSource() instanceof Player thrower)) return;
|
||||
boolean harmful = false;
|
||||
for (PotionEffect effect : event.getEntity().getBasePotionType().getPotionEffects()) {
|
||||
if (!PotionEffectType.Category.HARMFUL.equals(effect.getType().getEffectCategory())) continue;
|
||||
harmful = true;
|
||||
break;
|
||||
}
|
||||
if (!harmful) return;
|
||||
event.getAffectedEntities().removeIf(victim -> {
|
||||
if (thrower == victim) return false;
|
||||
boolean shouldRemoveFromAffected = false;
|
||||
DamageCheckResult result = plugin.getPlayerManager().canDamage(thrower, victim);
|
||||
if (!result.ableToDamage()) {
|
||||
shouldRemoveFromAffected = true;
|
||||
}
|
||||
plugin.getPlayerManager().handleDamageCheck(result);
|
||||
return shouldRemoveFromAffected;
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onFish(PlayerFishEvent event) {
|
||||
if (event.getCaught() instanceof Item) return;
|
||||
if (plugin.getConfigCache().allow_fishing_rod_pull) return;
|
||||
Player attacker = event.getPlayer();
|
||||
Entity victim = event.getCaught();
|
||||
if (victim == null) return;
|
||||
if (attacker == victim) return;
|
||||
DamageCheckResult result = plugin.getPlayerManager().canDamage(attacker, victim);
|
||||
if (!result.ableToDamage()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
plugin.getPlayerManager().handleDamageCheck(result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package me.youhavetrouble.preventstabby.listeners;
|
||||
|
||||
import me.youhavetrouble.preventstabby.data.Target;
|
||||
import org.bukkit.entity.EnderCrystal;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.entity.minecart.ExplosiveMinecart;
|
||||
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.EntityPlaceEvent;
|
||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEntityCollisionEvent;
|
||||
|
||||
/**
|
||||
* This class is a listener that performs various operations related to tagging entities with player UUIDs.
|
||||
*/
|
||||
public class UtilListener implements Listener {
|
||||
|
||||
/**
|
||||
* Tag TNT minecart with uuid of player who placed it
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerPlacedTntMinecart(EntityPlaceEvent event) {
|
||||
if (!(event.getEntity() instanceof ExplosiveMinecart minecart)) return;
|
||||
if (event.getPlayer() == null) return;
|
||||
Target.assignPlayerSourceId(minecart, event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag TNT minecart with uuid of player who last nudged it
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerNudgedTntMinecart(VehicleEntityCollisionEvent event) {
|
||||
if (!(event.getVehicle() instanceof ExplosiveMinecart minecart)) return;
|
||||
if (!(event.getEntity() instanceof Player player)) return;
|
||||
Target.assignPlayerSourceId(minecart, player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag primed TNT with players uuid
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerPrimedTnt(ExplosionPrimeEvent event) {
|
||||
if (!(event.getEntity() instanceof TNTPrimed tntPrimed)) return;
|
||||
if (tntPrimed.getSource() instanceof TNTPrimed primingTnt) {
|
||||
Target primingTntTarget = Target.getTarget(primingTnt);
|
||||
if (primingTntTarget == null) return;
|
||||
Target.assignPlayerSourceId(tntPrimed, primingTntTarget.playerUuid);
|
||||
return;
|
||||
}
|
||||
if (tntPrimed.getSource() instanceof Player primingPlayer) {
|
||||
Target.assignPlayerSourceId(tntPrimed, primingPlayer.getUniqueId());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tags ender crystal with exploding players uuid
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerHitEnderCrystal(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getEntity() instanceof EnderCrystal enderCrystal)) return;
|
||||
if (event.getDamager() instanceof Player player) {
|
||||
Target.assignPlayerSourceId(enderCrystal, player.getUniqueId());
|
||||
return;
|
||||
}
|
||||
if (event.getDamager() instanceof Projectile projectile && projectile.getShooter() instanceof Player player) {
|
||||
Target.assignPlayerSourceId(enderCrystal, player.getUniqueId());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.mount;
|
||||
|
||||
import me.youhavetrouble.preventstabby.util.Util;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class MountHitByExplosionListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onMountHitByExplosion(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Player) || event.getEntity().getPassengers().isEmpty()) return;
|
||||
if (!event.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION)) return;
|
||||
UUID damager = event.getDamager().getUniqueId();
|
||||
Entity mount = event.getEntity();
|
||||
if (Util.processMountAttack(damager, mount))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.mount;
|
||||
|
||||
import me.youhavetrouble.preventstabby.util.Util;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class MountHitByFireworkListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onMountHitByFireWork(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Firework) || event.getEntity().getPassengers().isEmpty()) return;
|
||||
if (!event.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION)) return;
|
||||
Firework firework = (Firework) event.getDamager();
|
||||
if (!(firework.getShooter() instanceof Player)) return;
|
||||
UUID damager = ((Player) firework.getShooter()).getUniqueId();
|
||||
Entity mount = event.getEntity();
|
||||
if (Util.processMountAttack(damager, mount))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.mount;
|
||||
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import me.youhavetrouble.preventstabby.util.Util;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class MountHitBySplashPotionListener implements Listener {
|
||||
|
||||
/**
|
||||
* If thrown potion applies negative effects and it's thrown by a player
|
||||
* it will have no effect on a pet of a player with pvp off
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onMountHitBySplashPotion(org.bukkit.event.entity.PotionSplashEvent event) {
|
||||
if (!(event.getEntity().getShooter() instanceof Player)) return;
|
||||
boolean harmful = false;
|
||||
for (PotionEffect effect : event.getPotion().getEffects()) {
|
||||
if (Util.isPotionEffectHarmful(effect.getType())) {
|
||||
harmful = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!harmful) return;
|
||||
UUID damager = ((Player) event.getEntity().getShooter()).getUniqueId();
|
||||
for (LivingEntity entity : event.getAffectedEntities()) {
|
||||
if (entity.getPassengers().isEmpty()) continue;
|
||||
if (Util.processMountAttack(damager, entity))
|
||||
event.setIntensity(entity, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.mount;
|
||||
|
||||
import me.youhavetrouble.preventstabby.util.Util;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PlayerAttackMountListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerAttackMount(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Player) || event.getEntity().getPassengers().isEmpty()) return;
|
||||
Entity entity = event.getEntity();
|
||||
UUID damager = event.getDamager().getUniqueId();
|
||||
if (Util.processMountAttack(damager, entity))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.mount;
|
||||
|
||||
import me.youhavetrouble.preventstabby.util.Util;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
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 java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PlayerHitMountWithProjectileListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerHitMountWithProjectile(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Projectile)) return;
|
||||
Projectile projectile = (Projectile) event.getDamager();
|
||||
if (!(projectile.getShooter() instanceof Player) || event.getEntity().getPassengers().isEmpty()) return;
|
||||
Entity entity = event.getEntity();
|
||||
UUID damager = event.getDamager().getUniqueId();
|
||||
if (Util.processMountAttack(damager, entity))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.pets;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PetHitByExplosionListener implements Listener {
|
||||
|
||||
/**
|
||||
* Cancels explosion damage for pets with pvp off that is caused by players
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPetHitByExplosion(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
if (!(event.getEntity() instanceof Tameable)) return;
|
||||
if (!event.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION)) return;
|
||||
Tameable tameable = (Tameable) event.getEntity();
|
||||
if (tameable.getOwner() == null) return;
|
||||
|
||||
UUID victim = tameable.getOwner().getUniqueId();
|
||||
|
||||
try {
|
||||
UUID damager = UUID.fromString(event.getDamager().getMetadata("PLAYEREXPLODED").get(0).asString());
|
||||
if (victim.equals(damager))
|
||||
return;
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true, false))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
} catch (NullPointerException | IndexOutOfBoundsException ignored) {}
|
||||
|
||||
}
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.pets;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PetHitByFireworkListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPetFireworkDamage(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
if (event.getDamager() instanceof Firework && event.getEntity() instanceof Tameable) {
|
||||
Tameable tameable = (Tameable) event.getEntity();
|
||||
if (tameable.getOwner() == null) return;
|
||||
Firework firework = (Firework) event.getDamager();
|
||||
if (!(firework.getShooter() instanceof Player)) return;
|
||||
UUID damager = ((Player) firework.getShooter()).getUniqueId();
|
||||
UUID victim = tameable.getOwner().getUniqueId();
|
||||
if (victim.equals(damager)) return;
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true, false))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.pets;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import me.youhavetrouble.preventstabby.util.Util;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PetHitBySplashPotionListener implements Listener {
|
||||
|
||||
/**
|
||||
* If thrown potion applies negative effects and it's thrown by a player
|
||||
* it will have no effect on a pet of a player with pvp off
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPetHitBySplashPotion(org.bukkit.event.entity.PotionSplashEvent event) {
|
||||
|
||||
if (!(event.getEntity().getShooter() instanceof Player)) return;
|
||||
boolean harmful = false;
|
||||
|
||||
for (PotionEffect effect : event.getPotion().getEffects()) {
|
||||
if (Util.isPotionEffectHarmful(effect.getType())) {
|
||||
harmful = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!harmful) return;
|
||||
UUID damager = ((Player) event.getEntity().getShooter()).getUniqueId();
|
||||
for (Entity entity : event.getAffectedEntities()) {
|
||||
if (entity instanceof Tameable) {
|
||||
Tameable tameable = (Tameable) entity;
|
||||
if (tameable.getOwner() == null) continue;
|
||||
UUID victim = tameable.getOwner().getUniqueId();
|
||||
if (victim == damager) return;
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true, false))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.pets;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PetLeashListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPetLeash(org.bukkit.event.entity.PlayerLeashEntityEvent event) {
|
||||
if (event.getEntity() instanceof Tameable) {
|
||||
Tameable tameable = (Tameable) event.getEntity();
|
||||
if (tameable.getOwner() == null) return;
|
||||
|
||||
UUID damager = event.getPlayer().getUniqueId();
|
||||
UUID victim = tameable.getOwner().getUniqueId();
|
||||
if (victim == damager) return;
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true, false))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.pets;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.players.SmartCache;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import me.youhavetrouble.preventstabby.util.Util;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PetTargettingMountListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onWolfAttackMount(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Tameable) || event.getEntity().getPassengers().isEmpty()) return;
|
||||
Tameable damager = (Tameable) event.getDamager();
|
||||
Entity victim = event.getEntity();
|
||||
if (damager.getOwner() == null) return;
|
||||
|
||||
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
||||
boolean damagerPvpEnabled = smartCache.getPlayerData(damager.getOwner().getUniqueId()).isPvpEnabled();
|
||||
boolean victimPvpEnabled = !Util.processMountAttack(damager.getOwner().getUniqueId(), victim);
|
||||
|
||||
if (!victimPvpEnabled || !damagerPvpEnabled) {
|
||||
if (damager instanceof Wolf) {
|
||||
Wolf wolf = (Wolf) damager;
|
||||
wolf.setAngry(false);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.pets;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.players.SmartCache;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PetTargettingPetListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onWolfAttackWolf(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
if (event.getDamager() instanceof Tameable && event.getEntity() instanceof Tameable) {
|
||||
Tameable damager = (Tameable) event.getDamager();
|
||||
Tameable victim = (Tameable) event.getEntity();
|
||||
if (damager.getOwner() == null || victim.getOwner() == null) return;
|
||||
|
||||
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
||||
boolean damagerPvpEnabled = smartCache.getPlayerData(damager.getOwner().getUniqueId()).isPvpEnabled();
|
||||
boolean victimPvpEnabled = smartCache.getPlayerData(victim.getOwner().getUniqueId()).isPvpEnabled();
|
||||
|
||||
if (!victimPvpEnabled || !damagerPvpEnabled) {
|
||||
if (damager instanceof Wolf) {
|
||||
Wolf wolf = (Wolf) damager;
|
||||
wolf.setAngry(false);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.pets;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PetTargettingPlayerListener implements Listener {
|
||||
/**
|
||||
* Stops pets with owners targetting players with pvp off
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPetTargetPlayer(org.bukkit.event.entity.EntityTargetEvent event) {
|
||||
if (!(event.getEntity() instanceof Tameable)) return;
|
||||
Tameable entity = (Tameable) event.getEntity();
|
||||
if (!(entity.getOwner() instanceof Player)) return;
|
||||
if (!(event.getTarget() instanceof Player)) return;
|
||||
|
||||
UUID damager = entity.getOwner().getUniqueId();
|
||||
UUID victim = event.getTarget().getUniqueId();
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true, false))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
}
|
||||
-49
@@ -1,49 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.pets;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.config.ConfigCache;
|
||||
import me.youhavetrouble.preventstabby.players.SmartCache;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PlayerAttackPetListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerAttackPet(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
|
||||
if (event.getDamager() instanceof Player && event.getEntity() instanceof Tameable) {
|
||||
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
||||
Tameable tameable = (Tameable) event.getEntity();
|
||||
if (tameable.getOwner() == null) return;
|
||||
|
||||
UUID damager = event.getDamager().getUniqueId();
|
||||
UUID victim = tameable.getOwner().getUniqueId();
|
||||
|
||||
if (damager.equals(victim)) return;
|
||||
|
||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||
boolean damagerPvpState = PreventStabby.getPlugin().getPlayerManager().getPlayerPvPState(damager);
|
||||
if (!damagerPvpState) {
|
||||
PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_attacker());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!smartCache.getPlayerData(victim).isPvpEnabled()) {
|
||||
PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_victim());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
CombatTimer.refreshPlayersCombatTime(damager);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.pets;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.config.ConfigCache;
|
||||
import me.youhavetrouble.preventstabby.players.SmartCache;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PlayerHitPetWithProjectileListener implements Listener {
|
||||
|
||||
/**
|
||||
* Cancels damage done by projectiles to pets of players with pvp off
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerHitPetWithProjectile(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
if (event.getEntity() instanceof Tameable && event.getDamager() instanceof Projectile) {
|
||||
Projectile projectile = (Projectile) event.getDamager();
|
||||
if (!(projectile.getShooter() instanceof Player)) return;
|
||||
Tameable tameable = (Tameable) event.getEntity();
|
||||
if (tameable.getOwner() == null) return;
|
||||
|
||||
UUID damager = ((Player) projectile.getShooter()).getUniqueId();
|
||||
UUID victim = tameable.getOwner().getUniqueId();
|
||||
|
||||
if (damager.equals(victim)) return;
|
||||
|
||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
||||
|
||||
if (!smartCache.getPlayerData(damager).isPvpEnabled()) {
|
||||
PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_attacker());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!smartCache.getPlayerData(victim).isPvpEnabled()) {
|
||||
PluginMessages.sendActionBar(damager, config.getCannot_attack_pets_victim());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
CombatTimer.refreshPlayersCombatTime(damager);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.pets;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PlayerInteractWithPetListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerInteractWithPet(org.bukkit.event.player.PlayerInteractEntityEvent event) {
|
||||
|
||||
if (!PreventStabby.getPlugin().getConfigCache().isOnly_owner_can_interact_with_pet()) return;
|
||||
if (!(event.getRightClicked() instanceof Tameable)) return;
|
||||
|
||||
Tameable tameable = (Tameable) event.getRightClicked();
|
||||
if (tameable.getOwner() == null) return;
|
||||
if (tameable.getOwner().getUniqueId().equals(event.getPlayer().getUniqueId())) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
}
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.player;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.players.PlayerManager;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PetAttackPlayerListener implements Listener {
|
||||
|
||||
/**
|
||||
* Pets stop following player with pvp off after trying to hit them
|
||||
* This is to fix any inconsistancy with pet behavior
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPetAttack(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
|
||||
if (!(event.getDamager() instanceof Tameable)) return;
|
||||
|
||||
Tameable entity = (Tameable) event.getDamager();
|
||||
if (entity.getOwner() != null && event.getEntity() instanceof Player) {
|
||||
|
||||
UUID victim = event.getEntity().getUniqueId();
|
||||
UUID damager = entity.getOwner().getUniqueId();
|
||||
PlayerManager playerManager = PreventStabby.getPlugin().getPlayerManager();
|
||||
|
||||
if (!playerManager.canDamage(damager, victim, false)) {
|
||||
if (entity instanceof Wolf) {
|
||||
Wolf wolf = (Wolf) entity;
|
||||
wolf.setAngry(false);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.player;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PlayerAttackListener implements Listener {
|
||||
|
||||
/**
|
||||
* Cancels basic attacks done to player with pvp off
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerAttack(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
Entity damagerEntity = event.getDamager();
|
||||
Entity victimEntity = event.getEntity();
|
||||
|
||||
if (damagerEntity instanceof Player && victimEntity instanceof Player) {
|
||||
UUID damager = damagerEntity.getUniqueId();
|
||||
UUID victim = victimEntity.getUniqueId();
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.player;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.players.PlayerData;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PlayerDeathListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPlayerDeath(org.bukkit.event.entity.EntityDeathEvent event) {
|
||||
|
||||
if (!(event.getEntity() instanceof Player)) return;
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
PlayerData playerData = PreventStabby.getPlugin().getSmartCache().getPlayerData(player.getUniqueId());
|
||||
playerData.setCombattime(0);
|
||||
playerData.setLastCombatCheck(false);
|
||||
playerData.setInCombat(false);
|
||||
}
|
||||
|
||||
}
|
||||
-109
@@ -1,109 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.player;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.EnderCrystal;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.minecart.ExplosiveMinecart;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PlayerHitByExplosionListener implements Listener {
|
||||
|
||||
/**
|
||||
* Cancels explosion damage for players with pvp off that is caused by players
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerHitByExplosion(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
if (!event.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION)) return;
|
||||
|
||||
UUID victim = event.getEntity().getUniqueId();
|
||||
try {
|
||||
UUID damager = UUID.fromString(event.getDamager().getMetadata("PLAYEREXPLODED").get(0).asString());
|
||||
if (victim.equals(damager)) return;
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
|
||||
} catch (NullPointerException | IndexOutOfBoundsException ignored) { }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tags ender crystal with exploder uuid
|
||||
*/
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerHitEnderCrystal(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
if (event.getEntity() instanceof EnderCrystal) {
|
||||
EnderCrystal enderCrystal = (EnderCrystal) event.getEntity();
|
||||
if (event.getDamager() instanceof Player) {
|
||||
enderCrystal.setMetadata("PLAYEREXPLODED", new FixedMetadataValue(PreventStabby.getPlugin(), event.getDamager().getUniqueId().toString()));
|
||||
} else if (event.getDamager() instanceof Projectile) {
|
||||
Projectile projectile = (Projectile) event.getDamager();
|
||||
if (projectile.getShooter() instanceof Player) {
|
||||
Player damager = (Player) projectile.getShooter();
|
||||
enderCrystal.setMetadata("PLAYEREXPLODED", new FixedMetadataValue(PreventStabby.getPlugin(), damager.getUniqueId().toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag ender crystal with destroying players uuid
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerPrimedTnt(org.bukkit.event.entity.ExplosionPrimeEvent event) {
|
||||
if (event.getEntity() instanceof TNTPrimed) {
|
||||
TNTPrimed tntPrimed = (TNTPrimed) event.getEntity();
|
||||
if (tntPrimed.getSource() instanceof Player) {
|
||||
Player damager = (Player) tntPrimed.getSource();
|
||||
tntPrimed.setMetadata("PLAYEREXPLODED", new FixedMetadataValue(PreventStabby.getPlugin(), damager.getUniqueId().toString()));
|
||||
} else if (tntPrimed.getSource() instanceof TNTPrimed) {
|
||||
try {
|
||||
TNTPrimed sourceTnt = (TNTPrimed) tntPrimed.getSource();
|
||||
String damagerUuid = sourceTnt.getMetadata("PLAYEREXPLODED").get(0).asString();
|
||||
tntPrimed.setMetadata("PLAYEREXPLODED", new FixedMetadataValue(PreventStabby.getPlugin(), damagerUuid));
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag TNT minecart with placing player uuid
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerPlacedTntMinecart(org.bukkit.event.entity.EntityPlaceEvent event) {
|
||||
if (event.getEntityType().equals(EntityType.MINECART_TNT)) {
|
||||
if (event.getPlayer() != null) {
|
||||
event.getEntity().setMetadata("PLAYEREXPLODED", new FixedMetadataValue(PreventStabby.getPlugin(), event.getPlayer().getUniqueId().toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag TNT minecart with uuid of player who last nudged it
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerNudgedTntMinecart(org.bukkit.event.vehicle.VehicleEntityCollisionEvent event) {
|
||||
if (event.getVehicle() instanceof ExplosiveMinecart && event.getEntity() instanceof Player) {
|
||||
Player damager = (Player) event.getEntity();
|
||||
event.getVehicle().setMetadata("PLAYEREXPLODED", new FixedMetadataValue(PreventStabby.getPlugin(), damager.getUniqueId().toString()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.player;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PlayerHitByFireworkListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onFireworkDamage(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
if (event.getDamager() instanceof Firework && event.getEntity() instanceof Player) {
|
||||
UUID victim = event.getEntity().getUniqueId();
|
||||
Firework firework = (Firework) event.getDamager();
|
||||
if (firework.getShooter() instanceof Player) {
|
||||
UUID damager = ((Player) firework.getShooter()).getUniqueId();
|
||||
if (damager == victim) return;
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.player;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PlayerHitByProjectileListener implements Listener {
|
||||
|
||||
/**
|
||||
* Cancels damage done by projectiles to player with pvp off
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerHitProjectile(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
|
||||
if (event.getEntity() instanceof Player && event.getDamager() instanceof Projectile) {
|
||||
Projectile projectile = (Projectile) event.getDamager();
|
||||
if (projectile.getShooter() instanceof Player) {
|
||||
UUID damager = ((Player) projectile.getShooter()).getUniqueId();
|
||||
UUID victim = event.getEntity().getUniqueId();
|
||||
|
||||
if (PreventStabby.getPlugin().getConfigCache().isSnowballs_knockback() && event.getDamager() instanceof Snowball) {
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true)) {
|
||||
((Player) event.getEntity()).damage(0.01, (Entity) projectile.getShooter());
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
} else if (PreventStabby.getPlugin().getConfigCache().isEgg_knockback() && event.getDamager() instanceof Egg) {
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true)) {
|
||||
((Player) event.getEntity()).damage(0.01, (Entity) projectile.getShooter());
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Ender pearls and other self-damage
|
||||
if (damager.equals(victim)) return;
|
||||
|
||||
if (event.getDamage() == 0) return;
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.player;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import me.youhavetrouble.preventstabby.util.Util;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PlayerHitBySplashPotionListener implements Listener {
|
||||
|
||||
/**
|
||||
* If thrown potion is applies negative effects and it's thrown by a player it will have no effect on player with pvp off
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerHitBySplashPotion(org.bukkit.event.entity.PotionSplashEvent event) {
|
||||
|
||||
if (!(event.getEntity().getShooter() instanceof Player)) return;
|
||||
boolean harmful = false;
|
||||
|
||||
for (PotionEffect effect : event.getPotion().getEffects()) {
|
||||
if (Util.isPotionEffectHarmful(effect.getType())) {
|
||||
harmful = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!harmful) return;
|
||||
UUID damager = ((Player) event.getEntity().getShooter()).getUniqueId();
|
||||
for (LivingEntity entity : event.getAffectedEntities()) {
|
||||
if (!(entity instanceof Player)) continue;
|
||||
UUID victim = entity.getUniqueId();
|
||||
if (damager == victim) continue;
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true)) {
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
} else {
|
||||
event.setIntensity(entity, 0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.player;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.players.PlayerData;
|
||||
import me.youhavetrouble.preventstabby.players.SmartCache;
|
||||
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PlayerJoinAndLeaveListener implements Listener {
|
||||
/**
|
||||
* This event is here to get players saved options on join
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
||||
PlayerData playerData = PreventStabby.getPlugin().getPlayerManager().getPlayer(player.getUniqueId());
|
||||
long time = Instant.now().getEpochSecond();
|
||||
if (playerData == null) {
|
||||
PreventStabby.getPlugin().getPlayerManager().addPlayer(uuid, new PlayerData(uuid,false));
|
||||
Bukkit.getScheduler().runTaskAsynchronously(PreventStabby.getPlugin(), () -> {
|
||||
PlayerData data = PreventStabby.getPlugin().getSqLite().getPlayerInfo(uuid);
|
||||
PreventStabby.getPlugin().getPlayerManager().addPlayer(uuid, data);
|
||||
data.setLoginTimestamp(time);
|
||||
});
|
||||
return;
|
||||
}
|
||||
playerData.refreshCachetime();
|
||||
playerData.setLoginTimestamp(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is here to save player's data to database
|
||||
* Also punishes players who log out during combat
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerLeave(org.bukkit.event.player.PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(PreventStabby.getPlugin(), () -> PreventStabby.getPlugin().getSqLite().updatePlayerInfo(player.getUniqueId(), PreventStabby.getPlugin().getPlayerManager().getPlayer(player.getUniqueId())));
|
||||
|
||||
if (!PreventStabby.getPlugin().getConfigCache().isPunish_for_combat_logout()) return;
|
||||
|
||||
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
||||
PlayerData playerData = smartCache.getPlayerData(player.getUniqueId());
|
||||
|
||||
if (!playerData.isInCombat()) return;
|
||||
|
||||
player.setHealth(0);
|
||||
if (PreventStabby.getPlugin().getConfigCache().isPunish_for_combat_logout_announce())
|
||||
PluginMessages.broadcastMessage(player, PreventStabby.getPlugin().getConfigCache().getPunish_for_combat_logout_message());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.player;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.players.PlayerData;
|
||||
import me.youhavetrouble.preventstabby.players.SmartCache;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import java.time.Instant;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PlayerTeleportListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPlayerTeleport(org.bukkit.event.player.PlayerTeleportEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
||||
PlayerData playerData = smartCache.getPlayerData(player.getUniqueId());
|
||||
playerData.setTeleportTimestamp(Instant.now().getEpochSecond());
|
||||
}
|
||||
|
||||
}
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.toggles;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.players.PlayerManager;
|
||||
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class CombatCommandListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerCommandInCombat(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
|
||||
|
||||
if (!PreventStabby.getPlugin().getConfigCache().isBlock_commands_in_combat())
|
||||
return;
|
||||
|
||||
if (event.getPlayer().hasPermission("toglepvp.combatcommandblock.bypass"))
|
||||
return;
|
||||
|
||||
PlayerManager playerManager = PreventStabby.getPlugin().getPlayerManager();
|
||||
|
||||
if (!playerManager.getPlayer(event.getPlayer().getUniqueId()).isInCombat())
|
||||
return;
|
||||
|
||||
String command = event.getMessage().replaceFirst("/", "");
|
||||
|
||||
if (!PreventStabby.getPlugin().getConfigCache().getCombatBlockedCommands().contains(command))
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
PluginMessages.sendMessage(event.getPlayer(), PreventStabby.getPlugin().getConfigCache().getCant_do_that_during_combat());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.toggles;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.players.PlayerManager;
|
||||
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PlayerTeleportInCombatListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerTeleportInCombat(org.bukkit.event.player.PlayerTeleportEvent event) {
|
||||
|
||||
if (!PreventStabby.getPlugin().getConfigCache().isBlock_teleports_in_combat())
|
||||
return;
|
||||
|
||||
PlayerManager playerManager = PreventStabby.getPlugin().getPlayerManager();
|
||||
|
||||
if (!playerManager.getPlayer(event.getPlayer().getUniqueId()).isInCombat())
|
||||
return;
|
||||
|
||||
if (event.getPlayer().hasPermission("toglepvp.combatteleportblock.bypass"))
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
PluginMessages.sendMessage(event.getPlayer(), PreventStabby.getPlugin().getConfigCache().getCant_do_that_during_combat());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-75
@@ -1,75 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.unspecific;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.players.PlayerManager;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class AreaEffectCloudApplyListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onCloudEffects(AreaEffectCloudApplyEvent event) {
|
||||
|
||||
PotionEffectType potionEffectType = event.getEntity().getBasePotionData().getType().getEffectType();
|
||||
|
||||
if (potionEffectType == null)
|
||||
return;
|
||||
|
||||
if(event.getEntity().getSource() instanceof Player) {
|
||||
if (potionEffectType.equals(PotionEffectType.BLINDNESS) ||
|
||||
potionEffectType.equals(PotionEffectType.CONFUSION) ||
|
||||
potionEffectType.equals(PotionEffectType.HARM) ||
|
||||
potionEffectType.equals(PotionEffectType.HUNGER) ||
|
||||
potionEffectType.equals(PotionEffectType.POISON) ||
|
||||
potionEffectType.equals(PotionEffectType.SLOW_DIGGING) ||
|
||||
potionEffectType.equals(PotionEffectType.WEAKNESS) ||
|
||||
potionEffectType.equals(PotionEffectType.SLOW) ||
|
||||
potionEffectType.equals(PotionEffectType.WITHER)) {
|
||||
|
||||
PlayerManager playerManager = PreventStabby.getPlugin().getPlayerManager();
|
||||
|
||||
Iterator<LivingEntity> it = event.getAffectedEntities().iterator();
|
||||
UUID damager = ((Player) event.getEntity().getSource()).getUniqueId();
|
||||
while(it.hasNext()) {
|
||||
LivingEntity entity = it.next();
|
||||
if(entity instanceof Player) {
|
||||
|
||||
UUID victim = entity.getUniqueId();
|
||||
if (damager == victim)
|
||||
continue;
|
||||
|
||||
if (playerManager.canDamage(damager, victim, true))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
it.remove();
|
||||
|
||||
} else if (entity instanceof Tameable) {
|
||||
Tameable tameable = (Tameable) entity;
|
||||
|
||||
if (tameable.getOwner() == null)
|
||||
continue;
|
||||
|
||||
UUID victim = tameable.getOwner().getUniqueId();
|
||||
if (victim == damager)
|
||||
continue;
|
||||
|
||||
if (playerManager.canDamage(damager, victim, true, false))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-61
@@ -1,61 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.unspecific;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.LightningStrike;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.weather.LightningStrikeEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Listen for lightning strikes and tag the trident spawned ones.
|
||||
* Idea from aasmus' PvPToggle plugin
|
||||
*/
|
||||
@PreventStabbyListener
|
||||
public class EntityHitByLightningListener implements Listener {
|
||||
|
||||
/**
|
||||
* Cancels damage from lightning strike caused by channeling for players with pvp off
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerLightningDamage(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||
if (event.getDamager() instanceof LightningStrike && event.getDamager().getMetadata("TRIDENT").size() >= 1) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
UUID victim = event.getEntity().getUniqueId();
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().hasLoginProtection(victim)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PreventStabby.getPlugin().getSmartCache().getPlayerData(victim).isPvpEnabled()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (event.getEntity() instanceof Tameable) {
|
||||
Tameable victim = (Tameable) event.getEntity();
|
||||
if (victim.getOwner() != null && !PreventStabby.getPlugin().getSmartCache().getPlayerData(victim.getOwner().getUniqueId()).isPvpEnabled()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tags the lightning strike
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onLightningStrike(LightningStrikeEvent event){
|
||||
if(event.getCause() == LightningStrikeEvent.Cause.TRIDENT){
|
||||
if (PreventStabby.getPlugin().getConfigCache().isChanneling_enchant_disabled()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
event.getLightning().setMetadata("TRIDENT", new FixedMetadataValue(PreventStabby.getPlugin(), event.getLightning().getLocation()));
|
||||
}
|
||||
}
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.unspecific;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class FishingListener implements Listener {
|
||||
|
||||
/**
|
||||
* Prevents hooking players with disabled pvp with fishing rod
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onFish(org.bukkit.event.player.PlayerFishEvent event) {
|
||||
if (event.getCaught() instanceof Player) {
|
||||
UUID damager = event.getPlayer().getUniqueId();
|
||||
UUID victim = event.getCaught().getUniqueId();
|
||||
if (damager == victim)
|
||||
return;
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
} else if (event.getCaught() instanceof Tameable) {
|
||||
Tameable tameable = (Tameable) event.getCaught();
|
||||
UUID damager = event.getPlayer().getUniqueId();
|
||||
if (tameable.getOwner() == null)
|
||||
return;
|
||||
|
||||
UUID victim = tameable.getOwner().getUniqueId();
|
||||
|
||||
if (damager == victim)
|
||||
return;
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true, false))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
-125
@@ -1,125 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.unspecific;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.config.ConfigCache;
|
||||
import me.youhavetrouble.preventstabby.util.BoundingBoxUtil;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
@PreventStabbyListener
|
||||
public class LavaDumpAndIgniteListener implements Listener {
|
||||
|
||||
/**
|
||||
* Prevents dumping lava and pufferfish bucket near players with pvp off
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onLavaDump(org.bukkit.event.player.PlayerBucketEmptyEvent event) {
|
||||
|
||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||
|
||||
if (!config.isLava_and_fire_stopper_enabled())
|
||||
return;
|
||||
|
||||
if (event.getBucket().equals(Material.LAVA_BUCKET) || event.getBucket().equals(Material.PUFFERFISH_BUCKET)) {
|
||||
Location location = event.getBlockClicked().getLocation();
|
||||
UUID damager = event.getPlayer().getUniqueId();
|
||||
double radius = config.getLava_and_fire_stopper_radius();
|
||||
|
||||
BoundingBox boundingBox = BoundingBoxUtil.getBoundingBox(location, radius);
|
||||
for (Entity entity : location.getWorld().getNearbyEntities(boundingBox)) {
|
||||
if (entity instanceof Player) {
|
||||
UUID victim = entity.getUniqueId();
|
||||
if (victim != damager) {
|
||||
if (PreventStabby.getPlugin().getPlayerManager().hasLoginProtection(victim, damager)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
} else if (entity instanceof Tameable) {
|
||||
Tameable tameable = (Tameable) entity;
|
||||
if (tameable.getOwner() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
UUID victim = tameable.getOwner().getUniqueId();
|
||||
if (PreventStabby.getPlugin().getPlayerManager().hasLoginProtection(victim, damager)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents setting blocks on fire near players with pvp off
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onIgnite(org.bukkit.event.block.BlockIgniteEvent event) {
|
||||
|
||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||
|
||||
if (!config.isLava_and_fire_stopper_enabled())
|
||||
return;
|
||||
|
||||
if (event.getPlayer() == null)
|
||||
return;
|
||||
|
||||
Location location = event.getBlock().getLocation();
|
||||
UUID damager = event.getPlayer().getUniqueId();
|
||||
double radius = config.getLava_and_fire_stopper_radius();
|
||||
BoundingBox boundingBox = BoundingBoxUtil.getBoundingBox(location, radius);
|
||||
for (Entity entity : location.getWorld().getNearbyEntities(boundingBox)) {
|
||||
if (entity instanceof Player) {
|
||||
UUID victim = entity.getUniqueId();
|
||||
if (victim == damager)
|
||||
continue;
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
|
||||
} else if (entity instanceof Tameable) {
|
||||
Tameable tameable = (Tameable) entity;
|
||||
if (tameable.getOwner() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
UUID victim = tameable.getOwner().getUniqueId();
|
||||
if (victim == damager)
|
||||
continue;
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true, false))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.unspecific;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class LightningBlockIgniteListener implements Listener {
|
||||
|
||||
/**
|
||||
* Lightning strikes from channeling enchant won't ignite blocks if player with pvp off is in radius
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockIgnite(org.bukkit.event.block.BlockIgniteEvent event) {
|
||||
|
||||
if (event.getIgnitingEntity() instanceof LightningStrike && event.getIgnitingEntity().getMetadata("TRIDENT").size() >= 1) {
|
||||
LightningStrike lightningStrike = (LightningStrike) event.getIgnitingEntity();
|
||||
|
||||
for (Entity entity : lightningStrike.getNearbyEntities(2,2,2)) {
|
||||
if (entity instanceof Player) {
|
||||
Player victim = (Player) entity;
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().hasLoginProtection(victim.getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PreventStabby.getPlugin().getSmartCache().getPlayerData(victim.getUniqueId()).isPvpEnabled()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
} else if (entity instanceof Tameable) {
|
||||
Tameable victim = (Tameable) entity;
|
||||
if (victim.getOwner() == null) {
|
||||
return;
|
||||
}
|
||||
if (!PreventStabby.getPlugin().getSmartCache().getPlayerData(victim.getOwner().getUniqueId()).isPvpEnabled()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.listeners.unspecific;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.config.ConfigCache;
|
||||
import me.youhavetrouble.preventstabby.util.BoundingBoxUtil;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PreventStabbyListener;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@PreventStabbyListener
|
||||
public class PlaceWitherRoseListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerWitherRosePlace(org.bukkit.event.block.BlockPlaceEvent event) {
|
||||
|
||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||
|
||||
if (!config.isLava_and_fire_stopper_enabled())
|
||||
return;
|
||||
|
||||
if (event.getBlock().getType().equals(Material.WITHER_ROSE)) {
|
||||
Location location = event.getBlockPlaced().getLocation();
|
||||
double radius = config.getLava_and_fire_stopper_radius();
|
||||
BoundingBox boundingBox = BoundingBoxUtil.getBoundingBox(location, radius);
|
||||
for (Entity entity : location.getWorld().getNearbyEntities(boundingBox)) {
|
||||
if (entity instanceof Player) {
|
||||
UUID damager = event.getPlayer().getUniqueId();
|
||||
UUID victim = entity.getUniqueId();
|
||||
if (victim == damager)
|
||||
return;
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
} else if (entity instanceof Tameable) {
|
||||
Tameable tameable = (Tameable) entity;
|
||||
UUID damager = event.getPlayer().getUniqueId();
|
||||
if (tameable.getOwner() == null)
|
||||
return;
|
||||
|
||||
UUID victim = tameable.getOwner().getUniqueId();
|
||||
if (victim == damager)
|
||||
return;
|
||||
|
||||
if (PreventStabby.getPlugin().getPlayerManager().canDamage(damager, victim, true, false))
|
||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||
else
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.players;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerData {
|
||||
|
||||
private final UUID playerUuid;
|
||||
private long cachetime, combattime, loginTimestamp, teleportTimestamp;
|
||||
private boolean pvpEnabled, lastCombatCheck, inCombat;
|
||||
|
||||
public PlayerData(UUID playerUuid, boolean pvpEnabled) {
|
||||
this.playerUuid = playerUuid;
|
||||
this.pvpEnabled = pvpEnabled;
|
||||
this.combattime = Instant.now().getEpochSecond()-1;
|
||||
this.loginTimestamp = Instant.now().getEpochSecond()-1;
|
||||
this.teleportTimestamp = Instant.now().getEpochSecond()-1;
|
||||
this.inCombat = false;
|
||||
refreshCachetime();
|
||||
}
|
||||
|
||||
public UUID getPlayerUuid() {
|
||||
return playerUuid;
|
||||
}
|
||||
|
||||
public boolean isPvpEnabled() {
|
||||
return pvpEnabled;
|
||||
}
|
||||
|
||||
public void setPvpEnabled(boolean pvpEnabled) {
|
||||
this.pvpEnabled = pvpEnabled;
|
||||
}
|
||||
|
||||
public long getCachetime() {
|
||||
return cachetime;
|
||||
}
|
||||
|
||||
public void refreshCachetime() {
|
||||
this.cachetime = Instant.now().getEpochSecond()+ PreventStabby.getPlugin().getConfigCache().getCache_time();
|
||||
}
|
||||
|
||||
public long getCombattime() {
|
||||
return combattime;
|
||||
}
|
||||
|
||||
public void setCombattime(long combattime) {
|
||||
this.combattime = combattime;
|
||||
}
|
||||
|
||||
public void refreshCombatTime() {
|
||||
this.combattime = Instant.now().getEpochSecond()+ PreventStabby.getPlugin().getConfigCache().getCombat_time();
|
||||
}
|
||||
|
||||
public boolean getLastCombatCheck() {
|
||||
return lastCombatCheck;
|
||||
}
|
||||
|
||||
public void setLastCombatCheck(boolean bool) {
|
||||
lastCombatCheck = bool;
|
||||
}
|
||||
|
||||
public void setLoginTimestamp(long loginTimestamp) {
|
||||
this.loginTimestamp = loginTimestamp + PreventStabby.getPlugin().getConfigCache().getLogin_protection_time()-1;
|
||||
}
|
||||
|
||||
public long getLoginTimestamp() {
|
||||
return loginTimestamp;
|
||||
}
|
||||
|
||||
public void setTeleportTimestamp(long teleportTimestamp) {
|
||||
this.teleportTimestamp = teleportTimestamp + PreventStabby.getPlugin().getConfigCache().getTeleport_protection_time()-1;
|
||||
}
|
||||
|
||||
public long getTeleportTimestamp() {
|
||||
return teleportTimestamp;
|
||||
}
|
||||
|
||||
public boolean isInCombat() {
|
||||
return inCombat;
|
||||
}
|
||||
|
||||
public void setInCombat(boolean inCombat) {
|
||||
this.inCombat = inCombat;
|
||||
}
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.players;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.api.event.PlayerLeaveCombatEvent;
|
||||
import me.youhavetrouble.preventstabby.config.ConfigCache;
|
||||
import me.youhavetrouble.preventstabby.hooks.WorldGuardHook;
|
||||
import me.youhavetrouble.preventstabby.util.CombatTimer;
|
||||
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
||||
import lombok.Getter;
|
||||
import me.youhavetrouble.preventstabby.util.PvpState;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class PlayerManager {
|
||||
|
||||
@Getter
|
||||
ConcurrentHashMap<UUID, PlayerData> playerList = new ConcurrentHashMap<>();
|
||||
|
||||
private PvpState pvpForcedState = PvpState.NONE;
|
||||
|
||||
public final BukkitTask combatTrackerTask;
|
||||
|
||||
public PlayerManager() {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
PlayerData playerData = PreventStabby.getPlugin().getSqLite().getPlayerInfo(p.getUniqueId());
|
||||
playerList.put(p.getUniqueId(), playerData);
|
||||
}
|
||||
|
||||
combatTrackerTask = Bukkit.getScheduler().runTaskTimerAsynchronously(PreventStabby.getPlugin(), () -> {
|
||||
for (PlayerData playerData : playerList.values()) {
|
||||
UUID uuid = playerData.getPlayerUuid();
|
||||
if (!CombatTimer.isInCombat(uuid)) {
|
||||
if (playerData.getLastCombatCheck()) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null) continue;
|
||||
PlayerLeaveCombatEvent playerLeaveCombatEvent = new PlayerLeaveCombatEvent(player);
|
||||
Bukkit.getScheduler().runTask(PreventStabby.getPlugin(), () -> {
|
||||
Bukkit.getPluginManager().callEvent(playerLeaveCombatEvent);
|
||||
if (playerLeaveCombatEvent.isCancelled()) {
|
||||
playerData.refreshCombatTime();
|
||||
return;
|
||||
}
|
||||
playerData.setLastCombatCheck(false);
|
||||
playerData.setInCombat(false);
|
||||
PluginMessages.sendActionBar(uuid, PreventStabby.getPlugin().getConfigCache().getLeaving_combat());
|
||||
});
|
||||
}
|
||||
} else {
|
||||
playerData.setLastCombatCheck(true);
|
||||
}
|
||||
}
|
||||
}, 20, 20);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void refreshPlayersCacheTime(UUID uuid) {
|
||||
playerList.get(uuid).refreshCachetime();
|
||||
}
|
||||
|
||||
public void refreshPlayersCombatTime(UUID uuid) {
|
||||
PlayerData data = playerList.get(uuid);
|
||||
if (data == null) return;
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null || player.isDead()) return;
|
||||
data.refreshCombatTime();
|
||||
data.setInCombat(true);
|
||||
|
||||
}
|
||||
|
||||
public PlayerData getPlayer(UUID uuid) {
|
||||
return playerList.get(uuid);
|
||||
}
|
||||
|
||||
public void addPlayer(UUID uuid, PlayerData data) {
|
||||
playerList.put(uuid, data);
|
||||
}
|
||||
|
||||
public boolean getPlayerPvPState(UUID uuid) {
|
||||
return PreventStabby.getPlugin().getSmartCache().getPlayerData(uuid).isPvpEnabled();
|
||||
}
|
||||
|
||||
public void setPlayerPvpState(UUID uuid, boolean state) {
|
||||
PreventStabby.getPlugin().getSmartCache().getPlayerData(uuid).setPvpEnabled(state);
|
||||
}
|
||||
|
||||
public boolean togglePlayerPvpState(UUID uuid) {
|
||||
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
||||
if (smartCache.getPlayerData(uuid).isPvpEnabled()) {
|
||||
smartCache.getPlayerData(uuid).setPvpEnabled(false);
|
||||
return false;
|
||||
} else {
|
||||
smartCache.getPlayerData(uuid).setPvpEnabled(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canDamage(UUID attacker, UUID victim, boolean sendDenyMessage) {
|
||||
return canDamage(attacker, victim, sendDenyMessage, true);
|
||||
}
|
||||
|
||||
public boolean canDamage(UUID attacker, UUID victim, boolean sendDenyMessage, boolean checkVictimSpawnProtection) {
|
||||
|
||||
if (hasLoginProtection(attacker) || hasTeleportProtection(attacker)) return false;
|
||||
if (checkVictimSpawnProtection && hasLoginProtection(victim)) return false;
|
||||
if (checkVictimSpawnProtection && hasTeleportProtection(victim)) return false;
|
||||
|
||||
switch (pvpForcedState) {
|
||||
case ENABLED:
|
||||
return true;
|
||||
case DISABLED:
|
||||
PluginMessages.sendActionBar(attacker, PreventStabby.getPlugin().getConfigCache().getCannot_attack_pvp_force_off());
|
||||
return false;
|
||||
case NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
||||
|
||||
if (!smartCache.getPlayerData(attacker).isPvpEnabled()) {
|
||||
Player attackerPlayer = Bukkit.getPlayer(attacker);
|
||||
if (PreventStabby.worldGuardHookEnabled() && attackerPlayer != null && WorldGuardHook.isPlayerForcedToPvp(attackerPlayer))
|
||||
return true;
|
||||
|
||||
if (sendDenyMessage) {
|
||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||
PluginMessages.sendActionBar(attacker, config.getCannot_attack_attacker());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (!smartCache.getPlayerData(victim).isPvpEnabled()) {
|
||||
Player victimPlayer = Bukkit.getPlayer(victim);
|
||||
if (PreventStabby.worldGuardHookEnabled() && victimPlayer != null && WorldGuardHook.isPlayerForcedToPvp(victimPlayer))
|
||||
return true;
|
||||
|
||||
if (sendDenyMessage) {
|
||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||
PluginMessages.sendActionBar(attacker, config.getCannot_attack_victim());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uuid Player UUIDs
|
||||
* @return true if any of the provided UUIDs has spawn protection
|
||||
*/
|
||||
public boolean hasLoginProtection(UUID... uuid) {
|
||||
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
||||
for (UUID checkedUuid : uuid) {
|
||||
if (Instant.now().getEpochSecond() < smartCache.getPlayerData(checkedUuid).getLoginTimestamp())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasTeleportProtection(UUID uuid) {
|
||||
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
||||
return Instant.now().getEpochSecond() < smartCache.getPlayerData(uuid).getTeleportTimestamp();
|
||||
}
|
||||
|
||||
public PvpState getForcedPvpState() {
|
||||
return pvpForcedState;
|
||||
}
|
||||
|
||||
public void setForcedPvpState(PvpState forcedPvpState) {
|
||||
this.pvpForcedState = forcedPvpState;
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.players;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SmartCache {
|
||||
|
||||
public void runSmartCache() {
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(PreventStabby.getPlugin(), () -> {
|
||||
// Refresh cache timer if player is online
|
||||
for (Map.Entry<UUID, PlayerData> e : PreventStabby.getPlugin().getPlayerManager().getPlayerList().entrySet()) {
|
||||
try {
|
||||
Player player = Bukkit.getPlayer(e.getKey());
|
||||
if (player != null && player.isOnline()) {
|
||||
PreventStabby.getPlugin().getPlayerManager().refreshPlayersCacheTime(e.getKey());
|
||||
}
|
||||
} catch (NullPointerException ignored) {}
|
||||
}
|
||||
// Check for entries that should be invalidated
|
||||
try {
|
||||
long now = Instant.now().getEpochSecond();
|
||||
PreventStabby.getPlugin().getPlayerManager().getPlayerList().entrySet()
|
||||
.removeIf(cacheEntry -> cacheEntry.getValue().getCachetime() < now);
|
||||
} catch (Exception ignored) {}
|
||||
}, 100, 100);
|
||||
}
|
||||
|
||||
public PlayerData getPlayerData(UUID uuid) {
|
||||
// Try to get data from cache and refresh it
|
||||
try {
|
||||
PreventStabby.getPlugin().getPlayerManager().refreshPlayersCacheTime(uuid);
|
||||
return PreventStabby.getPlugin().getPlayerManager().getPlayer(uuid);
|
||||
} catch (NullPointerException e) {
|
||||
// If player data is not in cache get it from database and put into cache
|
||||
try {
|
||||
PlayerData playerData = PreventStabby.getPlugin().getSqLite().getPlayerInfo(uuid);
|
||||
PreventStabby.getPlugin().getPlayerManager().addPlayer(uuid, playerData);
|
||||
return playerData;
|
||||
} catch (NullPointerException ex) {
|
||||
// Return false if database call fails
|
||||
return new PlayerData(uuid,false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setPlayerPvpState(UUID uuid, boolean state) {
|
||||
// If player is in cache update that
|
||||
if (PreventStabby.getPlugin().getPlayerManager().getPlayer(uuid) != null) {
|
||||
PreventStabby.getPlugin().getPlayerManager().getPlayer(uuid).setPvpEnabled(state);
|
||||
}
|
||||
// Update the database aswell
|
||||
PreventStabby.getPlugin().getSqLite().updatePlayerInfo(uuid, new PlayerData(uuid, state));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
public class BoundingBoxUtil {
|
||||
|
||||
public static BoundingBox getBoundingBox(Location location, double radius) {
|
||||
|
||||
double x1 = location.getX()+radius;
|
||||
double y1 = location.getY()+radius;
|
||||
double z1 = location.getZ()+radius;
|
||||
|
||||
double x2 = location.getX()-radius;
|
||||
double y2 = location.getY()-radius;
|
||||
double z2 = location.getZ()-radius;
|
||||
|
||||
return new BoundingBox(x1, y1, z1, x2, y2, z2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.util;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.api.event.PlayerEnterCombatEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CombatTimer {
|
||||
|
||||
public static void refreshPlayersCombatTime(UUID uuid) {
|
||||
try {
|
||||
long now = Instant.now().getEpochSecond();
|
||||
long combattime = PreventStabby.getPlugin().getSmartCache().getPlayerData(uuid).getCombattime();
|
||||
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null || !player.isOnline()) return;
|
||||
PlayerEnterCombatEvent playerEnterCombatEvent = new PlayerEnterCombatEvent(player);
|
||||
Bukkit.getScheduler().runTask(PreventStabby.getPlugin(), () -> {
|
||||
Bukkit.getPluginManager().callEvent(playerEnterCombatEvent);
|
||||
if (playerEnterCombatEvent.isCancelled()) return;
|
||||
PreventStabby.getPlugin().getPlayerManager().refreshPlayersCombatTime(uuid);
|
||||
|
||||
if (combattime <= now) {
|
||||
PluginMessages.sendActionBar(uuid, PreventStabby.getPlugin().getConfigCache().getEntering_combat());
|
||||
}
|
||||
});
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void refreshPlayersCombatTime(UUID... uuid) {
|
||||
for (UUID id : uuid) {
|
||||
refreshPlayersCombatTime(id);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isInCombat(UUID uuid) {
|
||||
try {
|
||||
return PreventStabby.getPlugin().getPlayerManager().getPlayer(uuid).getCombattime() >= Instant.now().getEpochSecond();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,94 +1,73 @@
|
||||
package me.youhavetrouble.preventstabby.util;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.players.PlayerData;
|
||||
import me.youhavetrouble.preventstabby.data.PlayerData;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.*;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class DatabaseSQLite {
|
||||
|
||||
private final String url;
|
||||
private final File folder;
|
||||
private final Logger logger;
|
||||
|
||||
public DatabaseSQLite(String url, File folder) {
|
||||
public DatabaseSQLite(String url, File folder, Logger logger) {
|
||||
this.url = url;
|
||||
this.folder = folder;
|
||||
|
||||
this.logger = logger;
|
||||
createDatabaseFile();
|
||||
}
|
||||
|
||||
public boolean createDatabaseFile() {
|
||||
private void createDatabaseFile() {
|
||||
this.folder.mkdir();
|
||||
try (Connection conn = DriverManager.getConnection(url)) {
|
||||
if (conn != null) {
|
||||
if (conn == null) return;
|
||||
DatabaseMetaData meta = conn.getMetaData();
|
||||
System.out.println("The driver name is " + meta.getDriverName());
|
||||
logger.info("The driver name is " + meta.getDriverName());
|
||||
Statement statement = conn.createStatement();
|
||||
String sql = "CREATE TABLE IF NOT EXISTS `players` (`player_uuid` varchar(36) UNIQUE PRIMARY KEY, `pvpenabled` boolean);";
|
||||
statement.execute(sql);
|
||||
conn.close();
|
||||
} catch (SQLException exception) {
|
||||
logger.warning(exception.getMessage());
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
System.out.println(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean testConnection() {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = DriverManager.getConnection(url);
|
||||
System.out.println("Connection to SQLite has been established.");
|
||||
if (conn != null) {
|
||||
conn.close();
|
||||
return true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public PlayerData getPlayerInfo(UUID uuid) {
|
||||
try {
|
||||
Connection conn = DriverManager.getConnection(url);
|
||||
Statement insertnewuser = conn.createStatement();
|
||||
try {
|
||||
String newuserdata = "INSERT OR IGNORE INTO `players` (player_uuid, pvpenabled) VALUES ('" + uuid.toString() + "', " + PreventStabby.getPlugin().getConfigCache().isPvp_enabled_by_default() + ")";
|
||||
insertnewuser.execute(newuserdata);
|
||||
} catch (SQLException e) {
|
||||
if (e.getErrorCode() != 19) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Statement statement = conn.createStatement();
|
||||
String sql = "SELECT * FROM `players` WHERE `player_uuid` = '" + uuid + "';";
|
||||
statement.execute(sql);
|
||||
ResultSet result = statement.getResultSet();
|
||||
try (Connection conn = DriverManager.getConnection(url)) {
|
||||
PreparedStatement statement = conn.prepareStatement(
|
||||
"INSERT OR IGNORE INTO `players` (player_uuid, pvpenabled) VALUES (?, ?);"
|
||||
);
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setBoolean(2, PreventStabby.getPlugin().getConfigCache().pvp_enabled_by_default);
|
||||
statement.executeUpdate();
|
||||
statement = conn.prepareStatement("SELECT * FROM `players` WHERE `player_uuid` = ?;");
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.executeQuery();
|
||||
ResultSet result = statement.executeQuery();
|
||||
boolean state = result.getBoolean("pvpenabled");
|
||||
conn.close();
|
||||
return new PlayerData(uuid, state);
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
} catch (SQLException exception) {
|
||||
logger.warning(exception.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void updatePlayerInfo(UUID uuid, PlayerData data) {
|
||||
try (Connection conn = DriverManager.getConnection(url)) {
|
||||
try {
|
||||
Connection conn = DriverManager.getConnection(url);
|
||||
Statement insertnewuser = conn.createStatement();
|
||||
try {
|
||||
String newuserdata = "UPDATE `players` SET pvpenabled = "+data.isPvpEnabled()+" WHERE `player_uuid` = '"+uuid.toString()+"';";
|
||||
insertnewuser.execute(newuserdata);
|
||||
} catch (SQLException e) {
|
||||
PreventStabby.getPlugin().getLogger().severe("Error while saving player data!");
|
||||
e.printStackTrace();
|
||||
PreparedStatement statement = conn.prepareStatement("UPDATE `players` SET pvpenabled = ? WHERE `player_uuid` = ?;");
|
||||
statement.setBoolean(1, data.isPvpEnabled());
|
||||
statement.setString(2, uuid.toString());
|
||||
statement.executeUpdate();
|
||||
} catch (SQLException exception) {
|
||||
logger.severe("Error while saving player data!");
|
||||
logger.warning(exception.getMessage());
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
} catch (SQLException exception) {
|
||||
logger.warning(exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package me.youhavetrouble.preventstabby.util;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import me.youhavetrouble.preventstabby.data.DamageCheckResult;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
@@ -15,7 +15,6 @@ import java.util.UUID;
|
||||
public class PluginMessages {
|
||||
|
||||
public static final MiniMessage MINIMESSAGE = MiniMessage.miniMessage();
|
||||
private static final BukkitAudiences audiences = PreventStabby.getAudiences();
|
||||
|
||||
public static Component parseMessage(String message) {
|
||||
message = makeColorsWork('&', message);
|
||||
@@ -24,9 +23,7 @@ public class PluginMessages {
|
||||
}
|
||||
|
||||
public static Component parseMessage(CommandSender sender,String message) {
|
||||
|
||||
if (sender instanceof Player && isPlaceholderApiEnabled()) {
|
||||
Player player = (Player) sender;
|
||||
if (sender instanceof Player player && isPlaceholderApiEnabled()) {
|
||||
message = PlaceholderAPI.setPlaceholders(player, message);
|
||||
}
|
||||
return parseMessage(message);
|
||||
@@ -37,15 +34,18 @@ public class PluginMessages {
|
||||
}
|
||||
|
||||
public static void sendMessage(CommandSender sender, String message) {
|
||||
audiences.sender(sender).sendMessage(parseMessage(sender, message));
|
||||
if ("".equals(message)) return;
|
||||
sender.sendMessage(parseMessage(sender, message));
|
||||
}
|
||||
|
||||
public static void sendActionBar(Player player, String message) {
|
||||
if ("".equals(message)) return;
|
||||
Component parsedMessage = parseMessage(player, message);
|
||||
audiences.player(player).sendActionBar(parsedMessage);
|
||||
player.sendActionBar(parsedMessage);
|
||||
}
|
||||
|
||||
public static void sendActionBar(UUID uuid, String message) {
|
||||
if ("".equals(message)) return;
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null) return;
|
||||
sendActionBar(player, message);
|
||||
@@ -57,15 +57,23 @@ public class PluginMessages {
|
||||
}
|
||||
|
||||
public static void broadcastMessage(Player player, String message) {
|
||||
if ("".equals(message)) return;
|
||||
message = parsePlayerName(player, message);
|
||||
if (PreventStabby.getPlugin().getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(player, message);
|
||||
}
|
||||
audiences.all().sendMessage(parseMessage(message));
|
||||
Bukkit.broadcast(parseMessage(message));
|
||||
}
|
||||
|
||||
public static void broadcastMessage(String message) {
|
||||
audiences.all().sendMessage(parseMessage(message));
|
||||
if ("".equals(message)) return;
|
||||
Bukkit.broadcast(parseMessage(message));
|
||||
}
|
||||
|
||||
public static void sendOutMessages(DamageCheckResult damageCheckResult) {
|
||||
if (damageCheckResult.attackerId() != null && damageCheckResult.feedbackForAttacker() != null) {
|
||||
sendActionBar(damageCheckResult.attackerId(), damageCheckResult.feedbackForAttacker());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.util;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE})
|
||||
|
||||
public @interface PreventStabbyListener {}
|
||||
@@ -1,73 +0,0 @@
|
||||
package me.youhavetrouble.preventstabby.util;
|
||||
|
||||
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||
import me.youhavetrouble.preventstabby.config.ConfigCache;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Util {
|
||||
|
||||
private static final HashSet<PotionEffectType> harmfulPotions = new HashSet<>();
|
||||
|
||||
public static void initData() {
|
||||
harmfulPotions.add(PotionEffectType.BLINDNESS);
|
||||
harmfulPotions.add(PotionEffectType.CONFUSION);
|
||||
harmfulPotions.add(PotionEffectType.HARM);
|
||||
harmfulPotions.add(PotionEffectType.HUNGER);
|
||||
harmfulPotions.add(PotionEffectType.POISON);
|
||||
harmfulPotions.add(PotionEffectType.SLOW_DIGGING);
|
||||
harmfulPotions.add(PotionEffectType.WEAKNESS);
|
||||
harmfulPotions.add(PotionEffectType.SLOW);
|
||||
harmfulPotions.add(PotionEffectType.WITHER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param attacker Player attacking the mount
|
||||
* @param mount Entity being ridden
|
||||
* @return true if event should be cancelled
|
||||
*/
|
||||
public static boolean processMountAttack(UUID attacker, Entity mount) {
|
||||
|
||||
// Don't cancel attacks on players that have passengers
|
||||
if (mount instanceof Player) return false;
|
||||
|
||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||
|
||||
Set<UUID> playerPassengersWithPvpEnabled = new HashSet<>();
|
||||
|
||||
boolean hasPlayerPassengers = false;
|
||||
for (Entity passenger : mount.getPassengers()) {
|
||||
if (!(passenger instanceof Player)) continue;
|
||||
Player player = (Player) passenger;
|
||||
hasPlayerPassengers = true;
|
||||
if (PreventStabby.getPlugin().getPlayerManager().getPlayerPvPState(player.getUniqueId()))
|
||||
playerPassengersWithPvpEnabled.add(player.getUniqueId());
|
||||
}
|
||||
|
||||
if (!hasPlayerPassengers) return false;
|
||||
|
||||
if (!PreventStabby.getPlugin().getPlayerManager().getPlayerPvPState(attacker)) {
|
||||
PluginMessages.sendActionBar(attacker, config.getCannot_attack_mounts_attacker());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (playerPassengersWithPvpEnabled.isEmpty()) {
|
||||
PluginMessages.sendActionBar(attacker, config.getCannot_attack_mounts_victim());
|
||||
return true;
|
||||
}
|
||||
|
||||
playerPassengersWithPvpEnabled.forEach(CombatTimer::refreshPlayersCombatTime);
|
||||
CombatTimer.refreshPlayersCombatTime(attacker);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isPotionEffectHarmful(PotionEffectType effect) {
|
||||
return harmfulPotions.contains(effect);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,8 @@ name: PreventStabby
|
||||
version: ${project.version}
|
||||
main: me.youhavetrouble.preventstabby.PreventStabby
|
||||
authors: [YouHaveTrouble]
|
||||
api-version: 1.13
|
||||
api-version: 1.20
|
||||
folia-supported: true
|
||||
description: Stop people from getting stabbed!
|
||||
soft-depend:
|
||||
- WorldGuard
|
||||
@@ -22,15 +23,28 @@ permissions:
|
||||
preventstabby.command:
|
||||
default: true
|
||||
description: Allows usage of /pvp command
|
||||
preventstabby.command.help:
|
||||
default: true
|
||||
description: Allows usage of /pvp help command
|
||||
children:
|
||||
preventstabby.command: true
|
||||
preventstabby.command.toggle:
|
||||
default: true
|
||||
description: Allows usage of /pvp <toggle/enable/disable> command
|
||||
children:
|
||||
preventstabby.command: true
|
||||
preventstabby.command.toggle.others:
|
||||
default: op
|
||||
description: Allows usage of /pvp <toggle/enable/disable> <player> command
|
||||
children:
|
||||
preventstabby.command: true
|
||||
preventstabby.command.toggle.global:
|
||||
default: op
|
||||
description: Allows usage of /pvp override <enabled/disabled/none> command
|
||||
children:
|
||||
preventstabby.command: true
|
||||
preventstabby.command.reload:
|
||||
default: op
|
||||
description: Allows usage of /pvp reload command
|
||||
children:
|
||||
preventstabby.command: true
|
||||
Reference in New Issue
Block a user