mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-01 05:57:54 +01:00
Changes made due to addon development.
Added a method to easily get named addons from other addons. Fixed bugs with addonclassloader. Added ignores to some unavoidable line items Added auto-cancel to panels so that items cannot be taken from them by default.
This commit is contained in:
parent
49764c151d
commit
023a68546c
@ -3,6 +3,7 @@ package us.tastybento.bskyblock.api.addons;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Optional;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.logging.Logger;
|
||||
@ -254,4 +255,12 @@ public abstract class Addon implements AddonInterface {
|
||||
public IslandsManager getIslands() {
|
||||
return getBSkyBlock().getIslands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Addon By Name
|
||||
* @return Optional Addon
|
||||
*/
|
||||
public Optional<Addon> getAddonByName(String name) {
|
||||
return getBSkyBlock().getAddonsManager().getAddonByName(name);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import java.net.URLClassLoader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.InvalidDescriptionException;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
|
@ -29,7 +29,7 @@ public class PanelItemBuilder {
|
||||
this.icon = icon;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set icon to player's head
|
||||
* @param playerUUID - player's UUID
|
||||
@ -38,7 +38,7 @@ public class PanelItemBuilder {
|
||||
public PanelItemBuilder icon(UUID playerUUID) {
|
||||
return icon(Bukkit.getServer().getOfflinePlayer(playerUUID).getName());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set icon to player's head
|
||||
* @param playerName - player's name
|
||||
|
@ -444,6 +444,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
return object;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private Object deserialize(Object value, Class<? extends Object> clazz) {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("DEBUG: deserialize - class is " + clazz.getCanonicalName());
|
||||
|
@ -19,6 +19,7 @@ import us.tastybento.bskyblock.api.flags.Flag;
|
||||
*/
|
||||
public class FlagSerializer implements AdapterInterface<Map<Flag, Integer>, Map<String, Integer>> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Map<Flag, Integer> serialize(Object object) {
|
||||
Map<Flag, Integer> result = new HashMap<>();
|
||||
@ -41,6 +42,7 @@ public class FlagSerializer implements AdapterInterface<Map<Flag, Integer>, Map<
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Map<String, Integer> deserialize(Object object) {
|
||||
Map<String, Integer> result = new HashMap<>();
|
||||
|
@ -24,12 +24,13 @@ public class PanelListenerManager implements Listener {
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
User user = User.getInstance(event.getWhoClicked()); // The player that
|
||||
// clicked the item
|
||||
//UUID playerUUID = player.getUniqueId();
|
||||
Inventory inventory = event.getInventory(); // The inventory that was
|
||||
// Open the inventory panel that this player has open (they can only ever have one)
|
||||
if (openPanels.containsKey(user.getUniqueId())) {
|
||||
// Check the name of the panel
|
||||
if (inventory.getName().equals(openPanels.get(user.getUniqueId()).getInventory().getName())) {
|
||||
// Cancel the event. If they don't want it to be canceled then the click handler(s) should uncancel it
|
||||
event.setCancelled(true);
|
||||
// Get the panel itself
|
||||
Panel panel = openPanels.get(user.getUniqueId());
|
||||
// Check that they clicked on a specific item
|
||||
|
@ -35,12 +35,10 @@ import us.tastybento.bskyblock.api.panels.PanelItem;
|
||||
@RunWith(PowerMockRunner.class)
|
||||
public class PanelItemBuilderTest {
|
||||
|
||||
private static PanelItemBuilder builder;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
builder = new PanelItemBuilder();
|
||||
public static void setUp() throws Exception {
|
||||
Server server = mock(Server.class);
|
||||
World world = mock(World.class);
|
||||
world = mock(World.class);
|
||||
@ -71,6 +69,7 @@ public class PanelItemBuilderTest {
|
||||
|
||||
@Test
|
||||
public void testIconMaterial() {
|
||||
PanelItemBuilder builder = new PanelItemBuilder();
|
||||
builder.icon(Material.STONE);
|
||||
PanelItem item = builder.build();
|
||||
assertNotNull(item.getItem().getType());
|
||||
@ -79,6 +78,7 @@ public class PanelItemBuilderTest {
|
||||
|
||||
@Test
|
||||
public void testIconItemStack() {
|
||||
PanelItemBuilder builder = new PanelItemBuilder();
|
||||
builder.icon(new ItemStack(Material.IRON_ORE));
|
||||
PanelItem item = builder.build();
|
||||
assertNotNull(item.getItem().getType());
|
||||
@ -87,6 +87,7 @@ public class PanelItemBuilderTest {
|
||||
|
||||
@Test
|
||||
public void testIconUUID() {
|
||||
PanelItemBuilder builder = new PanelItemBuilder();
|
||||
builder.icon(UUID.fromString("5988eecd-1dcd-4080-a843-785b62419"));
|
||||
PanelItem item = builder.build();
|
||||
assertNotNull(item.getItem().getType());
|
||||
@ -96,6 +97,7 @@ public class PanelItemBuilderTest {
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testIconString() {
|
||||
PanelItemBuilder builder = new PanelItemBuilder();
|
||||
builder.icon("tastybento");
|
||||
PanelItem item = builder.build();
|
||||
assertNotNull(item.getItem().getType());
|
||||
@ -106,6 +108,7 @@ public class PanelItemBuilderTest {
|
||||
|
||||
@Test
|
||||
public void testName() {
|
||||
PanelItemBuilder builder = new PanelItemBuilder();
|
||||
builder.name("test");
|
||||
PanelItem item = builder.build();
|
||||
assertEquals("test",item.getName());
|
||||
@ -113,6 +116,7 @@ public class PanelItemBuilderTest {
|
||||
|
||||
@Test
|
||||
public void testDescriptionListOfString() {
|
||||
PanelItemBuilder builder = new PanelItemBuilder();
|
||||
List<String> test = Arrays.asList("test line 1", "test line 2");
|
||||
builder.description(test);
|
||||
PanelItem item = builder.build();
|
||||
@ -121,7 +125,8 @@ public class PanelItemBuilderTest {
|
||||
|
||||
@Test
|
||||
public void testDescriptionStringArray() {
|
||||
List<String> test = Arrays.asList("test line 1", "test line 2", "test line 3", "test line 4");
|
||||
PanelItemBuilder builder = new PanelItemBuilder();
|
||||
List<String> test = Arrays.asList("test line 3", "test line 4");
|
||||
builder.description("test line 3", "test line 4");
|
||||
PanelItem item = builder.build();
|
||||
assertEquals(test, item.getDescription());
|
||||
@ -129,7 +134,8 @@ public class PanelItemBuilderTest {
|
||||
|
||||
@Test
|
||||
public void testDescriptionString() {
|
||||
List<String> test = Arrays.asList("test line 1", "test line 2", "test line 3", "test line 4", "test line 5");
|
||||
PanelItemBuilder builder = new PanelItemBuilder();
|
||||
List<String> test = Arrays.asList("test line 5");
|
||||
builder.description("test line 5");
|
||||
PanelItem item = builder.build();
|
||||
assertEquals(test, item.getDescription());
|
||||
@ -137,6 +143,7 @@ public class PanelItemBuilderTest {
|
||||
|
||||
@Test
|
||||
public void testClickHandler() {
|
||||
PanelItemBuilder builder = new PanelItemBuilder();
|
||||
// Test without click handler
|
||||
PanelItem item = builder.clickHandler(null).build();
|
||||
assertFalse(item.getClickHandler().isPresent());
|
||||
|
Loading…
Reference in New Issue
Block a user