use of org.cubeengine.butler.parameter.IncorrectUsageException 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