Skip to content
This repository was archived by the owner on Aug 13, 2022. It is now read-only.

Commit 1ab51bf

Browse files
committed
Merge branch 'main' of github.com:Invvk/WorldGuardExtraFlags into main
2 parents 914adfa + 9bb024a commit 1ab51bf

File tree

7 files changed

+62
-3
lines changed

7 files changed

+62
-3
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ body:
8282
label: Checklist
8383
description: Make sure you have followed each of the steps outlined here.
8484
options:
85-
- label: I'm using java 16 and running my server in 1.17.1
85+
- label: I'm using java 16+ and running my server in 1.17.1+
8686
required: true
8787
- label: I am using the newest build from https://github.com/Invvk/WorldGuardExtraFlagsPlugin/releases and the issue still persists.
8888
required: true

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
blank_issues_enabled: false
22
contact_links:
3+
- name: WGEF Wiki
4+
url: https://github.com/Invvk/WorldGuardExtraFlags/wiki
5+
about: WGEF Wiki page, please view it before asking for help
36
- name: VVKs Discord
47
url: https://discord.gg/xcFJvXYsnD
58
about: Our support Discord, please ask questions and seek support here.

WGEF-Abstraction/src/main/java/io/github/invvk/wgef/abstraction/WGEFUtils.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.sk89q.worldedit.bukkit.BukkitPlayer;
44
import com.sk89q.worldguard.LocalPlayer;
5+
import com.sk89q.worldguard.protection.ApplicableRegionSet;
56
import com.sk89q.worldguard.protection.FlagValueCalculator;
67
import com.sk89q.worldguard.protection.flags.Flag;
78
import com.sk89q.worldguard.protection.flags.StateFlag;
@@ -40,6 +41,14 @@ public static boolean hasBypass(Player player, World world, ProtectedRegion regi
4041
return player.hasPermission("worldguard.region.bypass." + world.getName() + "." + region.getId() + "." + flag.getName());
4142
}
4243

44+
public static boolean isPartOfRegion(Player bukkitPlayer, ApplicableRegionSet set) {
45+
final LocalPlayer player = wrapPlayer(bukkitPlayer);
46+
for (ProtectedRegion region: set)
47+
if (region.isMember(player) || region.isOwner(player))
48+
return true;
49+
return false;
50+
}
51+
4352
public static StateFlag.State queryState(Player player, World world, Set<ProtectedRegion> regions, StateFlag flag) {
4453
return WGEFUtils.createFlagValueCalculator(player, world, regions, flag)
4554
.queryState(WGEFUtils.wrapPlayer(player), flag);

WGEF-Abstraction/src/main/java/io/github/invvk/wgef/abstraction/flags/WGEFlags.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,6 @@ public final class WGEFlags {
5151

5252
public final static StateFlag ITEM_DURABILITY = new StateFlag("item-durability", true);
5353

54+
public final static StateFlag VILLAGER_TRADE = new StateFlag("villager-trade", true);
55+
5456
}

WGEF-Core/src/main/java/io/github/invvk/wgef/WGPluginManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public void load() {
7070
registry.register(WGEFlags.FLY_SPEED);
7171
registry.register(WGEFlags.NETHER_PORTALS);
7272
registry.register(WGEFlags.ITEM_DURABILITY);
73+
registry.register(WGEFlags.VILLAGER_TRADE);
7374

7475
this.dependency();
7576
}
@@ -111,7 +112,8 @@ public void enable() {
111112
new DeathListener(this.plugin),
112113
new NetherPortalListener(this.plugin),
113114
new ItemListener(this.plugin),
114-
new SpeedListener(this.plugin));
115+
new SpeedListener(this.plugin),
116+
new VillagerTradeListener(this.plugin));
115117
}
116118

117119
@Override
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package io.github.invvk.wgef.listeners;
2+
3+
import com.sk89q.worldguard.protection.ApplicableRegionSet;
4+
import com.sk89q.worldguard.protection.flags.StateFlag;
5+
import io.github.invvk.wgef.WGEFPlugin;
6+
import io.github.invvk.wgef.abstraction.WGEFUtils;
7+
import io.github.invvk.wgef.abstraction.flags.WGEFlags;
8+
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftVillager;
9+
import org.bukkit.entity.Player;
10+
import org.bukkit.entity.Villager;
11+
import org.bukkit.event.EventHandler;
12+
import org.bukkit.event.Listener;
13+
import org.bukkit.event.inventory.InventoryOpenEvent;
14+
import org.bukkit.event.inventory.InventoryType;
15+
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
16+
import org.bukkit.event.player.PlayerInteractEntityEvent;
17+
import org.bukkit.inventory.InventoryHolder;
18+
19+
public class VillagerTradeListener implements Listener {
20+
21+
private final WGEFPlugin plugin;
22+
23+
public VillagerTradeListener(WGEFPlugin plugin) {
24+
this.plugin = plugin;
25+
}
26+
27+
@EventHandler
28+
public void onInteract(PlayerInteractEntityEvent event) {
29+
if (event.getRightClicked() instanceof Villager villager) {
30+
final Player player = event.getPlayer();
31+
final ApplicableRegionSet set =
32+
plugin.getFork().getRegionContainer().createQuery().getApplicableRegions(villager.getLocation());
33+
34+
if (WGEFUtils.isPartOfRegion(player, set))
35+
return;
36+
37+
final StateFlag.State state = WGEFUtils.queryState(player, player.getWorld(), set.getRegions(), WGEFlags.VILLAGER_TRADE);
38+
if (WGEFUtils.isDeny(state))
39+
event.setCancelled(true);
40+
}
41+
}
42+
43+
}

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ subprojects {
4747
}
4848

4949
dependencies {
50-
compileOnly 'org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT'
50+
compileOnly 'org.spigotmc:spigot:1.17-R0.1-SNAPSHOT'
5151

5252
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.6'
5353

0 commit comments

Comments
 (0)