use of org.cubeengine.butler.filter.Restricted in project modules-extra by CubeEngine.
the class ThrowCommands method throwCommand.
@Command(name = "throw", desc = "Throw something!")
@Restricted(value = Player.class, msg = "This command can only be used by a player!")
public void throwCommand(Player context, String material, @Optional Integer amount, @Named({ "delay", "d" }) Integer delay, @Flag boolean unsafe) {
EntityType type = null;
boolean showNotification = true;
ThrowTask task = this.thrownItems.remove(context.getUniqueId());
if (task != null) {
int aDelay = delay == null ? task.getInterval() : delay;
if (material == null || (type = entityMatcher.any(material, context.getLocale())) == task.getType() && task.getInterval() == aDelay && task.getPreventDamage() != unsafe && delay == null) {
task.stop(true);
return;
}
task.stop(showNotification = false);
}
amount = amount == null ? -1 : 1;
if ((amount > this.module.getConfig().command.throwSection.maxAmount || amount < 1) && amount != -1) {
i18n.send(context, NEGATIVE, "The amount must be a number from 1 to {integer}", this.module.getConfig().command.throwSection.maxAmount);
return;
}
delay = delay == null ? 3 : delay;
if (delay > this.module.getConfig().command.throwSection.maxDelay || delay < 0) {
i18n.send(context, NEGATIVE, "The delay must be a number from 0 to {integer}", this.module.getConfig().command.throwSection.maxDelay);
return;
}
if (unsafe && !context.hasPermission(module.perms().COMMAND_THROW_UNSAFE.getId())) {
i18n.send(context, NEGATIVE, "You are not allowed to execute this command in unsafe mode.");
return;
}
if (type == null) {
type = entityMatcher.any(material, context.getLocale());
}
if (type == null) {
i18n.send(context, NEGATIVE, "The given object was not found!");
return;
}
if (!context.hasPermission(perms.get(type).getId())) {
i18n.send(context, NEGATIVE, "You are not allowed to throw this.");
return;
}
if ((BUGGED_ENTITIES.contains(type) || entityMatcher.isMonster(type)) && !unsafe) {
i18n.send(context, NEUTRAL, "This object can only be thrown in unsafe mode. Add -u to enable the unsafe mode.");
return;
}
task = new ThrowTask(context, type, amount, delay, !unsafe);
if (task.start(showNotification)) {
this.thrownItems.put(context.getUniqueId(), task);
} else {
i18n.send(context, NEGATIVE, "Failed to throw this!");
}
}
use of org.cubeengine.butler.filter.Restricted in project modules-extra by CubeEngine.
the class AuthCommands method login.
@Unloggable
@Command(desc = "Logs you in with your password!")
// TODO assign by default
@CommandPermission(checkPermission = false)
@Restricted(value = Player.class, msg = "Only players can log in!")
public void login(Player context, String password) throws InterruptedException, ExecutionException {
if (module.isLoggedIn(context.getUniqueId())) {
i18n.send(context, POSITIVE, "You are already logged in!");
return;
}
boolean isLoggedIn = module.login(context, password).get();
if (isLoggedIn) {
i18n.send(context, POSITIVE, "You logged in successfully!");
return;
}
i18n.send(context, NEGATIVE, "Wrong password!");
if (module.getConfig().fail2ban) {
if (fails.get(context.getUniqueId()) != null) {
if (fails.get(context.getUniqueId()) + SECONDS.toMillis(10) > currentTimeMillis()) {
Text msg = Text.of(i18n.translate(context, NEGATIVE, "Too many wrong passwords!") + "\n" + i18n.translate(context, NEUTRAL, "For your security you were banned 10 seconds."));
Instant expires = Instant.now().plus(module.getConfig().banDuration, ChronoUnit.SECONDS);
module.getBanService().addBan(Ban.builder().profile(context.getProfile()).reason(msg).expirationDate(expires).source(context).build());
if (!Sponge.getServer().getOnlineMode()) {
module.getBanService().addBan(Ban.builder().address(context.getConnection().getAddress().getAddress()).reason(msg).expirationDate(expires).source(context).build());
}
context.kick(msg);
}
}
fails.put(context.getUniqueId(), currentTimeMillis());
}
}
use of org.cubeengine.butler.filter.Restricted in project modules-extra by CubeEngine.
the class KitCommand method create.
@Command(alias = "open", desc = "Opens the configured kit if the kit does not exists a new is created")
@Restricted(value = Player.class, msg = "Just log in or use the config!")
public void create(Player context, String kitname) {
if (!FileUtil.isValidFileName(kitname)) {
i18n.send(context, NEGATIVE, "{name#kit} is is not a valid name! Do not use characters like *, | or ?", kitname);
return;
}
Inventory inventory = Inventory.builder().of(InventoryArchetypes.DOUBLE_CHEST).property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(Text.of(i18n.getTranslation(context, "Kit Contents: "), kitname))).build(module.getPlugin());
List<ItemStack> itemList = new ArrayList<>();
Kit kit = manager.getKit(kitname);
if (kit == null) {
kit = new Kit(module, kitname, false, 0, -1, true, "", new ArrayList<>(), itemList);
} else {
itemList = kit.getItems();
}
showKit(context, inventory, itemList, kit);
}
use of org.cubeengine.butler.filter.Restricted in project modules-extra by CubeEngine.
the class IgnoreCommands method unignore.
@Command(desc = "Stops ignoring all messages from a player")
@Restricted(value = Player.class, msg = "Congratulations! You are now looking at this text!")
public void unignore(Player context, List<User> players) {
List<String> added = new ArrayList<>();
for (User user : players) {
if (!this.removeIgnore(context, user)) {
i18n.send(context, NEGATIVE, "You haven't ignored {user}!", user);
} else {
added.add(user.getName());
}
}
if (added.isEmpty()) {
return;
}
i18n.send(context, POSITIVE, "You removed {user#list} from your ignore list!", StringUtils.implode(ChatFormat.WHITE + ", " + ChatFormat.DARK_GREEN, added));
}
use of org.cubeengine.butler.filter.Restricted in project modules-extra by CubeEngine.
the class EditModeCommand method copy.
@Restricted(Player.class)
@Command(desc = "Copies the settings from the previous sign")
public void copy(Player context) {
ImmutableMarketSignData data = manager.getPreviousData(context);
if (data == null) {
i18n.send(context, NEGATIVE, "No previous market sign");
return;
}
if (data.getOwner().equals(IMarketSignData.ADMIN_SIGN)) {
if (!context.hasPermission(module.perms().EDIT_ADMIN.getId())) {
throw new PermissionDeniedException(module.perms().EDIT_ADMIN);
}
} else {
if (!context.hasPermission(module.perms().EDIT_USE.getId())) {
throw new PermissionDeniedException(module.perms().EDIT_USE);
}
}
MarketSignData copy = data.asMutable();
if (!copy.isAdminOwner()) {
copy.setStock(0);
}
Location<World> loc = manager.updateData(copy, context);
manager.executeShowInfo(copy, context, loc);
}
Aggregations