use of com.alessiodp.core.common.user.OfflineUser in project Parties by AlessioDP.
the class MigrationsTest method setUp.
@BeforeAll
public static void setUp(@TempDir Path tempDir) {
LoggerManager mockLoggerManager = mock(LoggerManager.class);
when(mockPlugin.getLoggerManager()).thenReturn(mockLoggerManager);
when(mockPlugin.getPluginFallbackName()).thenReturn("parties");
when(mockPlugin.getFolder()).thenReturn(tempDir);
when(mockPlugin.getResource(anyString())).thenAnswer((mock) -> ClassLoader.getSystemResourceAsStream(mock.getArgument(0)));
when(mockLoggerManager.isDebugEnabled()).thenReturn(true);
// Mock managers for player/party initialization
ColorManager mockColorManager = mock(ColorManager.class);
when(mockPlugin.getColorManager()).thenReturn(mockColorManager);
when(mockColorManager.searchColorByName(anyString())).thenReturn(null);
PlayerManager mockPlayerManager = mock(PlayerManager.class);
when(mockPlugin.getPlayerManager()).thenReturn(mockPlayerManager);
when(mockPlayerManager.initializePlayer(any())).thenAnswer((mock) -> SQLDispatcherTest.initializePlayer(mockPlugin, mock.getArgument(0)));
PartyManager mockPartyManager = mock(PartyManager.class);
when(mockPlugin.getPartyManager()).thenReturn(mockPartyManager);
when(mockPartyManager.initializeParty(any())).thenAnswer((mock) -> SQLDispatcherTest.initializeParty(mockPlugin, mock.getArgument(0)));
// Mock names
OfflineUser mockOfflineUser = mock(OfflineUser.class);
when(mockPlugin.getOfflinePlayer(any())).thenReturn(mockOfflineUser);
when(mockOfflineUser.getName()).thenReturn("Dummy");
ConfigMain.STORAGE_SETTINGS_GENERAL_SQL_PREFIX = "test_";
staticPlugin = Mockito.mockStatic(ADPPlugin.class);
when(ADPPlugin.getInstance()).thenReturn(mockPlugin);
}
use of com.alessiodp.core.common.user.OfflineUser in project Parties by AlessioDP.
the class CommandRank method onCommand.
@Override
public void onCommand(@NotNull CommandData commandData) {
User sender = commandData.getSender();
PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
// Command handling
String playerName = commandData.getArgs()[1];
UUID playerUUID = null;
Set<UUID> matchingPlayers;
if (LLAPIHandler.isEnabled()) {
// Use LastLoginAPI to get a list of players with the same name
matchingPlayers = LLAPIHandler.getPlayerByName(playerName);
} else {
// Get only the online player with the same name
matchingPlayers = new HashSet<>();
User user = plugin.getPlayerByName(playerName);
if (user != null)
matchingPlayers.add(user.getUUID());
}
List<UUID> listPlayers = new LinkedList<>(matchingPlayers);
listPlayers.removeIf((uuid) -> !getPlugin().getPlayerManager().getPlayer(uuid).isInParty());
Collections.sort(listPlayers);
if (listPlayers.size() > 1) {
// Check if the player have selected someone
if (commandData.getArgs().length > 2) {
try {
int sel = Integer.parseInt(commandData.getArgs()[3]);
playerUUID = listPlayers.get(sel - 1);
} catch (Exception ignored) {
}
}
// The player didn't select a player
if (playerUUID == null) {
for (String str : Messages.MAINCMD_RANK_CONFLICT_CONTENT) {
if (str.contains("%list_players%")) {
int i = 1;
for (UUID uuid : listPlayers) {
PartyPlayerImpl pp = getPlugin().getPlayerManager().getPlayer(uuid);
if (pp.isInParty()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_CONFLICT_PLAYER.replace("%number%", Integer.toString(i)).replace("%username%", playerName), pp, getPlugin().getPartyManager().getPartyOfPlayer(pp));
i++;
}
}
} else {
sendMessage(sender, partyPlayer, str);
}
}
return;
}
} else if (listPlayers.size() == 1) {
// Player found
playerUUID = listPlayers.get(0);
} else {
// Not found
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PLAYER_NOT_FOUND.replace("%player%", playerName));
return;
}
OfflineUser promotedPlayer = plugin.getOfflinePlayer(playerUUID);
Objects.requireNonNull(promotedPlayer);
PartyPlayerImpl promotedPp = getPlugin().getPlayerManager().getPlayer(playerUUID);
PartyRankImpl rank = getPlugin().getRankManager().searchRankByName(commandData.getArgs()[2]);
if (rank == null) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_WRONGRANK.replace("%rank_name%", commandData.getArgs()[2]).replace("%rank_chat%", commandData.getArgs()[2]));
return;
}
if (sender.isPlayer() && promotedPlayer.getUUID().equals(sender.getUUID()) && !(promotedPlayer.isOnline() && commandData.havePermission(PartiesPermission.ADMIN_RANK_BYPASS))) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_CHANGINGYOURSELF);
return;
}
PartyImpl party = partyPlayer != null ? getPlugin().getPartyManager().getPartyOfPlayer(partyPlayer) : null;
boolean otherParty = (party == null || !party.getMembers().contains(promotedPlayer.getUUID()));
if (otherParty) {
// Other party
party = getPlugin().getPartyManager().getPartyOfPlayer(promotedPp);
if (sender.isPlayer() && !commandData.havePermission(PartiesPermission.ADMIN_RANK_OTHERS)) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_PLAYERNOTINPARTY, promotedPp);
return;
}
if (party == null) {
sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PLAYER_NOT_IN_PARTY, promotedPp);
return;
}
} else if (sender.isPlayer() && !commandData.havePermission(PartiesPermission.ADMIN_RANK_OTHERS)) {
// Do not bypass rank restrictions
if (rank.getLevel() == promotedPp.getRank()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_SAMERANK.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()).replace("%player%", promotedPlayer.getName()));
return;
}
if (partyPlayer.getRank() <= promotedPp.getRank()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_LOWRANK.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()).replace("%player%", promotedPlayer.getName()));
return;
}
if ((rank.getLevel() != ConfigParties.RANK_SET_HIGHER) && (rank.getLevel() >= partyPlayer.getRank())) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_TOHIGHERRANK.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()));
return;
}
}
if (party.isFixed() && rank.getLevel() == ConfigParties.RANK_SET_HIGHER) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_FIXEDLEADER);
return;
}
if (promotedPp.getRank() == ConfigParties.RANK_SET_HIGHER) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_DEMOTELEADER);
return;
}
if (rank.getSlot() > 0 && countMembersWithRank((PartiesPlugin) plugin, party, rank) >= rank.getSlot()) {
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_FULL.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()));
return;
}
// Command start
int oldRank = promotedPp.getRank();
if (rank.getLevel() == ConfigParties.RANK_SET_HIGHER) {
party.changeLeader(promotedPp);
} else {
promotedPp.setRank(rank.getLevel());
}
sendMessage(sender, partyPlayer, Messages.MAINCMD_RANK_CHANGED.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()), promotedPp);
party.broadcastMessage(Messages.MAINCMD_RANK_BROADCAST.replace("%rank_name%", rank.getName()).replace("%rank_chat%", rank.getChat()), promotedPp);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_RANK, sender.getName(), promotedPp.getName(), party.getName() != null ? party.getName() : "_", oldRank, rank.getLevel(), otherParty), true);
}
use of com.alessiodp.core.common.user.OfflineUser in project Parties by AlessioDP.
the class PartiesPlaceholderTest method setUp.
@BeforeAll
public static void setUp() {
LoggerManager mockLoggerManager = mock(LoggerManager.class);
when(mockPlugin.getLoggerManager()).thenReturn(mockLoggerManager);
when(mockPlugin.getDatabaseManager()).thenReturn(mockDatabaseManager);
when(mockPlugin.getMessageUtils()).thenReturn(mockMessageUtils);
when(mockMessageUtils.convertRawPlaceholder(any(), any(), any(), any())).thenCallRealMethod();
// Mock names
OfflineUser mockOfflineUser = mock(OfflineUser.class);
when(mockPlugin.getOfflinePlayer(any())).thenReturn(mockOfflineUser);
when(mockOfflineUser.getName()).thenReturn("Dummy");
staticPlugin = mockStatic(ADPPlugin.class);
when(ADPPlugin.getInstance()).thenReturn(mockPlugin);
}
use of com.alessiodp.core.common.user.OfflineUser in project Parties by AlessioDP.
the class FileDispatcherTest method setUp.
@BeforeAll
public static void setUp(@TempDir Path tempDir) {
ADPBootstrap mockBootstrap = mock(ADPBootstrap.class);
LoggerManager mockLoggerManager = mock(LoggerManager.class);
when(mockPlugin.getPluginFallbackName()).thenReturn("parties");
when(mockPlugin.getFolder()).thenReturn(tempDir);
when(mockPlugin.getBootstrap()).thenReturn(mockBootstrap);
when(mockPlugin.getLoggerManager()).thenReturn(mockLoggerManager);
when(mockPlugin.getVersion()).thenReturn("1.0.0");
ColorManager mockColorManager = mock(ColorManager.class);
when(mockPlugin.getColorManager()).thenReturn(mockColorManager);
when(mockColorManager.searchColorByName(anyString())).thenReturn(null);
// Mock debug methods
when(mockPlugin.getResource(anyString())).thenAnswer((mock) -> ClassLoader.getSystemResourceAsStream(mock.getArgument(0)));
when(mockLoggerManager.isDebugEnabled()).thenReturn(true);
doAnswer((args) -> {
System.out.println((String) args.getArgument(0));
return null;
}).when(mockLoggerManager).logDebug(anyString(), anyBoolean());
doAnswer((args) -> {
System.out.println((String) args.getArgument(0));
return null;
}).when(mockLoggerManager).logError(anyString());
doAnswer((args) -> {
((Exception) args.getArgument(1)).printStackTrace();
return null;
}).when(mockLoggerManager).logError(any(), any());
// Mock names
OfflineUser mockOfflineUser = mock(OfflineUser.class);
when(mockPlugin.getOfflinePlayer(any())).thenReturn(mockOfflineUser);
when(mockOfflineUser.getName()).thenReturn("Dummy");
staticPlugin = Mockito.mockStatic(ADPPlugin.class);
when(ADPPlugin.getInstance()).thenReturn(mockPlugin);
}
use of com.alessiodp.core.common.user.OfflineUser in project Parties by AlessioDP.
the class SQLDispatcherTest method setUp.
@BeforeAll
public static void setUp() {
ADPBootstrap mockBootstrap = mock(ADPBootstrap.class);
LoggerManager mockLoggerManager = mock(LoggerManager.class);
when(mockPlugin.getPluginFallbackName()).thenReturn("parties");
when(mockPlugin.getFolder()).thenReturn(Paths.get("../testing/"));
when(mockPlugin.getBootstrap()).thenReturn(mockBootstrap);
when(mockPlugin.getLoggerManager()).thenReturn(mockLoggerManager);
when(mockPlugin.getVersion()).thenReturn("1.0.0");
ColorManager mockColorManager = mock(ColorManager.class);
when(mockPlugin.getColorManager()).thenReturn(mockColorManager);
when(mockColorManager.searchColorByName(anyString())).thenReturn(null);
// Mock debug methods
when(mockPlugin.getResource(anyString())).thenAnswer((mock) -> ClassLoader.getSystemResourceAsStream(mock.getArgument(0)));
when(mockLoggerManager.isDebugEnabled()).thenReturn(true);
doAnswer((args) -> {
System.out.println((String) args.getArgument(0));
return null;
}).when(mockLoggerManager).logDebug(anyString(), anyBoolean());
doAnswer((args) -> {
((Exception) args.getArgument(1)).printStackTrace();
return null;
}).when(mockLoggerManager).logError(any(), any());
// Mock names
OfflineUser mockOfflineUser = mock(OfflineUser.class);
when(mockPlugin.getOfflinePlayer(any())).thenReturn(mockOfflineUser);
when(mockOfflineUser.getName()).thenReturn("Dummy");
ConfigMain.STORAGE_SETTINGS_GENERAL_SQL_PREFIX = "test_";
staticPlugin = mockStatic(ADPPlugin.class);
when(ADPPlugin.getInstance()).thenReturn(mockPlugin);
}
Aggregations