mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-24 11:45:31 +01:00
Merge remote-tracking branch 'origin/develop' into schem-command-improvements
This commit is contained in:
commit
1c24619450
@ -107,6 +107,14 @@ public class Settings implements DataObject {
|
|||||||
@ConfigEntry(path = "island.cooldown.invite")
|
@ConfigEntry(path = "island.cooldown.invite")
|
||||||
private int inviteCooldown = 60;
|
private int inviteCooldown = 60;
|
||||||
|
|
||||||
|
@ConfigComment("How long a player must wait until they can coop a player in minutes.")
|
||||||
|
@ConfigEntry(path = "island.cooldown.coop")
|
||||||
|
private int coopCooldown = 5;
|
||||||
|
|
||||||
|
@ConfigComment("How long a player must wait until they can trust a player in minutes.")
|
||||||
|
@ConfigEntry(path = "island.cooldown.trust")
|
||||||
|
private int trustCooldown = 5;
|
||||||
|
|
||||||
@ConfigComment("How long a player must wait until they can ban a player")
|
@ConfigComment("How long a player must wait until they can ban a player")
|
||||||
@ConfigComment("after unbanning them. In minutes.")
|
@ConfigComment("after unbanning them. In minutes.")
|
||||||
@ConfigEntry(path = "island.cooldown.ban")
|
@ConfigEntry(path = "island.cooldown.ban")
|
||||||
@ -286,6 +294,22 @@ public class Settings implements DataObject {
|
|||||||
this.inviteCooldown = inviteCooldown;
|
this.inviteCooldown = inviteCooldown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCoopCooldown() {
|
||||||
|
return coopCooldown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoopCooldown(int coopCooldown) {
|
||||||
|
this.coopCooldown = coopCooldown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTrustCooldown() {
|
||||||
|
return trustCooldown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTrustCooldown(int trustCooldown) {
|
||||||
|
this.trustCooldown = trustCooldown;
|
||||||
|
}
|
||||||
|
|
||||||
public int getBanCooldown() {
|
public int getBanCooldown() {
|
||||||
return banCooldown;
|
return banCooldown;
|
||||||
}
|
}
|
||||||
|
@ -48,11 +48,12 @@ public abstract class ConfirmableCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells user to confirm command by retyping
|
* Tells user to confirm command by retyping it.
|
||||||
* @param user - user
|
* @param user User to ask confirmation to.
|
||||||
* @param confirmed - runnable to be executed if confirmed
|
* @param message Optional message to send to the user to give them a bit more context. It must already be translated.
|
||||||
|
* @param confirmed Runnable to be executed if successfully confirmed.
|
||||||
*/
|
*/
|
||||||
public void askConfirmation(User user, Runnable confirmed) {
|
public void askConfirmation(User user, String message, Runnable confirmed) {
|
||||||
// Check for pending confirmations
|
// Check for pending confirmations
|
||||||
if (toBeConfirmed.containsKey(user)) {
|
if (toBeConfirmed.containsKey(user)) {
|
||||||
if (toBeConfirmed.get(user).getTopLabel().equals(getTopLabel()) && toBeConfirmed.get(user).getLabel().equalsIgnoreCase(getLabel())) {
|
if (toBeConfirmed.get(user).getTopLabel().equals(getTopLabel()) && toBeConfirmed.get(user).getLabel().equalsIgnoreCase(getLabel())) {
|
||||||
@ -65,6 +66,10 @@ public abstract class ConfirmableCommand extends CompositeCommand {
|
|||||||
user.sendMessage("commands.confirmation.previous-request-cancelled");
|
user.sendMessage("commands.confirmation.previous-request-cancelled");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Send user the context message if it is not empty
|
||||||
|
if (!message.trim().isEmpty()) {
|
||||||
|
user.sendRawMessage(message);
|
||||||
|
}
|
||||||
// Tell user that they need to confirm
|
// Tell user that they need to confirm
|
||||||
user.sendMessage("commands.confirmation.confirm", "[seconds]", String.valueOf(getSettings().getConfirmationTime()));
|
user.sendMessage("commands.confirmation.confirm", "[seconds]", String.valueOf(getSettings().getConfirmationTime()));
|
||||||
// Set up a cancellation task
|
// Set up a cancellation task
|
||||||
@ -77,6 +82,15 @@ public abstract class ConfirmableCommand extends CompositeCommand {
|
|||||||
toBeConfirmed.put(user, new Confirmer(getTopLabel(), getLabel(), confirmed, task));
|
toBeConfirmed.put(user, new Confirmer(getTopLabel(), getLabel(), confirmed, task));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells user to confirm command by retyping it.
|
||||||
|
* @param user User to ask confirmation to.
|
||||||
|
* @param confirmed Runnable to be executed if successfully confirmed.
|
||||||
|
*/
|
||||||
|
public void askConfirmation(User user, Runnable confirmed) {
|
||||||
|
askConfirmation(user, "", confirmed);
|
||||||
|
}
|
||||||
|
|
||||||
private class Confirmer {
|
private class Confirmer {
|
||||||
private final String topLabel;
|
private final String topLabel;
|
||||||
private final String label;
|
private final String label;
|
||||||
|
@ -54,7 +54,7 @@ public class IslandTeamCoopCommand extends CompositeCommand {
|
|||||||
user.sendMessage("general.errors.unknown-player");
|
user.sendMessage("general.errors.unknown-player");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (getSettings().getInviteCooldown() <= 0 || !checkCooldown(user, targetUUID)) && coopCmd(user, targetUUID);
|
return (getSettings().getCoopCooldown() <= 0 || !checkCooldown(user, targetUUID)) && coopCmd(user, targetUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean coopCmd(User user, UUID targetUUID) {
|
private boolean coopCmd(User user, UUID targetUUID) {
|
||||||
|
@ -58,7 +58,7 @@ public class IslandTeamTrustCommand extends CompositeCommand {
|
|||||||
user.sendMessage("general.errors.unknown-player");
|
user.sendMessage("general.errors.unknown-player");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (getSettings().getInviteCooldown() <= 0 || !checkCooldown(user, targetUUID)) && trustCmd(user, targetUUID);
|
return (getSettings().getTrustCooldown() <= 0 || !checkCooldown(user, targetUUID)) && trustCmd(user, targetUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean trustCmd(User user, UUID targetUUID) {
|
private boolean trustCmd(User user, UUID targetUUID) {
|
||||||
|
@ -84,9 +84,9 @@ public class IslandTeamUncoopCommand extends CompositeCommand {
|
|||||||
user.sendMessage("general.success");
|
user.sendMessage("general.success");
|
||||||
target.sendMessage("commands.island.team.uncoop.you-are-no-longer-a-coop-member", TextVariables.NAME, user.getName());
|
target.sendMessage("commands.island.team.uncoop.you-are-no-longer-a-coop-member", TextVariables.NAME, user.getName());
|
||||||
// Set cooldown
|
// Set cooldown
|
||||||
if (getSettings().getInviteCooldown() > 0 && getParent() != null) {
|
if (getSettings().getCoopCooldown() > 0 && getParent() != null) {
|
||||||
getParent().getSubCommand("coop").ifPresent(subCommand ->
|
getParent().getSubCommand("coop").ifPresent(subCommand ->
|
||||||
subCommand.setCooldown(user.getUniqueId(), targetUUID, getSettings().getInviteCooldown() * 60));
|
subCommand.setCooldown(user.getUniqueId(), targetUUID, getSettings().getCoopCooldown() * 60));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -84,9 +84,9 @@ public class IslandTeamUntrustCommand extends CompositeCommand {
|
|||||||
user.sendMessage("general.success");
|
user.sendMessage("general.success");
|
||||||
target.sendMessage("commands.island.team.untrust.you-are-no-longer-trusted", TextVariables.NAME, user.getName());
|
target.sendMessage("commands.island.team.untrust.you-are-no-longer-trusted", TextVariables.NAME, user.getName());
|
||||||
// Set cooldown
|
// Set cooldown
|
||||||
if (getSettings().getInviteCooldown() > 0 && getParent() != null) {
|
if (getSettings().getTrustCooldown() > 0 && getParent() != null) {
|
||||||
getParent().getSubCommand("trust").ifPresent(subCommand ->
|
getParent().getSubCommand("trust").ifPresent(subCommand ->
|
||||||
subCommand.setCooldown(user.getUniqueId(), targetUUID, getSettings().getInviteCooldown() * 60));
|
subCommand.setCooldown(user.getUniqueId(), targetUUID, getSettings().getTrustCooldown() * 60));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -190,6 +190,7 @@ public class Island implements DataObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Members > MEMBER_RANK
|
||||||
* @return the members of the island (owner included)
|
* @return the members of the island (owner included)
|
||||||
*/
|
*/
|
||||||
public ImmutableSet<UUID> getMemberSet(){
|
public ImmutableSet<UUID> getMemberSet(){
|
||||||
@ -605,14 +606,14 @@ public class Island implements DataObject {
|
|||||||
// Fixes #getLastPlayed() returning 0 when it is the owner's first connection.
|
// Fixes #getLastPlayed() returning 0 when it is the owner's first connection.
|
||||||
long lastPlayed = (plugin.getServer().getOfflinePlayer(owner).getLastPlayed() != 0) ?
|
long lastPlayed = (plugin.getServer().getOfflinePlayer(owner).getLastPlayed() != 0) ?
|
||||||
plugin.getServer().getOfflinePlayer(owner).getLastPlayed() : plugin.getServer().getOfflinePlayer(owner).getFirstPlayed();
|
plugin.getServer().getOfflinePlayer(owner).getLastPlayed() : plugin.getServer().getOfflinePlayer(owner).getFirstPlayed();
|
||||||
user.sendMessage("commands.admin.info.last-login","[date]", new Date(lastPlayed).toString());
|
user.sendMessage("commands.admin.info.last-login","[date]", new Date(lastPlayed).toString());
|
||||||
|
|
||||||
user.sendMessage("commands.admin.info.deaths", "[number]", String.valueOf(plugin.getPlayers().getDeaths(world, owner)));
|
user.sendMessage("commands.admin.info.deaths", "[number]", String.valueOf(plugin.getPlayers().getDeaths(world, owner)));
|
||||||
String resets = String.valueOf(plugin.getPlayers().getResets(world, owner));
|
String resets = String.valueOf(plugin.getPlayers().getResets(world, owner));
|
||||||
String total = plugin.getIWM().getResetLimit(world) < 0 ? "Unlimited" : String.valueOf(plugin.getIWM().getResetLimit(world));
|
String total = plugin.getIWM().getResetLimit(world) < 0 ? "Unlimited" : String.valueOf(plugin.getIWM().getResetLimit(world));
|
||||||
user.sendMessage("commands.admin.info.resets-left", "[number]", resets, "[total]", total);
|
user.sendMessage("commands.admin.info.resets-left", "[number]", resets, "[total]", total);
|
||||||
// Show team members
|
// Show team members
|
||||||
showMembers(plugin, user, world);
|
showMembers(plugin, user, world);
|
||||||
}
|
}
|
||||||
Vector location = center.toVector();
|
Vector location = center.toVector();
|
||||||
user.sendMessage("commands.admin.info.island-location", "[xyz]", Util.xyz(location));
|
user.sendMessage("commands.admin.info.island-location", "[xyz]", Util.xyz(location));
|
||||||
|
@ -36,9 +36,9 @@ public class JoinLeaveListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UUID playerUUID = user.getUniqueId();
|
UUID playerUUID = user.getUniqueId();
|
||||||
|
// Load player
|
||||||
|
players.addPlayer(playerUUID);
|
||||||
if (plugin.getPlayers().isKnown(playerUUID)) {
|
if (plugin.getPlayers().isKnown(playerUUID)) {
|
||||||
// Load player
|
|
||||||
players.addPlayer(playerUUID);
|
|
||||||
// Reset island resets if required
|
// Reset island resets if required
|
||||||
plugin.getIWM().getOverWorlds().stream()
|
plugin.getIWM().getOverWorlds().stream()
|
||||||
.filter(w -> event.getPlayer().getLastPlayed() < plugin.getIWM().getResetEpoch(w))
|
.filter(w -> event.getPlayer().getLastPlayed() < plugin.getIWM().getResetEpoch(w))
|
||||||
|
@ -50,9 +50,9 @@ public class PVPListener extends AbstractFlagListener {
|
|||||||
// Protect visitors
|
// Protect visitors
|
||||||
if (e.getCause().equals(DamageCause.ENTITY_ATTACK) && protectedVisitor((Player)e.getEntity())) {
|
if (e.getCause().equals(DamageCause.ENTITY_ATTACK) && protectedVisitor((Player)e.getEntity())) {
|
||||||
if (e.getDamager() instanceof Player) {
|
if (e.getDamager() instanceof Player) {
|
||||||
User.getInstance(e.getDamager()).sendMessage(Flags.INVINCIBLE_VISITORS.getHintReference());
|
User.getInstance(e.getDamager()).notify(Flags.INVINCIBLE_VISITORS.getHintReference());
|
||||||
} else if (e.getDamager() instanceof Projectile && ((Projectile)e.getDamager()).getShooter() instanceof Player) {
|
} else if (e.getDamager() instanceof Projectile && ((Projectile)e.getDamager()).getShooter() instanceof Player) {
|
||||||
User.getInstance((Player)((Projectile)e.getDamager()).getShooter()).sendMessage(Flags.INVINCIBLE_VISITORS.getHintReference());
|
User.getInstance((Player)((Projectile)e.getDamager()).getShooter()).notify(Flags.INVINCIBLE_VISITORS.getHintReference());
|
||||||
}
|
}
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
} else {
|
} else {
|
||||||
@ -73,7 +73,7 @@ public class PVPListener extends AbstractFlagListener {
|
|||||||
if (damager instanceof Player) {
|
if (damager instanceof Player) {
|
||||||
User user = User.getInstance(damager);
|
User user = User.getInstance(damager);
|
||||||
if (!setUser(user).checkIsland((Event)e, damager.getLocation(), flag)) {
|
if (!setUser(user).checkIsland((Event)e, damager.getLocation(), flag)) {
|
||||||
user.sendMessage(Flags.PVP_OVERWORLD.getHintReference());
|
user.notify(Flags.PVP_OVERWORLD.getHintReference());
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
} else if (damager instanceof Projectile) {
|
} else if (damager instanceof Projectile) {
|
||||||
@ -88,7 +88,7 @@ public class PVPListener extends AbstractFlagListener {
|
|||||||
if (!setUser(user).checkIsland((Event)e, damager.getLocation(), flag)) {
|
if (!setUser(user).checkIsland((Event)e, damager.getLocation(), flag)) {
|
||||||
damager.setFireTicks(0);
|
damager.setFireTicks(0);
|
||||||
damager.remove();
|
damager.remove();
|
||||||
user.sendMessage(Flags.PVP_OVERWORLD.getHintReference());
|
user.notify(Flags.PVP_OVERWORLD.getHintReference());
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,11 +104,11 @@ public class PVPListener extends AbstractFlagListener {
|
|||||||
}
|
}
|
||||||
// Protect visitors
|
// Protect visitors
|
||||||
if (protectedVisitor((Player)e.getCaught())) {
|
if (protectedVisitor((Player)e.getCaught())) {
|
||||||
User.getInstance(e.getPlayer()).sendMessage(Flags.INVINCIBLE_VISITORS.getHintReference());
|
User.getInstance(e.getPlayer()).notify(Flags.INVINCIBLE_VISITORS.getHintReference());
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
} else if (!checkIsland(e, e.getCaught().getLocation(), getFlag(e.getCaught().getWorld()))) {
|
} else if (!checkIsland(e, e.getCaught().getLocation(), getFlag(e.getCaught().getWorld()))) {
|
||||||
e.getHook().remove();
|
e.getHook().remove();
|
||||||
User.getInstance(e.getPlayer()).sendMessage(Flags.PVP_OVERWORLD.getHintReference());
|
User.getInstance(e.getPlayer()).notify(Flags.PVP_OVERWORLD.getHintReference());
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,12 +143,12 @@ public class PVPListener extends AbstractFlagListener {
|
|||||||
if (le instanceof Player) {
|
if (le instanceof Player) {
|
||||||
// Protect visitors
|
// Protect visitors
|
||||||
if (protectedVisitor(le)) {
|
if (protectedVisitor(le)) {
|
||||||
user.sendMessage(Flags.INVINCIBLE_VISITORS.getHintReference());
|
user.notify(Flags.INVINCIBLE_VISITORS.getHintReference());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Check if PVP is allowed or not
|
// Check if PVP is allowed or not
|
||||||
if (!checkIsland(e, le.getLocation(), flag)) {
|
if (!checkIsland(e, le.getLocation(), flag)) {
|
||||||
user.sendMessage(Flags.PVP_OVERWORLD.getHintReference());
|
user.notify(Flags.PVP_OVERWORLD.getHintReference());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -285,7 +285,9 @@ public class IslandsManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the island at the location or Optional empty if there is none.
|
* Returns the island at the location or Optional empty if there is none.
|
||||||
* This includes the full island space, not just the protected area
|
* This includes the full island space, not just the protected area.
|
||||||
|
* Use {@link #getProtectedIslandAt(Location)} for only the protected
|
||||||
|
* island space.
|
||||||
*
|
*
|
||||||
* @param location - the location
|
* @param location - the location
|
||||||
* @return Optional Island object
|
* @return Optional Island object
|
||||||
@ -334,7 +336,9 @@ public class IslandsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the island being public at the location or Optional Empty if there is none
|
* Returns the island at the location or Optional empty if there is none.
|
||||||
|
* This includes only the protected area. Use {@link #getIslandAt(Location)}
|
||||||
|
* for the full island space.
|
||||||
*
|
*
|
||||||
* @param location - the location
|
* @param location - the location
|
||||||
* @return Optional Island object
|
* @return Optional Island object
|
||||||
@ -631,7 +635,11 @@ public class IslandsManager {
|
|||||||
if (user == null) {
|
if (user == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return Optional.ofNullable(getIsland(world, user)).map(i -> i.onIsland(user.getLocation())).orElse(false);
|
return getProtectedIslandAt(user.getLocation())
|
||||||
|
.map(i -> i.getMembers().entrySet().stream()
|
||||||
|
.map(en -> en.getKey().equals(user.getUniqueId()) && en.getValue() > RanksManager.VISITOR_RANK)
|
||||||
|
.findAny().orElse(false))
|
||||||
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -122,7 +122,7 @@ public class PlayersManager {
|
|||||||
* in the database too.
|
* in the database too.
|
||||||
*
|
*
|
||||||
* @param uniqueID - unique ID
|
* @param uniqueID - unique ID
|
||||||
* @return true if player is know, otherwise false
|
* @return true if player is known, otherwise false
|
||||||
*/
|
*/
|
||||||
public boolean isKnown(UUID uniqueID) {
|
public boolean isKnown(UUID uniqueID) {
|
||||||
return uniqueID != null && (playerCache.containsKey(uniqueID) || handler.objectExists(uniqueID.toString()));
|
return uniqueID != null && (playerCache.containsKey(uniqueID) || handler.objectExists(uniqueID.toString()));
|
||||||
|
@ -4,7 +4,6 @@ import java.util.Comparator;
|
|||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.flags.Flag;
|
import world.bentobox.bentobox.api.flags.Flag;
|
||||||
|
@ -64,6 +64,7 @@ import world.bentobox.bentobox.api.configuration.WorldSettings;
|
|||||||
import world.bentobox.bentobox.api.flags.Flag;
|
import world.bentobox.bentobox.api.flags.Flag;
|
||||||
import world.bentobox.bentobox.api.panels.Panel;
|
import world.bentobox.bentobox.api.panels.Panel;
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
|
import world.bentobox.bentobox.api.user.Notifier;
|
||||||
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.lists.Flags;
|
import world.bentobox.bentobox.lists.Flags;
|
||||||
@ -91,6 +92,7 @@ public class PVPListenerTest {
|
|||||||
private Zombie zombie;
|
private Zombie zombie;
|
||||||
private Creeper creeper;
|
private Creeper creeper;
|
||||||
private World world;
|
private World world;
|
||||||
|
private Notifier notifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception
|
* @throws java.lang.Exception
|
||||||
@ -100,6 +102,8 @@ public class PVPListenerTest {
|
|||||||
// Set up plugin
|
// Set up plugin
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
BentoBox plugin = mock(BentoBox.class);
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
|
// Make sure you set the plung for the User class otherwise it'll use an old object
|
||||||
|
User.setPlugin(plugin);
|
||||||
// Island World Manager
|
// Island World Manager
|
||||||
iwm = mock(IslandWorldManager.class);
|
iwm = mock(IslandWorldManager.class);
|
||||||
when(iwm.inWorld(Mockito.any())).thenReturn(true);
|
when(iwm.inWorld(Mockito.any())).thenReturn(true);
|
||||||
@ -184,6 +188,10 @@ public class PVPListenerTest {
|
|||||||
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
||||||
Map<String, Boolean> worldFlags = new HashMap<>();
|
Map<String, Boolean> worldFlags = new HashMap<>();
|
||||||
when(ws.getWorldFlags()).thenReturn(worldFlags);
|
when(ws.getWorldFlags()).thenReturn(worldFlags);
|
||||||
|
|
||||||
|
// Notifier
|
||||||
|
notifier = mock(Notifier.class);
|
||||||
|
when(plugin.getNotifier()).thenReturn(notifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -199,7 +207,7 @@ public class PVPListenerTest {
|
|||||||
new PVPListener().onEntityDamage(e);
|
new PVPListener().onEntityDamage(e);
|
||||||
assertFalse(e.isCancelled());
|
assertFalse(e.isCancelled());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.listeners.flags.PVPListener#onEntityDamage(org.bukkit.event.entity.EntityDamageByEntityEvent)}.
|
* Test method for {@link world.bentobox.bentobox.listeners.flags.PVPListener#onEntityDamage(org.bukkit.event.entity.EntityDamageByEntityEvent)}.
|
||||||
*/
|
*/
|
||||||
@ -387,7 +395,6 @@ public class PVPListenerTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testOnEntityDamagePVPNotAllowed() {
|
public void testOnEntityDamagePVPNotAllowed() {
|
||||||
|
|
||||||
// No visitor protection
|
// No visitor protection
|
||||||
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(player, player2, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
|
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(player, player2, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
|
||||||
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
|
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
|
||||||
@ -395,7 +402,18 @@ public class PVPListenerTest {
|
|||||||
new PVPListener().onEntityDamage(e);
|
new PVPListener().onEntityDamage(e);
|
||||||
// PVP should be banned
|
// PVP should be banned
|
||||||
assertTrue(e.isCancelled());
|
assertTrue(e.isCancelled());
|
||||||
Mockito.verify(player).sendMessage(Flags.PVP_OVERWORLD.getHintReference());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.PVP_OVERWORLD.getHintReference()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.bentobox.listeners.flags.PVPListener#onEntityDamage(org.bukkit.event.entity.EntityDamageByEntityEvent)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testOnEntityDamagePVPNotAllowedInvVisitor() {
|
||||||
|
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(player, player2, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
|
||||||
|
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
|
||||||
|
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
|
||||||
|
|
||||||
// Enable visitor protection
|
// Enable visitor protection
|
||||||
// This player is a visitor and any damage is not allowed
|
// This player is a visitor and any damage is not allowed
|
||||||
@ -404,7 +422,7 @@ public class PVPListenerTest {
|
|||||||
new PVPListener().onEntityDamage(e);
|
new PVPListener().onEntityDamage(e);
|
||||||
// visitor should be protected
|
// visitor should be protected
|
||||||
assertTrue(e.isCancelled());
|
assertTrue(e.isCancelled());
|
||||||
Mockito.verify(player).sendMessage(Flags.INVINCIBLE_VISITORS.getHintReference());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -429,7 +447,7 @@ public class PVPListenerTest {
|
|||||||
new PVPListener().onEntityDamage(e);
|
new PVPListener().onEntityDamage(e);
|
||||||
// visitor should be protected
|
// visitor should be protected
|
||||||
assertTrue(e.isCancelled());
|
assertTrue(e.isCancelled());
|
||||||
Mockito.verify(player).sendMessage(Flags.INVINCIBLE_VISITORS.getHintReference());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -447,7 +465,7 @@ public class PVPListenerTest {
|
|||||||
new PVPListener().onEntityDamage(e);
|
new PVPListener().onEntityDamage(e);
|
||||||
// PVP should be banned
|
// PVP should be banned
|
||||||
assertTrue(e.isCancelled());
|
assertTrue(e.isCancelled());
|
||||||
Mockito.verify(player).sendMessage(Flags.PVP_OVERWORLD.getHintReference());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.PVP_OVERWORLD.getHintReference()));
|
||||||
|
|
||||||
// Visitor protection
|
// Visitor protection
|
||||||
// This player is a visitor and any damage is not allowed
|
// This player is a visitor and any damage is not allowed
|
||||||
@ -457,10 +475,10 @@ public class PVPListenerTest {
|
|||||||
// visitor should be protected
|
// visitor should be protected
|
||||||
assertTrue(e.isCancelled());
|
assertTrue(e.isCancelled());
|
||||||
// PVP trumps visitor protection
|
// PVP trumps visitor protection
|
||||||
Mockito.verify(player).sendMessage(Flags.PVP_OVERWORLD.getHintReference());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.PVP_OVERWORLD.getHintReference()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.listeners.flags.PVPListener#onEntityDamage(org.bukkit.event.entity.EntityDamageByEntityEvent)}.
|
* Test method for {@link world.bentobox.bentobox.listeners.flags.PVPListener#onEntityDamage(org.bukkit.event.entity.EntityDamageByEntityEvent)}.
|
||||||
*/
|
*/
|
||||||
@ -502,7 +520,7 @@ public class PVPListenerTest {
|
|||||||
new PVPListener().onEntityDamage(e);
|
new PVPListener().onEntityDamage(e);
|
||||||
// visitor should be protected
|
// visitor should be protected
|
||||||
assertTrue(e.isCancelled());
|
assertTrue(e.isCancelled());
|
||||||
Mockito.verify(player).sendMessage(Flags.INVINCIBLE_VISITORS.getHintReference());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,7 +543,7 @@ public class PVPListenerTest {
|
|||||||
|
|
||||||
// PVP should be banned
|
// PVP should be banned
|
||||||
assertTrue(pfe.isCancelled());
|
assertTrue(pfe.isCancelled());
|
||||||
Mockito.verify(player).sendMessage(Flags.PVP_OVERWORLD.getHintReference());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.PVP_OVERWORLD.getHintReference()));
|
||||||
// Hook should be removed
|
// Hook should be removed
|
||||||
Mockito.verify(hook).remove();
|
Mockito.verify(hook).remove();
|
||||||
|
|
||||||
@ -571,7 +589,7 @@ public class PVPListenerTest {
|
|||||||
new PVPListener().onFishing(pfe);
|
new PVPListener().onFishing(pfe);
|
||||||
// visitor should be protected
|
// visitor should be protected
|
||||||
assertTrue(pfe.isCancelled());
|
assertTrue(pfe.isCancelled());
|
||||||
Mockito.verify(player).sendMessage(Flags.INVINCIBLE_VISITORS.getHintReference());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -607,7 +625,7 @@ public class PVPListenerTest {
|
|||||||
new PVPListener().onFishing(pfe);
|
new PVPListener().onFishing(pfe);
|
||||||
// visitor should be protected
|
// visitor should be protected
|
||||||
assertTrue(pfe.isCancelled());
|
assertTrue(pfe.isCancelled());
|
||||||
Mockito.verify(player).sendMessage(Flags.INVINCIBLE_VISITORS.getHintReference());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -659,7 +677,7 @@ public class PVPListenerTest {
|
|||||||
PotionSplashEvent e = new PotionSplashEvent(tp, map);
|
PotionSplashEvent e = new PotionSplashEvent(tp, map);
|
||||||
new PVPListener().onSplashPotionSplash(e);
|
new PVPListener().onSplashPotionSplash(e);
|
||||||
assertTrue(e.isCancelled());
|
assertTrue(e.isCancelled());
|
||||||
Mockito.verify(player).sendMessage(Flags.PVP_OVERWORLD.getHintReference());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.PVP_OVERWORLD.getHintReference()));
|
||||||
|
|
||||||
// Wrong world
|
// Wrong world
|
||||||
when(iwm.inWorld(Mockito.any())).thenReturn(false);
|
when(iwm.inWorld(Mockito.any())).thenReturn(false);
|
||||||
@ -667,7 +685,7 @@ public class PVPListenerTest {
|
|||||||
new PVPListener().onSplashPotionSplash(e);
|
new PVPListener().onSplashPotionSplash(e);
|
||||||
assertFalse(e.isCancelled());
|
assertFalse(e.isCancelled());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.listeners.flags.PVPListener#onSplashPotionSplash(org.bukkit.event.entity.PotionSplashEvent)}.
|
* Test method for {@link world.bentobox.bentobox.listeners.flags.PVPListener#onSplashPotionSplash(org.bukkit.event.entity.PotionSplashEvent)}.
|
||||||
*/
|
*/
|
||||||
@ -742,7 +760,7 @@ public class PVPListenerTest {
|
|||||||
new PVPListener().onSplashPotionSplash(e);
|
new PVPListener().onSplashPotionSplash(e);
|
||||||
// visitor should be protected
|
// visitor should be protected
|
||||||
assertTrue(e.isCancelled());
|
assertTrue(e.isCancelled());
|
||||||
Mockito.verify(player).sendMessage(Flags.INVINCIBLE_VISITORS.getHintReference());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
|
||||||
|
|
||||||
// Wrong world
|
// Wrong world
|
||||||
when(iwm.inWorld(Mockito.any())).thenReturn(false);
|
when(iwm.inWorld(Mockito.any())).thenReturn(false);
|
||||||
@ -813,14 +831,14 @@ public class PVPListenerTest {
|
|||||||
listener.onLingeringPotionDamage(ae);
|
listener.onLingeringPotionDamage(ae);
|
||||||
assertEquals(3, ae.getAffectedEntities().size());
|
assertEquals(3, ae.getAffectedEntities().size());
|
||||||
assertFalse(ae.getAffectedEntities().contains(player2));
|
assertFalse(ae.getAffectedEntities().contains(player2));
|
||||||
Mockito.verify(player).sendMessage(Flags.PVP_OVERWORLD.getHintReference());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.PVP_OVERWORLD.getHintReference()));
|
||||||
// Wrong world
|
// Wrong world
|
||||||
when(iwm.inWorld(Mockito.any())).thenReturn(false);
|
when(iwm.inWorld(Mockito.any())).thenReturn(false);
|
||||||
listener.onLingeringPotionSplash(e);
|
listener.onLingeringPotionSplash(e);
|
||||||
// No change to results
|
// No change to results
|
||||||
assertEquals(3, ae.getAffectedEntities().size());
|
assertEquals(3, ae.getAffectedEntities().size());
|
||||||
assertFalse(ae.getAffectedEntities().contains(player2));
|
assertFalse(ae.getAffectedEntities().contains(player2));
|
||||||
Mockito.verify(player).sendMessage(Flags.PVP_OVERWORLD.getHintReference());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.PVP_OVERWORLD.getHintReference()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -888,13 +906,13 @@ public class PVPListenerTest {
|
|||||||
listener.onLingeringPotionDamage(ae);
|
listener.onLingeringPotionDamage(ae);
|
||||||
assertEquals(3, ae.getAffectedEntities().size());
|
assertEquals(3, ae.getAffectedEntities().size());
|
||||||
assertFalse(ae.getAffectedEntities().contains(player2));
|
assertFalse(ae.getAffectedEntities().contains(player2));
|
||||||
Mockito.verify(player).sendMessage(Flags.INVINCIBLE_VISITORS.getHintReference());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
|
||||||
// Wrong world
|
// Wrong world
|
||||||
when(iwm.inWorld(Mockito.any())).thenReturn(false);
|
when(iwm.inWorld(Mockito.any())).thenReturn(false);
|
||||||
listener.onLingeringPotionSplash(e);
|
listener.onLingeringPotionSplash(e);
|
||||||
assertEquals(3, ae.getAffectedEntities().size());
|
assertEquals(3, ae.getAffectedEntities().size());
|
||||||
assertFalse(ae.getAffectedEntities().contains(player2));
|
assertFalse(ae.getAffectedEntities().contains(player2));
|
||||||
Mockito.verify(player).sendMessage(Flags.INVINCIBLE_VISITORS.getHintReference());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -928,12 +946,12 @@ public class PVPListenerTest {
|
|||||||
listener.onLingeringPotionDamage(ae);
|
listener.onLingeringPotionDamage(ae);
|
||||||
assertEquals(3, ae.getAffectedEntities().size());
|
assertEquals(3, ae.getAffectedEntities().size());
|
||||||
assertFalse(ae.getAffectedEntities().contains(player2));
|
assertFalse(ae.getAffectedEntities().contains(player2));
|
||||||
Mockito.verify(player).sendMessage(Flags.INVINCIBLE_VISITORS.getHintReference());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
|
||||||
// Wrong world
|
// Wrong world
|
||||||
when(iwm.inWorld(Mockito.any())).thenReturn(false);
|
when(iwm.inWorld(Mockito.any())).thenReturn(false);
|
||||||
listener.onLingeringPotionSplash(e);
|
listener.onLingeringPotionSplash(e);
|
||||||
assertEquals(3, ae.getAffectedEntities().size());
|
assertEquals(3, ae.getAffectedEntities().size());
|
||||||
assertFalse(ae.getAffectedEntities().contains(player2));
|
assertFalse(ae.getAffectedEntities().contains(player2));
|
||||||
Mockito.verify(player).sendMessage(Flags.INVINCIBLE_VISITORS.getHintReference());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,7 @@ public class IslandsManagerTest {
|
|||||||
private IslandWorldManager iwm;
|
private IslandWorldManager iwm;
|
||||||
private IslandCache islandCache;
|
private IslandCache islandCache;
|
||||||
private Optional<Island> optionalIsland;
|
private Optional<Island> optionalIsland;
|
||||||
|
private Island is;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception
|
* @throws java.lang.Exception
|
||||||
@ -163,7 +164,7 @@ public class IslandsManagerTest {
|
|||||||
|
|
||||||
// Mock island cache
|
// Mock island cache
|
||||||
islandCache = mock(IslandCache.class);
|
islandCache = mock(IslandCache.class);
|
||||||
Island is = mock(Island.class);
|
is = mock(Island.class);
|
||||||
when(islandCache.getIslandAt(Mockito.any(Location.class))).thenReturn(is);
|
when(islandCache.getIslandAt(Mockito.any(Location.class))).thenReturn(is);
|
||||||
optionalIsland = Optional.ofNullable(is);
|
optionalIsland = Optional.ofNullable(is);
|
||||||
|
|
||||||
@ -704,26 +705,30 @@ public class IslandsManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for .
|
* Test method for user is on island
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testUserIsOnIsland() throws Exception {
|
public void testUserIsOnIsland() throws Exception {
|
||||||
// Mock island cache
|
|
||||||
Island is = mock(Island.class);
|
|
||||||
|
|
||||||
when(islandCache.get(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is);
|
|
||||||
|
|
||||||
IslandsManager im = new IslandsManager(plugin);
|
IslandsManager im = new IslandsManager(plugin);
|
||||||
im.setIslandCache(islandCache);
|
im.setIslandCache(islandCache);
|
||||||
|
|
||||||
|
// Null user
|
||||||
assertFalse(im.userIsOnIsland(world, null));
|
assertFalse(im.userIsOnIsland(world, null));
|
||||||
|
|
||||||
when(is.onIsland(Mockito.any())).thenReturn(false);
|
|
||||||
|
// User is on island is determined by whether the user's location is on
|
||||||
|
// an island that has them as a memebr (rank > 0)
|
||||||
|
when(is.onIsland(Mockito.any())).thenReturn(true);
|
||||||
|
Map<UUID, Integer> members = new HashMap<>();
|
||||||
|
when(is.getMembers()).thenReturn(members);
|
||||||
assertFalse(im.userIsOnIsland(world, user));
|
assertFalse(im.userIsOnIsland(world, user));
|
||||||
|
|
||||||
when(is.onIsland(Mockito.any())).thenReturn(true);
|
members.put(user.getUniqueId(), RanksManager.MEMBER_RANK);
|
||||||
assertTrue(im.userIsOnIsland(world, user));
|
assertTrue(im.userIsOnIsland(world, user));
|
||||||
|
|
||||||
|
members.put(user.getUniqueId(), RanksManager.BANNED_RANK);
|
||||||
|
assertFalse(im.userIsOnIsland(world, user));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user