mirror of
https://github.com/zeshan321/ActionHealth.git
synced 2024-06-25 06:04:54 +02:00
Refractor and WG 6/7 support
- Refactored code - Added support for both WG 6/7 - Fixed 'Show Player' setting toggle not working - Added ability to change 'Delay Tick' amount
This commit is contained in:
parent
2aa58f553a
commit
92f7845249
10
config.yml
10
config.yml
|
@ -34,18 +34,19 @@ Use Permissions: false
|
||||||
Show Mob: true
|
Show Mob: true
|
||||||
|
|
||||||
# If set to false player will not see health messages from other players.
|
# If set to false player will not see health messages from other players.
|
||||||
|
|
||||||
Show Player: true
|
Show Player: true
|
||||||
|
|
||||||
# If set to true player will get the message in a delay to get 100% accurate health. Useful for plugins that add damage by reading item lore.
|
# If set to true player will get the message in a delay to get 100% accurate health. Useful for plugins that add damage by reading item lore.
|
||||||
# This also uses more resources :(
|
|
||||||
Delay Message: false
|
Delay Message: false
|
||||||
|
# Amount delayed by
|
||||||
|
Delay Tick: 1
|
||||||
|
|
||||||
# Style Health
|
# Style Health
|
||||||
Full Health Icon: "&4\u2764"
|
Full Health Icon: "&4\u2764"
|
||||||
Half Health Icon: "&c\u2764"
|
Half Health Icon: "&c\u2764"
|
||||||
Empty Health Icon: "&7\u2764"
|
Empty Health Icon: "&7\u2764"
|
||||||
|
|
||||||
# Set names. Case sensitive!
|
# Translate names. Case sensitive!
|
||||||
Name Change: false
|
Name Change: false
|
||||||
Name:
|
Name:
|
||||||
- Snow Golem = New name
|
- Snow Golem = New name
|
||||||
|
@ -64,6 +65,7 @@ Region PvP: true
|
||||||
Limit Health: 10
|
Limit Health: 10
|
||||||
|
|
||||||
# Saves players /actionhealth toggle state.
|
# Saves players /actionhealth toggle state.
|
||||||
|
# Uses flat file. If interested in SQL support ask in discussion.
|
||||||
Remember Toggle: false
|
Remember Toggle: false
|
||||||
|
|
||||||
# Blacklist by entity name or entity display name.
|
# Blacklist by entity name or entity display name.
|
||||||
|
@ -71,7 +73,7 @@ Blacklist:
|
||||||
- 'CCPD Officer'
|
- 'CCPD Officer'
|
||||||
|
|
||||||
# Show the health of the entity that the player is looking at.
|
# Show the health of the entity that the player is looking at.
|
||||||
Show On Look: false
|
Show On Look: true
|
||||||
Look Distance: 10
|
Look Distance: 10
|
||||||
|
|
||||||
# Check if player can see entity before sending health.
|
# Check if player can see entity before sending health.
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,7 +1,7 @@
|
||||||
name: ActionHealth
|
name: ActionHealth
|
||||||
main: com.zeshanaslam.actionhealth.Main
|
main: com.zeshanaslam.actionhealth.Main
|
||||||
version: 3.3.0
|
version: 3.3.2
|
||||||
softdepend: [PlaceholderAPI, MVdWPlaceholderAPI, WorldGuard]
|
softdepend: [PlaceholderAPI, MVdWPlaceholderAPI, WorldGuard]
|
||||||
commands:
|
commands:
|
||||||
Actionhealth:
|
Actionhealth:
|
||||||
description: Actionhealth main command.
|
description: Actionhealth main commands.
|
|
@ -1,5 +1,6 @@
|
||||||
package com.zeshanaslam.actionhealth;
|
package com.zeshanaslam.actionhealth;
|
||||||
|
|
||||||
|
import com.zeshanaslam.actionhealth.utils.TargetHelper;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -31,13 +32,13 @@ public class LookThread extends BukkitRunnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if (plugin.toggle.contains(player.getUniqueId())) {
|
if (plugin.toggle.contains(player.getUniqueId())) {
|
||||||
if (plugin.settingsManager.toggleMessage != null && !plugin.settingsManager.toggleMessage.equals("")) {
|
if (plugin.configStore.toggleMessage != null && !plugin.configStore.toggleMessage.equals("")) {
|
||||||
plugin.healthUtil.sendActionBar(player, plugin.settingsManager.toggleMessage.replace("{name}", player.getName()));
|
plugin.healthUtil.sendActionBar(player, plugin.configStore.toggleMessage.replace("{name}", player.getName()));
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<LivingEntity> entities = TargetHelper.getLivingTargets(player, plugin.settingsManager.lookDistance);
|
List<LivingEntity> entities = TargetHelper.getLivingTargets(player, plugin.configStore.lookDistance);
|
||||||
if (!entities.isEmpty()) {
|
if (!entities.isEmpty()) {
|
||||||
for (LivingEntity livingEntity : entities) {
|
for (LivingEntity livingEntity : entities) {
|
||||||
if (livingEntity.getType().name().equals("ARMOR_STAND")) continue;
|
if (livingEntity.getType().name().equals("ARMOR_STAND")) continue;
|
||||||
|
@ -50,7 +51,7 @@ public class LookThread extends BukkitRunnable {
|
||||||
name = livingEntity.getCustomName();
|
name = livingEntity.getCustomName();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TargetHelper.canSee(player, livingEntity.getLocation(), transparentTypeIds) && !plugin.settingsManager.blacklist.contains(name) && !livingEntity.hasMetadata("NPC")) {
|
if (TargetHelper.canSee(player, livingEntity.getLocation(), transparentTypeIds) && !plugin.configStore.blacklist.contains(name) && !livingEntity.hasMetadata("NPC")) {
|
||||||
plugin.healthUtil.sendHealth(player, livingEntity, livingEntity.getHealth());
|
plugin.healthUtil.sendHealth(player, livingEntity, livingEntity.getHealth());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
package com.zeshanaslam.actionhealth;
|
package com.zeshanaslam.actionhealth;
|
||||||
|
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
|
import com.zeshanaslam.actionhealth.commands.HealthCommand;
|
||||||
|
import com.zeshanaslam.actionhealth.config.ConfigStore;
|
||||||
|
import com.zeshanaslam.actionhealth.events.HealthListeners;
|
||||||
|
import com.zeshanaslam.actionhealth.support.WorldGuardAPI;
|
||||||
|
import com.zeshanaslam.actionhealth.utils.HealthUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
@ -11,8 +16,9 @@ import java.util.UUID;
|
||||||
|
|
||||||
public class Main extends JavaPlugin {
|
public class Main extends JavaPlugin {
|
||||||
|
|
||||||
public SettingsManager settingsManager;
|
public ConfigStore configStore;
|
||||||
public WorldGuardPlugin worldGuardPlugin;
|
public WorldGuardPlugin worldGuardPlugin;
|
||||||
|
public WorldGuardAPI worldGuardAPI;
|
||||||
public HealthUtil healthUtil;
|
public HealthUtil healthUtil;
|
||||||
public int taskID = -1;
|
public int taskID = -1;
|
||||||
|
|
||||||
|
@ -26,7 +32,7 @@ public class Main extends JavaPlugin {
|
||||||
this.healthUtil = new HealthUtil(this);
|
this.healthUtil = new HealthUtil(this);
|
||||||
|
|
||||||
// Load config settings
|
// Load config settings
|
||||||
settingsManager = new SettingsManager(this);
|
configStore = new ConfigStore(this);
|
||||||
|
|
||||||
// Create player folder
|
// Create player folder
|
||||||
File file = new File("plugins/ActionHealth/players/");
|
File file = new File("plugins/ActionHealth/players/");
|
||||||
|
@ -35,11 +41,12 @@ public class Main extends JavaPlugin {
|
||||||
// Register listeners
|
// Register listeners
|
||||||
getServer().getPluginManager().registerEvents(new HealthListeners(this), this);
|
getServer().getPluginManager().registerEvents(new HealthListeners(this), this);
|
||||||
|
|
||||||
// Register command
|
// Register commands
|
||||||
getCommand("Actionhealth").setExecutor(new HealthCommand(this));
|
getCommand("Actionhealth").setExecutor(new HealthCommand(this));
|
||||||
|
|
||||||
if (Bukkit.getServer().getPluginManager().isPluginEnabled("WorldGuard")) {
|
if (Bukkit.getServer().getPluginManager().isPluginEnabled("WorldGuard")) {
|
||||||
this.worldGuardPlugin = ((WorldGuardPlugin) getServer().getPluginManager().getPlugin("WorldGuard"));
|
this.worldGuardPlugin = ((WorldGuardPlugin) getServer().getPluginManager().getPlugin("WorldGuard"));
|
||||||
|
this.worldGuardAPI = new WorldGuardAPI(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package com.zeshanaslam.actionhealth;
|
package com.zeshanaslam.actionhealth.commands;
|
||||||
|
|
||||||
|
import com.zeshanaslam.actionhealth.Main;
|
||||||
|
import com.zeshanaslam.actionhealth.config.ConfigStore;
|
||||||
|
import com.zeshanaslam.actionhealth.utils.FileHandler;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
@ -27,7 +30,7 @@ public class HealthCommand implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.reloadConfig();
|
plugin.reloadConfig();
|
||||||
plugin.settingsManager = new SettingsManager(plugin);
|
plugin.configStore = new ConfigStore(plugin);
|
||||||
sender.sendMessage(ChatColor.RED + "ActionHealth " + ChatColor.GRAY + "has been reloaded!");
|
sender.sendMessage(ChatColor.RED + "ActionHealth " + ChatColor.GRAY + "has been reloaded!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -39,14 +42,14 @@ public class HealthCommand implements CommandExecutor {
|
||||||
if (plugin.toggle.contains(player.getUniqueId())) {
|
if (plugin.toggle.contains(player.getUniqueId())) {
|
||||||
plugin.toggle.remove(player.getUniqueId());
|
plugin.toggle.remove(player.getUniqueId());
|
||||||
|
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.settingsManager.enableMessage).replace("{name}", player.getName()));
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.configStore.enableMessage).replace("{name}", player.getName()));
|
||||||
} else {
|
} else {
|
||||||
plugin.toggle.add(player.getUniqueId());
|
plugin.toggle.add(player.getUniqueId());
|
||||||
|
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.settingsManager.disableMessage).replace("{name}", player.getName()));
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.configStore.disableMessage).replace("{name}", player.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.settingsManager.rememberToggle) {
|
if (plugin.configStore.rememberToggle) {
|
||||||
FileHandler fileHandler = new FileHandler("plugins/ActionHealth/players/" + player.getUniqueId() + ".yml");
|
FileHandler fileHandler = new FileHandler("plugins/ActionHealth/players/" + player.getUniqueId() + ".yml");
|
||||||
fileHandler.set("toggle", plugin.toggle.contains(player.getUniqueId()));
|
fileHandler.set("toggle", plugin.toggle.contains(player.getUniqueId()));
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.zeshanaslam.actionhealth;
|
package com.zeshanaslam.actionhealth.config;
|
||||||
|
|
||||||
|
import com.zeshanaslam.actionhealth.LookThread;
|
||||||
|
import com.zeshanaslam.actionhealth.Main;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
@ -9,7 +11,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class SettingsManager {
|
public class ConfigStore {
|
||||||
|
|
||||||
public String healthMessage;
|
public String healthMessage;
|
||||||
public String healthMessageOther;
|
public String healthMessageOther;
|
||||||
|
@ -17,6 +19,7 @@ public class SettingsManager {
|
||||||
public boolean showMobs;
|
public boolean showMobs;
|
||||||
public boolean showPlayers;
|
public boolean showPlayers;
|
||||||
public boolean delay;
|
public boolean delay;
|
||||||
|
public long delayTick;
|
||||||
public boolean checkPvP;
|
public boolean checkPvP;
|
||||||
public boolean stripName;
|
public boolean stripName;
|
||||||
public boolean rememberToggle;
|
public boolean rememberToggle;
|
||||||
|
@ -41,7 +44,7 @@ public class SettingsManager {
|
||||||
public boolean hasPlaceholderAPI;
|
public boolean hasPlaceholderAPI;
|
||||||
public int limitHealth;
|
public int limitHealth;
|
||||||
|
|
||||||
public SettingsManager(Main plugin) {
|
public ConfigStore(Main plugin) {
|
||||||
// Clear settings for reloads
|
// Clear settings for reloads
|
||||||
worlds.clear();
|
worlds.clear();
|
||||||
regions.clear();
|
regions.clear();
|
||||||
|
@ -68,6 +71,12 @@ public class SettingsManager {
|
||||||
showMobs = plugin.getConfig().getBoolean("Show Mob");
|
showMobs = plugin.getConfig().getBoolean("Show Mob");
|
||||||
showPlayers = plugin.getConfig().getBoolean("Show Player");
|
showPlayers = plugin.getConfig().getBoolean("Show Player");
|
||||||
delay = plugin.getConfig().getBoolean("Delay Message");
|
delay = plugin.getConfig().getBoolean("Delay Message");
|
||||||
|
if (plugin.getConfig().contains("Delay Tick")) {
|
||||||
|
delayTick = plugin.getConfig().getLong("Delay Tick");
|
||||||
|
} else {
|
||||||
|
delayTick = 1L;
|
||||||
|
}
|
||||||
|
|
||||||
checkPvP = plugin.getConfig().getBoolean("Region PvP");
|
checkPvP = plugin.getConfig().getBoolean("Region PvP");
|
||||||
stripName = plugin.getConfig().getBoolean("Strip Name");
|
stripName = plugin.getConfig().getBoolean("Strip Name");
|
||||||
filledHeartIcon = plugin.getConfig().getString("Full Health Icon");
|
filledHeartIcon = plugin.getConfig().getString("Full Health Icon");
|
|
@ -1,5 +1,7 @@
|
||||||
package com.zeshanaslam.actionhealth;
|
package com.zeshanaslam.actionhealth.events;
|
||||||
|
|
||||||
|
import com.zeshanaslam.actionhealth.Main;
|
||||||
|
import com.zeshanaslam.actionhealth.utils.FileHandler;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -21,7 +23,7 @@ public class HealthListeners implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onDamage(EntityDamageByEntityEvent event) {
|
public void onDamage(EntityDamageByEntityEvent event) {
|
||||||
if (plugin.settingsManager.checkPvP && event.isCancelled()) {
|
if (plugin.configStore.checkPvP && event.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,14 +31,20 @@ public class HealthListeners implements Listener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.settingsManager.worlds.contains(event.getDamager().getWorld().getName())) {
|
if (plugin.configStore.worlds.contains(event.getDamager().getWorld().getName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.settingsManager.usePerms && !event.getDamager().hasPermission("ActionHealth.Health")) {
|
if (plugin.configStore.usePerms && !event.getDamager().hasPermission("ActionHealth.Health")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the setting 'Show Player' is enabled
|
||||||
|
if (event.getEntity() instanceof Player) {
|
||||||
|
if (!plugin.configStore.showPlayers) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Entity damaged = event.getEntity();
|
Entity damaged = event.getEntity();
|
||||||
if (damaged.getType().name().equals("ARMOR_STAND")) return;
|
if (damaged.getType().name().equals("ARMOR_STAND")) return;
|
||||||
|
@ -47,14 +55,7 @@ public class HealthListeners implements Listener {
|
||||||
if (projectile.getShooter() instanceof Player) {
|
if (projectile.getShooter() instanceof Player) {
|
||||||
Player player = (Player) projectile.getShooter();
|
Player player = (Player) projectile.getShooter();
|
||||||
|
|
||||||
// Check if the setting 'Show Player' is enabled
|
if (!plugin.configStore.showMobs) {
|
||||||
if (event.getEntity() instanceof Player) {
|
|
||||||
if (!plugin.settingsManager.showPlayers) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!plugin.settingsManager.showMobs) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,9 +64,7 @@ public class HealthListeners implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.toggle.contains(player.getUniqueId())) {
|
if (plugin.toggle.contains(player.getUniqueId())) {
|
||||||
if (plugin.settingsManager.toggleMessage != null && !plugin.settingsManager.toggleMessage.equals("")) {
|
sendMessage(player);
|
||||||
plugin.healthUtil.sendActionBar(player, plugin.settingsManager.toggleMessage.replace("{name}", player.getName()));
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +85,7 @@ public class HealthListeners implements Listener {
|
||||||
|
|
||||||
// Check if the setting 'Show Player' is enabled
|
// Check if the setting 'Show Player' is enabled
|
||||||
if (event.getEntity() instanceof Player) {
|
if (event.getEntity() instanceof Player) {
|
||||||
if (!plugin.settingsManager.showPlayers) {
|
if (!plugin.configStore.showPlayers) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,14 +94,12 @@ public class HealthListeners implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!plugin.settingsManager.showMobs) {
|
if (!plugin.configStore.showMobs) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.toggle.contains(player.getUniqueId())) {
|
if (plugin.toggle.contains(player.getUniqueId())) {
|
||||||
if (plugin.settingsManager.toggleMessage != null && !plugin.settingsManager.toggleMessage.equals("")) {
|
sendMessage(player);
|
||||||
plugin.healthUtil.sendActionBar(player, plugin.settingsManager.toggleMessage.replace("{name}", player.getName()));
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,11 +111,17 @@ public class HealthListeners implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendMessage(Player player) {
|
||||||
|
if (plugin.configStore.toggleMessage != null && !plugin.configStore.toggleMessage.equals("")) {
|
||||||
|
plugin.healthUtil.sendActionBar(player, plugin.configStore.toggleMessage.replace("{name}", player.getName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onJoin(PlayerJoinEvent event) {
|
public void onJoin(PlayerJoinEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (plugin.settingsManager.rememberToggle) {
|
if (plugin.configStore.rememberToggle) {
|
||||||
FileHandler fileHandler = new FileHandler("plugins/ActionHealth/players/" + player.getUniqueId() + ".yml");
|
FileHandler fileHandler = new FileHandler("plugins/ActionHealth/players/" + player.getUniqueId() + ".yml");
|
||||||
|
|
||||||
if (fileHandler.getBoolean("toggle")) {
|
if (fileHandler.getBoolean("toggle")) {
|
||||||
|
@ -131,8 +134,6 @@ public class HealthListeners implements Listener {
|
||||||
public void onLeave(PlayerQuitEvent event) {
|
public void onLeave(PlayerQuitEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (plugin.toggle.contains(player.getUniqueId())) {
|
plugin.toggle.remove(player.getUniqueId());
|
||||||
plugin.toggle.remove(player.getUniqueId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package com.zeshanaslam.actionhealth;
|
package com.zeshanaslam.actionhealth.support;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
222
src/com/zeshanaslam/actionhealth/support/WorldGuardAPI.java
Normal file
222
src/com/zeshanaslam/actionhealth/support/WorldGuardAPI.java
Normal file
|
@ -0,0 +1,222 @@
|
||||||
|
package com.zeshanaslam.actionhealth.support;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
|
import com.sk89q.worldguard.domains.Association;
|
||||||
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
|
import com.sk89q.worldguard.protection.association.Associables;
|
||||||
|
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||||
|
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||||
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
|
import com.zeshanaslam.actionhealth.Main;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class WorldGuardAPI {
|
||||||
|
private final Main main;
|
||||||
|
private Object worldGuard = null;
|
||||||
|
private WorldGuardPlugin worldGuardPlugin = null;
|
||||||
|
private Object regionContainer = null;
|
||||||
|
private Method regionContainerGetMethod = null;
|
||||||
|
private Method createQueryMethod = null;
|
||||||
|
private Method regionQueryTestStateMethod = null;
|
||||||
|
private Method locationAdaptMethod = null;
|
||||||
|
private Method worldAdaptMethod = null;
|
||||||
|
private Method regionManagerGetMethod = null;
|
||||||
|
private Constructor<?> vectorConstructor = null;
|
||||||
|
private Method vectorConstructorAsAMethodBecauseWhyNot = null;
|
||||||
|
private StateFlag buildFlag;
|
||||||
|
private StateFlag pvpFlag;
|
||||||
|
private StateFlag exitFlag;
|
||||||
|
private boolean initialized = false;
|
||||||
|
|
||||||
|
public WorldGuardAPI(Main main) {
|
||||||
|
this.main = main;
|
||||||
|
worldGuardPlugin = main.worldGuardPlugin;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class<?> worldGuardClass = Class.forName("com.sk89q.worldguard.WorldGuard");
|
||||||
|
Method getInstanceMethod = worldGuardClass.getMethod("getInstance");
|
||||||
|
worldGuard = getInstanceMethod.invoke(null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected RegionAssociable getAssociable(Player player) {
|
||||||
|
RegionAssociable associable;
|
||||||
|
if (player == null) {
|
||||||
|
associable = Associables.constant(Association.NON_MEMBER);
|
||||||
|
} else {
|
||||||
|
associable = worldGuardPlugin.wrapPlayer(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
return associable;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initialize() {
|
||||||
|
if (!initialized) {
|
||||||
|
initialized = true;
|
||||||
|
// Super hacky reflection to deal with differences in WorldGuard 6 and 7+
|
||||||
|
if (worldGuard != null) {
|
||||||
|
try {
|
||||||
|
Method getPlatFormMethod = worldGuard.getClass().getMethod("getPlatform");
|
||||||
|
Object platform = getPlatFormMethod.invoke(worldGuard);
|
||||||
|
Method getRegionContainerMethod = platform.getClass().getMethod("getRegionContainer");
|
||||||
|
regionContainer = getRegionContainerMethod.invoke(platform);
|
||||||
|
createQueryMethod = regionContainer.getClass().getMethod("createQuery");
|
||||||
|
Class<?> worldEditLocationClass = Class.forName("com.sk89q.worldedit.util.Location");
|
||||||
|
Class<?> worldEditWorldClass = Class.forName("com.sk89q.worldedit.world.World");
|
||||||
|
Class<?> worldEditAdapterClass = Class.forName("com.sk89q.worldedit.bukkit.BukkitAdapter");
|
||||||
|
worldAdaptMethod = worldEditAdapterClass.getMethod("adapt", World.class);
|
||||||
|
locationAdaptMethod = worldEditAdapterClass.getMethod("adapt", Location.class);
|
||||||
|
regionContainerGetMethod = regionContainer.getClass().getMethod("get", worldEditWorldClass);
|
||||||
|
Class<?> regionQueryClass = Class.forName("com.sk89q.worldguard.protection.regions.RegionQuery");
|
||||||
|
regionQueryTestStateMethod = regionQueryClass.getMethod("testState", worldEditLocationClass, RegionAssociable.class, StateFlag[].class);
|
||||||
|
|
||||||
|
Class<?> flagsClass = Class.forName("com.sk89q.worldguard.protection.flags.Flags");
|
||||||
|
buildFlag = (StateFlag) flagsClass.getField("BUILD").get(null);
|
||||||
|
pvpFlag = (StateFlag) flagsClass.getField("PVP").get(null);
|
||||||
|
exitFlag = (StateFlag) flagsClass.getField("EXIT").get(null);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
regionContainer = null;
|
||||||
|
main.getLogger().log(Level.SEVERE, "Unable to hook into WG. SE: 1", ex);
|
||||||
|
main.worldGuardPlugin = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
regionContainer = worldGuardPlugin.getRegionContainer();
|
||||||
|
try {
|
||||||
|
createQueryMethod = regionContainer.getClass().getMethod("createQuery");
|
||||||
|
regionContainerGetMethod = regionContainer.getClass().getMethod("get", World.class);
|
||||||
|
Class<?> regionQueryClass = Class.forName("com.sk89q.worldguard.bukkit.RegionQuery");
|
||||||
|
regionQueryTestStateMethod = regionQueryClass.getMethod("testState", Location.class, RegionAssociable.class, StateFlag[].class);
|
||||||
|
|
||||||
|
Class<?> flagsClass = Class.forName("com.sk89q.worldguard.protection.flags.DefaultFlag");
|
||||||
|
buildFlag = (StateFlag) flagsClass.getField("BUILD").get(null);
|
||||||
|
pvpFlag = (StateFlag) flagsClass.getField("PVP").get(null);
|
||||||
|
exitFlag = (StateFlag) flagsClass.getField("EXIT").get(null);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
main.getLogger().log(Level.SEVERE, "Unable to hook into WG. SE: 2", ex);
|
||||||
|
main.worldGuardPlugin = null;
|
||||||
|
regionContainer = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ugh guys, API much?
|
||||||
|
try {
|
||||||
|
Class<?> vectorClass = Class.forName("com.sk89q.worldedit.Vector");
|
||||||
|
vectorConstructor = vectorClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE);
|
||||||
|
regionManagerGetMethod = RegionManager.class.getMethod("getApplicableRegions", vectorClass);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
try {
|
||||||
|
Class<?> vectorClass = Class.forName("com.sk89q.worldedit.math.BlockVector3");
|
||||||
|
vectorConstructorAsAMethodBecauseWhyNot = vectorClass.getMethod("at", Double.TYPE, Double.TYPE, Double.TYPE);
|
||||||
|
regionManagerGetMethod = RegionManager.class.getMethod("getApplicableRegions", vectorClass);
|
||||||
|
} catch (Exception sodonewiththis) {
|
||||||
|
main.getLogger().log(Level.SEVERE, "Unable to hook into WG. SE: 3", ex);
|
||||||
|
main.worldGuardPlugin = null;
|
||||||
|
regionContainer = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (regionContainer == null) {
|
||||||
|
main.getLogger().log(Level.SEVERE, "Unable to hook into WG. SE: 2");
|
||||||
|
main.worldGuardPlugin = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private RegionManager getRegionManager(World world) {
|
||||||
|
initialize();
|
||||||
|
if (regionContainer == null || regionContainerGetMethod == null) return null;
|
||||||
|
RegionManager regionManager = null;
|
||||||
|
try {
|
||||||
|
if (worldAdaptMethod != null) {
|
||||||
|
Object worldEditWorld = worldAdaptMethod.invoke(null, world);
|
||||||
|
regionManager = (RegionManager) regionContainerGetMethod.invoke(regionContainer, worldEditWorld);
|
||||||
|
} else {
|
||||||
|
regionManager = (RegionManager) regionContainerGetMethod.invoke(regionContainer, world);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
main.getLogger().log(Level.SEVERE, "Unable to run WG lookup. SE: 1");
|
||||||
|
}
|
||||||
|
return regionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private ApplicableRegionSet getRegionSet(Location location) {
|
||||||
|
RegionManager regionManager = getRegionManager(location.getWorld());
|
||||||
|
if (regionManager == null) return null;
|
||||||
|
// The Location version of this method is gone in 7.0
|
||||||
|
// Oh and then they also randomly changed the Vector class at some point without even a version bump.
|
||||||
|
// So awesome!
|
||||||
|
try {
|
||||||
|
Object vector = vectorConstructorAsAMethodBecauseWhyNot == null
|
||||||
|
? vectorConstructor.newInstance(location.getX(), location.getY(), location.getZ())
|
||||||
|
: vectorConstructorAsAMethodBecauseWhyNot.invoke(null, location.getX(), location.getY(), location.getZ());
|
||||||
|
return (ApplicableRegionSet) regionManagerGetMethod.invoke(regionManager, vector);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
main.getLogger().log(Level.SEVERE, "Unable to run WG lookup. SE: 2");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPVPAllowed(Player player, Location location) {
|
||||||
|
if (worldGuardPlugin == null || location == null) return true;
|
||||||
|
|
||||||
|
ApplicableRegionSet checkSet = getRegionSet(location);
|
||||||
|
if (checkSet == null) return true;
|
||||||
|
|
||||||
|
return checkSet.queryState(getAssociable(player), pvpFlag) != StateFlag.State.DENY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isExitAllowed(Player player, Location location) {
|
||||||
|
if (worldGuardPlugin == null || location == null) return true;
|
||||||
|
|
||||||
|
ApplicableRegionSet checkSet = getRegionSet(location);
|
||||||
|
if (checkSet == null) return true;
|
||||||
|
|
||||||
|
return checkSet.queryState(getAssociable(player), exitFlag) != StateFlag.State.DENY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getRegionNames(Location location) {
|
||||||
|
ApplicableRegionSet applicableRegionSet = getRegionSet(location);
|
||||||
|
return Objects.requireNonNull(applicableRegionSet).getRegions().stream()
|
||||||
|
.map(ProtectedRegion::getId).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasBuildPermission(Player player, Block block) {
|
||||||
|
initialize();
|
||||||
|
if (block != null && createQueryMethod != null && regionContainer != null) {
|
||||||
|
try {
|
||||||
|
boolean result;
|
||||||
|
Object query = createQueryMethod.invoke(regionContainer);
|
||||||
|
if (locationAdaptMethod != null) {
|
||||||
|
Object location = locationAdaptMethod.invoke(null, block.getLocation());
|
||||||
|
result = (boolean) regionQueryTestStateMethod.invoke(query, location, getAssociable(player), new StateFlag[]{buildFlag});
|
||||||
|
} else {
|
||||||
|
result = (boolean) regionQueryTestStateMethod.invoke(query, block.getLocation(), getAssociable(player), new StateFlag[]{buildFlag});
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
main.getLogger().log(Level.SEVERE, "Unable to run WG lookup. SE: 3");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package com.zeshanaslam.actionhealth;
|
package com.zeshanaslam.actionhealth.utils;
|
||||||
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfigurationOptions;
|
import org.bukkit.configuration.file.YamlConfigurationOptions;
|
|
@ -1,10 +1,7 @@
|
||||||
package com.zeshanaslam.actionhealth;
|
package com.zeshanaslam.actionhealth.utils;
|
||||||
|
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.zeshanaslam.actionhealth.Main;
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
import com.zeshanaslam.actionhealth.support.PreAction;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
|
||||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
|
||||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
@ -24,7 +21,7 @@ public class HealthUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendHealth(Player receiver, LivingEntity entity, double health) {
|
public void sendHealth(Player receiver, LivingEntity entity, double health) {
|
||||||
if (plugin.settingsManager.canSee) {
|
if (plugin.configStore.canSee) {
|
||||||
|
|
||||||
if (entity instanceof Player) {
|
if (entity instanceof Player) {
|
||||||
Player player = (Player) entity;
|
Player player = (Player) entity;
|
||||||
|
@ -35,7 +32,7 @@ public class HealthUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.settingsManager.spectatorMode) {
|
if (plugin.configStore.spectatorMode) {
|
||||||
|
|
||||||
if (entity instanceof Player) {
|
if (entity instanceof Player) {
|
||||||
Player player = (Player) entity;
|
Player player = (Player) entity;
|
||||||
|
@ -47,13 +44,13 @@ public class HealthUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.settingsManager.invisiblePotion) {
|
if (plugin.configStore.invisiblePotion) {
|
||||||
if (entity.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
|
if (entity.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.settingsManager.delay) {
|
if (plugin.configStore.delay) {
|
||||||
|
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -62,7 +59,7 @@ public class HealthUtil {
|
||||||
if (output != null)
|
if (output != null)
|
||||||
sendActionBar(receiver, output);
|
sendActionBar(receiver, output);
|
||||||
}
|
}
|
||||||
}.runTaskLater(plugin, 1L);
|
}.runTaskLater(plugin, plugin.configStore.delayTick);
|
||||||
} else {
|
} else {
|
||||||
String output = getOutput(health, receiver, entity);
|
String output = getOutput(health, receiver, entity);
|
||||||
|
|
||||||
|
@ -83,13 +80,13 @@ public class HealthUtil {
|
||||||
name = entity.getCustomName();
|
name = entity.getCustomName();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.settingsManager.blacklist.contains(name)) return null;
|
if (plugin.configStore.blacklist.contains(name)) return null;
|
||||||
|
|
||||||
if (plugin.settingsManager.stripName) name = ChatColor.stripColor(name);
|
if (plugin.configStore.stripName) name = ChatColor.stripColor(name);
|
||||||
if (plugin.settingsManager.translate.containsKey(entity.getName()))
|
if (plugin.configStore.translate.containsKey(entity.getName()))
|
||||||
name = plugin.settingsManager.translate.get(entity.getName());
|
name = plugin.configStore.translate.get(entity.getName());
|
||||||
|
|
||||||
String output = plugin.settingsManager.healthMessage;
|
String output = plugin.configStore.healthMessage;
|
||||||
|
|
||||||
if (entity instanceof Player) {
|
if (entity instanceof Player) {
|
||||||
String displayName;
|
String displayName;
|
||||||
|
@ -104,17 +101,17 @@ public class HealthUtil {
|
||||||
output = output.replace("{displayname}", displayName);
|
output = output.replace("{displayname}", displayName);
|
||||||
|
|
||||||
// Placeholder apis
|
// Placeholder apis
|
||||||
if (plugin.settingsManager.hasMVdWPlaceholderAPI) {
|
if (plugin.configStore.hasMVdWPlaceholderAPI) {
|
||||||
output = be.maximvdw.placeholderapi.PlaceholderAPI.replacePlaceholders(player, output);
|
output = be.maximvdw.placeholderapi.PlaceholderAPI.replacePlaceholders(player, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.settingsManager.hasPlaceholderAPI) {
|
if (plugin.configStore.hasPlaceholderAPI) {
|
||||||
output = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, output);
|
output = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, output);
|
||||||
output = me.clip.placeholderapi.PlaceholderAPI.setRelationalPlaceholders(receiver, player, output);
|
output = me.clip.placeholderapi.PlaceholderAPI.setRelationalPlaceholders(receiver, player, output);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!plugin.settingsManager.healthMessageOther.isEmpty()) {
|
if (!plugin.configStore.healthMessageOther.isEmpty()) {
|
||||||
output = plugin.settingsManager.healthMessageOther;
|
output = plugin.configStore.healthMessageOther;
|
||||||
}
|
}
|
||||||
|
|
||||||
output = output.replace("{displayname}", name);
|
output = output.replace("{displayname}", name);
|
||||||
|
@ -126,17 +123,17 @@ public class HealthUtil {
|
||||||
|
|
||||||
if (output.contains("{usestyle}")) {
|
if (output.contains("{usestyle}")) {
|
||||||
StringBuilder style = new StringBuilder();
|
StringBuilder style = new StringBuilder();
|
||||||
int left = plugin.settingsManager.limitHealth;
|
int left = plugin.configStore.limitHealth;
|
||||||
double heart = maxHealth / plugin.settingsManager.limitHealth;
|
double heart = maxHealth / plugin.configStore.limitHealth;
|
||||||
double halfHeart = heart / 2;
|
double halfHeart = heart / 2;
|
||||||
double tempHealth = health;
|
double tempHealth = health;
|
||||||
|
|
||||||
if (maxHealth != health && health >= 0 && !entity.isDead()) {
|
if (maxHealth != health && health >= 0 && !entity.isDead()) {
|
||||||
for (int i = 0; i < plugin.settingsManager.limitHealth; i++) {
|
for (int i = 0; i < plugin.configStore.limitHealth; i++) {
|
||||||
if (tempHealth - heart > 0) {
|
if (tempHealth - heart > 0) {
|
||||||
tempHealth = tempHealth - heart;
|
tempHealth = tempHealth - heart;
|
||||||
|
|
||||||
style.append(plugin.settingsManager.filledHeartIcon);
|
style.append(plugin.configStore.filledHeartIcon);
|
||||||
left--;
|
left--;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
@ -144,21 +141,21 @@ public class HealthUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tempHealth > halfHeart) {
|
if (tempHealth > halfHeart) {
|
||||||
style.append(plugin.settingsManager.filledHeartIcon);
|
style.append(plugin.configStore.filledHeartIcon);
|
||||||
left--;
|
left--;
|
||||||
} else if (tempHealth > 0 && tempHealth <= halfHeart) {
|
} else if (tempHealth > 0 && tempHealth <= halfHeart) {
|
||||||
style.append(plugin.settingsManager.halfHeartIcon);
|
style.append(plugin.configStore.halfHeartIcon);
|
||||||
left--;
|
left--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxHealth != health) {
|
if (maxHealth != health) {
|
||||||
for (int i = 0; i < left; i++) {
|
for (int i = 0; i < left; i++) {
|
||||||
style.append(plugin.settingsManager.emptyHeartIcon);
|
style.append(plugin.configStore.emptyHeartIcon);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < left; i++) {
|
for (int i = 0; i < left; i++) {
|
||||||
style.append(plugin.settingsManager.filledHeartIcon);
|
style.append(plugin.configStore.filledHeartIcon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,17 +169,17 @@ public class HealthUtil {
|
||||||
message = ChatColor.translateAlternateColorCodes('&', message);
|
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (plugin.settingsManager.mcVersion.equals("v1_12_R1") || plugin.settingsManager.mcVersion.startsWith("v1_13") || plugin.settingsManager.mcVersion.startsWith("v1_14_")) {
|
if (plugin.configStore.mcVersion.equals("v1_12_R1") || plugin.configStore.mcVersion.startsWith("v1_13") || plugin.configStore.mcVersion.startsWith("v1_14_")) {
|
||||||
new PreAction(player, message);
|
new PreAction(player, message);
|
||||||
} else if (!(plugin.settingsManager.mcVersion.equalsIgnoreCase("v1_8_R1") || (plugin.settingsManager.mcVersion.contains("v1_7_")))) {
|
} else if (!(plugin.configStore.mcVersion.equalsIgnoreCase("v1_8_R1") || (plugin.configStore.mcVersion.contains("v1_7_")))) {
|
||||||
Class<?> c1 = Class.forName("org.bukkit.craftbukkit." + plugin.settingsManager.mcVersion + ".entity.CraftPlayer");
|
Class<?> c1 = Class.forName("org.bukkit.craftbukkit." + plugin.configStore.mcVersion + ".entity.CraftPlayer");
|
||||||
Object p = c1.cast(player);
|
Object p = c1.cast(player);
|
||||||
Object ppoc;
|
Object ppoc;
|
||||||
Class<?> c4 = Class.forName("net.minecraft.server." + plugin.settingsManager.mcVersion + ".PacketPlayOutChat");
|
Class<?> c4 = Class.forName("net.minecraft.server." + plugin.configStore.mcVersion + ".PacketPlayOutChat");
|
||||||
Class<?> c5 = Class.forName("net.minecraft.server." + plugin.settingsManager.mcVersion + ".Packet");
|
Class<?> c5 = Class.forName("net.minecraft.server." + plugin.configStore.mcVersion + ".Packet");
|
||||||
|
|
||||||
Class<?> c2 = Class.forName("net.minecraft.server." + plugin.settingsManager.mcVersion + ".ChatComponentText");
|
Class<?> c2 = Class.forName("net.minecraft.server." + plugin.configStore.mcVersion + ".ChatComponentText");
|
||||||
Class<?> c3 = Class.forName("net.minecraft.server." + plugin.settingsManager.mcVersion + ".IChatBaseComponent");
|
Class<?> c3 = Class.forName("net.minecraft.server." + plugin.configStore.mcVersion + ".IChatBaseComponent");
|
||||||
Object o = c2.getConstructor(new Class<?>[]{String.class}).newInstance(message);
|
Object o = c2.getConstructor(new Class<?>[]{String.class}).newInstance(message);
|
||||||
ppoc = c4.getConstructor(new Class<?>[]{c3, byte.class}).newInstance(o, (byte) 2);
|
ppoc = c4.getConstructor(new Class<?>[]{c3, byte.class}).newInstance(o, (byte) 2);
|
||||||
|
|
||||||
|
@ -195,14 +192,14 @@ public class HealthUtil {
|
||||||
Method sendPacket = playerConnection.getClass().getDeclaredMethod("sendPacket", c5);
|
Method sendPacket = playerConnection.getClass().getDeclaredMethod("sendPacket", c5);
|
||||||
sendPacket.invoke(playerConnection, ppoc);
|
sendPacket.invoke(playerConnection, ppoc);
|
||||||
} else {
|
} else {
|
||||||
Class<?> c1 = Class.forName("org.bukkit.craftbukkit." + plugin.settingsManager.mcVersion + ".entity.CraftPlayer");
|
Class<?> c1 = Class.forName("org.bukkit.craftbukkit." + plugin.configStore.mcVersion + ".entity.CraftPlayer");
|
||||||
Object p = c1.cast(player);
|
Object p = c1.cast(player);
|
||||||
Object ppoc;
|
Object ppoc;
|
||||||
Class<?> c4 = Class.forName("net.minecraft.server." + plugin.settingsManager.mcVersion + ".PacketPlayOutChat");
|
Class<?> c4 = Class.forName("net.minecraft.server." + plugin.configStore.mcVersion + ".PacketPlayOutChat");
|
||||||
Class<?> c5 = Class.forName("net.minecraft.server." + plugin.settingsManager.mcVersion + ".Packet");
|
Class<?> c5 = Class.forName("net.minecraft.server." + plugin.configStore.mcVersion + ".Packet");
|
||||||
|
|
||||||
Class<?> c2 = Class.forName("net.minecraft.server." + plugin.settingsManager.mcVersion + ".ChatSerializer");
|
Class<?> c2 = Class.forName("net.minecraft.server." + plugin.configStore.mcVersion + ".ChatSerializer");
|
||||||
Class<?> c3 = Class.forName("net.minecraft.server." + plugin.settingsManager.mcVersion + ".IChatBaseComponent");
|
Class<?> c3 = Class.forName("net.minecraft.server." + plugin.configStore.mcVersion + ".IChatBaseComponent");
|
||||||
Method m3 = c2.getDeclaredMethod("a", String.class);
|
Method m3 = c2.getDeclaredMethod("a", String.class);
|
||||||
Object cbc = c3.cast(m3.invoke(c2, "{\"text\": \"" + message + "\"}"));
|
Object cbc = c3.cast(m3.invoke(c2, "{\"text\": \"" + message + "\"}"));
|
||||||
ppoc = c4.getConstructor(new Class<?>[]{c3, byte.class}).newInstance(cbc, (byte) 2);
|
ppoc = c4.getConstructor(new Class<?>[]{c3, byte.class}).newInstance(cbc, (byte) 2);
|
||||||
|
@ -226,11 +223,8 @@ public class HealthUtil {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegionContainer regionContainer = com.sk89q.worldguard.WorldGuard.getInstance().getPlatform().getRegionContainer();
|
for (String regionName : plugin.worldGuardAPI.getRegionNames(location)) {
|
||||||
RegionQuery regionQuery = regionContainer.createQuery();
|
if (plugin.configStore.regions.contains(regionName)) {
|
||||||
ApplicableRegionSet applicableRegions = regionQuery.getApplicableRegions(BukkitAdapter.adapt(location));
|
|
||||||
for (ProtectedRegion region : applicableRegions) {
|
|
||||||
if (plugin.settingsManager.regions.contains(region.getId())) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
package com.zeshanaslam.actionhealth;
|
package com.zeshanaslam.actionhealth.utils;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
@ -47,6 +46,10 @@ public class TargetHelper {
|
||||||
* @return all entities in the player's vision line
|
* @return all entities in the player's vision line
|
||||||
*/
|
*/
|
||||||
public static List<LivingEntity> getLivingTargets(LivingEntity source, double range, double tolerance) {
|
public static List<LivingEntity> getLivingTargets(LivingEntity source, double range, double tolerance) {
|
||||||
|
if (source == null) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
List<Entity> list = source.getNearbyEntities(range, range, range);
|
List<Entity> list = source.getNearbyEntities(range, range, range);
|
||||||
List<LivingEntity> targets = new ArrayList<LivingEntity>();
|
List<LivingEntity> targets = new ArrayList<LivingEntity>();
|
||||||
|
|
||||||
|
@ -157,6 +160,8 @@ public class TargetHelper {
|
||||||
* @return true if the target is in front of the entity
|
* @return true if the target is in front of the entity
|
||||||
*/
|
*/
|
||||||
public static boolean isInFront(Entity entity, Entity target) {
|
public static boolean isInFront(Entity entity, Entity target) {
|
||||||
|
if (entity.getWorld() != target.getWorld())
|
||||||
|
return false;
|
||||||
|
|
||||||
// Get the necessary vectors
|
// Get the necessary vectors
|
||||||
Vector facing = entity.getLocation().getDirection();
|
Vector facing = entity.getLocation().getDirection();
|
Loading…
Reference in New Issue
Block a user