mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-12 13:26:56 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4088a6dd5b | |||
| a8e606dab5 | |||
| 35f0e6c9d8 | |||
| 51f0f6c93b | |||
| 52fb010270 | |||
| cd26d621e5 | |||
| 4c08041ee6 | |||
| 643511df31 | |||
| 94f97568d5 | |||
| 9a9a44939a | |||
| 1e7adf398a | |||
| c0ca85c44d | |||
| a86485a089 |
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>me.youhavetrouble</groupId>
|
<groupId>me.youhavetrouble</groupId>
|
||||||
<artifactId>PreventStabby</artifactId>
|
<artifactId>PreventStabby</artifactId>
|
||||||
<version>1.3-pre4</version>
|
<version>1.5.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>PreventStabby</name>
|
<name>PreventStabby</name>
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.1</version>
|
<version>3.8.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${java.version}</source>
|
<source>${java.version}</source>
|
||||||
<target>${java.version}</target>
|
<target>${java.version}</target>
|
||||||
@@ -47,7 +47,6 @@
|
|||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>org.bstats</pattern>
|
<pattern>org.bstats</pattern>
|
||||||
<!-- Replace this with your package! -->
|
|
||||||
<shadedPattern>bstats</shadedPattern>
|
<shadedPattern>bstats</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
@@ -81,6 +80,10 @@
|
|||||||
<id>sk89q-repo</id>
|
<id>sk89q-repo</id>
|
||||||
<url>https://maven.enginehub.org/repo/</url>
|
<url>https://maven.enginehub.org/repo/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>placeholderapi</id>
|
||||||
|
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -93,13 +96,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.18.12</version>
|
<version>1.18.22</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.reflections</groupId>
|
<groupId>org.reflections</groupId>
|
||||||
<artifactId>reflections</artifactId>
|
<artifactId>reflections</artifactId>
|
||||||
<version>0.9.12</version>
|
<version>0.10.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.thatsmusic99</groupId>
|
<groupId>com.github.thatsmusic99</groupId>
|
||||||
@@ -109,7 +112,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bstats</groupId>
|
<groupId>org.bstats</groupId>
|
||||||
<artifactId>bstats-bukkit</artifactId>
|
<artifactId>bstats-bukkit</artifactId>
|
||||||
<version>2.2.1</version>
|
<version>3.0.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -118,5 +121,11 @@
|
|||||||
<version>7.0.4-SNAPSHOT</version>
|
<version>7.0.4-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.clip</groupId>
|
||||||
|
<artifactId>placeholderapi</artifactId>
|
||||||
|
<version>2.11.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package me.youhavetrouble.preventstabby;
|
|||||||
|
|
||||||
import me.youhavetrouble.preventstabby.commands.MainCommand;
|
import me.youhavetrouble.preventstabby.commands.MainCommand;
|
||||||
import me.youhavetrouble.preventstabby.config.ConfigCache;
|
import me.youhavetrouble.preventstabby.config.ConfigCache;
|
||||||
|
import me.youhavetrouble.preventstabby.hooks.PlacoholderApiHook;
|
||||||
import me.youhavetrouble.preventstabby.hooks.WorldGuardHook;
|
import me.youhavetrouble.preventstabby.hooks.WorldGuardHook;
|
||||||
import me.youhavetrouble.preventstabby.players.PlayerManager;
|
import me.youhavetrouble.preventstabby.players.PlayerManager;
|
||||||
import me.youhavetrouble.preventstabby.players.SmartCache;
|
import me.youhavetrouble.preventstabby.players.SmartCache;
|
||||||
@@ -25,6 +26,7 @@ public final class PreventStabby extends JavaPlugin {
|
|||||||
private PlayerManager playerManager;
|
private PlayerManager playerManager;
|
||||||
private DatabaseSQLite sqLite;
|
private DatabaseSQLite sqLite;
|
||||||
private SmartCache smartCache;
|
private SmartCache smartCache;
|
||||||
|
private static boolean worldGuardHook;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@@ -45,7 +47,7 @@ public final class PreventStabby extends JavaPlugin {
|
|||||||
smartCache.runSmartCache();
|
smartCache.runSmartCache();
|
||||||
|
|
||||||
// Register listeners
|
// Register listeners
|
||||||
Reflections reflections = new Reflections(new String[]{"me.youhavetrouble.preventstabby"});
|
Reflections reflections = new Reflections((Object[]) new String[]{"me.youhavetrouble.preventstabby"});
|
||||||
Set<Class<?>> listenerClasses = reflections.getTypesAnnotatedWith(PreventStabbyListener.class);
|
Set<Class<?>> listenerClasses = reflections.getTypesAnnotatedWith(PreventStabbyListener.class);
|
||||||
listenerClasses.forEach((listener)-> {
|
listenerClasses.forEach((listener)-> {
|
||||||
try {
|
try {
|
||||||
@@ -71,9 +73,20 @@ public final class PreventStabby extends JavaPlugin {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
WorldGuardHook.init();
|
WorldGuardHook.init();
|
||||||
} catch (NoClassDefFoundError ignored) {}
|
worldGuardHook = true;
|
||||||
|
} catch (NoClassDefFoundError e) {
|
||||||
|
worldGuardHook = false;
|
||||||
|
}
|
||||||
|
|
||||||
Metrics metrics = new Metrics(this, 10597);
|
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||||
|
new PlacoholderApiHook(this).register();
|
||||||
|
}
|
||||||
|
|
||||||
|
Metrics metrics = new Metrics(this, 14074);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean worldGuardHookEnabled() {
|
||||||
|
return worldGuardHook;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadPluginConfig() {
|
public void reloadPluginConfig() {
|
||||||
|
|||||||
@@ -65,6 +65,26 @@ public class PreventStabbyAPI {
|
|||||||
return PreventStabby.getPlugin().getPlayerManager().canDamage(attacker.getUniqueId(), victim.getUniqueId(), 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.
|
* Checks if player has login protection.
|
||||||
* @param uuid UUID of player to check
|
* @param uuid UUID of player to check
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ public class HelpCommand {
|
|||||||
|
|
||||||
public static void help(CommandSender sender, String[] args) {
|
public static void help(CommandSender sender, String[] args) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(PreventStabby.getPlugin(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(PreventStabby.getPlugin(), () -> {
|
||||||
|
|
||||||
List<String> helpPage = new ArrayList<>();
|
List<String> helpPage = new ArrayList<>();
|
||||||
|
|
||||||
helpPage.add(PluginMessages.parseMessage("&b&m &bPreventStabby Help&b&m "));
|
helpPage.add(PluginMessages.parseMessage("&b&m &bPreventStabby Help&b&m "));
|
||||||
helpPage.add(PluginMessages.parseMessage("&9/pvp &b&lhelp &f- shows this message"));
|
helpPage.add(PluginMessages.parseMessage("&9/pvp &b&lhelp &f- shows this message"));
|
||||||
if (sender.hasPermission("preventstabby.command.toggle")) {
|
if (sender.hasPermission("preventstabby.command.toggle")) {
|
||||||
@@ -22,7 +20,6 @@ public class HelpCommand {
|
|||||||
}
|
}
|
||||||
String[] helpReady = helpPage.toArray(new String[0]);
|
String[] helpReady = helpPage.toArray(new String[0]);
|
||||||
sender.sendMessage(helpReady);
|
sender.sendMessage(helpReady);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ import org.bukkit.entity.Player;
|
|||||||
public class PvpToggleCommand {
|
public class PvpToggleCommand {
|
||||||
|
|
||||||
public static void toggle(CommandSender sender, String[] args) {
|
public static void toggle(CommandSender sender, String[] args) {
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(PreventStabby.getPlugin(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(PreventStabby.getPlugin(), () -> {
|
||||||
|
|
||||||
if (!sender.hasPermission("preventstabby.command.toggle")) {
|
if (!sender.hasPermission("preventstabby.command.toggle")) {
|
||||||
String message = ChatColor.translateAlternateColorCodes('&', PreventStabby.getPlugin().getConfigCache().getNo_permission());
|
String message = ChatColor.translateAlternateColorCodes('&', PreventStabby.getPlugin().getConfigCache().getNo_permission());
|
||||||
sender.sendMessage(message);
|
sender.sendMessage(message);
|
||||||
@@ -47,7 +45,6 @@ public class PvpToggleCommand {
|
|||||||
sender.sendMessage(message);
|
sender.sendMessage(message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
if (CombatTimer.isInCombat(player.getUniqueId())) {
|
if (CombatTimer.isInCombat(player.getUniqueId())) {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import org.bukkit.command.CommandSender;
|
|||||||
public class ReloadCommand {
|
public class ReloadCommand {
|
||||||
|
|
||||||
public static void reload(CommandSender sender) {
|
public static void reload(CommandSender sender) {
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(PreventStabby.getPlugin(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(PreventStabby.getPlugin(), () -> {
|
||||||
if (!sender.hasPermission("preventstabby.command.reload")) {
|
if (!sender.hasPermission("preventstabby.command.reload")) {
|
||||||
String message = ChatColor.translateAlternateColorCodes('&', PreventStabby.getPlugin().getConfigCache().getNo_permission());
|
String message = ChatColor.translateAlternateColorCodes('&', PreventStabby.getPlugin().getConfigCache().getNo_permission());
|
||||||
@@ -17,7 +16,6 @@ public class ReloadCommand {
|
|||||||
}
|
}
|
||||||
PreventStabby.getPlugin().reloadPluginConfig(sender);
|
PreventStabby.getPlugin().reloadPluginConfig(sender);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ public class ConfigCache {
|
|||||||
@Getter private final String pvp_enabled, pvp_disabled, cannot_attack_victim, cannot_attack_attacker,
|
@Getter private 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,
|
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,
|
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;
|
cant_do_that_during_combat, cannot_attack_mounts_attacker, cannot_attack_mounts_victim,
|
||||||
|
placeholder_combat_time, placeholder_not_in_combat;
|
||||||
@Getter private final double lava_and_fire_stopper_radius;
|
@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 long cache_time, combat_time, login_protection_time, teleport_protection_time;
|
||||||
@Getter private final Set<String> combatBlockedCommands = new HashSet<>();
|
@Getter private final Set<String> combatBlockedCommands = new HashSet<>();
|
||||||
@@ -82,12 +83,14 @@ public class ConfigCache {
|
|||||||
addDefault("messages.entering_combat", "&cEntering combat");
|
addDefault("messages.entering_combat", "&cEntering combat");
|
||||||
addDefault("messages.leaving_combat", "&cLeaving combat");
|
addDefault("messages.leaving_combat", "&cLeaving combat");
|
||||||
addDefault("messages.cant_do_that_during_combat", "&cYou can't do that while in combat!");
|
addDefault("messages.cant_do_that_during_combat", "&cYou can't do that while in combat!");
|
||||||
|
addDefault("placeholder.placeholder_combat_time", "Combat time: %time%");
|
||||||
|
addDefault("placeholder.not_in_combat", "Not in combat");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
configFile.setDescription("PvP toggle that CARES about your pets!");
|
configFile.setDescription("Prevent people from getting stabbed!");
|
||||||
configFile.addLink("Spigot", "https://www.spigotmc.org/resources/togglepvp.89376/");
|
configFile.addLink("Spigot", "https://www.spigotmc.org/resources/89376/");
|
||||||
configFile.addLink("Source", "https://github.com/YouHaveTrouble/TogglePvP");
|
configFile.addLink("Source", "https://github.com/YouHaveTrouble/PreventStabby");
|
||||||
|
|
||||||
configFile.load();
|
configFile.load();
|
||||||
FileConfiguration config = configFile.getConfig();
|
FileConfiguration config = configFile.getConfig();
|
||||||
@@ -112,7 +115,7 @@ public class ConfigCache {
|
|||||||
if (block_commands_in_combat) {
|
if (block_commands_in_combat) {
|
||||||
this.combatBlockedCommands.addAll(config.getStringList("settings.block_in_combat.block_commands.commands"));
|
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", true);
|
this.block_teleports_in_combat = config.getBoolean("settings.block_in_combat.block_teleports", false);
|
||||||
|
|
||||||
this.cache_time = config.getLong("settings.cache_time", 30L);
|
this.cache_time = config.getLong("settings.cache_time", 30L);
|
||||||
|
|
||||||
@@ -136,7 +139,8 @@ public class ConfigCache {
|
|||||||
this.leaving_combat = config.getString("messages.leaving_combat", "&cLeaving combat");
|
this.leaving_combat = config.getString("messages.leaving_combat", "&cLeaving combat");
|
||||||
this.cant_do_that_during_combat = config.getString("messages.cant_do_that_during_combat", "&cYou can't do that while in combat!");
|
this.cant_do_that_during_combat = config.getString("messages.cant_do_that_during_combat", "&cYou can't do that while in combat!");
|
||||||
|
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package me.youhavetrouble.preventstabby.hooks;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
|
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||||
|
import me.youhavetrouble.preventstabby.util.PluginMessages;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public PlacoholderApiHook(PreventStabby preventStabby) {
|
||||||
|
plugin = preventStabby;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 PluginMessages.parseMessage(msg);
|
||||||
|
}
|
||||||
|
return PluginMessages.parseMessage(plugin.getConfigCache().getPlaceholder_not_in_combat());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -18,27 +18,23 @@ import org.bukkit.plugin.Plugin;
|
|||||||
|
|
||||||
public class WorldGuardHook {
|
public class WorldGuardHook {
|
||||||
|
|
||||||
private static WorldGuardPlugin worldGuardPlugin;
|
|
||||||
private static FlagRegistry flagRegistry;
|
private static FlagRegistry flagRegistry;
|
||||||
public static StateFlag FORCE_PVP_FLAG;
|
public static StateFlag FORCE_PVP_FLAG;
|
||||||
|
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
PreventStabby plugin = PreventStabby.getPlugin();
|
PreventStabby plugin = PreventStabby.getPlugin();
|
||||||
try {
|
try {
|
||||||
Class.forName("com.sk89q.worldguard.protection.flags.registry.FlagConflictException");
|
Class.forName("com.sk89q.worldguard.protection.flags.registry.FlagRegistry");
|
||||||
worldGuardPlugin = WorldGuardPlugin.inst();
|
WorldGuardPlugin worldGuardPlugin = WorldGuardPlugin.inst();
|
||||||
if (WorldGuard.getInstance() == null || worldGuardPlugin == null) return;
|
if (WorldGuard.getInstance() == null || worldGuardPlugin == null) return;
|
||||||
plugin.getLogger().info("Hooking into WorldGuard");
|
plugin.getLogger().info("Hooking into WorldGuard");
|
||||||
flagRegistry = WorldGuard.getInstance().getFlagRegistry();
|
flagRegistry = WorldGuard.getInstance().getFlagRegistry();
|
||||||
createForcePvpFlag(plugin);
|
createForcePvpFlag(plugin);
|
||||||
} catch (NoClassDefFoundError | ClassNotFoundException e) {
|
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createForcePvpFlag(Plugin plugin) {
|
private static void createForcePvpFlag(Plugin plugin) {
|
||||||
if (!isHooked()) return;
|
|
||||||
if (flagRegistry == null) return;
|
if (flagRegistry == null) return;
|
||||||
String flagName = "preventstabby-force-pvp";
|
String flagName = "preventstabby-force-pvp";
|
||||||
try {
|
try {
|
||||||
@@ -56,7 +52,6 @@ public class WorldGuardHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPlayerForcedToPvp(Player player) {
|
public static boolean isPlayerForcedToPvp(Player player) {
|
||||||
if (!isHooked()) return false;
|
|
||||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||||
RegionQuery query = container.createQuery();
|
RegionQuery query = container.createQuery();
|
||||||
org.bukkit.Location loc = player.getLocation();
|
org.bukkit.Location loc = player.getLocation();
|
||||||
@@ -65,10 +60,4 @@ public class WorldGuardHook {
|
|||||||
return set.testState(localPlayer, FORCE_PVP_FLAG);
|
return set.testState(localPlayer, FORCE_PVP_FLAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isHooked() {
|
|
||||||
return worldGuardPlugin != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ import java.util.UUID;
|
|||||||
public class MountHitByExplosionListener implements Listener {
|
public class MountHitByExplosionListener implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onPlayerAttackMount(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
public void onMountHitByExplosion(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||||
if (!(event.getDamager() instanceof Player) || event.getEntity().getPassengers().isEmpty()) return;
|
if (!(event.getDamager() instanceof Player) || event.getEntity().getPassengers().isEmpty()) return;
|
||||||
if (!event.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION)) return;
|
if (!event.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION)) return;
|
||||||
UUID damager = event.getDamager().getUniqueId();
|
UUID damager = event.getDamager().getUniqueId();
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ import java.util.UUID;
|
|||||||
public class MountHitByFireworkListener implements Listener {
|
public class MountHitByFireworkListener implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onPlayerAttackMount(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
public void onMountHitByFireWork(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||||
if (!(event.getDamager() instanceof Firework) || event.getEntity().getPassengers().isEmpty()) return;
|
if (!(event.getDamager() instanceof Firework) || event.getEntity().getPassengers().isEmpty()) return;
|
||||||
if (!event.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION)) return;
|
if (!event.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION)) return;
|
||||||
Firework firework = (Firework) event.getDamager();
|
Firework firework = (Firework) event.getDamager();
|
||||||
|
|||||||
+3
-3
@@ -15,10 +15,10 @@ import java.util.UUID;
|
|||||||
public class PlayerHitMountWithProjectileListener implements Listener {
|
public class PlayerHitMountWithProjectileListener implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onPlayerAttackMount(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
public void onPlayerHitMountWithProjectile(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
|
||||||
if (!(event.getDamager() instanceof Player) || event.getEntity().getPassengers().isEmpty()) return;
|
if (!(event.getDamager() instanceof Projectile)) return;
|
||||||
Projectile projectile = (Projectile) event.getDamager();
|
Projectile projectile = (Projectile) event.getDamager();
|
||||||
if (!(projectile.getShooter() instanceof Player)) return;
|
if (!(projectile.getShooter() instanceof Player) || event.getEntity().getPassengers().isEmpty()) return;
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
UUID damager = event.getDamager().getUniqueId();
|
UUID damager = event.getDamager().getUniqueId();
|
||||||
if (Util.processMountAttack(damager, entity))
|
if (Util.processMountAttack(damager, entity))
|
||||||
|
|||||||
+3
-3
@@ -20,9 +20,9 @@ public class PetTargettingPlayerListener implements Listener {
|
|||||||
public void onPetTargetPlayer(org.bukkit.event.entity.EntityTargetEvent event) {
|
public void onPetTargetPlayer(org.bukkit.event.entity.EntityTargetEvent event) {
|
||||||
if (!(event.getEntity() instanceof Tameable)) return;
|
if (!(event.getEntity() instanceof Tameable)) return;
|
||||||
Tameable entity = (Tameable) event.getEntity();
|
Tameable entity = (Tameable) event.getEntity();
|
||||||
if (entity.getOwner() == null) return;
|
if (!(entity.getOwner() instanceof Player)) return;
|
||||||
|
if (!(event.getTarget() instanceof Player)) return;
|
||||||
|
|
||||||
if (event.getTarget() instanceof Player) {
|
|
||||||
UUID damager = entity.getOwner().getUniqueId();
|
UUID damager = entity.getOwner().getUniqueId();
|
||||||
UUID victim = event.getTarget().getUniqueId();
|
UUID victim = event.getTarget().getUniqueId();
|
||||||
|
|
||||||
@@ -30,6 +30,6 @@ public class PetTargettingPlayerListener implements Listener {
|
|||||||
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
CombatTimer.refreshPlayersCombatTime(damager, victim);
|
||||||
else
|
else
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -17,6 +17,9 @@ public class CombatCommandListener implements Listener {
|
|||||||
if (!PreventStabby.getPlugin().getConfigCache().isBlock_commands_in_combat())
|
if (!PreventStabby.getPlugin().getConfigCache().isBlock_commands_in_combat())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (event.getPlayer().hasPermission("toglepvp.combatcommandblock.bypass"))
|
||||||
|
return;
|
||||||
|
|
||||||
PlayerManager playerManager = PreventStabby.getPlugin().getPlayerManager();
|
PlayerManager playerManager = PreventStabby.getPlugin().getPlayerManager();
|
||||||
|
|
||||||
if (!playerManager.getPlayer(event.getPlayer().getUniqueId()).isInCombat())
|
if (!playerManager.getPlayer(event.getPlayer().getUniqueId()).isInCombat())
|
||||||
@@ -27,9 +30,6 @@ public class CombatCommandListener implements Listener {
|
|||||||
if (!PreventStabby.getPlugin().getConfigCache().getCombatBlockedCommands().contains(command))
|
if (!PreventStabby.getPlugin().getConfigCache().getCombatBlockedCommands().contains(command))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (event.getPlayer().hasPermission("toglepvp.combatcommandblock.bypass"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
PluginMessages.sendMessage(event.getPlayer(), PreventStabby.getPlugin().getConfigCache().getCant_do_that_during_combat());
|
PluginMessages.sendMessage(event.getPlayer(), PreventStabby.getPlugin().getConfigCache().getCant_do_that_during_combat());
|
||||||
|
|
||||||
|
|||||||
@@ -12,14 +12,13 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class PlayerManager {
|
public class PlayerManager {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
HashMap<UUID, PlayerData> playerList = new HashMap<>();
|
ConcurrentHashMap<UUID, PlayerData> playerList = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public final BukkitTask combatTrackerTask;
|
public final BukkitTask combatTrackerTask;
|
||||||
|
|
||||||
@@ -30,9 +29,7 @@ public class PlayerManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
combatTrackerTask = Bukkit.getScheduler().runTaskTimerAsynchronously(PreventStabby.getPlugin(), () -> {
|
combatTrackerTask = Bukkit.getScheduler().runTaskTimerAsynchronously(PreventStabby.getPlugin(), () -> {
|
||||||
Iterator<PlayerData> iterator = playerList.values().iterator();
|
for (PlayerData playerData : playerList.values()) {
|
||||||
while (iterator.hasNext()) {
|
|
||||||
PlayerData playerData = iterator.next();
|
|
||||||
UUID uuid = playerData.getPlayerUuid();
|
UUID uuid = playerData.getPlayerUuid();
|
||||||
if (!CombatTimer.isInCombat(uuid)) {
|
if (!CombatTimer.isInCombat(uuid)) {
|
||||||
if (playerData.getLastCombatCheck()) {
|
if (playerData.getLastCombatCheck()) {
|
||||||
@@ -112,24 +109,27 @@ public class PlayerManager {
|
|||||||
public boolean canDamage(UUID attacker, UUID victim, boolean sendDenyMessage, boolean checkVictimSpawnProtection) {
|
public boolean canDamage(UUID attacker, UUID victim, boolean sendDenyMessage, boolean checkVictimSpawnProtection) {
|
||||||
|
|
||||||
if (hasLoginProtection(attacker) || hasTeleportProtection(attacker)) return false;
|
if (hasLoginProtection(attacker) || hasTeleportProtection(attacker)) return false;
|
||||||
|
|
||||||
if (checkVictimSpawnProtection && hasLoginProtection(victim)) return false;
|
if (checkVictimSpawnProtection && hasLoginProtection(victim)) return false;
|
||||||
|
|
||||||
if (checkVictimSpawnProtection && hasTeleportProtection(victim)) return false;
|
if (checkVictimSpawnProtection && hasTeleportProtection(victim)) return false;
|
||||||
|
|
||||||
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
||||||
|
|
||||||
|
if (!smartCache.getPlayerData(attacker).isPvpEnabled()) {
|
||||||
Player attackerPlayer = Bukkit.getPlayer(attacker);
|
Player attackerPlayer = Bukkit.getPlayer(attacker);
|
||||||
Player victimPlayer = Bukkit.getPlayer(victim);
|
if (PreventStabby.worldGuardHookEnabled() && attackerPlayer != null && WorldGuardHook.isPlayerForcedToPvp(attackerPlayer))
|
||||||
|
return true;
|
||||||
|
|
||||||
if (!smartCache.getPlayerData(attacker).isPvpEnabled() && (attackerPlayer != null && !isInForcedPvpRegion(attackerPlayer))) {
|
|
||||||
if (sendDenyMessage) {
|
if (sendDenyMessage) {
|
||||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||||
PluginMessages.sendActionBar(attacker, config.getCannot_attack_attacker());
|
PluginMessages.sendActionBar(attacker, config.getCannot_attack_attacker());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!smartCache.getPlayerData(victim).isPvpEnabled() && (victimPlayer != null && !isInForcedPvpRegion(victimPlayer))) {
|
if (!smartCache.getPlayerData(victim).isPvpEnabled()) {
|
||||||
|
Player victimPlayer = Bukkit.getPlayer(victim);
|
||||||
|
if (PreventStabby.worldGuardHookEnabled() && victimPlayer != null && WorldGuardHook.isPlayerForcedToPvp(victimPlayer))
|
||||||
|
return true;
|
||||||
|
|
||||||
if (sendDenyMessage) {
|
if (sendDenyMessage) {
|
||||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||||
PluginMessages.sendActionBar(attacker, config.getCannot_attack_victim());
|
PluginMessages.sendActionBar(attacker, config.getCannot_attack_victim());
|
||||||
@@ -157,9 +157,4 @@ public class PlayerManager {
|
|||||||
return Instant.now().getEpochSecond() < smartCache.getPlayerData(uuid).getTeleportTimestamp();
|
return Instant.now().getEpochSecond() < smartCache.getPlayerData(uuid).getTeleportTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInForcedPvpRegion(Player player) {
|
|
||||||
if (!WorldGuardHook.isHooked()) return false;
|
|
||||||
return WorldGuardHook.isPlayerForcedToPvp(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package me.youhavetrouble.preventstabby.util;
|
package me.youhavetrouble.preventstabby.util;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
|
import me.youhavetrouble.preventstabby.PreventStabby;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
@@ -9,30 +11,33 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
public class PluginMessages {
|
public class PluginMessages {
|
||||||
|
|
||||||
public static String parseMessage(String message) {
|
public static String parseMessage(String message) {
|
||||||
//TODO PAPI support
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', message);
|
return ChatColor.translateAlternateColorCodes('&', message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendMessage(Player player, String message) {
|
public static void sendMessage(Player player, String message) {
|
||||||
String parsedMessage = ChatColor.translateAlternateColorCodes('&', message);
|
if (PreventStabby.getPlugin().getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||||
player.sendMessage(parsedMessage);
|
message = PlaceholderAPI.setPlaceholders(player, message);
|
||||||
|
}
|
||||||
|
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||||
|
player.sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendActionBar(Player player, String message) {
|
public static void sendActionBar(Player player, String message) {
|
||||||
// TODO use adventure
|
// TODO use adventure
|
||||||
|
if (PreventStabby.getPlugin().getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||||
|
message = PlaceholderAPI.setPlaceholders(player, message);
|
||||||
|
}
|
||||||
BaseComponent[] component = TextComponent.fromLegacyText(parseMessage(message));
|
BaseComponent[] component = TextComponent.fromLegacyText(parseMessage(message));
|
||||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, component);
|
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendActionBar(UUID uuid, String message) {
|
public static void sendActionBar(UUID uuid, String message) {
|
||||||
try {
|
|
||||||
Player player = Bukkit.getPlayer(uuid);
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
|
if (player == null) return;
|
||||||
sendActionBar(player, message);
|
sendActionBar(player, message);
|
||||||
} catch (NullPointerException ignored) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String parsePlayerName(Player player, String message) {
|
public static String parsePlayerName(Player player, String message) {
|
||||||
@@ -42,6 +47,9 @@ public class PluginMessages {
|
|||||||
|
|
||||||
public static void broadcastMessage(Player player, String message) {
|
public static void broadcastMessage(Player player, String message) {
|
||||||
message = parsePlayerName(player, message);
|
message = parsePlayerName(player, message);
|
||||||
|
if (PreventStabby.getPlugin().getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||||
|
message = PlaceholderAPI.setPlaceholders(player, message);
|
||||||
|
}
|
||||||
message = parseMessage(message);
|
message = parseMessage(message);
|
||||||
BaseComponent[] component = TextComponent.fromLegacyText(parseMessage(message));
|
BaseComponent[] component = TextComponent.fromLegacyText(parseMessage(message));
|
||||||
Bukkit.spigot().broadcast(component);
|
Bukkit.spigot().broadcast(component);
|
||||||
|
|||||||
@@ -38,11 +38,6 @@ public class Util {
|
|||||||
|
|
||||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||||
|
|
||||||
if (!PreventStabby.getPlugin().getPlayerManager().getPlayerPvPState(attacker)) {
|
|
||||||
PluginMessages.sendActionBar(attacker, config.getCannot_attack_mounts_attacker());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<UUID> playerPassengersWithPvpEnabled = new HashSet<>();
|
Set<UUID> playerPassengersWithPvpEnabled = new HashSet<>();
|
||||||
|
|
||||||
boolean hasPlayerPassengers = false;
|
boolean hasPlayerPassengers = false;
|
||||||
@@ -54,7 +49,14 @@ public class Util {
|
|||||||
playerPassengersWithPvpEnabled.add(player.getUniqueId());
|
playerPassengersWithPvpEnabled.add(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPlayerPassengers && playerPassengersWithPvpEnabled.isEmpty()) {
|
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());
|
PluginMessages.sendActionBar(attacker, config.getCannot_attack_mounts_victim());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,27 +6,28 @@ api-version: 1.13
|
|||||||
description: Stop people from getting stabbed!
|
description: Stop people from getting stabbed!
|
||||||
soft-depend:
|
soft-depend:
|
||||||
- WorldGuard
|
- WorldGuard
|
||||||
|
- PlaceholderAPI
|
||||||
commands:
|
commands:
|
||||||
preventstabby:
|
preventstabby:
|
||||||
permission: preventstabby.command
|
permission: preventstabby.command
|
||||||
aliases:
|
aliases:
|
||||||
- pvp
|
- pvp
|
||||||
permissions:
|
permissions:
|
||||||
toglepvp.combatcommandblock.bypass:
|
preventstabby.combatcommandblock.bypass:
|
||||||
default: op
|
default: op
|
||||||
description: Allows to bypass combat command blocker
|
description: Allows to bypass combat command blocker
|
||||||
toglepvp.combatteleportblock.bypass:
|
preventstabby.combatteleportblock.bypass:
|
||||||
default: op
|
default: op
|
||||||
description: Allows to bypass combat teleport blocker
|
description: Allows to bypass combat teleport blocker
|
||||||
togglepvp.command:
|
preventstabby.command:
|
||||||
default: true
|
default: true
|
||||||
description: Allows usage of /pvp command
|
description: Allows usage of /pvp command
|
||||||
togglepvp.command.toggle:
|
preventstabby.command.toggle:
|
||||||
default: true
|
default: true
|
||||||
description: Allows usage of /pvp <toggle/enable/disable> command
|
description: Allows usage of /pvp <toggle/enable/disable> command
|
||||||
togglepvp.command.toggle.others:
|
preventstabby.command.toggle.others:
|
||||||
default: op
|
default: op
|
||||||
description: Allows usage of /pvp <toggle/enable/disable> <player> command
|
description: Allows usage of /pvp <toggle/enable/disable> <player> command
|
||||||
togglepvp.command.reload:
|
preventstabby.command.reload:
|
||||||
default: op
|
default: op
|
||||||
description: Allows usage of /pvp reload command
|
description: Allows usage of /pvp reload command
|
||||||
Reference in New Issue
Block a user