1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Merge pull request #2377 from poma123/fix/cartography-table fixes #2357

Cartography Table fix
This commit is contained in:
TheBusyBiscuit 2020-10-03 21:29:26 +02:00 committed by GitHub
commit b6a3b38294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 6 deletions

View File

@ -41,8 +41,7 @@ public class VanillaMachinesListener implements Listener {
@EventHandler(ignoreCancelled = true)
public void onGrindstone(InventoryClickEvent e) {
// The Grindstone was only ever added in MC 1.14
MinecraftVersion minecraftVersion = SlimefunPlugin.getMinecraftVersion();
if (!minecraftVersion.isAtLeast(MinecraftVersion.MINECRAFT_1_14)) {
if (!SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14)) {
return;
}
@ -97,6 +96,24 @@ public class VanillaMachinesListener implements Listener {
}
}
@EventHandler(ignoreCancelled = true)
public void onCartographyTable(InventoryClickEvent e) {
// The Cartography Table was only ever added in MC 1.14
if (!SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14)) {
return;
}
if (e.getRawSlot() == 2 && e.getInventory().getType() == InventoryType.CARTOGRAPHY && e.getWhoClicked() instanceof Player) {
ItemStack item1 = e.getInventory().getContents()[0];
ItemStack item2 = e.getInventory().getContents()[1];
if (checkForUnallowedItems(item1, item2)) {
e.setResult(Result.DENY);
SlimefunPlugin.getLocalization().sendMessage((Player) e.getWhoClicked(), "cartography_table.not-working", true);
}
}
}
@EventHandler(ignoreCancelled = true)
public void onPreBrew(InventoryClickEvent e) {
Inventory clickedInventory = e.getClickedInventory();

View File

@ -260,20 +260,23 @@ machines:
finished: '&eYour Industrial Miner has finished! It obtained a total of %ores% ore(s)!'
anvil:
not-working: '&4You cannot use Slimefun Items in an anvil!'
not-working: '&4You cannot use Slimefun items in an anvil!'
brewing_stand:
not-working: '&4You cannot use Slimefun Items in a brewing stand!'
not-working: '&4You cannot use Slimefun items in a brewing stand!'
cartography_table:
not-working: '&4You cannot use Slimefun items in a cartography table!'
villagers:
no-trading: '&4You cannot trade Slimefun Items with Villagers!'
no-trading: '&4You cannot trade Slimefun items with Villagers!'
backpack:
already-open: '&cSorry, this Backpack is open somewhere else!'
no-stack: '&cYou cannot stack Backpacks'
workbench:
not-enhanced: '&4You cannot use Slimefun Items in a normal workbench'
not-enhanced: '&4You cannot use Slimefun items in a normal workbench'
gps:
deathpoint: '&4Deathpoint &7%date%'

View File

@ -76,6 +76,16 @@ public class TestVanillaMachinesListener {
return event;
}
private InventoryClickEvent mockCartographyTableEvent(ItemStack item) {
Player player = server.addPlayer();
Inventory inv = TestUtilities.mockInventory(InventoryType.CARTOGRAPHY, new ItemStack(Material.FILLED_MAP), item, new ItemStack(Material.FILLED_MAP));
InventoryView view = player.openInventory(inv);
InventoryClickEvent event = new InventoryClickEvent(view, SlotType.CONTAINER, 2, ClickType.LEFT, InventoryAction.PICKUP_ONE);
listener.onCartographyTable(event);
return event;
}
private InventoryClickEvent mockBrewingEvent(ItemStack item) {
Player player = server.addPlayer();
Inventory inv = TestUtilities.mockInventory(InventoryType.BREWING);
@ -242,6 +252,30 @@ public class TestVanillaMachinesListener {
Assertions.assertEquals(Result.DEFAULT, event.getResult());
}
@Test
public void testCartographyTableWithoutSlimefunItems() {
InventoryClickEvent event = mockCartographyTableEvent(new ItemStack(Material.PAPER));
Assertions.assertEquals(Result.DEFAULT, event.getResult());
}
@Test
public void testCartographyTableWithSlimefunItem() {
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "MOCKED_PAPER", new CustomItem(Material.PAPER, "&6Mock"));
item.register(plugin);
InventoryClickEvent event = mockCartographyTableEvent(item.getItem());
Assertions.assertEquals(Result.DENY, event.getResult());
}
@Test
public void testCartographyTableWithVanillaItem() {
VanillaItem item = TestUtilities.mockVanillaItem(plugin, Material.PAPER, true);
item.register(plugin);
InventoryClickEvent event = mockCartographyTableEvent(item.getItem());
Assertions.assertEquals(Result.DEFAULT, event.getResult());
}
@Test
public void testBrewingWithoutSlimefunItems() {
InventoryClickEvent event = mockBrewingEvent(new ItemStack(Material.BLAZE_POWDER));