diff --git a/pom.xml b/pom.xml index ee71d5d..4c3fc97 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ ${project.basedir}/res/ - 3.78.2 + 3.78.3 @@ -190,6 +190,14 @@ LATEST provided + + + com.earth2me + essentials + 2.18.0.0 + system + ${res}/EssentialsX-2.18.0.0.jar + diff --git a/res/._EssentialsX-2.18.0.0.jar b/res/._EssentialsX-2.18.0.0.jar new file mode 100644 index 0000000..eea906f Binary files /dev/null and b/res/._EssentialsX-2.18.0.0.jar differ diff --git a/res/EssentialsX-2.18.0.0.jar b/res/EssentialsX-2.18.0.0.jar new file mode 100644 index 0000000..1ffb825 Binary files /dev/null and b/res/EssentialsX-2.18.0.0.jar differ diff --git a/src/main/java/com/trophonix/tradeplus/TradePlus.java b/src/main/java/com/trophonix/tradeplus/TradePlus.java index 706e40a..e57fef8 100644 --- a/src/main/java/com/trophonix/tradeplus/TradePlus.java +++ b/src/main/java/com/trophonix/tradeplus/TradePlus.java @@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; public class TradePlus extends JavaPlugin { + public ConcurrentLinkedQueue ongoingTrades = new ConcurrentLinkedQueue<>(); @Getter private TaskChainFactory taskFactory; @@ -63,8 +64,6 @@ public void onLoad() { @Override public void onEnable() { - Bukkit.getScheduler().runTaskTimer(this, () -> logs.save(), 5 * 60 * 20, 5 * 60 * 20); - tradeConfig = new TradePlusConfig(this); taskFactory = BukkitTaskChainFactory.create(this); taskFactory @@ -107,6 +106,7 @@ public void reload() { if (logs == null && tradeConfig.isTradeLogs()) { try { logs = new Logs(new File(getDataFolder(), "logs")); + Bukkit.getScheduler().runTaskTimer(this, () -> logs.save(), 5 * 60 * 20, 5 * 60 * 20); log("Initialized trade logger."); } catch (IOException ex) { log("Failed to load trade logger. " + ex.getMessage()); diff --git a/src/main/java/com/trophonix/tradeplus/commands/TradeCommand.java b/src/main/java/com/trophonix/tradeplus/commands/TradeCommand.java index d96fe13..44fa9b3 100644 --- a/src/main/java/com/trophonix/tradeplus/commands/TradeCommand.java +++ b/src/main/java/com/trophonix/tradeplus/commands/TradeCommand.java @@ -217,7 +217,7 @@ public List onTabComplete(CommandSender sender, String[] args, String fu List args0 = new ArrayList<>(); args0.add("deny"); args0.addAll( - Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList())); + Bukkit.getOnlinePlayers().stream().filter(p -> !PlayerUtil.isVanished(p)).map(Player::getName).collect(Collectors.toList())); if (args.length == 0) { return args0; } else if (args.length == 1) { diff --git a/src/main/java/com/trophonix/tradeplus/commands/TradePlusCommand.java b/src/main/java/com/trophonix/tradeplus/commands/TradePlusCommand.java index 26dc477..4cdca19 100644 --- a/src/main/java/com/trophonix/tradeplus/commands/TradePlusCommand.java +++ b/src/main/java/com/trophonix/tradeplus/commands/TradePlusCommand.java @@ -3,6 +3,7 @@ import com.trophonix.tradeplus.TradePlus; import com.trophonix.tradeplus.trade.Trade; import com.trophonix.tradeplus.util.MsgUtils; +import com.trophonix.tradeplus.util.PlayerUtil; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -116,6 +117,7 @@ public List onTabComplete(CommandSender sender, String[] args, String fu && !full.endsWith(" ") && (args[0].equalsIgnoreCase("force") || args[0].equalsIgnoreCase("spectate"))) { return Bukkit.getOnlinePlayers().stream() + .filter(p -> !PlayerUtil.isVanished(p)) .map(Player::getName) .filter( name -> diff --git a/src/main/java/com/trophonix/tradeplus/hooks/EssentialsHook.java b/src/main/java/com/trophonix/tradeplus/hooks/EssentialsHook.java new file mode 100644 index 0000000..daf658c --- /dev/null +++ b/src/main/java/com/trophonix/tradeplus/hooks/EssentialsHook.java @@ -0,0 +1,16 @@ +package com.trophonix.tradeplus.hooks; + +import com.earth2me.essentials.Essentials; +import com.earth2me.essentials.User; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class EssentialsHook { + + public static boolean isVanished(Player player) { + Essentials essentials = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials"); + User user = essentials.getUser(player); + return user.isVanished(); + } + +} diff --git a/src/main/java/com/trophonix/tradeplus/trade/Trade.java b/src/main/java/com/trophonix/tradeplus/trade/Trade.java index d20f408..d7ecbb9 100644 --- a/src/main/java/com/trophonix/tradeplus/trade/Trade.java +++ b/src/main/java/com/trophonix/tradeplus/trade/Trade.java @@ -228,19 +228,20 @@ public void onClick(InventoryClickEvent event) { event.setCancelled(true); return; } + + // don't let players interact + // with a cancelled trade window + if (cancelled) { + event.setCancelled(true); + return; + } + // if it's in the left side, // the event will affect the // player's trade if (slot != pl.getTradeConfig().getAcceptSlot() && pl.getTradeConfig().getMySlots().contains(slot) && getExtra(slot) == null) { - // don't let players interact - // with a cancelled trade window - if (cancelled) { - event.setCancelled(true); - return; - } - if (accept1 && accept2) { event.setCancelled(true); return; diff --git a/src/main/java/com/trophonix/tradeplus/util/PlayerUtil.java b/src/main/java/com/trophonix/tradeplus/util/PlayerUtil.java index 602fc38..106750d 100644 --- a/src/main/java/com/trophonix/tradeplus/util/PlayerUtil.java +++ b/src/main/java/com/trophonix/tradeplus/util/PlayerUtil.java @@ -1,11 +1,17 @@ package com.trophonix.tradeplus.util; +import com.trophonix.tradeplus.hooks.EssentialsHook; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.metadata.MetadataValue; public class PlayerUtil { public static boolean isVanished(Player player) { + if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) { + if (EssentialsHook.isVanished(player)) return true; + } + for (MetadataValue meta : player.getMetadata("vanished")) { if (meta.asBoolean()) return true; }