package me.km.scrolls; import java.util.Arrays; import java.util.stream.Collectors; import me.km.api.GlobalText; import me.km.api.Module; import me.km.api.ModuleTabCommand; import me.km.api.Utils; import me.km.effects.ActiveEffectBase; import me.km.effects.Effect; import me.km.effects.EffectUtils; import me.km.items.ModItems; import me.km.permissions.Permissions; import me.km.utils.ItemStackBuilder; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; public class CommandScroll extends ModuleTabCommand { public CommandScroll(Module m) { super("magicscroll", m, Arrays.stream(Effect.values()).map(n -> n.getEffectString()).filter(o -> o != null).collect(Collectors.toList()), 0); super.setDescription("Erstellt Schriftrollen"); super.setUsage("/magicscroll [level] [amount]"); super.setPermission(Permissions.SCROLL); super.addAlias("msc"); } @Override public boolean execute(ICommandSender cs, String[] arg) { if(arg.length < 1) { return false; } if(!(cs instanceof EntityPlayer)) { this.getModule().send(cs, GlobalText.onlyPlayer()); return true; } EntityPlayer p = (EntityPlayer) cs; Class c = EffectUtils.getEffectClass(arg[0]); if(c == null) { this.getModule().send(cs, "Dieser aktive Effekt existiert nicht."); return true; } int level = 1; try { level = Integer.parseInt(arg[1]); if(level <= 0) { this.getModule().send(cs, GlobalText.noPositiveNaturalNumber()); return true; } } catch(NumberFormatException | ArrayIndexOutOfBoundsException ex) { } int amount = 1; try { amount = Integer.parseInt(arg[2]); if(amount <= 0) { this.getModule().send(cs, GlobalText.noPositiveNaturalNumber()); return true; } } catch(NumberFormatException | ArrayIndexOutOfBoundsException ex) { } new ItemStackBuilder(ModItems.scroll, amount).setName(arg[0] + " " + Utils.intToRoman(level)).drop(p.world, p.getPosition()); return true; } }