use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.
the class CommandSpyCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
ModularUserService service = Nucleus.getNucleus().getUserDataManager().getUnchecked(src);
CommandSpyUserDataModule c = service.get(CommandSpyUserDataModule.class);
boolean to = args.<Boolean>getOne(truefalse).orElseGet(() -> !c.isCommandSpy());
c.setCommandSpy(to);
MessageProvider mp = plugin.getMessageProvider();
src.sendMessage(mp.getTextMessageWithFormat("command.commandspy.success", mp.getMessageWithFormat(to ? "standard.enabled" : "standard.disabled")));
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.
the class WorldCorrector method worldCheck.
public static void worldCheck() throws IOException, ObjectMappingException {
final Map<String, UUID> m = get();
// Now get the file out.
Path path = Nucleus.getNucleus().getDataPath().resolve("worlduuids.json");
ConfigurationLoader<ConfigurationNode> cl = GsonConfigurationLoader.builder().setPath(path).build();
Map<String, UUID> ms = cl.load().getValue(new TypeToken<Map<String, UUID>>() {
}, Maps.newHashMap());
final Map<UUID, UUID> fromToConverter = Maps.newHashMap();
for (String r : ms.keySet()) {
UUID oldUuid = ms.get(r);
@Nullable UUID newUuid = m.get(r);
if (newUuid != null && !oldUuid.equals(newUuid)) {
fromToConverter.put(newUuid, oldUuid);
}
}
cl.save(cl.createEmptyNode().setValue(new TypeToken<Map<String, UUID>>() {
}, m));
if (fromToConverter.isEmpty()) {
return;
}
MessageProvider mp = Nucleus.getNucleus().getMessageProvider();
ConsoleSource cs = Sponge.getServer().getConsole();
List<Text> msg = Lists.newArrayList();
Nucleus.getNucleus().addX(msg, 0);
msg.forEach(cs::sendMessage);
cs.sendMessage(Text.of(TextColors.RED, "--------------------"));
cs.sendMessage(mp.getTextMessageWithFormat("worldrepair.detected"));
for (Map.Entry<UUID, UUID> u : fromToConverter.entrySet()) {
cs.sendMessage(mp.getTextMessageWithFormat("worldrepair.worldlist", Sponge.getServer().getWorldProperties(u.getKey()).get().getWorldName(), u.getValue().toString(), u.getKey().toString()));
}
Method method;
try {
method = Sponge.getServer().getDefaultWorld().get().getClass().getDeclaredMethod("setUniqueId", UUID.class);
method.setAccessible(true);
} catch (NoSuchMethodException e) {
cs.sendMessage(mp.getTextMessageWithFormat("worldrepair.whitelist.nocmd"));
return;
}
cs.sendMessage(mp.getTextMessageWithFormat("worldrepair.whitelist.cmd"));
cs.sendMessage(Text.of(TextColors.RED, "--------------------"));
cs.sendMessage(mp.getTextMessageWithFormat("worldrepair.whitelist.cmd2"));
Sponge.getServer().setHasWhitelist(true);
Sponge.getCommandManager().register(Nucleus.getNucleus(), CommandSpec.builder().executor((s, a) -> {
MessageProvider mpr = Nucleus.getNucleus().getMessageProvider();
if (s instanceof ConsoleSource) {
cs.sendMessage(mpr.getTextMessageWithFormat("worldrepair.repair.start"));
Sponge.getEventManager().registerListener(Nucleus.getNucleus(), GameStoppedServerEvent.class, event -> {
for (Map.Entry<UUID, UUID> meuu : fromToConverter.entrySet()) {
// Magic!
WorldProperties wp = Sponge.getServer().getWorldProperties(meuu.getKey()).orElseThrow(() -> new NoSuchElementException(mpr.getMessageWithFormat("worldrepair.repair.nouuid", meuu.getKey().toString())));
final String name = wp.getWorldName();
try {
cs.sendMessage(mpr.getTextMessageWithFormat("worldrepair.repair.try", name));
method.invoke(wp, meuu.getValue());
Sponge.getServer().saveWorldProperties(wp);
cs.sendMessage(mpr.getTextMessageWithFormat("worldrepair.repair.success", name));
} catch (Exception e) {
cs.sendMessage(mpr.getTextMessageWithFormat("worldrepair.repair.fail", name));
e.printStackTrace();
}
}
try {
cl.save(cl.createEmptyNode().setValue(new TypeToken<Map<String, UUID>>() {
}, get()));
} catch (IOException | ObjectMappingException e) {
e.printStackTrace();
}
});
Sponge.getServer().shutdown();
return CommandResult.success();
} else {
s.sendMessage(mpr.getTextMessageWithFormat("command.consoleonly"));
return CommandResult.empty();
}
}).build(), "repairuuids");
}
use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.
the class NucleusCommandException method getText.
@Nullable
@Override
public Text getText() {
if (exceptions.isEmpty()) {
// Unable to get the error.
return Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.exception.nomoreinfo");
}
MessageProvider mp = Nucleus.getNucleus().getMessageProvider();
// Is it only command permission exceptions?
if (exceptions.stream().allMatch(x -> CommandPermissionException.class.isInstance(x.getSecond()))) {
return exceptions.get(0).getSecond().getText();
}
if (exceptions.stream().allMatch(x -> {
CommandException e = x.getSecond();
return e instanceof NucleusArgumentParseException && ((NucleusArgumentParseException) e).isEnd();
})) {
if (exceptions.size() == 1) {
Tuple<String, CommandException> exceptionTuple = exceptions.get(0);
return Text.of(mp.getTextMessageWithFormat("command.exception.fromcommand", exceptionTuple.getFirst()), Text.NEW_LINE, TextColors.RED, exceptionTuple.getSecond().getText());
} else {
return print(exceptions);
}
}
List<Tuple<String, CommandException>> lce = exceptions.stream().filter(x -> {
CommandException e = x.getSecond();
return !(e instanceof NucleusArgumentParseException) || !((NucleusArgumentParseException) e).isEnd();
}).filter(x -> !CommandPermissionException.class.isInstance(x)).collect(Collectors.toList());
if (lce.size() == 1) {
Tuple<String, CommandException> exceptionTuple = exceptions.get(0);
return Text.of(mp.getTextMessageWithFormat("command.exception.fromcommand", exceptionTuple.getFirst()), Text.NEW_LINE, TextColors.RED, exceptionTuple.getSecond().getText());
}
return print(lce);
}
use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.
the class ShowAttributesCommand method executeCommand.
@Override
protected CommandResult executeCommand(Player src, CommandContext args) throws Exception {
ItemStack itemStack = src.getItemInHand(HandTypes.MAIN_HAND).orElseThrow(() -> ReturnMessageException.fromKey("command.generalerror.handempty"));
boolean b = args.<Boolean>getOne(flag).orElseGet(() -> itemStack.get(Keys.HIDE_ATTRIBUTES).orElse(false));
// Command is show, key is hide. We invert.
itemStack.offer(Keys.HIDE_ATTRIBUTES, !b);
src.setItemInHand(HandTypes.MAIN_HAND, itemStack);
MessageProvider mp = plugin.getMessageProvider();
src.sendMessage(plugin.getMessageProvider().getTextMessageWithTextFormat("command.showitemattributes.success." + String.valueOf(b), Text.of(itemStack)));
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.
the class ItemNameClearCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
MessageProvider provider = Nucleus.getNucleus().getMessageProvider();
if (!src.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
throw ReturnMessageException.fromKey("command.itemname.clear.noitem");
}
ItemStack stack = src.getItemInHand(HandTypes.MAIN_HAND).get();
Optional<Text> data = stack.get(Keys.DISPLAY_NAME);
if (!data.isPresent()) {
// No display name.
throw ReturnMessageException.fromKey("command.lore.clear.none");
}
if (stack.remove(Keys.DISPLAY_NAME).isSuccessful()) {
src.setItemInHand(HandTypes.MAIN_HAND, stack);
src.sendMessage(provider.getTextMessageWithFormat("command.itemname.clear.success"));
return CommandResult.success();
}
throw ReturnMessageException.fromKey("command.itemname.clear.fail");
}
Aggregations