mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-06-29 08:14:56 +02:00
Fix for double calling of events (#1111)
* Fixes tests for AdminSetrankCommand https://github.com/BentoBoxWorld/BentoBox/issues/1107 * Fixes double calling of events. https://github.com/BentoBoxWorld/BentoBox/issues/1110 * Makes AddonEvent static https://github.com/BentoBoxWorld/BentoBox/pull/1111
This commit is contained in:
parent
c385ee78f5
commit
aa5c253e03
|
@ -5,13 +5,11 @@ import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
|
||||||
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
@ -85,14 +83,14 @@ public class AdminRegisterCommand extends ConfirmableCommand {
|
||||||
}
|
}
|
||||||
user.sendMessage("commands.admin.register.registered-island", "[xyz]", Util.xyz(i.getCenter().toVector()));
|
user.sendMessage("commands.admin.register.registered-island", "[xyz]", Util.xyz(i.getCenter().toVector()));
|
||||||
user.sendMessage("general.success");
|
user.sendMessage("general.success");
|
||||||
IslandBaseEvent event = IslandEvent.builder()
|
// Build and call event
|
||||||
.island(i)
|
IslandEvent.builder()
|
||||||
.location(i.getCenter())
|
.island(i)
|
||||||
.reason(IslandEvent.Reason.REGISTERED)
|
.location(i.getCenter())
|
||||||
.involvedPlayer(targetUUID)
|
.reason(IslandEvent.Reason.REGISTERED)
|
||||||
.admin(true)
|
.involvedPlayer(targetUUID)
|
||||||
.build();
|
.admin(true)
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
.build();
|
||||||
return true;
|
return true;
|
||||||
}).orElse(false)) {
|
}).orElse(false)) {
|
||||||
// Island does not exist - this is a reservation
|
// Island does not exist - this is a reservation
|
||||||
|
@ -108,14 +106,14 @@ public class AdminRegisterCommand extends ConfirmableCommand {
|
||||||
i.setReserved(true);
|
i.setReserved(true);
|
||||||
i.getCenter().getBlock().setType(Material.BEDROCK);
|
i.getCenter().getBlock().setType(Material.BEDROCK);
|
||||||
user.sendMessage("commands.admin.register.reserved-island", "[xyz]", Util.xyz(i.getCenter().toVector()));
|
user.sendMessage("commands.admin.register.reserved-island", "[xyz]", Util.xyz(i.getCenter().toVector()));
|
||||||
IslandBaseEvent event = IslandEvent.builder()
|
// Build and fire event
|
||||||
.island(i)
|
IslandEvent.builder()
|
||||||
.location(i.getCenter())
|
.island(i)
|
||||||
.reason(IslandEvent.Reason.RESERVED)
|
.location(i.getCenter())
|
||||||
.involvedPlayer(targetUUID)
|
.reason(IslandEvent.Reason.RESERVED)
|
||||||
.admin(true)
|
.involvedPlayer(targetUUID)
|
||||||
.build();
|
.admin(true)
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
.build();
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class AdminSetrankCommand extends CompositeCommand {
|
||||||
// We want to change the player's rank on the island he is part of.
|
// We want to change the player's rank on the island he is part of.
|
||||||
|
|
||||||
// Check if the target is part of an island
|
// Check if the target is part of an island
|
||||||
if (!getPlugin().getIslands().hasIsland(getWorld(), targetUUID) && !getPlugin().getIslands().inTeam(getWorld(), targetUUID)) {
|
if (!getIslands().hasIsland(getWorld(), targetUUID) && !getPlugin().getIslands().inTeam(getWorld(), targetUUID)) {
|
||||||
user.sendMessage("general.errors.player-has-no-island");
|
user.sendMessage("general.errors.player-has-no-island");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -96,9 +96,9 @@ public class AdminSetrankCommand extends CompositeCommand {
|
||||||
User target = User.getInstance(targetUUID);
|
User target = User.getInstance(targetUUID);
|
||||||
Island island;
|
Island island;
|
||||||
if (ownerUUID != null) {
|
if (ownerUUID != null) {
|
||||||
island = getPlugin().getIslands().getIsland(getWorld(), ownerUUID);
|
island = getIslands().getIsland(getWorld(), ownerUUID);
|
||||||
} else {
|
} else {
|
||||||
island = getPlugin().getIslands().getIsland(getWorld(), targetUUID);
|
island = getIslands().getIsland(getWorld(), targetUUID);
|
||||||
}
|
}
|
||||||
int currentRank = island.getRank(target);
|
int currentRank = island.getRank(target);
|
||||||
island.setRank(target, rankValue);
|
island.setRank(target, rankValue);
|
||||||
|
|
|
@ -4,14 +4,12 @@ import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
|
||||||
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||||
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;
|
||||||
|
@ -57,15 +55,14 @@ public class AdminSetspawnCommand extends ConfirmableCommand {
|
||||||
private void setSpawn(User user, Island i) {
|
private void setSpawn(User user, Island i) {
|
||||||
if (!i.getMembers().isEmpty()) {
|
if (!i.getMembers().isEmpty()) {
|
||||||
if (i.isOwned()) {
|
if (i.isOwned()) {
|
||||||
// Fire event
|
// Build and fire event
|
||||||
IslandBaseEvent event = IslandEvent.builder()
|
IslandEvent.builder()
|
||||||
.island(i)
|
.island(i)
|
||||||
.location(i.getCenter())
|
.location(i.getCenter())
|
||||||
.reason(IslandEvent.Reason.UNREGISTERED)
|
.reason(IslandEvent.Reason.UNREGISTERED)
|
||||||
.involvedPlayer(i.getOwner())
|
.involvedPlayer(i.getOwner())
|
||||||
.admin(true)
|
.admin(true)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
}
|
}
|
||||||
// If island is owned, then unregister the owner and any members
|
// If island is owned, then unregister the owner and any members
|
||||||
new ImmutableSet.Builder<UUID>().addAll(i.getMembers().keySet()).build().forEach(m -> {
|
new ImmutableSet.Builder<UUID>().addAll(i.getMembers().keySet()).build().forEach(m -> {
|
||||||
|
|
|
@ -5,13 +5,10 @@ import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
|
||||||
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
@ -63,14 +60,13 @@ public class AdminUnregisterCommand extends ConfirmableCommand {
|
||||||
private void unregisterPlayer(User user, UUID targetUUID) {
|
private void unregisterPlayer(User user, UUID targetUUID) {
|
||||||
// Unregister island
|
// Unregister island
|
||||||
Island oldIsland = getIslands().getIsland(getWorld(), targetUUID);
|
Island oldIsland = getIslands().getIsland(getWorld(), targetUUID);
|
||||||
IslandBaseEvent event = IslandEvent.builder()
|
IslandEvent.builder()
|
||||||
.island(oldIsland)
|
.island(oldIsland)
|
||||||
.location(oldIsland.getCenter())
|
.location(oldIsland.getCenter())
|
||||||
.reason(IslandEvent.Reason.UNREGISTERED)
|
.reason(IslandEvent.Reason.UNREGISTERED)
|
||||||
.involvedPlayer(targetUUID)
|
.involvedPlayer(targetUUID)
|
||||||
.admin(true)
|
.admin(true)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
// Remove all island members
|
// Remove all island members
|
||||||
new ImmutableSet.Builder<UUID>().addAll(oldIsland.getMembers().keySet()).build().forEach(m -> {
|
new ImmutableSet.Builder<UUID>().addAll(oldIsland.getMembers().keySet()).build().forEach(m -> {
|
||||||
getIslands().removePlayer(getWorld(), m);
|
getIslands().removePlayer(getWorld(), m);
|
||||||
|
|
|
@ -3,10 +3,7 @@ package world.bentobox.bentobox.api.commands.admin.team;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
@ -69,13 +66,12 @@ public class AdminTeamAddCommand extends CompositeCommand {
|
||||||
if (teamIsland != null) {
|
if (teamIsland != null) {
|
||||||
getIslands().setJoinTeam(teamIsland, targetUUID);
|
getIslands().setJoinTeam(teamIsland, targetUUID);
|
||||||
user.sendMessage("commands.admin.team.add.success", TextVariables.NAME, target.getName(), "[owner]", owner.getName());
|
user.sendMessage("commands.admin.team.add.success", TextVariables.NAME, target.getName(), "[owner]", owner.getName());
|
||||||
IslandBaseEvent event = TeamEvent.builder()
|
TeamEvent.builder()
|
||||||
.island(teamIsland)
|
.island(teamIsland)
|
||||||
.reason(TeamEvent.Reason.JOINED)
|
.reason(TeamEvent.Reason.JOINED)
|
||||||
.involvedPlayer(targetUUID)
|
.involvedPlayer(targetUUID)
|
||||||
.admin(true)
|
.admin(true)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
user.sendMessage("general.errors.player-has-no-island");
|
user.sendMessage("general.errors.player-has-no-island");
|
||||||
|
|
|
@ -3,10 +3,7 @@ package world.bentobox.bentobox.api.commands.admin.team;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
@ -57,13 +54,12 @@ public class AdminTeamDisbandCommand extends CompositeCommand {
|
||||||
// The owner gets to keep the island
|
// The owner gets to keep the island
|
||||||
if (!m.equals(targetUUID)) {
|
if (!m.equals(targetUUID)) {
|
||||||
getIslands().setLeaveTeam(getWorld(), m);
|
getIslands().setLeaveTeam(getWorld(), m);
|
||||||
IslandBaseEvent event = TeamEvent.builder()
|
TeamEvent.builder()
|
||||||
.island(island)
|
.island(island)
|
||||||
.reason(TeamEvent.Reason.KICK)
|
.reason(TeamEvent.Reason.KICK)
|
||||||
.involvedPlayer(targetUUID)
|
.involvedPlayer(targetUUID)
|
||||||
.admin(true)
|
.admin(true)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
user.sendMessage("commands.admin.team.disband.success", TextVariables.NAME, args.get(0));
|
user.sendMessage("commands.admin.team.disband.success", TextVariables.NAME, args.get(0));
|
||||||
|
|
|
@ -3,11 +3,9 @@ package world.bentobox.bentobox.api.commands.admin.team;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
@ -71,13 +69,12 @@ public class AdminTeamKickCommand extends CompositeCommand {
|
||||||
user.sendMessage("commands.admin.team.kick.success", TextVariables.NAME, target.getName(), "[owner]", getPlayers().getName(island.getOwner()));
|
user.sendMessage("commands.admin.team.kick.success", TextVariables.NAME, target.getName(), "[owner]", getPlayers().getName(island.getOwner()));
|
||||||
|
|
||||||
// Fire event so add-ons know
|
// Fire event so add-ons know
|
||||||
IslandBaseEvent event = TeamEvent.builder()
|
TeamEvent.builder()
|
||||||
.island(island)
|
.island(island)
|
||||||
.reason(TeamEvent.Reason.KICK)
|
.reason(TeamEvent.Reason.KICK)
|
||||||
.involvedPlayer(targetUUID)
|
.involvedPlayer(targetUUID)
|
||||||
.admin(true)
|
.admin(true)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,7 @@ package world.bentobox.bentobox.api.commands.admin.team;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
@ -55,13 +52,12 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
|
||||||
user.sendMessage("commands.admin.team.setowner.success", TextVariables.NAME, args.get(0));
|
user.sendMessage("commands.admin.team.setowner.success", TextVariables.NAME, args.get(0));
|
||||||
// Fire event so add-ons know
|
// Fire event so add-ons know
|
||||||
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
||||||
IslandBaseEvent event = TeamEvent.builder()
|
TeamEvent.builder()
|
||||||
.island(island)
|
.island(island)
|
||||||
.reason(TeamEvent.Reason.SETOWNER)
|
.reason(TeamEvent.Reason.SETOWNER)
|
||||||
.involvedPlayer(targetUUID)
|
.involvedPlayer(targetUUID)
|
||||||
.admin(true)
|
.admin(true)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import org.eclipse.jdt.annotation.NonNull;
|
||||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
|
||||||
import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
|
import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
|
@ -223,12 +222,11 @@ public class IslandResetCommand extends ConfirmableCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fire event
|
// Fire event
|
||||||
IslandBaseEvent e = TeamEvent.builder()
|
TeamEvent.builder()
|
||||||
.island(island)
|
.island(island)
|
||||||
.reason(TeamEvent.Reason.DELETE)
|
.reason(TeamEvent.Reason.DELETE)
|
||||||
.involvedPlayer(memberUUID)
|
.involvedPlayer(memberUUID)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getPluginManager().callEvent(e);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
@ -158,14 +157,13 @@ public class IslandTeamCommand extends CompositeCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean fireEvent(User user) {
|
private boolean fireEvent(User user) {
|
||||||
IslandBaseEvent event = TeamEvent.builder()
|
return TeamEvent.builder()
|
||||||
.island(getIslands()
|
.island(getIslands()
|
||||||
.getIsland(getWorld(), user.getUniqueId()))
|
.getIsland(getWorld(), user.getUniqueId()))
|
||||||
.reason(TeamEvent.Reason.INFO)
|
.reason(TeamEvent.Reason.INFO)
|
||||||
.involvedPlayer(user.getUniqueId())
|
.involvedPlayer(user.getUniqueId())
|
||||||
.build();
|
.build()
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
.isCancelled();
|
||||||
return event.isCancelled();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,11 +3,8 @@ package world.bentobox.bentobox.api.commands.island.team;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||||
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
@ -58,13 +55,12 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Fire event so add-ons can run commands, etc.
|
// Fire event so add-ons can run commands, etc.
|
||||||
IslandBaseEvent event = TeamEvent.builder()
|
return !TeamEvent.builder()
|
||||||
.island(getIslands().getIsland(getWorld(), prospectiveOwnerUUID))
|
.island(getIslands().getIsland(getWorld(), prospectiveOwnerUUID))
|
||||||
.reason(TeamEvent.Reason.JOIN)
|
.reason(TeamEvent.Reason.JOIN)
|
||||||
.involvedPlayer(playerUUID)
|
.involvedPlayer(playerUUID)
|
||||||
.build();
|
.build()
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
.isCancelled();
|
||||||
return !event.isCancelled();
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -148,12 +144,11 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
||||||
}
|
}
|
||||||
getIslands().save(teamIsland);
|
getIslands().save(teamIsland);
|
||||||
// Fire event
|
// Fire event
|
||||||
IslandBaseEvent e = TeamEvent.builder()
|
TeamEvent.builder()
|
||||||
.island(getIslands().getIsland(getWorld(), prospectiveOwnerUUID))
|
.island(getIslands().getIsland(getWorld(), prospectiveOwnerUUID))
|
||||||
.reason(TeamEvent.Reason.JOINED)
|
.reason(TeamEvent.Reason.JOINED)
|
||||||
.involvedPlayer(playerUUID)
|
.involvedPlayer(playerUUID)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getPluginManager().callEvent(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanPlayer(User user) {
|
private void cleanPlayer(User user) {
|
||||||
|
|
|
@ -6,12 +6,10 @@ import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
@ -120,13 +118,12 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
||||||
user.sendMessage("commands.island.team.invite.removing-invite");
|
user.sendMessage("commands.island.team.invite.removing-invite");
|
||||||
}
|
}
|
||||||
// Fire event so add-ons can run commands, etc.
|
// Fire event so add-ons can run commands, etc.
|
||||||
IslandBaseEvent event = TeamEvent.builder()
|
if (TeamEvent.builder()
|
||||||
.island(getIslands().getIsland(getWorld(), user.getUniqueId()))
|
.island(getIslands().getIsland(getWorld(), user.getUniqueId()))
|
||||||
.reason(TeamEvent.Reason.INVITE)
|
.reason(TeamEvent.Reason.INVITE)
|
||||||
.involvedPlayer(invitedPlayer.getUniqueId())
|
.involvedPlayer(invitedPlayer.getUniqueId())
|
||||||
.build();
|
.build()
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
.isCancelled()) {
|
||||||
if (event.isCancelled()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Put the invited player (key) onto the list with inviter (value)
|
// Put the invited player (key) onto the list with inviter (value)
|
||||||
|
|
|
@ -3,10 +3,7 @@ package world.bentobox.bentobox.api.commands.island.team;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
@ -33,14 +30,13 @@ public class IslandTeamInviteRejectCommand extends CompositeCommand {
|
||||||
// Reject /island reject
|
// Reject /island reject
|
||||||
if (itc.isInvited(playerUUID)) {
|
if (itc.isInvited(playerUUID)) {
|
||||||
// Fire event so add-ons can run commands, etc.
|
// Fire event so add-ons can run commands, etc.
|
||||||
IslandBaseEvent event = TeamEvent.builder()
|
if (TeamEvent.builder()
|
||||||
.island(getIslands()
|
.island(getIslands()
|
||||||
.getIsland(getWorld(), itc.getInviter(playerUUID)))
|
.getIsland(getWorld(), itc.getInviter(playerUUID)))
|
||||||
.reason(TeamEvent.Reason.REJECT)
|
.reason(TeamEvent.Reason.REJECT)
|
||||||
.involvedPlayer(playerUUID)
|
.involvedPlayer(playerUUID)
|
||||||
.build();
|
.build()
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
.isCancelled()) {
|
||||||
if (event.isCancelled()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
@ -126,12 +125,11 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
||||||
}
|
}
|
||||||
user.sendMessage("commands.island.team.kick.success", TextVariables.NAME, target.getName());
|
user.sendMessage("commands.island.team.kick.success", TextVariables.NAME, target.getName());
|
||||||
// Fire event
|
// Fire event
|
||||||
IslandBaseEvent e = TeamEvent.builder()
|
TeamEvent.builder()
|
||||||
.island(oldIsland)
|
.island(oldIsland)
|
||||||
.reason(TeamEvent.Reason.KICK)
|
.reason(TeamEvent.Reason.KICK)
|
||||||
.involvedPlayer(targetUUID)
|
.involvedPlayer(targetUUID)
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getPluginManager().callEvent(e);
|
|
||||||
|
|
||||||
// Add cooldown for this player and target
|
// Add cooldown for this player and target
|
||||||
if (getSettings().getInviteCooldown() > 0 && getParent() != null) {
|
if (getSettings().getInviteCooldown() > 0 && getParent() != null) {
|
||||||
|
|
|
@ -7,7 +7,6 @@ import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
@ -121,11 +120,10 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
|
||||||
}
|
}
|
||||||
user.sendMessage("commands.island.team.leave.success");
|
user.sendMessage("commands.island.team.leave.success");
|
||||||
// Fire event
|
// Fire event
|
||||||
IslandBaseEvent e = TeamEvent.builder()
|
TeamEvent.builder()
|
||||||
.island(island)
|
.island(island)
|
||||||
.reason(TeamEvent.Reason.LEAVE)
|
.reason(TeamEvent.Reason.LEAVE)
|
||||||
.involvedPlayer(user.getUniqueId())
|
.involvedPlayer(user.getUniqueId())
|
||||||
.build();
|
.build();
|
||||||
Bukkit.getPluginManager().callEvent(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,7 +8,6 @@ import java.util.UUID;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
@ -63,13 +62,12 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
|
||||||
}
|
}
|
||||||
// Fire event so add-ons can run commands, etc.
|
// Fire event so add-ons can run commands, etc.
|
||||||
Island island = getIslands().getIsland(getWorld(), playerUUID);
|
Island island = getIslands().getIsland(getWorld(), playerUUID);
|
||||||
IslandBaseEvent event = TeamEvent.builder()
|
if (TeamEvent.builder()
|
||||||
.island(island)
|
.island(island)
|
||||||
.reason(TeamEvent.Reason.SETOWNER)
|
.reason(TeamEvent.Reason.SETOWNER)
|
||||||
.involvedPlayer(targetUUID)
|
.involvedPlayer(targetUUID)
|
||||||
.build();
|
.build()
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
.isCancelled()) {
|
||||||
if (event.isCancelled()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
getIslands().setOwner(getWorld(), user, targetUUID);
|
getIslands().setOwner(getWorld(), user, targetUUID);
|
||||||
|
|
|
@ -3,6 +3,8 @@ package world.bentobox.bentobox.api.events.addon;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.addons.Addon;
|
import world.bentobox.bentobox.api.addons.Addon;
|
||||||
|
|
||||||
public class AddonEvent {
|
public class AddonEvent {
|
||||||
|
@ -16,36 +18,36 @@ public class AddonEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public AddonEventBuilder builder() {
|
public static AddonEventBuilder builder() {
|
||||||
return new AddonEventBuilder();
|
return new AddonEventBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AddonEnableEvent extends AddonBaseEvent {
|
public static class AddonEnableEvent extends AddonBaseEvent {
|
||||||
private AddonEnableEvent(Addon addon, Map<String, Object> keyValues) {
|
private AddonEnableEvent(Addon addon, Map<String, Object> keyValues) {
|
||||||
// Final variables have to be declared in the constructor
|
// Final variables have to be declared in the constructor
|
||||||
super(addon, keyValues);
|
super(addon, keyValues);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class AddonDisableEvent extends AddonBaseEvent {
|
public static class AddonDisableEvent extends AddonBaseEvent {
|
||||||
private AddonDisableEvent(Addon addon, Map<String, Object> keyValues) {
|
private AddonDisableEvent(Addon addon, Map<String, Object> keyValues) {
|
||||||
// Final variables have to be declared in the constructor
|
// Final variables have to be declared in the constructor
|
||||||
super(addon, keyValues);
|
super(addon, keyValues);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class AddonLoadEvent extends AddonBaseEvent {
|
public static class AddonLoadEvent extends AddonBaseEvent {
|
||||||
private AddonLoadEvent(Addon addon, Map<String, Object> keyValues) {
|
private AddonLoadEvent(Addon addon, Map<String, Object> keyValues) {
|
||||||
// Final variables have to be declared in the constructor
|
// Final variables have to be declared in the constructor
|
||||||
super(addon, keyValues);
|
super(addon, keyValues);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class AddonGeneralEvent extends AddonBaseEvent {
|
public static class AddonGeneralEvent extends AddonBaseEvent {
|
||||||
private AddonGeneralEvent(Addon addon, Map<String, Object> keyValues) {
|
private AddonGeneralEvent(Addon addon, Map<String, Object> keyValues) {
|
||||||
// Final variables have to be declared in the constructor
|
// Final variables have to be declared in the constructor
|
||||||
super(addon, keyValues);
|
super(addon, keyValues);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AddonEventBuilder {
|
public static class AddonEventBuilder {
|
||||||
// Here field are NOT final. They are just used for the building.
|
// Here field are NOT final. They are just used for the building.
|
||||||
private Addon addon;
|
private Addon addon;
|
||||||
private Reason reason = Reason.UNKNOWN;
|
private Reason reason = Reason.UNKNOWN;
|
||||||
|
@ -71,7 +73,7 @@ public class AddonEvent {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddonBaseEvent build() {
|
private AddonBaseEvent getEvent() {
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case ENABLE:
|
case ENABLE:
|
||||||
return new AddonEnableEvent(addon, keyValues);
|
return new AddonEnableEvent(addon, keyValues);
|
||||||
|
@ -83,5 +85,15 @@ public class AddonEvent {
|
||||||
return new AddonGeneralEvent(addon, keyValues);
|
return new AddonGeneralEvent(addon, keyValues);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build and fire event
|
||||||
|
* @return event
|
||||||
|
*/
|
||||||
|
public AddonBaseEvent build() {
|
||||||
|
AddonBaseEvent e = getEvent();
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
return e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package world.bentobox.bentobox.api.events.team;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||||
|
@ -179,7 +180,7 @@ public class TeamEvent {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IslandBaseEvent build() {
|
private IslandBaseEvent getEvent() {
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case JOIN:
|
case JOIN:
|
||||||
return new TeamJoinEvent(island, player, admin, location);
|
return new TeamJoinEvent(island, player, admin, location);
|
||||||
|
@ -205,5 +206,15 @@ public class TeamEvent {
|
||||||
return new TeamGeneralEvent(island, player, admin, location);
|
return new TeamGeneralEvent(island, player, admin, location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the event and call it
|
||||||
|
* @return event
|
||||||
|
*/
|
||||||
|
public IslandBaseEvent build() {
|
||||||
|
IslandBaseEvent e = getEvent();
|
||||||
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
|
return e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ public class AddonsManager {
|
||||||
plugin.getLocalesManager().loadLocalesFromFile(addon.getDescription().getName());
|
plugin.getLocalesManager().loadLocalesFromFile(addon.getDescription().getName());
|
||||||
|
|
||||||
// Fire the load event
|
// Fire the load event
|
||||||
Bukkit.getPluginManager().callEvent(new AddonEvent().builder().addon(addon).reason(AddonEvent.Reason.LOAD).build());
|
AddonEvent.builder().addon(addon).reason(AddonEvent.Reason.LOAD).build();
|
||||||
|
|
||||||
// Add it to the list of addons
|
// Add it to the list of addons
|
||||||
addons.remove(addon);
|
addons.remove(addon);
|
||||||
|
@ -176,7 +176,7 @@ public class AddonsManager {
|
||||||
gameMode.getPlayerCommand().ifPresent(c -> c.setWorld(gameMode.getOverWorld()));
|
gameMode.getPlayerCommand().ifPresent(c -> c.setWorld(gameMode.getOverWorld()));
|
||||||
gameMode.getAdminCommand().ifPresent(c -> c.setWorld(gameMode.getOverWorld()));
|
gameMode.getAdminCommand().ifPresent(c -> c.setWorld(gameMode.getOverWorld()));
|
||||||
}
|
}
|
||||||
Bukkit.getPluginManager().callEvent(new AddonEvent().builder().addon(addon).reason(AddonEvent.Reason.ENABLE).build());
|
AddonEvent.builder().addon(addon).reason(AddonEvent.Reason.ENABLE).build();
|
||||||
addon.setState(Addon.State.ENABLED);
|
addon.setState(Addon.State.ENABLED);
|
||||||
plugin.log("Enabling " + addon.getDescription().getName() + "...");
|
plugin.log("Enabling " + addon.getDescription().getName() + "...");
|
||||||
} catch (NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) {
|
} catch (NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) {
|
||||||
|
@ -429,7 +429,7 @@ public class AddonsManager {
|
||||||
addon.getDescription().getAuthors().forEach(plugin::logError);
|
addon.getDescription().getAuthors().forEach(plugin::logError);
|
||||||
plugin.logStacktrace(e);
|
plugin.logStacktrace(e);
|
||||||
}
|
}
|
||||||
Bukkit.getPluginManager().callEvent(new AddonEvent().builder().addon(addon).reason(AddonEvent.Reason.DISABLE).build());
|
AddonEvent.builder().addon(addon).reason(AddonEvent.Reason.DISABLE).build();
|
||||||
}
|
}
|
||||||
// Clear loaders
|
// Clear loaders
|
||||||
if (loaders.containsKey(addon)) {
|
if (loaders.containsKey(addon)) {
|
||||||
|
|
|
@ -20,11 +20,12 @@ import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
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;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
import org.powermock.reflect.Whitebox;
|
import org.powermock.reflect.Whitebox;
|
||||||
|
@ -36,14 +37,14 @@ import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.managers.IslandsManager;
|
import world.bentobox.bentobox.managers.IslandsManager;
|
||||||
import world.bentobox.bentobox.managers.PlayersManager;
|
import world.bentobox.bentobox.managers.PlayersManager;
|
||||||
import world.bentobox.bentobox.managers.RanksManager;
|
import world.bentobox.bentobox.managers.RanksManager;
|
||||||
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Ignore("Sorry, I don't have the time to fix the tests right now.")
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
@PrepareForTest({Bukkit.class, BentoBox.class, Util.class})
|
||||||
public class AdminSetrankCommandTest {
|
public class AdminSetrankCommandTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
|
@ -55,7 +56,6 @@ public class AdminSetrankCommandTest {
|
||||||
@Mock
|
@Mock
|
||||||
private PlayersManager pm;
|
private PlayersManager pm;
|
||||||
|
|
||||||
@Mock
|
|
||||||
private RanksManager rm;
|
private RanksManager rm;
|
||||||
private AdminSetrankCommand c;
|
private AdminSetrankCommand c;
|
||||||
|
|
||||||
|
@ -71,6 +71,7 @@ public class AdminSetrankCommandTest {
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
|
|
||||||
// Ranks Manager
|
// Ranks Manager
|
||||||
|
rm = new RanksManager();
|
||||||
when(plugin.getRanksManager()).thenReturn(rm);
|
when(plugin.getRanksManager()).thenReturn(rm);
|
||||||
|
|
||||||
// Players Manager
|
// Players Manager
|
||||||
|
@ -85,6 +86,13 @@ public class AdminSetrankCommandTest {
|
||||||
when(p.getUniqueId()).thenReturn(targetUUID);
|
when(p.getUniqueId()).thenReturn(targetUUID);
|
||||||
User.getInstance(p);
|
User.getInstance(p);
|
||||||
|
|
||||||
|
// Online players
|
||||||
|
PowerMockito.mockStatic(Util.class);
|
||||||
|
when(Util.getOnlinePlayerList(any())).thenReturn(Collections.singletonList("tastybento"));
|
||||||
|
|
||||||
|
// Translations
|
||||||
|
when(user.getTranslation(anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||||
|
|
||||||
// Command
|
// Command
|
||||||
c = new AdminSetrankCommand(ac);
|
c = new AdminSetrankCommand(ac);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +161,7 @@ public class AdminSetrankCommandTest {
|
||||||
@Test
|
@Test
|
||||||
public void testCanExecuteKnownPlayerNoIsland() {
|
public void testCanExecuteKnownPlayerNoIsland() {
|
||||||
when(pm.getUUID(any())).thenReturn(targetUUID);
|
when(pm.getUUID(any())).thenReturn(targetUUID);
|
||||||
assertFalse(c.canExecute(user, "", Arrays.asList("tastybento", "member")));
|
assertFalse(c.canExecute(user, "", Arrays.asList("tastybento", "ranks.member")));
|
||||||
verify(user).sendMessage("general.errors.player-has-no-island");
|
verify(user).sendMessage("general.errors.player-has-no-island");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,9 +183,7 @@ public class AdminSetrankCommandTest {
|
||||||
public void testCanExecuteKnownPlayerHasIslandTooLowRank() {
|
public void testCanExecuteKnownPlayerHasIslandTooLowRank() {
|
||||||
when(pm.getUUID(any())).thenReturn(targetUUID);
|
when(pm.getUUID(any())).thenReturn(targetUUID);
|
||||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||||
when(rm.getRanks()).thenReturn(Collections.singletonMap("visitor", 0));
|
assertFalse(c.canExecute(user, "", Arrays.asList("tastybento", "ranks.visitor")));
|
||||||
when(user.getTranslation(anyString())).thenReturn("visitor");
|
|
||||||
assertFalse(c.canExecute(user, "", Arrays.asList("tastybento", "visitor")));
|
|
||||||
verify(user).sendMessage("commands.admin.setrank.not-possible");
|
verify(user).sendMessage("commands.admin.setrank.not-possible");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,9 +194,7 @@ public class AdminSetrankCommandTest {
|
||||||
public void testCanExecuteKnownPlayerHasIslandSuccess() {
|
public void testCanExecuteKnownPlayerHasIslandSuccess() {
|
||||||
when(pm.getUUID(any())).thenReturn(targetUUID);
|
when(pm.getUUID(any())).thenReturn(targetUUID);
|
||||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||||
when(rm.getRanks()).thenReturn(Collections.singletonMap("member", 500));
|
assertTrue(c.canExecute(user, "", Arrays.asList("tastybento", "ranks.member")));
|
||||||
when(user.getTranslation(anyString())).thenReturn("member");
|
|
||||||
assertTrue(c.canExecute(user, "", Arrays.asList("tastybento", "member")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -204,28 +208,26 @@ public class AdminSetrankCommandTest {
|
||||||
Island island = mock(Island.class);
|
Island island = mock(Island.class);
|
||||||
when(island.getRank(any())).thenReturn(RanksManager.SUB_OWNER_RANK);
|
when(island.getRank(any())).thenReturn(RanksManager.SUB_OWNER_RANK);
|
||||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
|
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
|
||||||
when(user.getTranslation(any())).thenReturn("sub-owner", "member");
|
|
||||||
assertTrue(c.execute(user, "", Arrays.asList("tastybento", "member")));
|
assertTrue(c.execute(user, "", Arrays.asList("tastybento", "member")));
|
||||||
verify(user).sendMessage(eq("commands.admin.setrank.rank-set"),
|
verify(user).sendMessage(eq("commands.admin.setrank.rank-set"),
|
||||||
eq("[from]"),
|
eq("[from]"),
|
||||||
eq("sub-owner"),
|
eq("ranks.sub-owner"),
|
||||||
eq("[to]"),
|
eq("[to]"),
|
||||||
eq("member"));
|
eq("ranks.member"),
|
||||||
|
eq("[name]"),
|
||||||
|
eq(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand#tabComplete(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand#tabComplete(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
*/
|
*/
|
||||||
@Ignore("NPE on Bukkit method")
|
|
||||||
@Test
|
@Test
|
||||||
public void testTabCompleteUserStringListOfString() {
|
public void testTabCompleteUserStringListOfString() {
|
||||||
when(rm.getRanks()).thenReturn(Collections.singletonMap("owner", 0));
|
|
||||||
when(user.getTranslation(any())).thenReturn("owner");
|
|
||||||
Optional<List<String>> result = c.tabComplete(user, "", Arrays.asList("setrank", ""));
|
Optional<List<String>> result = c.tabComplete(user, "", Arrays.asList("setrank", ""));
|
||||||
assertTrue(result.isPresent());
|
assertTrue(result.isPresent());
|
||||||
result.ifPresent(list -> {
|
result.ifPresent(list -> {
|
||||||
assertTrue(list.size() == 1);
|
assertTrue(list.size() == 1);
|
||||||
assertEquals("owner", list.get(0));
|
assertEquals("tastybento", list.get(0));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -286,7 +286,6 @@ public class IslandTeamInviteAcceptCommandTest {
|
||||||
when(teb.build()).thenReturn(ibe);
|
when(teb.build()).thenReturn(ibe);
|
||||||
when(TeamEvent.builder()).thenReturn(teb);
|
when(TeamEvent.builder()).thenReturn(teb);
|
||||||
assertFalse(c.canExecute(user, "accept", Collections.emptyList()));
|
assertFalse(c.canExecute(user, "accept", Collections.emptyList()));
|
||||||
verify(pim).callEvent(any());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user