use of org.bukkit.command.CommandSender in project LandLord by SpatiumPrinceps.
the class Update method onResetLands.
/**
* Resets all lands to the default flag state
*/
public void onResetLands(CommandSender sender) {
sender.sendMessage("Starting to reset lands...");
for (World w : Bukkit.getWorlds()) {
for (ProtectedRegion pr : plugin.getWgHandler().getWG().getRegionManager(w).getRegions().values()) {
if (pr.getId().split("_").length == 3 && Bukkit.getWorld(pr.getId().split("_")[0]) == w) {
List<String> flaggy = Landlord.getInstance().getConfig().getStringList("Flags");
Set<String> flags = new HashSet<>();
flaggy.forEach(s -> flags.add(s.split(" ")[0]));
// Iterate over all existing flags
for (Flag<?> flag : DefaultFlag.getFlags()) {
if (flag instanceof StateFlag) {
boolean failed = false;
if (flags.contains(flag.getName())) {
// Filters the config list for the right line and split that line in the mid at :
String[] rules = flaggy.stream().filter(s -> s.startsWith(flag.getName())).findFirst().get().split(":");
if (rules.length == 2) {
String[] defSplit = rules[0].split(" ");
if (defSplit.length == 3) {
StateFlag.State state = StateFlag.State.valueOf(defSplit[1].toUpperCase());
if (defSplit[2].equals("nonmembers"))
pr.setFlag(flag.getRegionGroupFlag(), RegionGroup.NON_MEMBERS);
pr.setFlag((StateFlag) flag, state);
} else {
failed = true;
}
} else {
failed = true;
}
} else {
pr.getFlags().remove(flag);
}
if (failed) {
Bukkit.getLogger().warning("ERROR: Your flag definition is invalid!");
break;
}
}
}
String name = Bukkit.getOfflinePlayer(pr.getOwners().getUniqueIds().iterator().next()).getName();
String greeting = lm.getRawString("Alerts.defaultGreeting").replace("%owner%", name);
String farewell = lm.getRawString("Alerts.defaultFarewell").replace("%owner%", name);
String actualGreeting = pr.getFlag(DefaultFlag.GREET_MESSAGE);
String actualFarewell = pr.getFlag(DefaultFlag.FAREWELL_MESSAGE);
if (!greeting.equals(actualGreeting)) {
pr.setFlag(DefaultFlag.GREET_MESSAGE, greeting);
}
if (!farewell.equals(actualFarewell)) {
pr.setFlag(DefaultFlag.FAREWELL_MESSAGE, farewell);
}
}
}
}
sender.sendMessage("Finished resetting lands!");
}
use of org.bukkit.command.CommandSender in project LandLord by SpatiumPrinceps.
the class Update method onUpdateLands.
/**
* Supposed to add missing flags to existing lands, remove non existing flags
*/
public void onUpdateLands(CommandSender issuer) {
issuer.sendMessage("Starting to update lands...");
for (World w : Bukkit.getWorlds()) {
for (ProtectedRegion pr : plugin.getWgHandler().getWG().getRegionManager(w).getRegions().values()) {
if (pr.getId().split("_").length == 3 && w.getName().equals(pr.getId().split("_")[0])) {
List<String> flaggy = Landlord.getInstance().getConfig().getStringList("Flags");
Set<String> flags = new HashSet<>();
flaggy.forEach(s -> flags.add(s.split(" ")[0]));
// Iterate over all existing flags
for (Flag<?> flag : DefaultFlag.getFlags()) {
if (flag instanceof StateFlag) {
boolean failed = false;
if (flags.contains(flag.getName())) {
// Filters the config list for the right line and split that line in the mid at :
String[] rules = flaggy.stream().filter(s -> s.startsWith(flag.getName())).findFirst().get().split(":");
if (rules.length == 2) {
if (!pr.getFlags().containsKey(flag)) {
String[] defSplit = rules[0].split(" ");
if (defSplit.length == 3) {
StateFlag.State state = StateFlag.State.valueOf(defSplit[1].toUpperCase());
if (defSplit[2].equals("nonmembers"))
pr.setFlag(flag.getRegionGroupFlag(), RegionGroup.NON_MEMBERS);
pr.setFlag((StateFlag) flag, state);
} else {
failed = true;
}
}
} else {
failed = true;
}
} else {
pr.getFlags().remove(flag);
}
if (failed) {
Bukkit.getLogger().warning("ERROR: Your flag definition is invalid!");
break;
}
}
}
String name = Bukkit.getOfflinePlayer(pr.getOwners().getUniqueIds().iterator().next()).getName();
String greeting = lm.getRawString("Alerts.defaultGreeting").replace("%owner%", name);
String farewell = lm.getRawString("Alerts.defaultFarewell").replace("%owner%", name);
if (!pr.getFlags().containsKey(DefaultFlag.GREET_MESSAGE)) {
pr.setFlag(DefaultFlag.GREET_MESSAGE, greeting);
}
if (!pr.getFlags().containsKey(DefaultFlag.FAREWELL_MESSAGE)) {
pr.setFlag(DefaultFlag.FAREWELL_MESSAGE, farewell);
}
}
}
}
issuer.sendMessage("Finished updating lands!");
}
use of org.bukkit.command.CommandSender in project AuthMeReloaded by AuthMe.
the class UnregisterAdminCommandTest method shouldHandleUnknownPlayer.
@Test
public void shouldHandleUnknownPlayer() {
// given
String user = "bobby";
given(dataSource.isAuthAvailable(user)).willReturn(false);
CommandSender sender = mock(CommandSender.class);
// when
command.executeCommand(sender, Collections.singletonList(user));
// then
verify(dataSource, only()).isAuthAvailable(user);
verify(commandService).send(sender, MessageKey.UNKNOWN_USER);
}
use of org.bukkit.command.CommandSender in project AuthMeReloaded by AuthMe.
the class UnregisterAdminCommandTest method shouldInvokeUnregisterProcess.
@Test
public void shouldInvokeUnregisterProcess() {
// given
String user = "personaNonGrata";
given(dataSource.isAuthAvailable(user)).willReturn(true);
Player player = mock(Player.class);
given(bukkitService.getPlayerExact(user)).willReturn(player);
CommandSender sender = mock(CommandSender.class);
// when
command.executeCommand(sender, Collections.singletonList(user));
// then
verify(dataSource, only()).isAuthAvailable(user);
verify(bukkitService).getPlayerExact(user);
verify(management).performUnregisterByAdmin(sender, user, player);
}
use of org.bukkit.command.CommandSender in project AuthMeReloaded by AuthMe.
the class DataStatisticsTest method shouldOutputStatistics.
@Test
public void shouldOutputStatistics() {
// given
CommandSender sender = mock(CommandSender.class);
given(singletonStore.retrieveAllOfType()).willReturn(mockListOfSize(Object.class, 7));
given(singletonStore.retrieveAllOfType(Reloadable.class)).willReturn(mockListOfSize(Reloadable.class, 4));
given(singletonStore.retrieveAllOfType(SettingsDependent.class)).willReturn(mockListOfSize(SettingsDependent.class, 3));
given(singletonStore.retrieveAllOfType(HasCleanup.class)).willReturn(mockListOfSize(HasCleanup.class, 2));
given(dataSource.getAccountsRegistered()).willReturn(219);
given(playerCache.getLogged()).willReturn(12);
// Clear any loggers that might exist and trigger the generation of two loggers
Map loggers = ReflectionTestUtils.getFieldValue(ConsoleLoggerFactory.class, null, "consoleLoggers");
loggers.clear();
ConsoleLoggerFactory.get(String.class);
ConsoleLoggerFactory.get(Integer.class);
// when
dataStatistics.execute(sender, Collections.emptyList());
// then
ArgumentCaptor<String> stringCaptor = ArgumentCaptor.forClass(String.class);
verify(sender, atLeastOnce()).sendMessage(stringCaptor.capture());
assertThat(stringCaptor.getAllValues(), containsInAnyOrder(ChatColor.BLUE + "AuthMe statistics", "Singleton Java classes: 7", "(Reloadable: 4 / SettingsDependent: 3 / HasCleanup: 2)", "LimboPlayers in memory: 1", "Total players in DB: 219", "PlayerCache size: 12 (= logged in players)", "Total logger instances: 2"));
}
Aggregations