mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Fixes #2205
This commit is contained in:
parent
16306c3472
commit
66f4c48b4b
@ -57,6 +57,7 @@
|
||||
* Fixed #2122
|
||||
* Fixed #2168
|
||||
* Fixed #2203
|
||||
* Fixed #2205
|
||||
|
||||
## Release Candidate 15 (01 Aug 2020)
|
||||
|
||||
|
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>io.github.thebusybiscuit</groupId>
|
||||
<groupId>com.github.thebusybiscuit</groupId>
|
||||
<artifactId>Slimefun</artifactId>
|
||||
|
||||
<!-- Our default version will be UNOFFICIAL, this will prevent auto updates -->
|
||||
|
@ -82,6 +82,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.listeners.SoulboundList
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.TalismanListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.VampireBladeListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.VanillaMachinesListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.VillagerTradingListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.WitherListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.WorldListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.resources.GEOResourcesSetup;
|
||||
@ -442,6 +443,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
||||
new IronGolemListener(this);
|
||||
new PlayerInteractEntityListener(this);
|
||||
new MobDropListener(this);
|
||||
new VillagerTradingListener(this);
|
||||
|
||||
if (minecraftVersion.isAtLeast(MinecraftVersion.MINECRAFT_1_15)) {
|
||||
new BeeListener(this);
|
||||
|
@ -0,0 +1,29 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.items.misc;
|
||||
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.VillagerTradingListener;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
* The {@link SyntheticEmerald} is an almost normal emerald.
|
||||
* It can even be used to trade with {@link Villager Villagers}.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
* @see VillagerTradingListener
|
||||
*
|
||||
*/
|
||||
public class SyntheticEmerald extends SlimefunItem {
|
||||
|
||||
public SyntheticEmerald(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||
super(category, item, recipeType, recipe);
|
||||
|
||||
setUseableInWorkbench(true);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.listeners;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.SyntheticEmerald;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
|
||||
/**
|
||||
* This {@link Listener} prevents any {@link SlimefunItem} from being used to trade with
|
||||
* Villagers, with one exception being {@link SyntheticEmerald}.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
*/
|
||||
public class VillagerTradingListener implements Listener {
|
||||
|
||||
public VillagerTradingListener(SlimefunPlugin plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPreBrew(InventoryClickEvent e) {
|
||||
Inventory clickedInventory = e.getClickedInventory();
|
||||
Inventory topInventory = e.getView().getTopInventory();
|
||||
|
||||
if (clickedInventory != null && topInventory.getType() == InventoryType.MERCHANT) {
|
||||
if (e.getAction() == InventoryAction.HOTBAR_SWAP) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (clickedInventory.getType() == InventoryType.MERCHANT) {
|
||||
e.setCancelled(isUnallowed(SlimefunItem.getByItem(e.getCursor())));
|
||||
}
|
||||
else {
|
||||
e.setCancelled(isUnallowed(SlimefunItem.getByItem(e.getCurrentItem())));
|
||||
}
|
||||
|
||||
if (e.getResult() == Result.DENY) {
|
||||
SlimefunPlugin.getLocalization().sendMessage((Player) e.getWhoClicked(), "villagers.no-trading", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isUnallowed(SlimefunItem item) {
|
||||
return item != null && !(item instanceof VanillaItem) && !(item instanceof SyntheticEmerald) && !item.isDisabled();
|
||||
}
|
||||
}
|
@ -144,6 +144,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.misc.BasicCircuit
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.CoolantCell;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.OrganicFertilizer;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.OrganicFood;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.SyntheticEmerald;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.ArmorForge;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.AutomatedPanningMachine;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.Compressor;
|
||||
@ -867,9 +868,8 @@ public final class SlimefunItemSetup {
|
||||
new ItemStack[] {SlimefunItems.GOLD_24K, SlimefunItems.IRON_DUST, null, null, null, null, null, null, null})
|
||||
.register(plugin);
|
||||
|
||||
new SlimefunItem(categories.resources, SlimefunItems.SYNTHETIC_EMERALD, RecipeType.SMELTERY,
|
||||
new SyntheticEmerald(categories.resources, SlimefunItems.SYNTHETIC_EMERALD, RecipeType.SMELTERY,
|
||||
new ItemStack[] {SlimefunItems.SYNTHETIC_SAPPHIRE, SlimefunItems.ALUMINUM_DUST, SlimefunItems.ALUMINUM_INGOT, new ItemStack(Material.GLASS_PANE), null, null, null, null, null})
|
||||
.setUseableInWorkbench(true)
|
||||
.register(plugin);
|
||||
|
||||
registerArmorSet(categories.armor, SlimefunItems.CHAIN, new ItemStack[] {
|
||||
|
@ -235,6 +235,9 @@ anvil:
|
||||
brewing_stand:
|
||||
not-working: '&4You cannot use Slimefun Items in a brewing stand!'
|
||||
|
||||
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'
|
||||
@ -248,6 +251,7 @@ gps:
|
||||
new: '&ePlease type in a name for your new waypoint in the chat. &7(Color Codes supported!)'
|
||||
added: '&aSuccessfully added a new waypoint'
|
||||
max: '&4You have reached the maximum amount of waypoints'
|
||||
duplicate: '&4You have already created a waypoint named: &f%waypoint%'
|
||||
|
||||
insufficient-complexity:
|
||||
- '&4Insufficient GPS Network Complexity: &c%complexity%'
|
||||
|
@ -0,0 +1,97 @@
|
||||
package io.github.thebusybiscuit.slimefun4.testing.tests.listeners;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.inventory.InventoryType.SlotType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.ServerMock;
|
||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.SyntheticEmerald;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.VillagerTradingListener;
|
||||
import io.github.thebusybiscuit.slimefun4.testing.TestUtilities;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
class TestVillagerTradingListener {
|
||||
|
||||
private static SlimefunPlugin plugin;
|
||||
private static VillagerTradingListener listener;
|
||||
private static ServerMock server;
|
||||
|
||||
@BeforeAll
|
||||
public static void load() {
|
||||
server = MockBukkit.mock();
|
||||
plugin = MockBukkit.load(SlimefunPlugin.class);
|
||||
listener = new VillagerTradingListener(plugin);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void unload() {
|
||||
MockBukkit.unmock();
|
||||
}
|
||||
|
||||
private InventoryClickEvent mockClickEvent(ItemStack item) {
|
||||
Player player = server.addPlayer();
|
||||
Inventory inv = TestUtilities.mockInventory(InventoryType.MERCHANT);
|
||||
Mockito.when(inv.getSize()).thenReturn(8);
|
||||
|
||||
InventoryView view = player.openInventory(inv);
|
||||
view.setCursor(item);
|
||||
InventoryClickEvent event = new InventoryClickEvent(view, SlotType.CONTAINER, 1, ClickType.LEFT, InventoryAction.PICKUP_ONE);
|
||||
listener.onPreBrew(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTradingWithoutSlimefunItems() {
|
||||
InventoryClickEvent event = mockClickEvent(new ItemStack(Material.EMERALD));
|
||||
Assertions.assertEquals(Result.ALLOW, event.getResult());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTradingWithSlimefunItem() {
|
||||
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "MOCKED_FAKE_EMERALD", new CustomItem(Material.EMERALD, "&aFake Emerald"));
|
||||
item.register(plugin);
|
||||
|
||||
InventoryClickEvent event = mockClickEvent(item.getItem());
|
||||
Assertions.assertEquals(Result.DENY, event.getResult());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTradingWithVanillaItem() {
|
||||
VanillaItem item = TestUtilities.mockVanillaItem(plugin, Material.EMERALD, true);
|
||||
item.register(plugin);
|
||||
|
||||
InventoryClickEvent event = mockClickEvent(item.getItem());
|
||||
Assertions.assertEquals(Result.ALLOW, event.getResult());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTradingWithSyntheticEmerald() {
|
||||
Category category = TestUtilities.getCategory(plugin, "shiny_emeralds");
|
||||
SlimefunItemStack stack = new SlimefunItemStack("FAKE_EMERALD", Material.EMERALD, "&aTrade me");
|
||||
SyntheticEmerald item = new SyntheticEmerald(category, stack, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[9]);
|
||||
item.register(plugin);
|
||||
|
||||
InventoryClickEvent event = mockClickEvent(item.getItem());
|
||||
Assertions.assertEquals(Result.ALLOW, event.getResult());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user