Skip to content

Commit

Permalink
essentials vanish support and dont let people accept in cancelled trades
Browse files Browse the repository at this point in the history
  • Loading branch information
Trophonix committed Aug 12, 2020
1 parent 851135e commit 5e8599f
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 11 deletions.
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<properties>
<res>${project.basedir}/res/</res>
<revision>3.78.2</revision>
<revision>3.78.3</revision>
</properties>

<repositories>
Expand Down Expand Up @@ -190,6 +190,14 @@
<version>LATEST</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.earth2me</groupId>
<artifactId>essentials</artifactId>
<version>2.18.0.0</version>
<scope>system</scope>
<systemPath>${res}/EssentialsX-2.18.0.0.jar</systemPath>
</dependency>
</dependencies>

<build>
Expand Down
Binary file added res/._EssentialsX-2.18.0.0.jar
Binary file not shown.
Binary file added res/EssentialsX-2.18.0.0.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions src/main/java/com/trophonix/tradeplus/TradePlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.concurrent.ConcurrentLinkedQueue;

public class TradePlus extends JavaPlugin {

public ConcurrentLinkedQueue<Trade> ongoingTrades = new ConcurrentLinkedQueue<>();
@Getter private TaskChainFactory taskFactory;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public List<String> onTabComplete(CommandSender sender, String[] args, String fu
List<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -116,6 +117,7 @@ public List<String> 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 ->
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/trophonix/tradeplus/hooks/EssentialsHook.java
Original file line number Diff line number Diff line change
@@ -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();
}

}
15 changes: 8 additions & 7 deletions src/main/java/com/trophonix/tradeplus/trade/Trade.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/trophonix/tradeplus/util/PlayerUtil.java
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down

0 comments on commit 5e8599f

Please sign in to comment.