1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 11:45:51 +00:00

Merge branch 'master' into legacy-gold-pan

This commit is contained in:
KyleEstein 2021-09-30 08:46:22 -04:00 committed by GitHub
commit 84dc096393
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 203 additions and 5 deletions

View File

@ -41,6 +41,8 @@
* Fixed #3218 * Fixed #3218
* Fixed #3241 * Fixed #3241
* Fixed #3248 * Fixed #3248
* Fixed #3273
* Fixed an exploit regarding the Smithing Table
## Release Candidate 28 (06 Sep 2021) ## Release Candidate 28 (06 Sep 2021)

View File

@ -388,7 +388,7 @@
<dependency> <dependency>
<groupId>com.github.seeseemelk</groupId> <groupId>com.github.seeseemelk</groupId>
<artifactId>MockBukkit-v1.16</artifactId> <artifactId>MockBukkit-v1.16</artifactId>
<version>1.5.0</version> <version>1.5.2</version>
<scope>test</scope> <scope>test</scope>
<exclusions> <exclusions>

View File

@ -101,6 +101,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.Cart
import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.CauldronListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.CauldronListener;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.CraftingTableListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.CraftingTableListener;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.GrindstoneListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.GrindstoneListener;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.SmithingTableListener;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.entity.BeeListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.entity.BeeListener;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.entity.EntityInteractionListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.entity.EntityInteractionListener;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.entity.FireworksListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.entity.FireworksListener;
@ -610,6 +611,7 @@ public final class Slimefun extends JavaPlugin implements SlimefunAddon {
new CauldronListener(this); new CauldronListener(this);
new GrindstoneListener(this); new GrindstoneListener(this);
new CartographyTableListener(this); new CartographyTableListener(this);
new SmithingTableListener(this);
new ButcherAndroidListener(this); new ButcherAndroidListener(this);
new MiningAndroidListener(this); new MiningAndroidListener(this);
new NetworkListener(this, networkManager); new NetworkListener(this, networkManager);

View File

@ -35,13 +35,20 @@ public class SolarGenerator extends SlimefunItem implements EnergyNetProvider {
private final int dayEnergy; private final int dayEnergy;
private final int nightEnergy; private final int nightEnergy;
private final int capacity;
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public SolarGenerator(ItemGroup itemGroup, int dayEnergy, int nightEnergy, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { public SolarGenerator(ItemGroup itemGroup, int dayEnergy, int nightEnergy, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, int capacity) {
super(itemGroup, item, recipeType, recipe); super(itemGroup, item, recipeType, recipe);
this.dayEnergy = dayEnergy; this.dayEnergy = dayEnergy;
this.nightEnergy = nightEnergy; this.nightEnergy = nightEnergy;
this.capacity = capacity;
}
@ParametersAreNonnullByDefault
public SolarGenerator(ItemGroup itemGroup, int dayEnergy, int nightEnergy, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
this(itemGroup, dayEnergy, nightEnergy, item, recipeType, recipe, 0);
} }
/** /**
@ -65,8 +72,8 @@ public class SolarGenerator extends SlimefunItem implements EnergyNetProvider {
} }
@Override @Override
public final int getCapacity() { public int getCapacity() {
return 0; return capacity;
} }
@Override @Override

View File

@ -22,6 +22,8 @@ public class ElectrifiedCrucible extends AContainer {
@Override @Override
protected void registerDefaultRecipes() { protected void registerDefaultRecipes() {
registerRecipe(10, new ItemStack[] { new ItemStack(Material.BUCKET), new ItemStack(Material.COBBLESTONE, 16) }, new ItemStack[] { new ItemStack(Material.LAVA_BUCKET) }); registerRecipe(10, new ItemStack[] { new ItemStack(Material.BUCKET), new ItemStack(Material.COBBLESTONE, 16) }, new ItemStack[] { new ItemStack(Material.LAVA_BUCKET) });
registerRecipe(8, new ItemStack[] { new ItemStack(Material.BUCKET), new ItemStack(Material.NETHERRACK, 16) }, new ItemStack[] { new ItemStack(Material.LAVA_BUCKET) });
registerRecipe(8, new ItemStack[] { new ItemStack(Material.BUCKET), new ItemStack(Material.STONE, 12) }, new ItemStack[] { new ItemStack(Material.LAVA_BUCKET) });
registerRecipe(8, new ItemStack[] { new ItemStack(Material.BUCKET), new ItemStack(Material.TERRACOTTA, 12) }, new ItemStack[] { new ItemStack(Material.LAVA_BUCKET) }); registerRecipe(8, new ItemStack[] { new ItemStack(Material.BUCKET), new ItemStack(Material.TERRACOTTA, 12) }, new ItemStack[] { new ItemStack(Material.LAVA_BUCKET) });
registerRecipe(10, new ItemStack[] { new ItemStack(Material.BUCKET), new ItemStack(Material.OBSIDIAN) }, new ItemStack[] { new ItemStack(Material.LAVA_BUCKET) }); registerRecipe(10, new ItemStack[] { new ItemStack(Material.BUCKET), new ItemStack(Material.OBSIDIAN) }, new ItemStack[] { new ItemStack(Material.LAVA_BUCKET) });

View File

@ -103,6 +103,13 @@ public class BackpackListener implements Listener {
e.setCancelled(true); e.setCancelled(true);
} }
} }
} else if (e.getClick() == ClickType.SWAP_OFFHAND && e.getClickedInventory().getType() != InventoryType.PLAYER) {
// Fixes #3265
ItemStack offHandItem = e.getWhoClicked().getInventory().getItemInOffHand();
if (!isAllowed((SlimefunBackpack) backpack, offHandItem)) {
e.setCancelled(true);
}
} else if (!isAllowed((SlimefunBackpack) backpack, e.getCurrentItem())) { } else if (!isAllowed((SlimefunBackpack) backpack, e.getCurrentItem())) {
e.setCancelled(true); e.setCancelled(true);
} }

View File

@ -0,0 +1,40 @@
package io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting;
import javax.annotation.Nonnull;
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.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
/**
* This {@link Listener} prevents any {@link SlimefunItem} from being used in a
* smithing table.
*
* @author Sefiraat
*/
public class SmithingTableListener implements SlimefunCraftingListener {
public SmithingTableListener(@Nonnull Slimefun plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler(ignoreCancelled = true)
public void onSmith(InventoryClickEvent e) {
if (e.getInventory().getType() == InventoryType.SMITHING && e.getRawSlot() == 2 && e.getWhoClicked() instanceof Player) {
ItemStack materialItem = e.getInventory().getContents()[1];
// Checks if the item in the Material/Netherite slot is allowed to be used.
if (isUnallowed(materialItem)) {
e.setResult(Result.DENY);
Slimefun.getLocalization().sendMessage(e.getWhoClicked(), "smithing_table.not-working", true);
}
}
}
}

View File

@ -1,5 +1,5 @@
/** /**
* This package holds every {@link org.bukkit.event.Listener} which is responsible for preventing that a * This package holds every {@link org.bukkit.event.Listener} which is responsible for preventing that a
* {@link me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem} is used in an unallowed crafting operation * {@link io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem} is used in an unallowed crafting operation
*/ */
package io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting; package io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting;

View File

@ -329,6 +329,9 @@ brewing_stand:
cartography_table: cartography_table:
not-working: '&4You cannot use Slimefun items in a cartography table!' not-working: '&4You cannot use Slimefun items in a cartography table!'
smithing_table:
not-working: '&4You cannot use a Slimefun item as a smithing material!'
villagers: villagers:
no-trading: '&4You cannot trade Slimefun items with Villagers!' no-trading: '&4You cannot trade Slimefun items with Villagers!'

View File

@ -0,0 +1,135 @@
package io.github.thebusybiscuit.slimefun4.implementation.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.junit.jupiter.api.DisplayName;
import io.github.bakedlibs.dough.items.CustomItemStack;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.SmithingTableListener;
import io.github.thebusybiscuit.slimefun4.test.TestUtilities;
import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.ServerMock;
class TestSmithingTableListener {
private static SmithingTableListener listener;
private static ServerMock server;
private static SlimefunItem slimefunIngot;
private static SlimefunItem slimefunTool;
private static VanillaItem vanillaIngot;
private static VanillaItem vanillaTool;
@BeforeAll
public static void load() {
server = MockBukkit.mock();
Slimefun plugin = MockBukkit.load(Slimefun.class);
listener = new SmithingTableListener(plugin);
slimefunTool = TestUtilities.mockSlimefunItem(plugin, "MOCK_DIAMOND_SWORD", new CustomItemStack(Material.DIAMOND_SWORD, "&6Mock"));
slimefunIngot = TestUtilities.mockSlimefunItem(plugin, "MOCK_NETHERITE_INGOT", new CustomItemStack(Material.NETHERITE_INGOT, "&6Mock"));
vanillaTool = TestUtilities.mockVanillaItem(plugin, Material.DIAMOND_SWORD, true);
vanillaIngot = TestUtilities.mockVanillaItem(plugin, Material.NETHERITE_INGOT, true);
slimefunTool.register(plugin);
slimefunIngot.register(plugin);
vanillaTool.register(plugin);
vanillaIngot.register(plugin);
}
@AfterAll
public static void unload() {
MockBukkit.unmock();
}
private InventoryClickEvent mockSmithingEvent(ItemStack tool, ItemStack material) {
Player player = server.addPlayer();
Inventory inv = TestUtilities.mockInventory(InventoryType.SMITHING, tool, material, null);
InventoryView view = player.openInventory(inv);
InventoryClickEvent event = new InventoryClickEvent(view, SlotType.CONTAINER, 2, ClickType.LEFT, InventoryAction.PICKUP_ONE);
listener.onSmith(event);
return event;
}
@Test
@DisplayName("Test that vanilla is unchanged (ItemStack tool x ItemStack material)")
void testSmithingTableWithItemStacks() {
InventoryClickEvent event = mockSmithingEvent(new ItemStack(Material.DIAMOND_SWORD), new ItemStack(Material.NETHERITE_INGOT));
Assertions.assertEquals(Result.DEFAULT, event.getResult());
}
@Test
@DisplayName("Test that SlimefunItem material doesn't work (ItemStack tool x SlimefunItem material)")
void testSmithingTableWithItemStackAndSlimefunItem() {
InventoryClickEvent event = mockSmithingEvent(new ItemStack(Material.DIAMOND_SWORD), slimefunIngot.getItem());
Assertions.assertEquals(Result.DENY, event.getResult());
}
@Test
@DisplayName("Test that VanillaItem material works (ItemStack tool x VanillaItem material)")
void testSmithingTableWithItemStackAndVanillaItem() {
InventoryClickEvent event = mockSmithingEvent(new ItemStack(Material.DIAMOND_SWORD), vanillaIngot.getItem());
Assertions.assertEquals(Result.DEFAULT, event.getResult());
}
@Test
@DisplayName("Test that SlimefunItems can upgrade with vanilla (SlimefunItem tool x ItemStack material)")
void testSmithingTableWithSlimefunItemAndItemStack() {
InventoryClickEvent event = mockSmithingEvent(slimefunTool.getItem(), new ItemStack(Material.NETHERITE_INGOT));
Assertions.assertEquals(Result.DEFAULT, event.getResult());
}
@Test
@DisplayName("Test that SlimefunItems can't upgrade with SlimefunItem materials (SlimefunItem tool x SlimefunItem material)")
void testSmithingTableWithSlimefunItems() {
InventoryClickEvent event = mockSmithingEvent(slimefunTool.getItem(), slimefunIngot.getItem());
Assertions.assertEquals(Result.DENY, event.getResult());
}
@Test
@DisplayName("Test that SlimefunItems can upgrade with VanillaItems (SlimefunItem tool x VanillaItem material)")
void testSmithingTableWithSlimefunItemAndVanillaItem() {
InventoryClickEvent event = mockSmithingEvent(slimefunTool.getItem(), vanillaIngot.getItem());
Assertions.assertEquals(Result.DEFAULT, event.getResult());
}
@Test
@DisplayName("Test that SlimefunItems can upgrade with vanilla (SlimefunItem tool x ItemStack material)")
void testSmithingTableWithVanillaItemAndItemStack() {
InventoryClickEvent event = mockSmithingEvent(vanillaTool.getItem(), new ItemStack(Material.NETHERITE_INGOT));
Assertions.assertEquals(Result.DEFAULT, event.getResult());
}
@Test
@DisplayName("Test that SlimefunItems can't upgrade with SlimefunItem materials (SlimefunItem tool x SlimefunItem material)")
void testSmithingTableWithVanillaItemAndSlimefunItem() {
InventoryClickEvent event = mockSmithingEvent(vanillaTool.getItem(), slimefunIngot.getItem());
Assertions.assertEquals(Result.DENY, event.getResult());
}
@Test
@DisplayName("Test that SlimefunItems can upgrade with VanillaItems (SlimefunItem tool x VanillaItem material)")
void testSmithingTableWithVanillaItemAndVanillaItem() {
InventoryClickEvent event = mockSmithingEvent(vanillaTool.getItem(), vanillaIngot.getItem());
Assertions.assertEquals(Result.DEFAULT, event.getResult());
}
}