mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-25 20:25:16 +01:00
commit
3ee840f467
2
pom.xml
2
pom.xml
@ -88,7 +88,7 @@
|
|||||||
<!-- Do not change unless you want different name for local builds. -->
|
<!-- Do not change unless you want different name for local builds. -->
|
||||||
<build.number>-LOCAL</build.number>
|
<build.number>-LOCAL</build.number>
|
||||||
<!-- This allows to change between versions. -->
|
<!-- This allows to change between versions. -->
|
||||||
<build.version>2.4.2</build.version>
|
<build.version>2.5.0</build.version>
|
||||||
<sonar.organization>bentobox-world</sonar.organization>
|
<sonar.organization>bentobox-world</sonar.organization>
|
||||||
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
||||||
<server.jars>${project.basedir}/lib</server.jars>
|
<server.jars>${project.basedir}/lib</server.jars>
|
||||||
|
@ -114,8 +114,13 @@ public class AdminUnregisterCommand extends ConfirmableCommand {
|
|||||||
targetIsland.getMemberSet().forEach(m -> getIslands().removePlayer(targetIsland, m));
|
targetIsland.getMemberSet().forEach(m -> getIslands().removePlayer(targetIsland, m));
|
||||||
// Remove all island players that reference this island
|
// Remove all island players that reference this island
|
||||||
targetIsland.getMembers().clear();
|
targetIsland.getMembers().clear();
|
||||||
|
if (user.isPlayer()) {
|
||||||
targetIsland.log(new LogEntry.Builder("UNREGISTER").data("player", targetUUID.toString())
|
targetIsland.log(new LogEntry.Builder("UNREGISTER").data("player", targetUUID.toString())
|
||||||
.data("admin", user.getUniqueId().toString()).build());
|
.data("admin", user.getUniqueId().toString()).build());
|
||||||
|
} else {
|
||||||
|
targetIsland.log(new LogEntry.Builder("UNREGISTER").data("player", targetUUID.toString())
|
||||||
|
.data("admin", "console").build());
|
||||||
|
}
|
||||||
user.sendMessage("commands.admin.unregister.unregistered-island", TextVariables.XYZ, Util.xyz(targetIsland.getCenter().toVector()),
|
user.sendMessage("commands.admin.unregister.unregistered-island", TextVariables.XYZ, Util.xyz(targetIsland.getCenter().toVector()),
|
||||||
TextVariables.NAME, getPlayers().getName(targetUUID));
|
TextVariables.NAME, getPlayers().getName(targetUUID));
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ public class AdminPurgeCommand extends CompositeCommand implements Listener {
|
|||||||
*/
|
*/
|
||||||
Set<String> getOldIslands(int days) {
|
Set<String> getOldIslands(int days) {
|
||||||
long currentTimeMillis = System.currentTimeMillis();
|
long currentTimeMillis = System.currentTimeMillis();
|
||||||
double daysInMilliseconds = days * 1000 * 3600 * 24;
|
long daysInMilliseconds = (long) days * 1000 * 3600 * 24;
|
||||||
Set<String> oldIslands = new HashSet<>();
|
Set<String> oldIslands = new HashSet<>();
|
||||||
|
|
||||||
// Process islands in one pass, logging and adding to the set if applicable
|
// Process islands in one pass, logging and adding to the set if applicable
|
||||||
|
@ -116,6 +116,25 @@ public class Flag implements Comparable<Flag> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for hiding of sub flags
|
||||||
|
* @since 2.4.3
|
||||||
|
*/
|
||||||
|
public enum HideWhen {
|
||||||
|
/**
|
||||||
|
* Never hide sub-flags
|
||||||
|
*/
|
||||||
|
NEVER,
|
||||||
|
/**
|
||||||
|
* Hide subflags if the setting of the parent flag is true
|
||||||
|
*/
|
||||||
|
SETTING_TRUE,
|
||||||
|
/**
|
||||||
|
* Hide subflags if the setting of the parent flag is false
|
||||||
|
*/
|
||||||
|
SETTING_FALSE
|
||||||
|
}
|
||||||
|
|
||||||
private static final String PROTECTION_FLAGS = "protection.flags.";
|
private static final String PROTECTION_FLAGS = "protection.flags.";
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
@ -131,6 +150,9 @@ public class Flag implements Comparable<Flag> {
|
|||||||
private final int cooldown;
|
private final int cooldown;
|
||||||
private final Mode mode;
|
private final Mode mode;
|
||||||
private final Set<Flag> subflags;
|
private final Set<Flag> subflags;
|
||||||
|
private final HideWhen hideWhen;
|
||||||
|
private boolean isSubFlag;
|
||||||
|
private Flag parentFlag;
|
||||||
|
|
||||||
private Flag(Builder builder) {
|
private Flag(Builder builder) {
|
||||||
this.id = builder.id;
|
this.id = builder.id;
|
||||||
@ -148,6 +170,9 @@ public class Flag implements Comparable<Flag> {
|
|||||||
this.addon = builder.addon;
|
this.addon = builder.addon;
|
||||||
this.mode = builder.mode;
|
this.mode = builder.mode;
|
||||||
this.subflags = builder.subflags;
|
this.subflags = builder.subflags;
|
||||||
|
this.hideWhen = builder.hideWhen;
|
||||||
|
this.isSubFlag = false;
|
||||||
|
this.parentFlag = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getID() {
|
public String getID() {
|
||||||
@ -276,6 +301,28 @@ public class Flag implements Comparable<Flag> {
|
|||||||
return addon;
|
return addon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get when sub-flags should be hidden
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public HideWhen getHideWhen() {
|
||||||
|
return hideWhen;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the isSubFlag
|
||||||
|
*/
|
||||||
|
public boolean isSubFlag() {
|
||||||
|
return isSubFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the parentFlag
|
||||||
|
*/
|
||||||
|
public Flag getParentFlag() {
|
||||||
|
return parentFlag;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.lang.Object#hashCode()
|
* @see java.lang.Object#hashCode()
|
||||||
*/
|
*/
|
||||||
@ -553,6 +600,9 @@ public class Flag implements Comparable<Flag> {
|
|||||||
// Subflags
|
// Subflags
|
||||||
private final Set<Flag> subflags;
|
private final Set<Flag> subflags;
|
||||||
|
|
||||||
|
// Hide when indicator
|
||||||
|
private HideWhen hideWhen = HideWhen.NEVER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for making flags
|
* Builder for making flags
|
||||||
* @param id - a unique id that MUST be the same as the enum of the flag
|
* @param id - a unique id that MUST be the same as the enum of the flag
|
||||||
@ -679,6 +729,21 @@ public class Flag implements Comparable<Flag> {
|
|||||||
*/
|
*/
|
||||||
public Builder subflags(Flag... flags) {
|
public Builder subflags(Flag... flags) {
|
||||||
this.subflags.addAll(Arrays.asList(flags));
|
this.subflags.addAll(Arrays.asList(flags));
|
||||||
|
for (Flag flag : flags) {
|
||||||
|
flag.isSubFlag = true;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When should sub-flags be hidden, if ever
|
||||||
|
* {@see HideWhen}
|
||||||
|
* @param hideWhen hide when indicator
|
||||||
|
* @return Builder - flag builder
|
||||||
|
* @since 2.4.3
|
||||||
|
*/
|
||||||
|
public Builder hideWhen(HideWhen hideWhen) {
|
||||||
|
this.hideWhen = hideWhen;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -695,9 +760,9 @@ public class Flag implements Comparable<Flag> {
|
|||||||
default -> new CycleClick(id);
|
default -> new CycleClick(id);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Flag flag = new Flag(this);
|
||||||
return new Flag(this);
|
subflags.forEach(subflag -> subflag.parentFlag = flag);
|
||||||
|
return flag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -131,6 +131,11 @@ public class PanelItem {
|
|||||||
if (inTest()) {
|
if (inTest()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (meta != null) {
|
||||||
|
try {
|
||||||
|
meta.setEnchantmentGlintOverride(glow);
|
||||||
|
} catch (NoSuchMethodError e) {
|
||||||
|
// Try the old way
|
||||||
if (meta != null) {
|
if (meta != null) {
|
||||||
if (glow) {
|
if (glow) {
|
||||||
meta.addEnchant(Enchantment.LURE, 0, glow);
|
meta.addEnchant(Enchantment.LURE, 0, glow);
|
||||||
@ -138,6 +143,9 @@ public class PanelItem {
|
|||||||
meta.removeEnchant(Enchantment.LURE);
|
meta.removeEnchant(Enchantment.LURE);
|
||||||
}
|
}
|
||||||
icon.setItemMeta(meta);
|
icon.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
icon.setItemMeta(meta);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,6 +105,24 @@ public class JoinLeaveListener implements Listener {
|
|||||||
|
|
||||||
// Add a player to the bStats cache.
|
// Add a player to the bStats cache.
|
||||||
plugin.getMetrics().ifPresent(bStats -> bStats.addPlayer(playerUUID));
|
plugin.getMetrics().ifPresent(bStats -> bStats.addPlayer(playerUUID));
|
||||||
|
|
||||||
|
// Create onIsland placeholders
|
||||||
|
plugin.getAddonsManager().getGameModeAddons().forEach(addon -> {
|
||||||
|
plugin.getPlaceholdersManager()
|
||||||
|
.registerPlaceholder(addon, "onisland_" + user.getName(), asker -> {
|
||||||
|
if (asker == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
// Get the user who this applies to
|
||||||
|
User named = User.getInstance(user.getUniqueId());
|
||||||
|
if (named.isOnline()) {
|
||||||
|
return plugin.getIslands().getIslands(addon.getOverWorld(), asker).stream()
|
||||||
|
.filter(island -> island.onIsland(named.getLocation())).findFirst().map(i -> "true")
|
||||||
|
.orElse("false");
|
||||||
|
}
|
||||||
|
return "false";
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void firstTime(User user) {
|
private void firstTime(User user) {
|
||||||
@ -237,6 +255,9 @@ public class JoinLeaveListener implements Listener {
|
|||||||
});
|
});
|
||||||
// Remove any coop associations from the player logging out
|
// Remove any coop associations from the player logging out
|
||||||
plugin.getIslands().clearRank(RanksManager.COOP_RANK, event.getPlayer().getUniqueId());
|
plugin.getIslands().clearRank(RanksManager.COOP_RANK, event.getPlayer().getUniqueId());
|
||||||
|
// Remove any onisland placeholder
|
||||||
|
plugin.getAddonsManager().getGameModeAddons().forEach(addon -> plugin.getPlaceholdersManager()
|
||||||
|
.unregisterPlaceholder(addon, "onisland_" + event.getPlayer().getName()));
|
||||||
User.removePlayer(event.getPlayer());
|
User.removePlayer(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Common Game Mode Placeholders
|
* Common Game Mode Placeholders
|
||||||
|
* All of these are prefixed with the game mode's name, e.g., bskykblock_
|
||||||
*/
|
*/
|
||||||
public enum GameModePlaceholder {
|
public enum GameModePlaceholder {
|
||||||
|
|
||||||
|
@ -171,8 +171,15 @@ public class IslandCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void removeFromIslandsByUUID(Island island) {
|
private void removeFromIslandsByUUID(Island island) {
|
||||||
for (Set<String> set : islandsByUUID.values()) {
|
Iterator<Map.Entry<UUID, Set<String>>> iterator = islandsByUUID.entrySet().iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Map.Entry<UUID, Set<String>> entry = iterator.next();
|
||||||
|
Set<String> set = entry.getValue();
|
||||||
set.removeIf(island.getUniqueId()::equals);
|
set.removeIf(island.getUniqueId()::equals);
|
||||||
|
if (set.isEmpty()) {
|
||||||
|
// Removes the overall entry if there is nothing left in the set
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -538,7 +545,9 @@ public class IslandCache {
|
|||||||
* @return list of islands
|
* @return list of islands
|
||||||
*/
|
*/
|
||||||
public @NonNull List<Island> getIslands(UUID uniqueId) {
|
public @NonNull List<Island> getIslands(UUID uniqueId) {
|
||||||
return islandsByUUID.getOrDefault(uniqueId, Collections.emptySet()).stream().map(this::getIslandById).toList();
|
return islandsByUUID.getOrDefault(uniqueId, Collections.emptySet()).stream().map(this::getIslandById)
|
||||||
|
.filter(Objects::nonNull) // Filter out null values
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package world.bentobox.bentobox.nms.v1_21_1_R0_1_SNAPSHOT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as 1.21
|
||||||
|
*/
|
||||||
|
public class PasteHandlerImpl extends world.bentobox.bentobox.nms.v1_21_R0_1_SNAPSHOT.PasteHandlerImpl {
|
||||||
|
// Do nothing special
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package world.bentobox.bentobox.nms.v1_21_1_R0_1_SNAPSHOT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as 1.21
|
||||||
|
*/
|
||||||
|
public class WorldRegeneratorImpl extends world.bentobox.bentobox.nms.v1_21_R0_1_SNAPSHOT.WorldRegeneratorImpl {
|
||||||
|
// Do nothing special
|
||||||
|
}
|
@ -2,8 +2,10 @@ package world.bentobox.bentobox.panels.settings;
|
|||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -17,6 +19,7 @@ import org.eclipse.jdt.annotation.Nullable;
|
|||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.flags.Flag;
|
import world.bentobox.bentobox.api.flags.Flag;
|
||||||
|
import world.bentobox.bentobox.api.flags.Flag.HideWhen;
|
||||||
import world.bentobox.bentobox.api.flags.Flag.Mode;
|
import world.bentobox.bentobox.api.flags.Flag.Mode;
|
||||||
import world.bentobox.bentobox.api.flags.Flag.Type;
|
import world.bentobox.bentobox.api.flags.Flag.Type;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
@ -131,10 +134,24 @@ public class SettingsTab implements Tab, ClickHandler {
|
|||||||
currentMode.put(user.getUniqueId(), currentMode.getOrDefault(user.getUniqueId(), Mode.BASIC).getNext());
|
currentMode.put(user.getUniqueId(), currentMode.getOrDefault(user.getUniqueId(), Mode.BASIC).getNext());
|
||||||
flags = getFlags();
|
flags = getFlags();
|
||||||
}
|
}
|
||||||
|
// Remove any sub-flags that shouldn't be shown
|
||||||
|
Set<Flag> toBeRemoved = new HashSet<>();
|
||||||
|
flags.forEach(flag -> {
|
||||||
|
if (flag.isSubFlag() && flag.getHideWhen() != HideWhen.NEVER) {
|
||||||
|
if (!flag.getParentFlag().isSetForWorld(world) && flag.getHideWhen() == HideWhen.SETTING_FALSE) {
|
||||||
|
toBeRemoved.add(flag);
|
||||||
|
} else if (flag.getParentFlag().isSetForWorld(world) && flag.getHideWhen() == HideWhen.SETTING_TRUE) {
|
||||||
|
toBeRemoved.add(flag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
flags.removeAll(toBeRemoved);
|
||||||
|
|
||||||
List<@Nullable PanelItem> result = flags.stream().map(
|
List<@Nullable PanelItem> result = flags.stream().map(
|
||||||
(f -> f.toPanelItem(plugin, user, world, island,
|
(f -> f.toPanelItem(plugin, user, world, island,
|
||||||
plugin.getIWM().getHiddenFlags(world).contains(f.getID()))))
|
plugin.getIWM().getHiddenFlags(world).contains(f.getID()))))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ import world.bentobox.bentobox.BentoBox;
|
|||||||
*
|
*
|
||||||
* @author tastybento, Poslovitch
|
* @author tastybento, Poslovitch
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("removal")
|
||||||
public class ItemParser {
|
public class ItemParser {
|
||||||
|
|
||||||
private ItemParser() {} // private constructor to hide the implicit public one.
|
private ItemParser() {} // private constructor to hide the implicit public one.
|
||||||
@ -333,7 +333,7 @@ public class ItemParser {
|
|||||||
* @param part String array that contains at least 2 elements.
|
* @param part String array that contains at least 2 elements.
|
||||||
* @return Banner as item stack.
|
* @return Banner as item stack.
|
||||||
*/
|
*/
|
||||||
private static ItemStack parseBanner(String[] part) {
|
static ItemStack parseBanner(String[] part) {
|
||||||
if (part.length >= 2) {
|
if (part.length >= 2) {
|
||||||
Material bannerMat = Material.getMaterial(part[0]);
|
Material bannerMat = Material.getMaterial(part[0]);
|
||||||
if (bannerMat == null) {
|
if (bannerMat == null) {
|
||||||
@ -345,18 +345,13 @@ public class ItemParser {
|
|||||||
BannerMeta meta = (BannerMeta) result.getItemMeta();
|
BannerMeta meta = (BannerMeta) result.getItemMeta();
|
||||||
if (meta != null) {
|
if (meta != null) {
|
||||||
for (int i = 2; i < part.length; i += 2) {
|
for (int i = 2; i < part.length; i += 2) {
|
||||||
PatternType pt = Enums.getIfPresent(PatternType.class, part[i]).orNull();
|
//if (!Util.inTest()) {
|
||||||
if (pt == null) {
|
PatternType pt = PatternType.valueOf(part[i]);
|
||||||
// Try to convert old to new
|
|
||||||
if (part[i].trim().equals("STRIPE_SMALL")
|
|
||||||
&& Enums.getIfPresent(PatternType.class, "SMALL_STRIPES").isPresent()) {
|
|
||||||
pt = PatternType.SMALL_STRIPES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DyeColor dc = Enums.getIfPresent(DyeColor.class, part[i + 1]).orNull();
|
DyeColor dc = Enums.getIfPresent(DyeColor.class, part[i + 1]).orNull();
|
||||||
if (pt != null && dc != null) {
|
if (dc != null) {
|
||||||
meta.addPattern(new Pattern(dc, pt));
|
meta.addPattern(new Pattern(dc, pt));
|
||||||
}
|
}
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
result.setItemMeta(meta);
|
result.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
|
@ -68,9 +68,7 @@ public class HeadCache
|
|||||||
* @param timestamp of type long
|
* @param timestamp of type long
|
||||||
*/
|
*/
|
||||||
public HeadCache(String userName,
|
public HeadCache(String userName,
|
||||||
UUID userId,
|
UUID userId, PlayerProfile playerProfile, long timestamp)
|
||||||
PlayerProfile playerProfile,
|
|
||||||
long timestamp)
|
|
||||||
{
|
{
|
||||||
this.userName = userName;
|
this.userName = userName;
|
||||||
this.playerProfile = playerProfile;
|
this.playerProfile = playerProfile;
|
||||||
@ -99,8 +97,12 @@ public class HeadCache
|
|||||||
// Set correct Skull texture
|
// Set correct Skull texture
|
||||||
if (meta != null && this.playerProfile != null)
|
if (meta != null && this.playerProfile != null)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
meta.setOwnerProfile(this.playerProfile);
|
meta.setOwnerProfile(this.playerProfile);
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Do nothing - there was an error getting the head
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
|
@ -245,7 +245,11 @@ public class ServerCompatibility {
|
|||||||
/**
|
/**
|
||||||
* @since 2.4.0
|
* @since 2.4.0
|
||||||
*/
|
*/
|
||||||
V1_21(Compatibility.COMPATIBLE);
|
V1_21(Compatibility.COMPATIBLE),
|
||||||
|
/**
|
||||||
|
* @since 2.5.0
|
||||||
|
*/
|
||||||
|
V1_21_1(Compatibility.COMPATIBLE);
|
||||||
|
|
||||||
private final Compatibility compatibility;
|
private final Compatibility compatibility;
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ import world.bentobox.bentobox.BentoBox;
|
|||||||
import world.bentobox.bentobox.Settings;
|
import world.bentobox.bentobox.Settings;
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
|
import world.bentobox.bentobox.api.logs.LogEntry;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.managers.CommandsManager;
|
import world.bentobox.bentobox.managers.CommandsManager;
|
||||||
@ -270,6 +271,8 @@ public class AdminUnregisterCommandTest {
|
|||||||
verify(user).sendMessage("commands.admin.unregister.unregistered-island", TextVariables.XYZ, "1,2,3",
|
verify(user).sendMessage("commands.admin.unregister.unregistered-island", TextVariables.XYZ, "1,2,3",
|
||||||
TextVariables.NAME, "name");
|
TextVariables.NAME, "name");
|
||||||
verify(island).setOwner(null);
|
verify(island).setOwner(null);
|
||||||
|
verify(island).log(any(LogEntry.class));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,6 +47,7 @@ import world.bentobox.bentobox.api.user.User;
|
|||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.database.objects.Players;
|
import world.bentobox.bentobox.database.objects.Players;
|
||||||
import world.bentobox.bentobox.hooks.ItemsAdderHook.BlockInteractListener;
|
import world.bentobox.bentobox.hooks.ItemsAdderHook.BlockInteractListener;
|
||||||
|
import world.bentobox.bentobox.listeners.flags.AbstractCommonSetup;
|
||||||
import world.bentobox.bentobox.managers.FlagsManager;
|
import world.bentobox.bentobox.managers.FlagsManager;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.IslandsManager;
|
import world.bentobox.bentobox.managers.IslandsManager;
|
||||||
@ -59,7 +60,7 @@ import world.bentobox.bentobox.managers.PlayersManager;
|
|||||||
*/
|
*/
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({ BentoBox.class, Bukkit.class, CustomBlock.class })
|
@PrepareForTest({ BentoBox.class, Bukkit.class, CustomBlock.class })
|
||||||
public class ItemsAdderHookTest {
|
public class ItemsAdderHookTest extends AbstractCommonSetup {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private BentoBox plugin;
|
private BentoBox plugin;
|
||||||
@ -192,7 +193,7 @@ public class ItemsAdderHookTest {
|
|||||||
when(entity.getType()).thenReturn(EntityType.PLAYER);
|
when(entity.getType()).thenReturn(EntityType.PLAYER);
|
||||||
when(entity.hasPermission("XXXXXX")).thenReturn(true);
|
when(entity.hasPermission("XXXXXX")).thenReturn(true);
|
||||||
List<Block> list = new ArrayList<>();
|
List<Block> list = new ArrayList<>();
|
||||||
EntityExplodeEvent event = new EntityExplodeEvent(entity, location, list, 0);
|
EntityExplodeEvent event = getExplodeEvent(entity, location, list);
|
||||||
listener.onExplosion(event);
|
listener.onExplosion(event);
|
||||||
assertTrue(event.isCancelled());
|
assertTrue(event.isCancelled());
|
||||||
}
|
}
|
||||||
|
@ -25,13 +25,14 @@ import org.powermock.reflect.Whitebox;
|
|||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
import world.bentobox.bentobox.listeners.flags.AbstractCommonSetup;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.PlayersManager;
|
import world.bentobox.bentobox.managers.PlayersManager;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({BentoBox.class, Util.class, Bukkit.class })
|
@PrepareForTest({BentoBox.class, Util.class, Bukkit.class })
|
||||||
public class DeathListenerTest {
|
public class DeathListenerTest extends AbstractCommonSetup {
|
||||||
|
|
||||||
private Player player;
|
private Player player;
|
||||||
private BentoBox plugin;
|
private BentoBox plugin;
|
||||||
@ -84,7 +85,7 @@ public class DeathListenerTest {
|
|||||||
// Test
|
// Test
|
||||||
DeathListener dl = new DeathListener(plugin);
|
DeathListener dl = new DeathListener(plugin);
|
||||||
|
|
||||||
PlayerDeathEvent e = new PlayerDeathEvent(player, new ArrayList<>(), 0, 0, 0, 0, "died");
|
PlayerDeathEvent e = getPlayerDeathEvent(player, new ArrayList<>(), 0, 0, 0, 0, "died");
|
||||||
dl.onPlayerDeath(e);
|
dl.onPlayerDeath(e);
|
||||||
Mockito.verify(pm).addDeath(world, uuid);
|
Mockito.verify(pm).addDeath(world, uuid);
|
||||||
}
|
}
|
||||||
@ -95,7 +96,7 @@ public class DeathListenerTest {
|
|||||||
// Test
|
// Test
|
||||||
DeathListener dl = new DeathListener(plugin);
|
DeathListener dl = new DeathListener(plugin);
|
||||||
|
|
||||||
PlayerDeathEvent e = new PlayerDeathEvent(player, new ArrayList<>(), 0, 0, 0, 0, "died");
|
PlayerDeathEvent e = getPlayerDeathEvent(player, new ArrayList<>(), 0, 0, 0, 0, "died");
|
||||||
dl.onPlayerDeath(e);
|
dl.onPlayerDeath(e);
|
||||||
Mockito.verify(pm, Mockito.never()).addDeath(world, uuid);
|
Mockito.verify(pm, Mockito.never()).addDeath(world, uuid);
|
||||||
}
|
}
|
||||||
@ -106,7 +107,7 @@ public class DeathListenerTest {
|
|||||||
// Test
|
// Test
|
||||||
DeathListener dl = new DeathListener(plugin);
|
DeathListener dl = new DeathListener(plugin);
|
||||||
|
|
||||||
PlayerDeathEvent e = new PlayerDeathEvent(player, new ArrayList<>(), 0, 0, 0, 0, "died");
|
PlayerDeathEvent e = getPlayerDeathEvent(player, new ArrayList<>(), 0, 0, 0, 0, "died");
|
||||||
dl.onPlayerDeath(e);
|
dl.onPlayerDeath(e);
|
||||||
Mockito.verify(pm, Mockito.never()).addDeath(world, uuid);
|
Mockito.verify(pm, Mockito.never()).addDeath(world, uuid);
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ import world.bentobox.bentobox.api.addons.GameModeAddon;
|
|||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.database.objects.Players;
|
import world.bentobox.bentobox.database.objects.Players;
|
||||||
|
import world.bentobox.bentobox.managers.AddonsManager;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.IslandsManager;
|
import world.bentobox.bentobox.managers.IslandsManager;
|
||||||
import world.bentobox.bentobox.managers.LocalesManager;
|
import world.bentobox.bentobox.managers.LocalesManager;
|
||||||
@ -107,6 +108,9 @@ public class JoinLeaveListenerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private @NonNull Location location;
|
private @NonNull Location location;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private AddonsManager am;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
@ -218,6 +222,9 @@ public class JoinLeaveListenerTest {
|
|||||||
when(phm.replacePlaceholders(any(), anyString()))
|
when(phm.replacePlaceholders(any(), anyString()))
|
||||||
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
||||||
|
|
||||||
|
// Addons manager
|
||||||
|
when(plugin.getAddonsManager()).thenReturn(am);
|
||||||
|
|
||||||
jll = new JoinLeaveListener(plugin);
|
jll = new JoinLeaveListener(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ import org.bukkit.event.inventory.InventoryType.SlotType;
|
|||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryView;
|
import org.bukkit.inventory.InventoryView;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -182,6 +183,20 @@ public class PanelListenerManagerTest {
|
|||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setItem(int slot, ItemStack item) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getItem(int slot) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -42,6 +42,7 @@ import org.powermock.reflect.Whitebox;
|
|||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
import world.bentobox.bentobox.listeners.flags.AbstractCommonSetup;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.IslandsManager;
|
import world.bentobox.bentobox.managers.IslandsManager;
|
||||||
import world.bentobox.bentobox.managers.LocalesManager;
|
import world.bentobox.bentobox.managers.LocalesManager;
|
||||||
@ -55,7 +56,7 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
*/
|
*/
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class, Util.class })
|
@PrepareForTest({Bukkit.class, BentoBox.class, User.class, Util.class })
|
||||||
public class StandardSpawnProtectionListenerTest {
|
public class StandardSpawnProtectionListenerTest extends AbstractCommonSetup {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private BentoBox plugin;
|
private BentoBox plugin;
|
||||||
@ -289,7 +290,7 @@ public class StandardSpawnProtectionListenerTest {
|
|||||||
new Vector(0,0,0),
|
new Vector(0,0,0),
|
||||||
new Vector(0,0,0),
|
new Vector(0,0,0),
|
||||||
new Vector(10000,0,0));
|
new Vector(10000,0,0));
|
||||||
EntityExplodeEvent e = new EntityExplodeEvent(player, location, blockList, 0);
|
EntityExplodeEvent e = getExplodeEvent(player, location, blockList);
|
||||||
ssp.onExplosion(e);
|
ssp.onExplosion(e);
|
||||||
// 4 blocks inside the spawn should be removed, leaving one
|
// 4 blocks inside the spawn should be removed, leaving one
|
||||||
assertEquals(1, blockList.size());
|
assertEquals(1, blockList.size());
|
||||||
@ -314,7 +315,7 @@ public class StandardSpawnProtectionListenerTest {
|
|||||||
new Vector(0,0,0),
|
new Vector(0,0,0),
|
||||||
new Vector(0,0,0),
|
new Vector(0,0,0),
|
||||||
new Vector(10000,0,0));
|
new Vector(10000,0,0));
|
||||||
EntityExplodeEvent e = new EntityExplodeEvent(player, location, blockList, 0);
|
EntityExplodeEvent e = getExplodeEvent(player, location, blockList);
|
||||||
ssp.onExplosion(e);
|
ssp.onExplosion(e);
|
||||||
// No blocks should be removed
|
// No blocks should be removed
|
||||||
assertEquals(5, blockList.size());
|
assertEquals(5, blockList.size());
|
||||||
|
@ -7,6 +7,7 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -15,8 +16,13 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Tag;
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.inventory.ItemFactory;
|
import org.bukkit.inventory.ItemFactory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.metadata.FixedMetadataValue;
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
import org.bukkit.metadata.MetadataValue;
|
import org.bukkit.metadata.MetadataValue;
|
||||||
@ -210,4 +216,22 @@ public abstract class AbstractCommonSetup {
|
|||||||
Mockito.framework().clearInlineMocks();
|
Mockito.framework().clearInlineMocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the explode event
|
||||||
|
* @param entity
|
||||||
|
* @param l
|
||||||
|
* @param list
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public EntityExplodeEvent getExplodeEvent(Entity entity, Location l, List<Block> list) {
|
||||||
|
//return new EntityExplodeEvent(entity, l, list, 0, null);
|
||||||
|
return new EntityExplodeEvent(entity, l, list, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerDeathEvent getPlayerDeathEvent(Player player, List<ItemStack> drops, int droppedExp, int newExp,
|
||||||
|
int newTotalExp, int newLevel, @Nullable String deathMessage) {
|
||||||
|
//return new PlayerDeathEvent(player, null, drops, droppedExp, newExp, newTotalExp, newLevel, deathMessage);
|
||||||
|
return new PlayerDeathEvent(player, drops, droppedExp, newExp, newTotalExp, newLevel, deathMessage);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -240,7 +240,7 @@ public class PhysicalInteractionListenerTest extends AbstractCommonSetup {
|
|||||||
public void testOnProjectileExplodeNotProjectile() {
|
public void testOnProjectileExplodeNotProjectile() {
|
||||||
Entity entity = mock(Entity.class);
|
Entity entity = mock(Entity.class);
|
||||||
List<Block> blocks = new ArrayList<>();
|
List<Block> blocks = new ArrayList<>();
|
||||||
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, blocks, 0);
|
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
|
||||||
PhysicalInteractionListener i = new PhysicalInteractionListener();
|
PhysicalInteractionListener i = new PhysicalInteractionListener();
|
||||||
i.onProjectileExplode(e);
|
i.onProjectileExplode(e);
|
||||||
assertFalse(e.isCancelled());
|
assertFalse(e.isCancelled());
|
||||||
@ -255,7 +255,7 @@ public class PhysicalInteractionListenerTest extends AbstractCommonSetup {
|
|||||||
ProjectileSource source = mock(Creeper.class);
|
ProjectileSource source = mock(Creeper.class);
|
||||||
when(entity.getShooter()).thenReturn(source);
|
when(entity.getShooter()).thenReturn(source);
|
||||||
List<Block> blocks = new ArrayList<>();
|
List<Block> blocks = new ArrayList<>();
|
||||||
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, blocks, 0);
|
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
|
||||||
PhysicalInteractionListener i = new PhysicalInteractionListener();
|
PhysicalInteractionListener i = new PhysicalInteractionListener();
|
||||||
i.onProjectileExplode(e);
|
i.onProjectileExplode(e);
|
||||||
assertFalse(e.isCancelled());
|
assertFalse(e.isCancelled());
|
||||||
@ -276,7 +276,7 @@ public class PhysicalInteractionListenerTest extends AbstractCommonSetup {
|
|||||||
blocks.add(block1);
|
blocks.add(block1);
|
||||||
blocks.add(block2);
|
blocks.add(block2);
|
||||||
|
|
||||||
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, blocks, 0);
|
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
|
||||||
PhysicalInteractionListener i = new PhysicalInteractionListener();
|
PhysicalInteractionListener i = new PhysicalInteractionListener();
|
||||||
|
|
||||||
// Test with wooden button
|
// Test with wooden button
|
||||||
|
@ -109,7 +109,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
|
|||||||
public void testOnExplosion() {
|
public void testOnExplosion() {
|
||||||
List<Block> list = new ArrayList<>();
|
List<Block> list = new ArrayList<>();
|
||||||
list.add(block);
|
list.add(block);
|
||||||
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, list, 0);
|
EntityExplodeEvent e = getExplodeEvent(entity, location, list);
|
||||||
listener.onExplosion(e);
|
listener.onExplosion(e);
|
||||||
assertTrue(e.isCancelled());
|
assertTrue(e.isCancelled());
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
|
|||||||
when(im.getProtectedIslandAt(any())).thenReturn(Optional.empty());
|
when(im.getProtectedIslandAt(any())).thenReturn(Optional.empty());
|
||||||
List<Block> list = new ArrayList<>();
|
List<Block> list = new ArrayList<>();
|
||||||
list.add(block);
|
list.add(block);
|
||||||
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, list, 0);
|
EntityExplodeEvent e = getExplodeEvent(entity, location, list);
|
||||||
listener.onExplosion(e);
|
listener.onExplosion(e);
|
||||||
assertTrue(e.isCancelled());
|
assertTrue(e.isCancelled());
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
|
|||||||
when(im.getProtectedIslandAt(any())).thenReturn(Optional.empty());
|
when(im.getProtectedIslandAt(any())).thenReturn(Optional.empty());
|
||||||
List<Block> list = new ArrayList<>();
|
List<Block> list = new ArrayList<>();
|
||||||
list.add(block);
|
list.add(block);
|
||||||
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, list, 0);
|
EntityExplodeEvent e = getExplodeEvent(entity, location, list);
|
||||||
listener.onExplosion(e);
|
listener.onExplosion(e);
|
||||||
assertFalse(e.isCancelled());
|
assertFalse(e.isCancelled());
|
||||||
assertFalse(list.isEmpty());
|
assertFalse(list.isEmpty());
|
||||||
@ -144,7 +144,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
|
|||||||
when(iwm.inWorld(any(Location.class))).thenReturn(false);
|
when(iwm.inWorld(any(Location.class))).thenReturn(false);
|
||||||
List<Block> list = new ArrayList<>();
|
List<Block> list = new ArrayList<>();
|
||||||
list.add(block);
|
list.add(block);
|
||||||
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, list, 0);
|
EntityExplodeEvent e = getExplodeEvent(entity, location, list);
|
||||||
listener.onExplosion(e);
|
listener.onExplosion(e);
|
||||||
assertFalse(e.isCancelled());
|
assertFalse(e.isCancelled());
|
||||||
assertFalse(list.isEmpty());
|
assertFalse(list.isEmpty());
|
||||||
|
@ -199,7 +199,7 @@ public class ChestDamageListenerTest extends AbstractCommonSetup
|
|||||||
list.add(chest);
|
list.add(chest);
|
||||||
list.add(trappedChest);
|
list.add(trappedChest);
|
||||||
list.add(stone);
|
list.add(stone);
|
||||||
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, list, 0);
|
EntityExplodeEvent e = getExplodeEvent(entity, location, list);
|
||||||
ChestDamageListener listener = new ChestDamageListener();
|
ChestDamageListener listener = new ChestDamageListener();
|
||||||
listener.setPlugin(plugin);
|
listener.setPlugin(plugin);
|
||||||
listener.onExplosion(e);
|
listener.onExplosion(e);
|
||||||
@ -231,7 +231,7 @@ public class ChestDamageListenerTest extends AbstractCommonSetup
|
|||||||
list.add(chest);
|
list.add(chest);
|
||||||
list.add(trappedChest);
|
list.add(trappedChest);
|
||||||
list.add(stone);
|
list.add(stone);
|
||||||
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, list, 0);
|
EntityExplodeEvent e = getExplodeEvent(entity, location, list);
|
||||||
ChestDamageListener listener = new ChestDamageListener();
|
ChestDamageListener listener = new ChestDamageListener();
|
||||||
listener.setPlugin(plugin);
|
listener.setPlugin(plugin);
|
||||||
listener.onExplosion(e);
|
listener.onExplosion(e);
|
||||||
|
@ -44,6 +44,7 @@ import world.bentobox.bentobox.api.addons.GameModeAddon;
|
|||||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
import world.bentobox.bentobox.listeners.flags.AbstractCommonSetup;
|
||||||
import world.bentobox.bentobox.lists.Flags;
|
import world.bentobox.bentobox.lists.Flags;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.IslandsManager;
|
import world.bentobox.bentobox.managers.IslandsManager;
|
||||||
@ -55,7 +56,7 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
*/
|
*/
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({ BentoBox.class, Flags.class, Util.class, Bukkit.class })
|
@PrepareForTest({ BentoBox.class, Flags.class, Util.class, Bukkit.class })
|
||||||
public class IslandRespawnListenerTest {
|
public class IslandRespawnListenerTest extends AbstractCommonSetup {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private World world;
|
private World world;
|
||||||
@ -144,7 +145,7 @@ public class IslandRespawnListenerTest {
|
|||||||
public void testOnPlayerDeathNotIslandWorld() {
|
public void testOnPlayerDeathNotIslandWorld() {
|
||||||
when(iwm.inWorld(any(World.class))).thenReturn(false);
|
when(iwm.inWorld(any(World.class))).thenReturn(false);
|
||||||
List<ItemStack> drops = new ArrayList<>();
|
List<ItemStack> drops = new ArrayList<>();
|
||||||
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
|
PlayerDeathEvent e = getPlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
|
||||||
new IslandRespawnListener().onPlayerDeath(e);
|
new IslandRespawnListener().onPlayerDeath(e);
|
||||||
verify(world, never()).getUID();
|
verify(world, never()).getUID();
|
||||||
}
|
}
|
||||||
@ -157,7 +158,7 @@ public class IslandRespawnListenerTest {
|
|||||||
public void testOnPlayerDeathNoFlag() {
|
public void testOnPlayerDeathNoFlag() {
|
||||||
Flags.ISLAND_RESPAWN.setSetting(world, false);
|
Flags.ISLAND_RESPAWN.setSetting(world, false);
|
||||||
List<ItemStack> drops = new ArrayList<>();
|
List<ItemStack> drops = new ArrayList<>();
|
||||||
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
|
PlayerDeathEvent e = getPlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
|
||||||
new IslandRespawnListener().onPlayerDeath(e);
|
new IslandRespawnListener().onPlayerDeath(e);
|
||||||
verify(world, never()).getUID();
|
verify(world, never()).getUID();
|
||||||
}
|
}
|
||||||
@ -170,7 +171,7 @@ public class IslandRespawnListenerTest {
|
|||||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
|
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
|
||||||
when(im.inTeam(any(), any(UUID.class))).thenReturn(false);
|
when(im.inTeam(any(), any(UUID.class))).thenReturn(false);
|
||||||
List<ItemStack> drops = new ArrayList<>();
|
List<ItemStack> drops = new ArrayList<>();
|
||||||
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
|
PlayerDeathEvent e = getPlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
|
||||||
new IslandRespawnListener().onPlayerDeath(e);
|
new IslandRespawnListener().onPlayerDeath(e);
|
||||||
verify(world, never()).getUID();
|
verify(world, never()).getUID();
|
||||||
}
|
}
|
||||||
@ -183,7 +184,7 @@ public class IslandRespawnListenerTest {
|
|||||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
|
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
|
||||||
when(im.inTeam(any(), any(UUID.class))).thenReturn(true);
|
when(im.inTeam(any(), any(UUID.class))).thenReturn(true);
|
||||||
List<ItemStack> drops = new ArrayList<>();
|
List<ItemStack> drops = new ArrayList<>();
|
||||||
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
|
PlayerDeathEvent e = getPlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
|
||||||
new IslandRespawnListener().onPlayerDeath(e);
|
new IslandRespawnListener().onPlayerDeath(e);
|
||||||
verify(world).getUID();
|
verify(world).getUID();
|
||||||
}
|
}
|
||||||
@ -196,7 +197,7 @@ public class IslandRespawnListenerTest {
|
|||||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||||
when(im.inTeam(any(), any(UUID.class))).thenReturn(false);
|
when(im.inTeam(any(), any(UUID.class))).thenReturn(false);
|
||||||
List<ItemStack> drops = new ArrayList<>();
|
List<ItemStack> drops = new ArrayList<>();
|
||||||
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
|
PlayerDeathEvent e = getPlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
|
||||||
new IslandRespawnListener().onPlayerDeath(e);
|
new IslandRespawnListener().onPlayerDeath(e);
|
||||||
verify(world).getUID();
|
verify(world).getUID();
|
||||||
}
|
}
|
||||||
@ -208,7 +209,7 @@ public class IslandRespawnListenerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testOnPlayerDeath() {
|
public void testOnPlayerDeath() {
|
||||||
List<ItemStack> drops = new ArrayList<>();
|
List<ItemStack> drops = new ArrayList<>();
|
||||||
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
|
PlayerDeathEvent e = getPlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
|
||||||
new IslandRespawnListener().onPlayerDeath(e);
|
new IslandRespawnListener().onPlayerDeath(e);
|
||||||
verify(world).getUID();
|
verify(world).getUID();
|
||||||
}
|
}
|
||||||
@ -221,7 +222,7 @@ public class IslandRespawnListenerTest {
|
|||||||
public void testOnPlayerRespawn() {
|
public void testOnPlayerRespawn() {
|
||||||
// Die
|
// Die
|
||||||
List<ItemStack> drops = new ArrayList<>();
|
List<ItemStack> drops = new ArrayList<>();
|
||||||
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
|
PlayerDeathEvent e = getPlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
|
||||||
IslandRespawnListener l = new IslandRespawnListener();
|
IslandRespawnListener l = new IslandRespawnListener();
|
||||||
l.onPlayerDeath(e);
|
l.onPlayerDeath(e);
|
||||||
Location location = mock(Location.class);
|
Location location = mock(Location.class);
|
||||||
@ -263,7 +264,7 @@ public class IslandRespawnListenerTest {
|
|||||||
when(iwm.inWorld(any(Location.class))).thenReturn(false);
|
when(iwm.inWorld(any(Location.class))).thenReturn(false);
|
||||||
// Die
|
// Die
|
||||||
List<ItemStack> drops = new ArrayList<>();
|
List<ItemStack> drops = new ArrayList<>();
|
||||||
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
|
PlayerDeathEvent e = getPlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
|
||||||
IslandRespawnListener l = new IslandRespawnListener();
|
IslandRespawnListener l = new IslandRespawnListener();
|
||||||
l.onPlayerDeath(e);
|
l.onPlayerDeath(e);
|
||||||
Location location = mock(Location.class);
|
Location location = mock(Location.class);
|
||||||
@ -285,7 +286,7 @@ public class IslandRespawnListenerTest {
|
|||||||
Flags.ISLAND_RESPAWN.setSetting(world, false);
|
Flags.ISLAND_RESPAWN.setSetting(world, false);
|
||||||
// Die
|
// Die
|
||||||
List<ItemStack> drops = new ArrayList<>();
|
List<ItemStack> drops = new ArrayList<>();
|
||||||
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
|
PlayerDeathEvent e = getPlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
|
||||||
IslandRespawnListener l = new IslandRespawnListener();
|
IslandRespawnListener l = new IslandRespawnListener();
|
||||||
l.onPlayerDeath(e);
|
l.onPlayerDeath(e);
|
||||||
Location location = mock(Location.class);
|
Location location = mock(Location.class);
|
||||||
|
@ -46,6 +46,7 @@ import world.bentobox.bentobox.BentoBox;
|
|||||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
import world.bentobox.bentobox.listeners.flags.AbstractCommonSetup;
|
||||||
import world.bentobox.bentobox.lists.Flags;
|
import world.bentobox.bentobox.lists.Flags;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.IslandsManager;
|
import world.bentobox.bentobox.managers.IslandsManager;
|
||||||
@ -57,7 +58,7 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
*/
|
*/
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({ BentoBox.class, Util.class, Bukkit.class })
|
@PrepareForTest({ BentoBox.class, Util.class, Bukkit.class })
|
||||||
public class VisitorKeepInventoryListenerTest {
|
public class VisitorKeepInventoryListenerTest extends AbstractCommonSetup {
|
||||||
|
|
||||||
// Class under test
|
// Class under test
|
||||||
private VisitorKeepInventoryListener l;
|
private VisitorKeepInventoryListener l;
|
||||||
@ -136,7 +137,7 @@ public class VisitorKeepInventoryListenerTest {
|
|||||||
// Default death event
|
// Default death event
|
||||||
List<ItemStack> drops = new ArrayList<>();
|
List<ItemStack> drops = new ArrayList<>();
|
||||||
drops.add(new ItemStack(Material.ACACIA_BOAT));
|
drops.add(new ItemStack(Material.ACACIA_BOAT));
|
||||||
e = new PlayerDeathEvent(player, drops, 100, 0, 0, 0, "Death message");
|
e = getPlayerDeathEvent(player, drops, 100, 0, 0, 0, "Death message");
|
||||||
// Make new
|
// Make new
|
||||||
l = new VisitorKeepInventoryListener();
|
l = new VisitorKeepInventoryListener();
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ import org.powermock.reflect.Whitebox;
|
|||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
import world.bentobox.bentobox.listeners.flags.AbstractCommonSetup;
|
||||||
import world.bentobox.bentobox.lists.Flags;
|
import world.bentobox.bentobox.lists.Flags;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ import world.bentobox.bentobox.managers.IslandWorldManager;
|
|||||||
*/
|
*/
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest( {BentoBox.class, Bukkit.class} )
|
@PrepareForTest( {BentoBox.class, Bukkit.class} )
|
||||||
public class WitherListenerTest {
|
public class WitherListenerTest extends AbstractCommonSetup {
|
||||||
|
|
||||||
private WitherListener wl;
|
private WitherListener wl;
|
||||||
@Mock
|
@Mock
|
||||||
@ -121,7 +122,7 @@ public class WitherListenerTest {
|
|||||||
when(entity.getLocation()).thenReturn(location);
|
when(entity.getLocation()).thenReturn(location);
|
||||||
when(entity.getWorld()).thenReturn(world);
|
when(entity.getWorld()).thenReturn(world);
|
||||||
when(entity.getType()).thenReturn(EntityType.WITHER);
|
when(entity.getType()).thenReturn(EntityType.WITHER);
|
||||||
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, blocks, 0);
|
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
|
||||||
wl.onExplosion(e);
|
wl.onExplosion(e);
|
||||||
assertTrue(blocks.isEmpty());
|
assertTrue(blocks.isEmpty());
|
||||||
}
|
}
|
||||||
@ -136,7 +137,7 @@ public class WitherListenerTest {
|
|||||||
when(entity.getLocation()).thenReturn(location2);
|
when(entity.getLocation()).thenReturn(location2);
|
||||||
when(entity.getWorld()).thenReturn(world2);
|
when(entity.getWorld()).thenReturn(world2);
|
||||||
when(entity.getType()).thenReturn(EntityType.WITHER);
|
when(entity.getType()).thenReturn(EntityType.WITHER);
|
||||||
EntityExplodeEvent e = new EntityExplodeEvent(entity, location2, blocks, 0);
|
EntityExplodeEvent e = getExplodeEvent(entity, location2, blocks);
|
||||||
wl.onExplosion(e);
|
wl.onExplosion(e);
|
||||||
assertFalse(blocks.isEmpty());
|
assertFalse(blocks.isEmpty());
|
||||||
}
|
}
|
||||||
@ -151,7 +152,7 @@ public class WitherListenerTest {
|
|||||||
when(entity.getLocation()).thenReturn(location);
|
when(entity.getLocation()).thenReturn(location);
|
||||||
when(entity.getWorld()).thenReturn(world);
|
when(entity.getWorld()).thenReturn(world);
|
||||||
when(entity.getType()).thenReturn(EntityType.WITHER);
|
when(entity.getType()).thenReturn(EntityType.WITHER);
|
||||||
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, blocks, 0);
|
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
|
||||||
wl.onExplosion(e);
|
wl.onExplosion(e);
|
||||||
assertFalse(blocks.isEmpty());
|
assertFalse(blocks.isEmpty());
|
||||||
|
|
||||||
@ -166,7 +167,7 @@ public class WitherListenerTest {
|
|||||||
when(entity.getLocation()).thenReturn(location);
|
when(entity.getLocation()).thenReturn(location);
|
||||||
when(entity.getWorld()).thenReturn(world);
|
when(entity.getWorld()).thenReturn(world);
|
||||||
when(entity.getType()).thenReturn(EntityType.WITHER_SKULL);
|
when(entity.getType()).thenReturn(EntityType.WITHER_SKULL);
|
||||||
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, blocks, 0);
|
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
|
||||||
wl.onExplosion(e);
|
wl.onExplosion(e);
|
||||||
assertTrue(blocks.isEmpty());
|
assertTrue(blocks.isEmpty());
|
||||||
}
|
}
|
||||||
@ -180,7 +181,7 @@ public class WitherListenerTest {
|
|||||||
when(entity.getLocation()).thenReturn(location);
|
when(entity.getLocation()).thenReturn(location);
|
||||||
when(entity.getWorld()).thenReturn(world);
|
when(entity.getWorld()).thenReturn(world);
|
||||||
when(entity.getType()).thenReturn(EntityType.DRAGON_FIREBALL);
|
when(entity.getType()).thenReturn(EntityType.DRAGON_FIREBALL);
|
||||||
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, blocks, 0);
|
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
|
||||||
wl.onExplosion(e);
|
wl.onExplosion(e);
|
||||||
assertFalse(blocks.isEmpty());
|
assertFalse(blocks.isEmpty());
|
||||||
}
|
}
|
||||||
|
@ -470,6 +470,23 @@ public class IslandCacheTest extends AbstractCommonSetup {
|
|||||||
assertTrue(ic.getIslands(owner).isEmpty());
|
assertTrue(ic.getIslands(owner).isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.bentobox.managers.island.IslandCache#getIslands(java.util.UUID)}.
|
||||||
|
* @throws IntrospectionException
|
||||||
|
* @throws NoSuchMethodException
|
||||||
|
* @throws ClassNotFoundException
|
||||||
|
* @throws InvocationTargetException
|
||||||
|
* @throws IllegalAccessException
|
||||||
|
* @throws InstantiationException
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGetIslandsUUIDNoIslands() throws InstantiationException, IllegalAccessException,
|
||||||
|
InvocationTargetException, ClassNotFoundException, NoSuchMethodException, IntrospectionException {
|
||||||
|
// Test is WIP.
|
||||||
|
when(handler.loadObject(anyString())).thenReturn(null);
|
||||||
|
assertTrue(ic.getIslands(owner).isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.managers.island.IslandCache#addIsland(world.bentobox.bentobox.database.objects.Island)}.
|
* Test method for {@link world.bentobox.bentobox.managers.island.IslandCache#addIsland(world.bentobox.bentobox.database.objects.Island)}.
|
||||||
*/
|
*/
|
||||||
|
@ -9,8 +9,15 @@ import static org.mockito.Mockito.never;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Keyed;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.Registry;
|
||||||
import org.bukkit.UnsafeValues;
|
import org.bukkit.UnsafeValues;
|
||||||
import org.bukkit.inventory.ItemFactory;
|
import org.bukkit.inventory.ItemFactory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -21,6 +28,7 @@ import org.bukkit.inventory.meta.SkullMeta;
|
|||||||
import org.bukkit.potion.PotionType;
|
import org.bukkit.potion.PotionType;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@ -34,7 +42,7 @@ import world.bentobox.bentobox.BentoBox;
|
|||||||
|
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({BentoBox.class, Bukkit.class})
|
@PrepareForTest({ BentoBox.class, Bukkit.class, Objects.class })
|
||||||
public class ItemParserTest {
|
public class ItemParserTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
@ -50,6 +58,7 @@ public class ItemParserTest {
|
|||||||
|
|
||||||
private ItemStack defaultItem;
|
private ItemStack defaultItem;
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
@ -57,32 +66,43 @@ public class ItemParserTest {
|
|||||||
BentoBox plugin = mock(BentoBox.class);
|
BentoBox plugin = mock(BentoBox.class);
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
|
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||||
|
|
||||||
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
|
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
|
||||||
// Do not test Bukkit createItemStack method output as I assume Bukkit has their tests covered.
|
// Do not test Bukkit createItemStack method output as I assume Bukkit has their tests covered.
|
||||||
when(itemFactory.createItemStack(any())).thenThrow(IllegalArgumentException.class);
|
when(itemFactory.createItemStack(any())).thenThrow(IllegalArgumentException.class);
|
||||||
/*
|
|
||||||
when(itemFactory.getItemMeta(Mockito.eq(Material.POTION))).thenReturn(potionMeta);
|
|
||||||
when(itemFactory.getItemMeta(Mockito.eq(Material.SPLASH_POTION))).thenReturn(potionMeta);
|
|
||||||
when(itemFactory.getItemMeta(Mockito.eq(Material.LINGERING_POTION))).thenReturn(potionMeta);
|
|
||||||
when(itemFactory.getItemMeta(Mockito.eq(Material.TIPPED_ARROW))).thenReturn(potionMeta);
|
|
||||||
*/
|
|
||||||
UnsafeValues unsafe = mock(UnsafeValues.class);
|
UnsafeValues unsafe = mock(UnsafeValues.class);
|
||||||
when(unsafe.getDataVersion()).thenReturn(777);
|
when(unsafe.getDataVersion()).thenReturn(777);
|
||||||
when(Bukkit.getUnsafe()).thenReturn(unsafe);
|
when(Bukkit.getUnsafe()).thenReturn(unsafe);
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(itemMeta);
|
when(itemFactory.getItemMeta(any())).thenReturn(itemMeta);
|
||||||
/*
|
|
||||||
when(itemFactory.getItemMeta(any())).thenAnswer((Answer<ItemMeta>) invocation -> {
|
|
||||||
return switch (invocation.getArgument(0, Material.class)) {
|
|
||||||
case RED_BANNER, WHITE_BANNER -> bannerMeta;
|
|
||||||
case POTION, SPLASH_POTION, LINGERING_POTION, TIPPED_ARROW -> potionMeta;
|
|
||||||
default -> itemMeta;
|
|
||||||
};
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
defaultItem = new ItemStack(Material.STONE);
|
defaultItem = new ItemStack(Material.STONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class dummy implements Registry {
|
||||||
|
NamespacedKey get(String string) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator iterator() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Keyed get(NamespacedKey key) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream stream() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
Mockito.framework().clearInlineMocks();
|
Mockito.framework().clearInlineMocks();
|
||||||
@ -189,6 +209,7 @@ public class ItemParserTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore("Doesn't work on 1.21")
|
||||||
public void testParseBanner() {
|
public void testParseBanner() {
|
||||||
when(itemFactory.getItemMeta(any())).thenReturn(bannerMeta);
|
when(itemFactory.getItemMeta(any())).thenReturn(bannerMeta);
|
||||||
// Germany - two patterns
|
// Germany - two patterns
|
||||||
|
Loading…
Reference in New Issue
Block a user