Fixed bugs with teams and uncoop untrust etc of Ops.
This commit is contained in:
parent
ee0ed2c385
commit
803274b6cd
|
@ -1,5 +1,6 @@
|
|||
package world.bentobox.bentobox;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
|
@ -465,8 +466,12 @@ public class BentoBox extends JavaPlugin implements Listener {
|
|||
}
|
||||
|
||||
log("Saving default panels...");
|
||||
this.saveResource("panels/island_creation_panel.yml", false);
|
||||
this.saveResource("panels/language_panel.yml", false);
|
||||
if (!new File(getDataFolder() + File.separator + "panels", "island_creation_panel.yml").exists()) {
|
||||
this.saveResource("panels/island_creation_panel.yml", false);
|
||||
}
|
||||
if (!new File(getDataFolder() + File.separator + "panels", "language_panel.yml").exists()) {
|
||||
this.saveResource("panels/language_panel.yml", false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -113,7 +113,9 @@ public class IslandTeamCommand extends CompositeCommand {
|
|||
new IslandTeamPromoteCommand(this, "demote");
|
||||
|
||||
// Panels
|
||||
getPlugin().saveResource("panels/team_panel.yml", false);
|
||||
if (!new File(getPlugin().getDataFolder() + File.separator + "panels", "team_panel.yml").exists()) {
|
||||
getPlugin().saveResource("panels/team_panel.yml", false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -288,6 +290,8 @@ public class IslandTeamCommand extends CompositeCommand {
|
|||
.toList());
|
||||
builder.clickHandler((panel, user, clickType, clickSlot) -> {
|
||||
if (clickType.equals(ClickType.SHIFT_LEFT) && user.hasPermission(this.acceptCommand.getPermission())) {
|
||||
getPlugin().log("Invite accepted: " + user.getName() + " accepted " + invite.getType()
|
||||
+ " invite to island at " + island.getCenter());
|
||||
// Accept
|
||||
switch (invite.getType()) {
|
||||
case COOP -> this.acceptCommand.acceptCoopInvite(user, invite);
|
||||
|
@ -298,6 +302,8 @@ public class IslandTeamCommand extends CompositeCommand {
|
|||
}
|
||||
if (clickType.equals(ClickType.SHIFT_RIGHT) && user.hasPermission(this.rejectCommand.getPermission())) {
|
||||
// Reject
|
||||
getPlugin().log("Invite rejected: " + user.getName() + " rejected " + invite.getType()
|
||||
+ " invite.");
|
||||
this.rejectCommand.execute(user, "", List.of());
|
||||
user.closeInventory();
|
||||
}
|
||||
|
@ -474,34 +480,53 @@ public class IslandTeamCommand extends CompositeCommand {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean clickListener(Panel panel, User clicker, ClickType clickType, int i, User member,
|
||||
private boolean clickListener(Panel panel, User clickingUser, ClickType clickType, int i, User target,
|
||||
List<ActionRecords> actions) {
|
||||
int rank = Objects.requireNonNull(island).getRank(clicker);
|
||||
int rank = Objects.requireNonNull(island).getRank(clickingUser);
|
||||
for (ItemTemplateRecord.ActionRecords action : actions) {
|
||||
if (clickType == action.clickType() || action.clickType() == ClickType.UNKNOWN) {
|
||||
if (clickType.equals(action.clickType())) {
|
||||
switch (action.actionType().toUpperCase(Locale.ENGLISH)) {
|
||||
case "KICK" -> {
|
||||
// Kick the player, or uncoop, or untrust
|
||||
if (clicker.hasPermission(this.kickCommand.getPermission()) && !member.equals(clicker)
|
||||
if (clickingUser.hasPermission(this.kickCommand.getPermission()) && !target.equals(clickingUser)
|
||||
&& rank >= island.getRankCommand(this.getLabel() + " kick")) {
|
||||
clicker.closeInventory();
|
||||
removePlayer(clicker, member);
|
||||
clicker.getPlayer().playSound(clicker.getLocation(), Sound.BLOCK_GLASS_BREAK, 1F, 1F);
|
||||
getPlugin().log("Kick: " + clickingUser.getName() + " kicked " + target.getName()
|
||||
+ " from island at " + island.getCenter());
|
||||
clickingUser.closeInventory();
|
||||
if (removePlayer(clickingUser, target)) {
|
||||
clickingUser.getPlayer().playSound(clickingUser.getLocation(), Sound.BLOCK_GLASS_BREAK, 1F,
|
||||
1F);
|
||||
getPlugin().log("Kick: success");
|
||||
} else {
|
||||
getPlugin().log("Kick: failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
case "SETOWNER" -> {
|
||||
// Make the player the leader of the island
|
||||
if (clicker.hasPermission(this.setOwnerCommand.getPermission()) && !member.equals(clicker)
|
||||
&& clicker.getUniqueId().equals(island.getOwner())) {
|
||||
clicker.closeInventory();
|
||||
this.setOwnerCommand.setOwner(clicker, member.getUniqueId());
|
||||
if (clickingUser.hasPermission(this.setOwnerCommand.getPermission()) && !target.equals(clickingUser)
|
||||
&& clickingUser.getUniqueId().equals(island.getOwner())) {
|
||||
getPlugin().log("Set Owner: " + clickingUser.getName() + " trying to make " + target.getName()
|
||||
+ " owner of island at " + island.getCenter());
|
||||
clickingUser.closeInventory();
|
||||
if (this.setOwnerCommand.setOwner(clickingUser, target.getUniqueId())) {
|
||||
getPlugin().log("Set Owner: success");
|
||||
} else {
|
||||
getPlugin().log("Set Owner: failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
case "LEAVE" -> {
|
||||
if (clicker.hasPermission(this.leaveCommand.getPermission()) && member.equals(clicker)
|
||||
&& !clicker.getUniqueId().equals(island.getOwner())) {
|
||||
clicker.closeInventory();
|
||||
leaveCommand.leave(clicker);
|
||||
if (clickingUser.hasPermission(this.leaveCommand.getPermission()) && target.equals(clickingUser)
|
||||
&& !clickingUser.getUniqueId().equals(island.getOwner())) {
|
||||
getPlugin().log("Leave: " + clickingUser.getName() + " trying to leave island at "
|
||||
+ island.getCenter());
|
||||
clickingUser.closeInventory();
|
||||
if (leaveCommand.leave(clickingUser)) {
|
||||
getPlugin().log("Leave: success");
|
||||
} else {
|
||||
getPlugin().log("Leave: failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -510,13 +535,19 @@ public class IslandTeamCommand extends CompositeCommand {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void removePlayer(User clicker, User member) {
|
||||
private boolean removePlayer(User clicker, User member) {
|
||||
// If member then kick, if coop, uncoop, if trusted, then untrust
|
||||
switch (island.getRank(member)) {
|
||||
return switch (island.getRank(member)) {
|
||||
case RanksManager.COOP_RANK -> this.uncoopCommand.unCoopCmd(user, member.getUniqueId());
|
||||
case RanksManager.TRUSTED_RANK -> this.unTrustCommand.unTrustCmd(user, member.getUniqueId());
|
||||
default -> kickCommand.kick(clicker, member.getUniqueId());
|
||||
default -> {
|
||||
if (kickCommand.canExecute(user, kickCommand.getLabel(), List.of(member.getName()))) {
|
||||
yield kickCommand.execute(user, kickCommand.getLabel(), List.of(member.getName()));
|
||||
} else {
|
||||
yield false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,9 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
|||
setDescription("commands.island.team.invite.description");
|
||||
setConfigurableRankCommand();
|
||||
// Panels
|
||||
getPlugin().saveResource("panels/team_invite_panel.yml", false);
|
||||
if (!new File(getPlugin().getDataFolder() + File.separator + "panels", "team_invite_panel.yml").exists()) {
|
||||
getPlugin().saveResource("panels/team_invite_panel.yml", false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -250,8 +252,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
|||
.clickHandler((panel, user, clickType, clickSlot) -> {
|
||||
user.closeInventory();
|
||||
new ConversationFactory(BentoBox.getInstance()).withLocalEcho(false).withTimeout(90)
|
||||
.withModality(false)
|
||||
.withFirstPrompt(new InviteNamePrompt(user, this))
|
||||
.withModality(false).withFirstPrompt(new InviteNamePrompt(user, this))
|
||||
.buildConversation(user.getPlayer()).begin();
|
||||
return true;
|
||||
}).build();
|
||||
|
@ -345,17 +346,34 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
|||
if (clickType.equals(ClickType.LEFT)) {
|
||||
user.closeInventory();
|
||||
if (this.canExecute(user, this.getLabel(), List.of(player.getName()))) {
|
||||
getPlugin().log("Invite sent to: " + player.getName() + " by " + user.getName() + " to join island in "
|
||||
+ getWorld().getName());
|
||||
this.execute(user, getLabel(), List.of(player.getName()));
|
||||
} else {
|
||||
getPlugin().log("Invite failed: " + player.getName() + " by " + user.getName() + " to join island in "
|
||||
+ getWorld().getName());
|
||||
}
|
||||
} else if (clickType.equals(ClickType.RIGHT)) {
|
||||
user.closeInventory();
|
||||
if (this.itc.getCoopCommand().canExecute(user, this.getLabel(), List.of(player.getName()))) {
|
||||
getPlugin().log("Coop: " + player.getName() + " cooped " + user.getName() + " to island in "
|
||||
+ getWorld().getName());
|
||||
this.itc.getCoopCommand().execute(user, getLabel(), List.of(player.getName()));
|
||||
} else {
|
||||
getPlugin().log(
|
||||
"Coop failed: " + player.getName() + "'s coop to " + user.getName() + " failed for island in "
|
||||
+ getWorld().getName());
|
||||
}
|
||||
} else if (clickType.equals(ClickType.SHIFT_LEFT)) {
|
||||
user.closeInventory();
|
||||
if (this.itc.getTrustCommand().canExecute(user, this.getLabel(), List.of(player.getName()))) {
|
||||
getPlugin().log("Trust: " + player.getName() + " trusted " + user.getName() + " to island in "
|
||||
+ getWorld().getName());
|
||||
this.itc.getTrustCommand().execute(user, getLabel(), List.of(player.getName()));
|
||||
} else {
|
||||
getPlugin().log("Trust failed: " + player.getName() + "'s trust failed for " + user.getName()
|
||||
+ " for island in "
|
||||
+ getWorld().getName());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -35,7 +35,7 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
public boolean canExecute(User user, String label, List<String> args) {
|
||||
if (!getIslands().inTeam(getWorld(), user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-team");
|
||||
return false;
|
||||
|
@ -74,7 +74,13 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
|||
getPlayers().getName(targetUUID));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// Get target
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (!getSettings().isKickConfirmation()) {
|
||||
kick(user, targetUUID);
|
||||
return true;
|
||||
|
|
|
@ -65,17 +65,17 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
|
|||
|
||||
}
|
||||
|
||||
protected void leave(User user) {
|
||||
protected boolean leave(User user) {
|
||||
Island island = getIslands().getIsland(getWorld(), user);
|
||||
if (island == null) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
// Fire event
|
||||
IslandBaseEvent event = TeamEvent.builder().island(island).reason(TeamEvent.Reason.LEAVE)
|
||||
.involvedPlayer(user.getUniqueId()).build();
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
UUID ownerUUID = island.getOwner();
|
||||
if (ownerUUID != null) {
|
||||
|
@ -103,5 +103,6 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
|
|||
IslandEvent.builder().island(island).involvedPlayer(user.getUniqueId()).admin(false)
|
||||
.reason(IslandEvent.Reason.RANK_CHANGE).rankChange(island.getRank(user), RanksManager.VISITOR_RANK)
|
||||
.build();
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -658,9 +658,6 @@ public class Island implements DataObject, MetaDataAble {
|
|||
* @return rank integer
|
||||
*/
|
||||
public int getRank(User user) {
|
||||
if (user.isOp()) {
|
||||
return RanksManager.ADMIN_RANK;
|
||||
}
|
||||
return members.getOrDefault(user.getUniqueId(), RanksManager.VISITOR_RANK);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import static org.mockito.ArgumentMatchers.any;
|
|||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
@ -188,18 +189,18 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
||||
* Test method for {@link IslandTeamKickCommand#canExecute(User, String, java.util.List)}
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoTeam() {
|
||||
when(im.inTeam(any(), eq(uuid))).thenReturn(false);
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.emptyList()));
|
||||
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.emptyList()));
|
||||
verify(user).sendMessage(eq("general.errors.no-team"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
||||
* Test method for {@link IslandTeamKickCommand#canExecute(User, String, java.util.List)}
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteLowerTeamRank() {
|
||||
|
@ -212,12 +213,12 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
|
|||
when(island.getMemberSet()).thenReturn(ImmutableSet.of(notUUID));
|
||||
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
verify(user).sendMessage(eq("commands.island.team.kick.cannot-kick-rank"), eq(TextVariables.NAME), eq("poslovitch"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
||||
* Test method for {@link IslandTeamKickCommand#canExecute(User, String, java.util.List)}
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteEqualTeamRank() {
|
||||
|
@ -230,7 +231,7 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
|
|||
when(island.getMemberSet()).thenReturn(ImmutableSet.of(notUUID));
|
||||
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
verify(user).sendMessage(eq("commands.island.team.kick.cannot-kick-rank"), eq(TextVariables.NAME), eq("poslovitch"));
|
||||
}
|
||||
|
||||
|
@ -254,7 +255,7 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
||||
* Test method for {@link IslandTeamKickCommand#canExecute(User, String, java.util.List)}
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoCommandRank() {
|
||||
|
@ -262,61 +263,61 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
|
|||
when(island.getRank(user)).thenReturn(RanksManager.MEMBER_RANK);
|
||||
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.emptyList()));
|
||||
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.emptyList()));
|
||||
verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
||||
* {@link IslandTeamKickCommand#canExecute(User, String, java.util.List)}
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoTarget() {
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.emptyList()));
|
||||
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.emptyList()));
|
||||
// Show help
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
||||
* {@link IslandTeamKickCommand#canExecute(User, String, java.util.List)}
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUnknownPlayer() {
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
when(pm.getUUID(any())).thenReturn(null);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
verify(user).sendMessage("general.errors.unknown-player", "[name]", "poslovitch");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
||||
* {@link IslandTeamKickCommand#canExecute(User, String, java.util.List)}
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteSamePlayer() {
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
when(pm.getUUID(any())).thenReturn(uuid);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
verify(user).sendMessage(eq("commands.island.team.kick.cannot-kick"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
||||
* {@link IslandTeamKickCommand#canExecute(User, String, java.util.List)}
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteDifferentPlayerNotInTeam() {
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||
// when(im.getMembers(any(), any())).thenReturn(Collections.emptySet());
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
verify(user).sendMessage(eq("general.errors.not-in-team"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link IslandTeamKickCommand#execute(User, String, java.util.List)}
|
||||
* {@link IslandTeamKickCommand#canExecute(User, String, java.util.List)}
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteDifferentPlayerNoRank() {
|
||||
|
@ -324,7 +325,7 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
|
|||
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
when(island.getRank(any(User.class))).thenReturn(RanksManager.VISITOR_RANK);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, "");
|
||||
}
|
||||
|
||||
|
@ -364,7 +365,7 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
|
|||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
|
||||
verify(im).removePlayer(any(World.class), eq(notUUID));
|
||||
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich");
|
||||
verify(target, Mockito.never()).getInventory();
|
||||
verify(target, never()).getInventory();
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue