mirror of
https://github.com/PretzelJohn/VillagerTradeLimiter.git
synced 2024-12-05 00:23:29 +01:00
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:
parent
ea98a911d3
commit
40c31a13c7
4
pom.xml
4
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.pretzel.dev</groupId>
|
<groupId>com.pretzel.dev</groupId>
|
||||||
<artifactId>VillagerTradeLimiter</artifactId>
|
<artifactId>VillagerTradeLimiter</artifactId>
|
||||||
<version>1.5.2</version>
|
<version>1.5.3</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
@ -46,7 +46,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
<version>8.0.27</version>
|
<version>8.0.28</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -15,6 +15,7 @@ import com.pretzel.dev.villagertradelimiter.settings.Settings;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -117,4 +118,7 @@ public class VillagerTradeLimiter extends JavaPlugin {
|
|||||||
|
|
||||||
/** Returns a player's data container */
|
/** Returns a player's data container */
|
||||||
public HashMap<UUID, PlayerData> getPlayerData() { return this.playerData; }
|
public HashMap<UUID, PlayerData> getPlayerData() { return this.playerData; }
|
||||||
|
|
||||||
|
/** Returns the invsee inventory's barrier block */
|
||||||
|
public ItemStack getBarrier() { return this.commandManager.getBarrier(); }
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,18 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
public class CommandManager {
|
public class CommandManager {
|
||||||
private final VillagerTradeLimiter instance;
|
private final VillagerTradeLimiter instance;
|
||||||
|
private final ItemStack barrier;
|
||||||
|
|
||||||
/** @param instance The instance of VillagerTradeLimiter.java */
|
/** @param instance The instance of VillagerTradeLimiter.java */
|
||||||
public CommandManager(final VillagerTradeLimiter instance) {
|
public CommandManager(final VillagerTradeLimiter instance) {
|
||||||
this.instance = 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 */
|
/** @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
|
//Get the closest villager. If a nearby villager wasn't found, send the player an error message
|
||||||
Entity closestEntity = getClosestEntity(p);
|
Entity closestEntity = getClosestEntity(p);
|
||||||
if(closestEntity == null) {
|
if(closestEntity == null) return;
|
||||||
Util.sendMsg(instance.getLang("see.novillager"), p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Gets the other player by name, using the first argument of the command
|
//Gets the other player by name, using the first argument of the command
|
||||||
OfflinePlayer otherPlayer = Bukkit.getOfflinePlayer(args[0]);
|
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
|
//Get the closest villager. If a nearby villager wasn't found, send the player an error message
|
||||||
Entity closestEntity = getClosestEntity(p);
|
Entity closestEntity = getClosestEntity(p);
|
||||||
if(closestEntity == null) {
|
if(closestEntity == null) return;
|
||||||
Util.sendMsg(instance.getLang("see.novillager"), p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Open the villager's inventory view for the calling player
|
//Open the villager's inventory view for the calling player
|
||||||
final Villager closestVillager = (Villager)closestEntity;
|
final Villager closestVillager = (Villager)closestEntity;
|
||||||
@ -92,7 +94,7 @@ public class CommandManager {
|
|||||||
if(item == null) continue;
|
if(item == null) continue;
|
||||||
inventory.addItem(item.clone());
|
inventory.addItem(item.clone());
|
||||||
}
|
}
|
||||||
inventory.setItem(8, getBarrier());
|
inventory.setItem(8, barrier);
|
||||||
p.openInventory(inventory);
|
p.openInventory(inventory);
|
||||||
}));
|
}));
|
||||||
return cmd;
|
return cmd;
|
||||||
@ -117,6 +119,9 @@ public class CommandManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(closestEntity == null) {
|
||||||
|
Util.sendMsg(instance.getLang("see.novillager"), player);
|
||||||
|
}
|
||||||
return closestEntity;
|
return closestEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,15 +145,8 @@ public class CommandManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return A custom barrier block to show players villagers only have 8 inventory slots */
|
/** @return The barrier item */
|
||||||
private ItemStack getBarrier() {
|
public ItemStack getBarrier() {
|
||||||
ItemStack barrier = new ItemStack(Material.BARRIER, 1);
|
return this.barrier;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,23 @@ public class InventoryListener implements Listener {
|
|||||||
this.settings = settings;
|
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 */
|
/** Handles when a player stops trading with a villager */
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerStopTrading(final InventoryCloseEvent event) {
|
public void onPlayerStopTrading(final InventoryCloseEvent event) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
name: VillagerTradeLimiter
|
name: VillagerTradeLimiter
|
||||||
author: PretzelJohn
|
author: PretzelJohn
|
||||||
main: com.pretzel.dev.villagertradelimiter.VillagerTradeLimiter
|
main: com.pretzel.dev.villagertradelimiter.VillagerTradeLimiter
|
||||||
version: 1.5.2
|
version: 1.5.3
|
||||||
api-version: 1.14
|
api-version: 1.14
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
|
Loading…
Reference in New Issue
Block a user