mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-24 03:35:11 +01:00
Fires team and island events. Adds new events.
A lot of the commands were not firing events. These events are now needed by addons. Added new JOINED, REGISTERED, UNREGISTERED reasons for events. Switched to using Bukkit.getServer() instead of plugin.getServer() in a number of classes because the former can be mocked but the latter cannot be because it's marked as a final method in JavaPlugin.
This commit is contained in:
parent
360cda5a1c
commit
f60a39a543
@ -150,7 +150,7 @@ public abstract class Addon {
|
|||||||
* @return the server object
|
* @return the server object
|
||||||
*/
|
*/
|
||||||
public Server getServer() {
|
public Server getServer() {
|
||||||
return getPlugin().getServer();
|
return Bukkit.getServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
|
@ -5,11 +5,14 @@ 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.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
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;
|
||||||
@ -69,6 +72,13 @@ public class AdminRegisterCommand extends ConfirmableCommand {
|
|||||||
getIslands().setOwner(user, targetUUID, i);
|
getIslands().setOwner(user, targetUUID, i);
|
||||||
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()
|
||||||
|
.island(i)
|
||||||
|
.reason(IslandEvent.Reason.REGISTERED)
|
||||||
|
.involvedPlayer(targetUUID)
|
||||||
|
.admin(true)
|
||||||
|
.build();
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
return true;
|
return true;
|
||||||
}).orElse(false)) {
|
}).orElse(false)) {
|
||||||
// Island does not exist
|
// Island does not exist
|
||||||
@ -80,6 +90,13 @@ public class AdminRegisterCommand extends ConfirmableCommand {
|
|||||||
getWorld().getBlockAt(i.getCenter()).setType(Material.BEDROCK);
|
getWorld().getBlockAt(i.getCenter()).setType(Material.BEDROCK);
|
||||||
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()
|
||||||
|
.island(i)
|
||||||
|
.reason(IslandEvent.Reason.CREATED)
|
||||||
|
.involvedPlayer(targetUUID)
|
||||||
|
.admin(true)
|
||||||
|
.build();
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,14 @@ 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 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.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;
|
||||||
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
public class AdminUnregisterCommand extends CompositeCommand {
|
public class AdminUnregisterCommand extends CompositeCommand {
|
||||||
@ -42,10 +47,18 @@ public class AdminUnregisterCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unregister island
|
// Unregister island
|
||||||
user.sendMessage("commands.admin.unregister.unregistered-island", "[xyz]", Util.xyz(getIslands().getIsland(getWorld(), targetUUID).getCenter().toVector()));
|
Island oldIsland = getIslands().getIsland(getWorld(), targetUUID);
|
||||||
|
user.sendMessage("commands.admin.unregister.unregistered-island", "[xyz]", Util.xyz(oldIsland.getCenter().toVector()));
|
||||||
getIslands().removePlayer(getWorld(), targetUUID);
|
getIslands().removePlayer(getWorld(), targetUUID);
|
||||||
getPlayers().clearHomeLocations(getWorld(), targetUUID);
|
getPlayers().clearHomeLocations(getWorld(), targetUUID);
|
||||||
user.sendMessage("general.success");
|
user.sendMessage("general.success");
|
||||||
|
IslandBaseEvent event = IslandEvent.builder()
|
||||||
|
.island(oldIsland)
|
||||||
|
.reason(IslandEvent.Reason.UNREGISTERED)
|
||||||
|
.involvedPlayer(targetUUID)
|
||||||
|
.admin(true)
|
||||||
|
.build();
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,11 @@ 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.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
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;
|
||||||
@ -65,6 +69,13 @@ public class AdminTeamAddCommand extends CompositeCommand {
|
|||||||
if (teamIsland != null) {
|
if (teamIsland != null) {
|
||||||
getIslands().setJoinTeam(teamIsland, targetUUID);
|
getIslands().setJoinTeam(teamIsland, targetUUID);
|
||||||
user.sendMessage("general.success");
|
user.sendMessage("general.success");
|
||||||
|
IslandBaseEvent event = TeamEvent.builder()
|
||||||
|
.island(teamIsland)
|
||||||
|
.reason(TeamEvent.Reason.JOINED)
|
||||||
|
.involvedPlayer(targetUUID)
|
||||||
|
.admin(true)
|
||||||
|
.build();
|
||||||
|
Bukkit.getServer().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,16 +3,21 @@ 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.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
|
||||||
public class AdminTeamDisbandCommand extends CompositeCommand {
|
public class AdminTeamDisbandCommand extends CompositeCommand {
|
||||||
|
|
||||||
public AdminTeamDisbandCommand(CompositeCommand parent) {
|
public AdminTeamDisbandCommand(CompositeCommand parent) {
|
||||||
super(parent, "disband");
|
super(parent, "disband");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
setPermission("admin.team");
|
setPermission("admin.team");
|
||||||
@ -46,11 +51,19 @@ public class AdminTeamDisbandCommand extends CompositeCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Disband team
|
// Disband team
|
||||||
|
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
||||||
getIslands().getMembers(getWorld(), targetUUID).forEach(m -> {
|
getIslands().getMembers(getWorld(), targetUUID).forEach(m -> {
|
||||||
User.getInstance(m).sendMessage("commands.admin.team.disband.disbanded");
|
User.getInstance(m).sendMessage("commands.admin.team.disband.disbanded");
|
||||||
// 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()
|
||||||
|
.island(island)
|
||||||
|
.reason(TeamEvent.Reason.KICK)
|
||||||
|
.involvedPlayer(targetUUID)
|
||||||
|
.admin(true)
|
||||||
|
.build();
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
user.sendMessage("general.success");
|
user.sendMessage("general.success");
|
||||||
|
@ -3,9 +3,14 @@ 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.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
|
||||||
public class AdminTeamKickCommand extends CompositeCommand {
|
public class AdminTeamKickCommand extends CompositeCommand {
|
||||||
|
|
||||||
@ -50,6 +55,15 @@ public class AdminTeamKickCommand extends CompositeCommand {
|
|||||||
User.getInstance(targetUUID).sendMessage("commands.admin.team.kick.admin-kicked");
|
User.getInstance(targetUUID).sendMessage("commands.admin.team.kick.admin-kicked");
|
||||||
getIslands().removePlayer(getWorld(), targetUUID);
|
getIslands().removePlayer(getWorld(), targetUUID);
|
||||||
user.sendMessage("general.success");
|
user.sendMessage("general.success");
|
||||||
|
// Fire event so add-ons know
|
||||||
|
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
||||||
|
IslandBaseEvent event = TeamEvent.builder()
|
||||||
|
.island(island)
|
||||||
|
.reason(TeamEvent.Reason.KICK)
|
||||||
|
.involvedPlayer(targetUUID)
|
||||||
|
.admin(true)
|
||||||
|
.build();
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
package world.bentobox.bentobox.api.commands.admin.team;
|
package world.bentobox.bentobox.api.commands.admin.team;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
|
||||||
import world.bentobox.bentobox.api.user.User;
|
|
||||||
|
|
||||||
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.events.IslandBaseEvent;
|
||||||
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
|
||||||
public class AdminTeamSetownerCommand extends CompositeCommand {
|
public class AdminTeamSetownerCommand extends CompositeCommand {
|
||||||
|
|
||||||
public AdminTeamSetownerCommand(CompositeCommand parent) {
|
public AdminTeamSetownerCommand(CompositeCommand parent) {
|
||||||
@ -44,6 +49,15 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
|
|||||||
// Make new owner
|
// Make new owner
|
||||||
getIslands().setOwner(getWorld(), user, targetUUID);
|
getIslands().setOwner(getWorld(), user, targetUUID);
|
||||||
user.sendMessage("general.success");
|
user.sendMessage("general.success");
|
||||||
|
// Fire event so add-ons know
|
||||||
|
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
||||||
|
IslandBaseEvent event = TeamEvent.builder()
|
||||||
|
.island(island)
|
||||||
|
.reason(TeamEvent.Reason.SETOWNER)
|
||||||
|
.involvedPlayer(targetUUID)
|
||||||
|
.admin(true)
|
||||||
|
.build();
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
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.IslandBaseEvent;
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
@ -74,7 +76,7 @@ public class IslandTeamCommand extends CompositeCommand {
|
|||||||
.reason(TeamEvent.Reason.INFO)
|
.reason(TeamEvent.Reason.INFO)
|
||||||
.involvedPlayer(user.getUniqueId())
|
.involvedPlayer(user.getUniqueId())
|
||||||
.build();
|
.build();
|
||||||
getPlugin().getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
return event.isCancelled();
|
return event.isCancelled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +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 org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
@ -59,7 +60,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
|||||||
.reason(TeamEvent.Reason.JOIN)
|
.reason(TeamEvent.Reason.JOIN)
|
||||||
.involvedPlayer(playerUUID)
|
.involvedPlayer(playerUUID)
|
||||||
.build();
|
.build();
|
||||||
getPlugin().getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -113,6 +114,14 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
|||||||
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", TextVariables.NAME, user.getName());
|
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", TextVariables.NAME, user.getName());
|
||||||
}
|
}
|
||||||
getIslands().save(teamIsland);
|
getIslands().save(teamIsland);
|
||||||
|
// Fire event
|
||||||
|
IslandBaseEvent e = TeamEvent.builder()
|
||||||
|
.island(getIslands()
|
||||||
|
.getIsland(getWorld(), prospectiveOwnerUUID))
|
||||||
|
.reason(TeamEvent.Reason.JOINED)
|
||||||
|
.involvedPlayer(playerUUID)
|
||||||
|
.build();
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -6,6 +6,7 @@ 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.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
@ -51,7 +52,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
|||||||
if (args.isEmpty() || args.size() > 1) {
|
if (args.isEmpty() || args.size() > 1) {
|
||||||
// Invite label with no name, i.e., /island invite - tells the player who has invited them so far
|
// Invite label with no name, i.e., /island invite - tells the player who has invited them so far
|
||||||
if (inviteList.containsKey(playerUUID)) {
|
if (inviteList.containsKey(playerUUID)) {
|
||||||
OfflinePlayer inviter = getPlugin().getServer().getOfflinePlayer(inviteList.get(playerUUID));
|
OfflinePlayer inviter = Bukkit.getServer().getOfflinePlayer(inviteList.get(playerUUID));
|
||||||
user.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, inviter.getName());
|
user.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, inviter.getName());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -105,7 +106,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
|||||||
.reason(TeamEvent.Reason.INVITE)
|
.reason(TeamEvent.Reason.INVITE)
|
||||||
.involvedPlayer(invitedPlayer.getUniqueId())
|
.involvedPlayer(invitedPlayer.getUniqueId())
|
||||||
.build();
|
.build();
|
||||||
getPlugin().getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +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.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
@ -10,7 +12,7 @@ import world.bentobox.bentobox.api.localization.TextVariables;
|
|||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
|
||||||
public class IslandTeamInviteRejectCommand extends CompositeCommand {
|
public class IslandTeamInviteRejectCommand extends CompositeCommand {
|
||||||
|
|
||||||
private IslandTeamCommand itc;
|
private IslandTeamCommand itc;
|
||||||
|
|
||||||
public IslandTeamInviteRejectCommand(IslandTeamCommand islandTeamCommand) {
|
public IslandTeamInviteRejectCommand(IslandTeamCommand islandTeamCommand) {
|
||||||
@ -37,7 +39,7 @@ public class IslandTeamInviteRejectCommand extends CompositeCommand {
|
|||||||
.reason(TeamEvent.Reason.REJECT)
|
.reason(TeamEvent.Reason.REJECT)
|
||||||
.involvedPlayer(playerUUID)
|
.involvedPlayer(playerUUID)
|
||||||
.build();
|
.build();
|
||||||
getPlugin().getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,15 @@ 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.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.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
|
||||||
public class IslandTeamKickCommand extends ConfirmableCommand {
|
public class IslandTeamKickCommand extends ConfirmableCommand {
|
||||||
|
|
||||||
@ -64,6 +69,7 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
|||||||
private void kick(User user, UUID targetUUID) {
|
private void kick(User user, UUID targetUUID) {
|
||||||
User target = User.getInstance(targetUUID);
|
User target = User.getInstance(targetUUID);
|
||||||
target.sendMessage("commands.island.team.kick.owner-kicked");
|
target.sendMessage("commands.island.team.kick.owner-kicked");
|
||||||
|
Island oldIsland = getIslands().getIsland(getWorld(), targetUUID);
|
||||||
getIslands().removePlayer(getWorld(), targetUUID);
|
getIslands().removePlayer(getWorld(), targetUUID);
|
||||||
// Remove money inventory etc.
|
// Remove money inventory etc.
|
||||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||||
@ -76,6 +82,13 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
|||||||
getPlugin().getVault().ifPresent(vault -> vault.withdraw(target, vault.getBalance(target)));
|
getPlugin().getVault().ifPresent(vault -> vault.withdraw(target, vault.getBalance(target)));
|
||||||
}
|
}
|
||||||
user.sendMessage("general.success");
|
user.sendMessage("general.success");
|
||||||
|
// Fire event
|
||||||
|
IslandBaseEvent e = TeamEvent.builder()
|
||||||
|
.island(oldIsland)
|
||||||
|
.reason(TeamEvent.Reason.KICK)
|
||||||
|
.involvedPlayer(targetUUID)
|
||||||
|
.build();
|
||||||
|
Bukkit.getServer().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) {
|
||||||
|
@ -3,10 +3,15 @@ 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.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.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
|
||||||
public class IslandTeamLeaveCommand extends ConfirmableCommand {
|
public class IslandTeamLeaveCommand extends ConfirmableCommand {
|
||||||
|
|
||||||
@ -41,6 +46,7 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void leave(User user) {
|
private void leave(User user) {
|
||||||
|
Island island = getIslands().getIsland(getWorld(), user);
|
||||||
UUID ownerUUID = getIslands().getOwner(getWorld(), user.getUniqueId());
|
UUID ownerUUID = getIslands().getOwner(getWorld(), user.getUniqueId());
|
||||||
if (ownerUUID != null) {
|
if (ownerUUID != null) {
|
||||||
User.getInstance(ownerUUID).sendMessage("commands.island.team.leave.left-your-island", TextVariables.NAME, user.getName());
|
User.getInstance(ownerUUID).sendMessage("commands.island.team.leave.left-your-island", TextVariables.NAME, user.getName());
|
||||||
@ -57,6 +63,13 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
|
|||||||
getPlugin().getVault().ifPresent(vault -> vault.withdraw(user, vault.getBalance(user)));
|
getPlugin().getVault().ifPresent(vault -> vault.withdraw(user, vault.getBalance(user)));
|
||||||
}
|
}
|
||||||
user.sendMessage("general.success");
|
user.sendMessage("general.success");
|
||||||
|
// Fire event
|
||||||
|
IslandBaseEvent e = TeamEvent.builder()
|
||||||
|
.island(island)
|
||||||
|
.reason(TeamEvent.Reason.LEAVE)
|
||||||
|
.involvedPlayer(user.getUniqueId())
|
||||||
|
.build();
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -5,6 +5,8 @@ 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 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.IslandBaseEvent;
|
||||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||||
@ -66,7 +68,7 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
|
|||||||
.reason(TeamEvent.Reason.SETOWNER)
|
.reason(TeamEvent.Reason.SETOWNER)
|
||||||
.involvedPlayer(targetUUID)
|
.involvedPlayer(targetUUID)
|
||||||
.build();
|
.build();
|
||||||
getPlugin().getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -81,7 +83,7 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
|
|||||||
List<String> options = new ArrayList<>();
|
List<String> options = new ArrayList<>();
|
||||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||||
for (UUID member : getPlugin().getIslands().getMembers(getWorld(), user.getUniqueId())) {
|
for (UUID member : getPlugin().getIslands().getMembers(getWorld(), user.getUniqueId())) {
|
||||||
options.add(getPlugin().getServer().getOfflinePlayer(member).getName());
|
options.add(Bukkit.getServer().getOfflinePlayer(member).getName());
|
||||||
}
|
}
|
||||||
return Optional.of(Util.tabLimit(options, lastArg));
|
return Optional.of(Util.tabLimit(options, lastArg));
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@ public class Config<T> {
|
|||||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||||
| ClassNotFoundException | IntrospectionException | NoSuchMethodException | SecurityException e) {
|
| ClassNotFoundException | IntrospectionException | NoSuchMethodException | SecurityException e) {
|
||||||
logger.severe(() -> "Could not load config object! " + e.getMessage());
|
logger.severe(() -> "Could not load config object! " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -6,8 +6,8 @@ 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;
|
||||||
import world.bentobox.bentobox.database.objects.IslandDeletion;
|
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
import world.bentobox.bentobox.database.objects.IslandDeletion;
|
||||||
import world.bentobox.bentobox.lists.Flags;
|
import world.bentobox.bentobox.lists.Flags;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,7 +107,17 @@ public class IslandEvent extends IslandBaseEvent {
|
|||||||
/**
|
/**
|
||||||
* Reserved
|
* Reserved
|
||||||
*/
|
*/
|
||||||
UNKNOWN
|
UNKNOWN,
|
||||||
|
/**
|
||||||
|
* Player was unregistered from the island by admin
|
||||||
|
* @since 1.3.0
|
||||||
|
*/
|
||||||
|
UNREGISTERED,
|
||||||
|
/**
|
||||||
|
* Player was registered to the island by admin
|
||||||
|
* @since 1.3.0
|
||||||
|
*/
|
||||||
|
REGISTERED
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IslandEventBuilder builder() {
|
public static IslandEventBuilder builder() {
|
||||||
@ -209,6 +219,27 @@ public class IslandEvent extends IslandBaseEvent {
|
|||||||
return deletedIslandInfo;
|
return deletedIslandInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired when a player is unregistered from an island.
|
||||||
|
* @since 1.3.0
|
||||||
|
*/
|
||||||
|
public static class IslandUnregisteredEvent extends IslandBaseEvent {
|
||||||
|
private IslandUnregisteredEvent(Island island, UUID player, boolean admin, Location location) {
|
||||||
|
super(island, player, admin, location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired when a player is registered from an island.
|
||||||
|
* @since 1.3.0
|
||||||
|
*/
|
||||||
|
public static class IslandRegisteredEvent extends IslandBaseEvent {
|
||||||
|
private IslandRegisteredEvent(Island island, UUID player, boolean admin, Location location) {
|
||||||
|
super(island, player, admin, location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fired when an a player enters an island.
|
* Fired when an a player enters an island.
|
||||||
* Cancellation has no effect.
|
* Cancellation has no effect.
|
||||||
@ -389,6 +420,14 @@ public class IslandEvent extends IslandBaseEvent {
|
|||||||
IslandUnlockEvent unlock = new IslandUnlockEvent(island, player, admin, location);
|
IslandUnlockEvent unlock = new IslandUnlockEvent(island, player, admin, location);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(unlock);
|
Bukkit.getServer().getPluginManager().callEvent(unlock);
|
||||||
return unlock;
|
return unlock;
|
||||||
|
case REGISTERED:
|
||||||
|
IslandRegisteredEvent reg = new IslandRegisteredEvent(island, player, admin, location);
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(reg);
|
||||||
|
return reg;
|
||||||
|
case UNREGISTERED:
|
||||||
|
IslandUnregisteredEvent unreg = new IslandUnregisteredEvent(island, player, admin, location);
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(unreg);
|
||||||
|
return unreg;
|
||||||
default:
|
default:
|
||||||
IslandGeneralEvent general = new IslandGeneralEvent(island, player, admin, location);
|
IslandGeneralEvent general = new IslandGeneralEvent(island, player, admin, location);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(general);
|
Bukkit.getServer().getPluginManager().callEvent(general);
|
||||||
|
@ -24,7 +24,8 @@ public class TeamEvent {
|
|||||||
INFO,
|
INFO,
|
||||||
DELETE,
|
DELETE,
|
||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
UNINVITE
|
UNINVITE,
|
||||||
|
JOINED
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TeamEventBuilder builder() {
|
public static TeamEventBuilder builder() {
|
||||||
@ -37,6 +38,24 @@ public class TeamEvent {
|
|||||||
super(island, player, admin, location);
|
super(island, player, admin, location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Called after a player has joined an island
|
||||||
|
* @since 1.3.0
|
||||||
|
*/
|
||||||
|
public static class TeamJoinedEvent extends IslandBaseEvent {
|
||||||
|
/**
|
||||||
|
* Called after a player has joined an island
|
||||||
|
* @param island - island
|
||||||
|
* @param player - player
|
||||||
|
* @param admin - whether this was due to an admin action
|
||||||
|
* @param location - location
|
||||||
|
* @since 1.3.0
|
||||||
|
*/
|
||||||
|
private TeamJoinedEvent(Island island, UUID player, boolean admin, Location location) {
|
||||||
|
// Final variables have to be declared in the constructor
|
||||||
|
super(island, player, admin, location);
|
||||||
|
}
|
||||||
|
}
|
||||||
public static class TeamInviteEvent extends IslandBaseEvent {
|
public static class TeamInviteEvent extends IslandBaseEvent {
|
||||||
private TeamInviteEvent(Island island, UUID player, boolean admin, Location location) {
|
private TeamInviteEvent(Island island, UUID player, boolean admin, Location location) {
|
||||||
// Final variables have to be declared in the constructor
|
// Final variables have to be declared in the constructor
|
||||||
@ -161,6 +180,8 @@ public class TeamEvent {
|
|||||||
switch (reason) {
|
switch (reason) {
|
||||||
case JOIN:
|
case JOIN:
|
||||||
return new TeamJoinEvent(island, player, admin, location);
|
return new TeamJoinEvent(island, player, admin, location);
|
||||||
|
case JOINED:
|
||||||
|
return new TeamJoinedEvent(island, player, admin, location);
|
||||||
case INVITE:
|
case INVITE:
|
||||||
return new TeamInviteEvent(island, player, admin, location);
|
return new TeamInviteEvent(island, player, admin, location);
|
||||||
case LEAVE:
|
case LEAVE:
|
||||||
|
@ -47,8 +47,8 @@ public abstract class AbstractJSONDatabaseHandler<T> extends AbstractDatabaseHan
|
|||||||
// enableComplexMapKeySerialization - forces GSON to use TypeAdapters even for Map keys
|
// enableComplexMapKeySerialization - forces GSON to use TypeAdapters even for Map keys
|
||||||
GsonBuilder builder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().enableComplexMapKeySerialization();
|
GsonBuilder builder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().enableComplexMapKeySerialization();
|
||||||
// Register adapters
|
// Register adapters
|
||||||
builder.registerTypeAdapter(Location.class, new LocationAdapter(plugin)) ;
|
builder.registerTypeAdapter(Location.class, new LocationAdapter()) ;
|
||||||
builder.registerTypeAdapter(World.class, new WorldAdapter(plugin));
|
builder.registerTypeAdapter(World.class, new WorldAdapter());
|
||||||
builder.registerTypeAdapter(Flag.class, new FlagAdapter(plugin));
|
builder.registerTypeAdapter(Flag.class, new FlagAdapter(plugin));
|
||||||
builder.registerTypeAdapter(PotionEffectType.class, new PotionEffectTypeAdapter());
|
builder.registerTypeAdapter(PotionEffectType.class, new PotionEffectTypeAdapter());
|
||||||
builder.registerTypeAdapter(ItemStack.class, new ItemStackTypeAdapter());
|
builder.registerTypeAdapter(ItemStack.class, new ItemStackTypeAdapter());
|
||||||
|
@ -2,9 +2,9 @@ package world.bentobox.bentobox.database.json.adapters;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import com.google.gson.TypeAdapter;
|
import com.google.gson.TypeAdapter;
|
||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
@ -13,12 +13,6 @@ import com.google.gson.stream.JsonWriter;
|
|||||||
|
|
||||||
public class LocationAdapter extends TypeAdapter<Location> {
|
public class LocationAdapter extends TypeAdapter<Location> {
|
||||||
|
|
||||||
private Plugin plugin;
|
|
||||||
|
|
||||||
public LocationAdapter(Plugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(JsonWriter out, Location location) throws IOException {
|
public void write(JsonWriter out, Location location) throws IOException {
|
||||||
if (location == null || location.getWorld() == null) {
|
if (location == null || location.getWorld() == null) {
|
||||||
@ -42,7 +36,7 @@ public class LocationAdapter extends TypeAdapter<Location> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
in.beginArray();
|
in.beginArray();
|
||||||
World world = plugin.getServer().getWorld(in.nextString());
|
World world = Bukkit.getServer().getWorld(in.nextString());
|
||||||
double x = in.nextDouble();
|
double x = in.nextDouble();
|
||||||
double y = in.nextDouble();
|
double y = in.nextDouble();
|
||||||
double z = in.nextDouble();
|
double z = in.nextDouble();
|
||||||
|
@ -2,8 +2,8 @@ package world.bentobox.bentobox.database.json.adapters;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import com.google.gson.TypeAdapter;
|
import com.google.gson.TypeAdapter;
|
||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
@ -12,12 +12,6 @@ import com.google.gson.stream.JsonWriter;
|
|||||||
|
|
||||||
public class WorldAdapter extends TypeAdapter<World> {
|
public class WorldAdapter extends TypeAdapter<World> {
|
||||||
|
|
||||||
private Plugin plugin;
|
|
||||||
|
|
||||||
public WorldAdapter(Plugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(JsonWriter out, World value) throws IOException {
|
public void write(JsonWriter out, World value) throws IOException {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
@ -27,13 +21,13 @@ public class WorldAdapter extends TypeAdapter<World> {
|
|||||||
out.value(value.getName());
|
out.value(value.getName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public World read(JsonReader reader) throws IOException {
|
public World read(JsonReader reader) throws IOException {
|
||||||
if (reader.peek() == JsonToken.NULL) {
|
if (reader.peek() == JsonToken.NULL) {
|
||||||
reader.nextNull();
|
reader.nextNull();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return plugin.getServer().getWorld(reader.nextString());
|
return Bukkit.getServer().getWorld(reader.nextString());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -177,6 +177,7 @@ public class AddonsManager {
|
|||||||
addon.setState(Addon.State.ERROR);
|
addon.setState(Addon.State.ERROR);
|
||||||
plugin.logError("Skipping " + addon.getDescription().getName() + " due to an unhandled exception...");
|
plugin.logError("Skipping " + addon.getDescription().getName() + " due to an unhandled exception...");
|
||||||
plugin.logError("STACKTRACE: " + throwable.getClass().getSimpleName() + " - " + throwable.getMessage() + " - " + throwable.getCause());
|
plugin.logError("STACKTRACE: " + throwable.getClass().getSimpleName() + " - " + throwable.getMessage() + " - " + throwable.getCause());
|
||||||
|
throwable.printStackTrace();
|
||||||
if (plugin.getConfig().getBoolean("debug")) {
|
if (plugin.getConfig().getBoolean("debug")) {
|
||||||
plugin.logDebug(throwable.toString());
|
plugin.logDebug(throwable.toString());
|
||||||
plugin.logDebug(throwable.getStackTrace());
|
plugin.logDebug(throwable.getStackTrace());
|
||||||
|
@ -43,10 +43,11 @@ public class AddonTest {
|
|||||||
@Mock
|
@Mock
|
||||||
static BentoBox plugin;
|
static BentoBox plugin;
|
||||||
static JavaPlugin javaPlugin;
|
static JavaPlugin javaPlugin;
|
||||||
|
private Server server;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
Server server = mock(Server.class);
|
server = mock(Server.class);
|
||||||
World world = mock(World.class);
|
World world = mock(World.class);
|
||||||
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||||
when(server.getWorld("world")).thenReturn(world);
|
when(server.getWorld("world")).thenReturn(world);
|
||||||
@ -134,7 +135,7 @@ public class AddonTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetServer() {
|
public void testGetServer() {
|
||||||
TestClass test = new TestClass();
|
TestClass test = new TestClass();
|
||||||
assertEquals(plugin.getServer(), test.getServer());
|
assertEquals(server, test.getServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -13,7 +13,9 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -118,6 +120,13 @@ public class AdminRegisterCommandTest {
|
|||||||
idm = mock(IslandDeletionManager.class);
|
idm = mock(IslandDeletionManager.class);
|
||||||
when(idm.inDeletion(Mockito.any())).thenReturn(false);
|
when(idm.inDeletion(Mockito.any())).thenReturn(false);
|
||||||
when(plugin.getIslandDeletionManager()).thenReturn(idm);
|
when(plugin.getIslandDeletionManager()).thenReturn(idm);
|
||||||
|
|
||||||
|
// Plugin Manager
|
||||||
|
Server server = mock(Server.class);
|
||||||
|
PluginManager pim = mock(PluginManager.class);
|
||||||
|
when(server.getPluginManager()).thenReturn(pim);
|
||||||
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,9 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -109,6 +111,13 @@ public class AdminUnregisterCommandTest {
|
|||||||
LocalesManager lm = mock(LocalesManager.class);
|
LocalesManager lm = mock(LocalesManager.class);
|
||||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
|
|
||||||
|
// Plugin Manager
|
||||||
|
Server server = mock(Server.class);
|
||||||
|
PluginManager pim = mock(PluginManager.class);
|
||||||
|
when(server.getPluginManager()).thenReturn(pim);
|
||||||
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,7 +13,9 @@ import java.util.Optional;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -114,6 +116,13 @@ public class AdminTeamAddCommandTest {
|
|||||||
|
|
||||||
// Addon
|
// Addon
|
||||||
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
// Plugin Manager
|
||||||
|
Server server = mock(Server.class);
|
||||||
|
PluginManager pim = mock(PluginManager.class);
|
||||||
|
when(server.getPluginManager()).thenReturn(pim);
|
||||||
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,9 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -114,6 +116,13 @@ public class AdminTeamDisbandCommandTest {
|
|||||||
|
|
||||||
// Addon
|
// Addon
|
||||||
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
// Plugin Manager
|
||||||
|
Server server = mock(Server.class);
|
||||||
|
PluginManager pim = mock(PluginManager.class);
|
||||||
|
when(server.getPluginManager()).thenReturn(pim);
|
||||||
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,7 +17,9 @@ import java.util.Optional;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -116,6 +118,13 @@ public class AdminTeamKickCommandTest {
|
|||||||
|
|
||||||
// Addon
|
// Addon
|
||||||
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
// Plugin Manager
|
||||||
|
Server server = mock(Server.class);
|
||||||
|
PluginManager pim = mock(PluginManager.class);
|
||||||
|
when(server.getPluginManager()).thenReturn(pim);
|
||||||
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,7 +14,9 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -110,6 +112,13 @@ public class AdminTeamSetownerCommandTest {
|
|||||||
LocalesManager lm = mock(LocalesManager.class);
|
LocalesManager lm = mock(LocalesManager.class);
|
||||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
|
|
||||||
|
// Plugin Manager
|
||||||
|
Server server = mock(Server.class);
|
||||||
|
PluginManager pim = mock(PluginManager.class);
|
||||||
|
when(server.getPluginManager()).thenReturn(pim);
|
||||||
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,9 +14,11 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -124,6 +126,13 @@ public class IslandTeamKickCommandTest {
|
|||||||
|
|
||||||
// Addon
|
// Addon
|
||||||
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
// Plugin Manager
|
||||||
|
Server server = mock(Server.class);
|
||||||
|
PluginManager pim = mock(PluginManager.class);
|
||||||
|
when(server.getPluginManager()).thenReturn(pim);
|
||||||
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,9 +10,11 @@ import java.util.HashMap;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -80,7 +82,7 @@ public class IslandTeamLeaveCommandTest {
|
|||||||
ic = mock(CompositeCommand.class);
|
ic = mock(CompositeCommand.class);
|
||||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||||
|
|
||||||
// Player has island to begin with
|
// Player has island to begin with
|
||||||
im = mock(IslandsManager.class);
|
im = mock(IslandsManager.class);
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||||
when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true);
|
when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||||
@ -99,6 +101,12 @@ public class IslandTeamLeaveCommandTest {
|
|||||||
// Island World Manager
|
// Island World Manager
|
||||||
iwm = mock(IslandWorldManager.class);
|
iwm = mock(IslandWorldManager.class);
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
|
// Plugin Manager
|
||||||
|
Server server = mock(Server.class);
|
||||||
|
PluginManager pim = mock(PluginManager.class);
|
||||||
|
when(server.getPluginManager()).thenReturn(pim);
|
||||||
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,7 +119,7 @@ public class IslandTeamLeaveCommandTest {
|
|||||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-team"));
|
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-team"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for .
|
* Test method for .
|
||||||
*/
|
*/
|
||||||
@ -121,7 +129,7 @@ public class IslandTeamLeaveCommandTest {
|
|||||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.leave.cannot-leave"));
|
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.leave.cannot-leave"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for .
|
* Test method for .
|
||||||
*/
|
*/
|
||||||
@ -138,7 +146,7 @@ public class IslandTeamLeaveCommandTest {
|
|||||||
Mockito.verify(im).setLeaveTeam(Mockito.any(), Mockito.eq(uuid));
|
Mockito.verify(im).setLeaveTeam(Mockito.any(), Mockito.eq(uuid));
|
||||||
Mockito.verify(user).sendMessage(Mockito.eq("general.success"));
|
Mockito.verify(user).sendMessage(Mockito.eq("general.success"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for .
|
* Test method for .
|
||||||
*/
|
*/
|
||||||
@ -168,7 +176,7 @@ public class IslandTeamLeaveCommandTest {
|
|||||||
when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||||
// Add a team owner - null
|
// Add a team owner - null
|
||||||
when(im.getOwner(Mockito.any(), Mockito.any())).thenReturn(null);
|
when(im.getOwner(Mockito.any(), Mockito.any())).thenReturn(null);
|
||||||
|
|
||||||
// Require resets
|
// Require resets
|
||||||
when(iwm.isOnLeaveResetEnderChest(Mockito.any())).thenReturn(true);
|
when(iwm.isOnLeaveResetEnderChest(Mockito.any())).thenReturn(true);
|
||||||
Inventory enderChest = mock(Inventory.class);
|
Inventory enderChest = mock(Inventory.class);
|
||||||
@ -182,7 +190,7 @@ public class IslandTeamLeaveCommandTest {
|
|||||||
assertTrue(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
assertTrue(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||||
Mockito.verify(im).setLeaveTeam(Mockito.any(), Mockito.eq(uuid));
|
Mockito.verify(im).setLeaveTeam(Mockito.any(), Mockito.eq(uuid));
|
||||||
Mockito.verify(user).sendMessage(Mockito.eq("general.success"));
|
Mockito.verify(user).sendMessage(Mockito.eq("general.success"));
|
||||||
|
|
||||||
Mockito.verify(enderChest).clear();
|
Mockito.verify(enderChest).clear();
|
||||||
Mockito.verify(inv).clear();
|
Mockito.verify(inv).clear();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user