Version 1.5.3-pre1:

* Prevent moving items to/from invsee gui
* Barrier item in invsee gui now closes gui when clicked
This commit is contained in:
PretzelJohn 2022-03-11 08:56:18 -05:00
parent ea98a911d3
commit 40c31a13c7
5 changed files with 41 additions and 22 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.pretzel.dev</groupId>
<artifactId>VillagerTradeLimiter</artifactId>
<version>1.5.2</version>
<version>1.5.3</version>
<properties>
<java.version>1.8</java.version>
@ -46,7 +46,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.27</version>
<version>8.0.28</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -15,6 +15,7 @@ import com.pretzel.dev.villagertradelimiter.settings.Settings;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
@ -117,4 +118,7 @@ public class VillagerTradeLimiter extends JavaPlugin {
/** Returns a player's data container */
public HashMap<UUID, PlayerData> getPlayerData() { return this.playerData; }
/** Returns the invsee inventory's barrier block */
public ItemStack getBarrier() { return this.commandManager.getBarrier(); }
}

View File

@ -19,10 +19,18 @@ import java.util.Arrays;
public class CommandManager {
private final VillagerTradeLimiter instance;
private final ItemStack barrier;
/** @param instance The instance of VillagerTradeLimiter.java */
public CommandManager(final VillagerTradeLimiter instance) {
this.instance = instance;
this.barrier = new ItemStack(Material.BARRIER, 1);
ItemMeta meta = barrier.getItemMeta();
if(meta != null) {
meta.setDisplayName(ChatColor.RED+"Close");
meta.setLore(Arrays.asList(ChatColor.GRAY+"Click to close", ChatColor.GRAY+"this inventory."));
}
barrier.setItemMeta(meta);
}
/** @return The root command node, to be registered by the plugin */
@ -53,10 +61,7 @@ public class CommandManager {
//Get the closest villager. If a nearby villager wasn't found, send the player an error message
Entity closestEntity = getClosestEntity(p);
if(closestEntity == null) {
Util.sendMsg(instance.getLang("see.novillager"), p);
return;
}
if(closestEntity == null) return;
//Gets the other player by name, using the first argument of the command
OfflinePlayer otherPlayer = Bukkit.getOfflinePlayer(args[0]);
@ -80,10 +85,7 @@ public class CommandManager {
//Get the closest villager. If a nearby villager wasn't found, send the player an error message
Entity closestEntity = getClosestEntity(p);
if(closestEntity == null) {
Util.sendMsg(instance.getLang("see.novillager"), p);
return;
}
if(closestEntity == null) return;
//Open the villager's inventory view for the calling player
final Villager closestVillager = (Villager)closestEntity;
@ -92,7 +94,7 @@ public class CommandManager {
if(item == null) continue;
inventory.addItem(item.clone());
}
inventory.setItem(8, getBarrier());
inventory.setItem(8, barrier);
p.openInventory(inventory);
}));
return cmd;
@ -117,6 +119,9 @@ public class CommandManager {
}
}
}
if(closestEntity == null) {
Util.sendMsg(instance.getLang("see.novillager"), player);
}
return closestEntity;
}
@ -140,15 +145,8 @@ public class CommandManager {
}
}
/** @return A custom barrier block to show players villagers only have 8 inventory slots */
private ItemStack getBarrier() {
ItemStack barrier = new ItemStack(Material.BARRIER, 1);
ItemMeta meta = barrier.getItemMeta();
if(meta != null) {
meta.setDisplayName(ChatColor.RED+"N/A");
meta.setLore(Arrays.asList(ChatColor.GRAY+"Villagers only have", ChatColor.GRAY+"8 inventory slots!"));
}
barrier.setItemMeta(meta);
return barrier;
/** @return The barrier item */
public ItemStack getBarrier() {
return this.barrier;
}
}

View File

@ -35,6 +35,23 @@ public class InventoryListener implements Listener {
this.settings = settings;
}
/** Handles when a player clicks in an inventory window */
@EventHandler
public void onPlayerClickInventory(final InventoryClickEvent event) {
if(event.getInventory().getType() != InventoryType.CHEST) return;
if(event.getInventory().getSize() != 9) return;
if(!(event.getWhoClicked() instanceof Player)) return;
if(settings.shouldSkipNPC(event.getWhoClicked())) return; //Skips NPCs
ItemStack barrier = event.getInventory().getItem(8);
if(barrier == null || !barrier.isSimilar(instance.getBarrier())) return;
//If the inventory matches the invsee inventory, cancel click events
event.setCancelled(true);
if(event.getCurrentItem() != null && event.getCurrentItem().isSimilar(instance.getBarrier())) {
Bukkit.getScheduler().runTaskLater(instance, () -> event.getWhoClicked().closeInventory(), 0L);
}
}
/** Handles when a player stops trading with a villager */
@EventHandler
public void onPlayerStopTrading(final InventoryCloseEvent event) {

View File

@ -1,7 +1,7 @@
name: VillagerTradeLimiter
author: PretzelJohn
main: com.pretzel.dev.villagertradelimiter.VillagerTradeLimiter
version: 1.5.2
version: 1.5.3
api-version: 1.14
commands: