mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-12 05:16:55 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 52fb010270 | |||
| cd26d621e5 | |||
| 4c08041ee6 | |||
| 643511df31 | |||
| 94f97568d5 | |||
| 9a9a44939a | |||
| 1e7adf398a | |||
| c0ca85c44d | |||
| a86485a089 |
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.youhavetrouble</groupId>
|
||||
<artifactId>PreventStabby</artifactId>
|
||||
<version>1.3-pre4</version>
|
||||
<version>1.4</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>PreventStabby</name>
|
||||
@@ -22,7 +22,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
@@ -47,7 +47,6 @@
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<!-- Replace this with your package! -->
|
||||
<shadedPattern>bstats</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
@@ -93,13 +92,13 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.12</version>
|
||||
<version>1.18.22</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.9.12</version>
|
||||
<version>0.10.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.thatsmusic99</groupId>
|
||||
@@ -109,7 +108,7 @@
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<version>3.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -25,6 +25,7 @@ public final class PreventStabby extends JavaPlugin {
|
||||
private PlayerManager playerManager;
|
||||
private DatabaseSQLite sqLite;
|
||||
private SmartCache smartCache;
|
||||
private static boolean worldGuardHook;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -45,7 +46,7 @@ public final class PreventStabby extends JavaPlugin {
|
||||
smartCache.runSmartCache();
|
||||
|
||||
// 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);
|
||||
listenerClasses.forEach((listener)-> {
|
||||
try {
|
||||
@@ -71,9 +72,16 @@ public final class PreventStabby extends JavaPlugin {
|
||||
|
||||
try {
|
||||
WorldGuardHook.init();
|
||||
} catch (NoClassDefFoundError ignored) {}
|
||||
worldGuardHook = true;
|
||||
} catch (NoClassDefFoundError e) {
|
||||
worldGuardHook = false;
|
||||
}
|
||||
|
||||
Metrics metrics = new Metrics(this, 10597);
|
||||
Metrics metrics = new Metrics(this, 14074);
|
||||
}
|
||||
|
||||
public static boolean worldGuardHookEnabled() {
|
||||
return worldGuardHook;
|
||||
}
|
||||
|
||||
public void reloadPluginConfig() {
|
||||
|
||||
@@ -11,9 +11,7 @@ public class HelpCommand {
|
||||
|
||||
public static void help(CommandSender sender, String[] args) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(PreventStabby.getPlugin(), () -> {
|
||||
|
||||
List<String> helpPage = new ArrayList<>();
|
||||
|
||||
helpPage.add(PluginMessages.parseMessage("&b&m &bPreventStabby Help&b&m "));
|
||||
helpPage.add(PluginMessages.parseMessage("&9/pvp &b&lhelp &f- shows this message"));
|
||||
if (sender.hasPermission("preventstabby.command.toggle")) {
|
||||
@@ -22,7 +20,6 @@ public class HelpCommand {
|
||||
}
|
||||
String[] helpReady = helpPage.toArray(new String[0]);
|
||||
sender.sendMessage(helpReady);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,7 @@ import org.bukkit.entity.Player;
|
||||
public class PvpToggleCommand {
|
||||
|
||||
public static void toggle(CommandSender sender, String[] args) {
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(PreventStabby.getPlugin(), () -> {
|
||||
|
||||
if (!sender.hasPermission("preventstabby.command.toggle")) {
|
||||
String message = ChatColor.translateAlternateColorCodes('&', PreventStabby.getPlugin().getConfigCache().getNo_permission());
|
||||
sender.sendMessage(message);
|
||||
@@ -47,7 +45,6 @@ public class PvpToggleCommand {
|
||||
sender.sendMessage(message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if (CombatTimer.isInCombat(player.getUniqueId())) {
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.bukkit.command.CommandSender;
|
||||
public class ReloadCommand {
|
||||
|
||||
public static void reload(CommandSender sender) {
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(PreventStabby.getPlugin(), () -> {
|
||||
if (!sender.hasPermission("preventstabby.command.reload")) {
|
||||
String message = ChatColor.translateAlternateColorCodes('&', PreventStabby.getPlugin().getConfigCache().getNo_permission());
|
||||
@@ -17,7 +16,6 @@ public class ReloadCommand {
|
||||
}
|
||||
PreventStabby.getPlugin().reloadPluginConfig(sender);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -85,9 +85,9 @@ public class ConfigCache {
|
||||
}
|
||||
};
|
||||
|
||||
configFile.setDescription("PvP toggle that CARES about your pets!");
|
||||
configFile.addLink("Spigot", "https://www.spigotmc.org/resources/togglepvp.89376/");
|
||||
configFile.addLink("Source", "https://github.com/YouHaveTrouble/TogglePvP");
|
||||
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();
|
||||
@@ -135,8 +135,6 @@ public class ConfigCache {
|
||||
this.entering_combat = config.getString("messages.entering_combat", "&cEntering 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!");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,27 +18,23 @@ import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class WorldGuardHook {
|
||||
|
||||
private static WorldGuardPlugin worldGuardPlugin;
|
||||
private static FlagRegistry flagRegistry;
|
||||
public static StateFlag FORCE_PVP_FLAG;
|
||||
|
||||
|
||||
public static void init() {
|
||||
PreventStabby plugin = PreventStabby.getPlugin();
|
||||
try {
|
||||
Class.forName("com.sk89q.worldguard.protection.flags.registry.FlagConflictException");
|
||||
worldGuardPlugin = WorldGuardPlugin.inst();
|
||||
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");
|
||||
flagRegistry = WorldGuard.getInstance().getFlagRegistry();
|
||||
createForcePvpFlag(plugin);
|
||||
} catch (NoClassDefFoundError | ClassNotFoundException e) {
|
||||
return;
|
||||
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private static void createForcePvpFlag(Plugin plugin) {
|
||||
if (!isHooked()) return;
|
||||
if (flagRegistry == null) return;
|
||||
String flagName = "preventstabby-force-pvp";
|
||||
try {
|
||||
@@ -56,7 +52,6 @@ public class WorldGuardHook {
|
||||
}
|
||||
|
||||
public static boolean isPlayerForcedToPvp(Player player) {
|
||||
if (!isHooked()) return false;
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery query = container.createQuery();
|
||||
org.bukkit.Location loc = player.getLocation();
|
||||
@@ -65,10 +60,4 @@ public class WorldGuardHook {
|
||||
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 {
|
||||
|
||||
@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.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION)) return;
|
||||
UUID damager = event.getDamager().getUniqueId();
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ import java.util.UUID;
|
||||
public class MountHitByFireworkListener implements Listener {
|
||||
|
||||
@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.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION)) return;
|
||||
Firework firework = (Firework) event.getDamager();
|
||||
|
||||
+3
-3
@@ -15,10 +15,10 @@ import java.util.UUID;
|
||||
public class PlayerHitMountWithProjectileListener 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;
|
||||
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)) return;
|
||||
if (!(projectile.getShooter() instanceof Player) || event.getEntity().getPassengers().isEmpty()) return;
|
||||
Entity entity = event.getEntity();
|
||||
UUID damager = event.getDamager().getUniqueId();
|
||||
if (Util.processMountAttack(damager, entity))
|
||||
|
||||
+3
-3
@@ -17,6 +17,9 @@ public class CombatCommandListener implements Listener {
|
||||
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())
|
||||
@@ -27,9 +30,6 @@ public class CombatCommandListener implements Listener {
|
||||
if (!PreventStabby.getPlugin().getConfigCache().getCombatBlockedCommands().contains(command))
|
||||
return;
|
||||
|
||||
if (event.getPlayer().hasPermission("toglepvp.combatcommandblock.bypass"))
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
PluginMessages.sendMessage(event.getPlayer(), PreventStabby.getPlugin().getConfigCache().getCant_do_that_during_combat());
|
||||
|
||||
|
||||
@@ -112,24 +112,25 @@ public class PlayerManager {
|
||||
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;
|
||||
|
||||
SmartCache smartCache = PreventStabby.getPlugin().getSmartCache();
|
||||
|
||||
Player attackerPlayer = Bukkit.getPlayer(attacker);
|
||||
Player victimPlayer = Bukkit.getPlayer(victim);
|
||||
if (!smartCache.getPlayerData(attacker).isPvpEnabled()) {
|
||||
Player attackerPlayer = Bukkit.getPlayer(attacker);
|
||||
if (PreventStabby.worldGuardHookEnabled() && WorldGuardHook.isPlayerForcedToPvp(attackerPlayer)) return true;
|
||||
|
||||
if (!smartCache.getPlayerData(attacker).isPvpEnabled() && (attackerPlayer != null && !isInForcedPvpRegion(attackerPlayer))) {
|
||||
if (sendDenyMessage) {
|
||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||
PluginMessages.sendActionBar(attacker, config.getCannot_attack_attacker());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (!smartCache.getPlayerData(victim).isPvpEnabled() && (victimPlayer != null && !isInForcedPvpRegion(victimPlayer))) {
|
||||
if (!smartCache.getPlayerData(victim).isPvpEnabled()) {
|
||||
Player victimPlayer = Bukkit.getPlayer(victim);
|
||||
if (PreventStabby.worldGuardHookEnabled() && WorldGuardHook.isPlayerForcedToPvp(victimPlayer)) return true;
|
||||
|
||||
if (sendDenyMessage) {
|
||||
ConfigCache config = PreventStabby.getPlugin().getConfigCache();
|
||||
PluginMessages.sendActionBar(attacker, config.getCannot_attack_victim());
|
||||
@@ -157,9 +158,4 @@ public class PlayerManager {
|
||||
return Instant.now().getEpochSecond() < smartCache.getPlayerData(uuid).getTeleportTimestamp();
|
||||
}
|
||||
|
||||
public boolean isInForcedPvpRegion(Player player) {
|
||||
if (!WorldGuardHook.isHooked()) return false;
|
||||
return WorldGuardHook.isPlayerForcedToPvp(player);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,11 +38,6 @@ public class Util {
|
||||
|
||||
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<>();
|
||||
|
||||
boolean hasPlayerPassengers = false;
|
||||
@@ -54,7 +49,14 @@ public class Util {
|
||||
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());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -12,21 +12,21 @@ commands:
|
||||
aliases:
|
||||
- pvp
|
||||
permissions:
|
||||
toglepvp.combatcommandblock.bypass:
|
||||
preventstabby.combatcommandblock.bypass:
|
||||
default: op
|
||||
description: Allows to bypass combat command blocker
|
||||
toglepvp.combatteleportblock.bypass:
|
||||
preventstabby.combatteleportblock.bypass:
|
||||
default: op
|
||||
description: Allows to bypass combat teleport blocker
|
||||
togglepvp.command:
|
||||
preventstabby.command:
|
||||
default: true
|
||||
description: Allows usage of /pvp command
|
||||
togglepvp.command.toggle:
|
||||
preventstabby.command.toggle:
|
||||
default: true
|
||||
description: Allows usage of /pvp <toggle/enable/disable> command
|
||||
togglepvp.command.toggle.others:
|
||||
preventstabby.command.toggle.others:
|
||||
default: op
|
||||
description: Allows usage of /pvp <toggle/enable/disable> <player> command
|
||||
togglepvp.command.reload:
|
||||
preventstabby.command.reload:
|
||||
default: op
|
||||
description: Allows usage of /pvp reload command
|
||||
Reference in New Issue
Block a user