use of org.cubeengine.libcube.service.command.exception.PermissionDeniedException in project modules-extra by CubeEngine.
the class EditModeCommand method admin.
@Command(desc = "Changes the sign to an admin-sign")
public void admin(Player context) {
if (!context.hasPermission(module.perms().EDIT_ADMIN.getId())) {
throw new PermissionDeniedException(module.perms().EDIT_ADMIN);
}
MarketSignData data = manager.getCurrentData(context);
if (data == null) {
i18n.send(context, NEGATIVE, "No active sign!");
return;
}
data.setOwner(IMarketSignData.ADMIN_SIGN);
Location<World> loc = manager.updateData(data, context);
manager.executeShowInfo(data, context, loc);
}
use of org.cubeengine.libcube.service.command.exception.PermissionDeniedException in project modules-extra by CubeEngine.
the class Kit method give.
public boolean give(CommandSource sender, Player player, boolean force) {
if (!force && this.getPermission() != null) {
if (!sender.hasPermission(getPermission().getId())) {
throw new PermissionDeniedException(getPermission());
}
}
if (!force) {
if (limitUsagePerPlayer > 0) {
boolean reached = false;
Optional<KitData> kitData = player.get(KitData.class);
if (kitData.isPresent()) {
reached = limitUsagePerPlayer <= kitData.get().getTimes().getOrDefault(this.name, 0);
}
if (reached) {
// TODO this messages are not displayed & translated
throw new IncorrectUsageException(false, "Kit-limit reached.");
}
}
if (limitUsageDelay > 0) {
boolean inDelay = false;
// System.currentTimeMillis() - lastUsage < limitUsageDelay)
Optional<KitData> kitData = player.get(KitData.class);
if (kitData.isPresent()) {
inDelay = limitUsageDelay <= System.currentTimeMillis() - kitData.get().getTime().getOrDefault(this.name, System.currentTimeMillis());
}
if (inDelay) {
throw new IncorrectUsageException(false, "This kit isn't available at the moment. Try again later!");
}
}
}
// TODO what if not enough place
items.forEach(i -> player.getInventory().offer(i.copy()));
KitData kitData = player.get(KitData.class).orElse(null);
if (kitData == null) {
kitData = new KitData();
}
kitData.getTime().put(name, System.currentTimeMillis());
kitData.getTimes().put(name, kitData.getTimes().getOrDefault(name, 0) + 1);
player.offer(kitData);
this.executeCommands(player);
return true;
}
Aggregations