|
@@ -2,6 +2,16 @@ package me.km.snuviscript;
|
|
|
|
|
|
import com.mojang.authlib.GameProfile;
|
|
|
import com.mojang.brigadier.StringReader;
|
|
|
+import com.mojang.brigadier.arguments.ArgumentType;
|
|
|
+import com.mojang.brigadier.arguments.BoolArgumentType;
|
|
|
+import com.mojang.brigadier.arguments.DoubleArgumentType;
|
|
|
+import com.mojang.brigadier.arguments.FloatArgumentType;
|
|
|
+import com.mojang.brigadier.arguments.IntegerArgumentType;
|
|
|
+import com.mojang.brigadier.arguments.LongArgumentType;
|
|
|
+import com.mojang.brigadier.arguments.StringArgumentType;
|
|
|
+import com.mojang.brigadier.builder.ArgumentBuilder;
|
|
|
+import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|
|
+import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
|
|
import java.sql.PreparedStatement;
|
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
@@ -46,6 +56,7 @@ import me.km.inventory.CustomContainer;
|
|
|
import me.km.inventory.ModInventory;
|
|
|
import me.km.networking.ModPacketHandler;
|
|
|
import me.km.overrides.ModEntityPlayerMP;
|
|
|
+import me.km.permissions.ModCommandManager;
|
|
|
import me.km.permissions.PermissionManager;
|
|
|
import me.km.playerbank.IPlayerBank;
|
|
|
import me.km.plots.PlotMap.Plot;
|
|
@@ -58,8 +69,15 @@ import net.minecraft.block.BlockState;
|
|
|
import net.minecraft.block.ChestBlock;
|
|
|
import net.minecraft.block.CropsBlock;
|
|
|
import net.minecraft.block.DoorBlock;
|
|
|
+import net.minecraft.command.CommandSource;
|
|
|
+import net.minecraft.command.Commands;
|
|
|
import net.minecraft.command.ICommandSource;
|
|
|
+import net.minecraft.command.arguments.BlockStateArgument;
|
|
|
import net.minecraft.command.arguments.BlockStateParser;
|
|
|
+import net.minecraft.command.arguments.EnchantmentArgument;
|
|
|
+import net.minecraft.command.arguments.ItemArgument;
|
|
|
+import net.minecraft.command.arguments.ItemInput;
|
|
|
+import net.minecraft.command.arguments.PotionArgument;
|
|
|
import net.minecraft.entity.AgeableEntity;
|
|
|
import net.minecraft.entity.EntityType;
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
@@ -153,11 +171,135 @@ public class MinecraftFunctions
|
|
|
PermissionManager perms, SnuviScheduler scheduler, MinecraftServer server,
|
|
|
IPlayerBank playerBank, CustomEventCaller cec,
|
|
|
IScriptBank scriptBank, DataBank dataBank, IBlockProtection blockProtection,
|
|
|
- WorldPlotMap plots)
|
|
|
+ WorldPlotMap plots, ModCommandManager commands)
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
+ sm.registerFunction("command.newhelp", (sc, in) -> Commands.literal(in[0].getString(sc)).requires(p -> perms.hasPermission(p, in[1].getString(sc))));
|
|
|
+ sm.registerFunction("command.newhelpliteral", (sc, in) ->
|
|
|
+ {
|
|
|
+ LiteralArgumentBuilder<CommandSource> arg = Commands.literal(in[0].getString(sc));
|
|
|
+ if(in.length >= 2)
|
|
|
+ {
|
|
|
+ arg.requires(p -> perms.hasPermission(p, in[1].getString(sc)));
|
|
|
+ }
|
|
|
+ return arg;
|
|
|
+ });
|
|
|
+ sm.registerFunction("command.newhelpbool", (sc, in) ->
|
|
|
+ {
|
|
|
+ RequiredArgumentBuilder<CommandSource, Boolean> arg = Commands.argument(in[0].getString(sc), BoolArgumentType.bool());
|
|
|
+ if(in.length >= 2)
|
|
|
+ {
|
|
|
+ arg.requires(p -> perms.hasPermission(p, in[1].getString(sc)));
|
|
|
+ }
|
|
|
+ return arg;
|
|
|
+ });
|
|
|
+ sm.registerFunction("command.newhelpdouble", (sc, in) ->
|
|
|
+ {
|
|
|
+ double min = in[1].getDouble(sc);
|
|
|
+ double max = in[2].getDouble(sc);
|
|
|
+ RequiredArgumentBuilder<CommandSource, Double> arg = Commands.argument(in[0].getString(sc), DoubleArgumentType.doubleArg(min, max));
|
|
|
+ if(in.length >= 4)
|
|
|
+ {
|
|
|
+ arg.requires(p -> perms.hasPermission(p, in[3].getString(sc)));
|
|
|
+ }
|
|
|
+ return arg;
|
|
|
+ });
|
|
|
+ sm.registerFunction("command.newhelpfloat", (sc, in) ->
|
|
|
+ {
|
|
|
+ float min = in[1].getFloat(sc);
|
|
|
+ float max = in[2].getFloat(sc);
|
|
|
+ RequiredArgumentBuilder<CommandSource, Float> arg = Commands.argument(in[0].getString(sc), FloatArgumentType.floatArg(min, max));
|
|
|
+ if(in.length >= 4)
|
|
|
+ {
|
|
|
+ arg.requires(p -> perms.hasPermission(p, in[3].getString(sc)));
|
|
|
+ }
|
|
|
+ return arg;
|
|
|
+ });
|
|
|
+ sm.registerFunction("command.newhelpint", (sc, in) ->
|
|
|
+ {
|
|
|
+ int min = in[1].getInt(sc);
|
|
|
+ int max = in[2].getInt(sc);
|
|
|
+ RequiredArgumentBuilder<CommandSource, Integer> arg = Commands.argument(in[0].getString(sc), IntegerArgumentType.integer(min, max));
|
|
|
+ if(in.length >= 4)
|
|
|
+ {
|
|
|
+ arg.requires(p -> perms.hasPermission(p, in[3].getString(sc)));
|
|
|
+ }
|
|
|
+ return arg;
|
|
|
+ });
|
|
|
+ sm.registerFunction("command.newhelplong", (sc, in) ->
|
|
|
+ {
|
|
|
+ long min = in[1].getLong(sc);
|
|
|
+ long max = in[2].getLong(sc);
|
|
|
+ RequiredArgumentBuilder<CommandSource, Long> arg = Commands.argument(in[0].getString(sc), LongArgumentType.longArg(min, max));
|
|
|
+ if(in.length >= 4)
|
|
|
+ {
|
|
|
+ arg.requires(p -> perms.hasPermission(p, in[3].getString(sc)));
|
|
|
+ }
|
|
|
+ return arg;
|
|
|
+ });
|
|
|
+ sm.registerFunction("command.newhelpstring", (sc, in) ->
|
|
|
+ {
|
|
|
+ RequiredArgumentBuilder<CommandSource, String> arg;
|
|
|
+ if(in[1].getBoolean(sc))
|
|
|
+ {
|
|
|
+ arg = Commands.argument(in[0].getString(sc), StringArgumentType.greedyString());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ arg = Commands.argument(in[0].getString(sc), StringArgumentType.string());
|
|
|
+ }
|
|
|
+ if(in.length >= 3)
|
|
|
+ {
|
|
|
+ arg.requires(p -> perms.hasPermission(p, in[2].getString(sc)));
|
|
|
+ }
|
|
|
+ return arg;
|
|
|
+ });
|
|
|
+ sm.registerFunction("command.newhelpspecial", (sc, in) ->
|
|
|
+ {
|
|
|
+ RequiredArgumentBuilder<CommandSource, ArgumentType> arg = null;
|
|
|
+ String name = in[0].getString(sc);
|
|
|
+ switch(name)
|
|
|
+ {
|
|
|
+ case "Item": arg = Commands.argument(in[1].getString(sc), (ArgumentType) ItemArgument.item()); break;
|
|
|
+ case "Block": arg = Commands.argument(in[1].getString(sc), (ArgumentType) BlockStateArgument.blockState()); break;
|
|
|
+ case "Potion": arg = Commands.argument(in[1].getString(sc), (ArgumentType) PotionArgument.mobEffect()); break;
|
|
|
+ case "Enchantment": arg = Commands.argument(in[1].getString(sc), (ArgumentType) EnchantmentArgument.enchantment()); break;
|
|
|
+ default:
|
|
|
+ throw new IllegalArgumentException(String.format("'%s' is not a valid special help", name));
|
|
|
+ }
|
|
|
+ if(in.length >= 3)
|
|
|
+ {
|
|
|
+ arg.requires(p -> perms.hasPermission(p, in[2].getString(sc)));
|
|
|
+ }
|
|
|
+ return arg;
|
|
|
+ });
|
|
|
+ sm.registerFunction("command.sendhelp", (sc, in) ->
|
|
|
+ {
|
|
|
+ server.getPlayerList().getPlayers().forEach(p -> commands.send(p));
|
|
|
+ return Void.TYPE;
|
|
|
+ });
|
|
|
+ sm.registerFunction("command.addhelpalias", (sc, in) ->
|
|
|
+ {
|
|
|
+ ((ArgumentBuilder) in[0].get(sc)).redirect(((ArgumentBuilder) in[1].get(sc)).build());
|
|
|
+ return Void.TYPE;
|
|
|
+ });
|
|
|
+ sm.registerFunction("command.addhelpchild", (sc, in) ->
|
|
|
+ {
|
|
|
+ ((ArgumentBuilder) in[0].get(sc)).then(((ArgumentBuilder) in[1].get(sc)).build());
|
|
|
+ return Void.TYPE;
|
|
|
+ });
|
|
|
+ sm.registerFunction("command.addhelp", (sc, in) ->
|
|
|
+ {
|
|
|
+ commands.addCustomNodes(((LiteralArgumentBuilder<CommandSource>) in[0].get(sc)).build());
|
|
|
+ return Void.TYPE;
|
|
|
+ });
|
|
|
+ sm.registerFunction("command.clearhelp", (sc, in) ->
|
|
|
+ {
|
|
|
+ commands.clearCustomNodes();
|
|
|
+ return Void.TYPE;
|
|
|
+ });
|
|
|
sm.registerFunction("command.add", (sc, in) ->
|
|
|
{
|
|
|
scripts.registerScriptCommand(in[0].getString(sc));
|
|
@@ -261,8 +403,6 @@ public class MinecraftFunctions
|
|
|
stack.setCount(InventoryUtils.addToInventory(((PlayerEntity) in[0].get(sc)).inventory, stack));
|
|
|
return stack;
|
|
|
});
|
|
|
- sm.registerFunction("player.shootprojectile", (sc, in) -> launchProjectile((PlayerEntity) in[0].get(sc),
|
|
|
- getClass(in[1].getString(sc)), in[2].getDouble(sc), in.length >= 4 ? in[3].get(sc) : null));
|
|
|
sm.registerFunction("player.respawn", (sc, in) ->
|
|
|
{
|
|
|
final ServerPlayerEntity p = ((ServerPlayerEntity) in[0].get(sc));
|
|
@@ -1146,9 +1286,9 @@ public class MinecraftFunctions
|
|
|
sm.registerFunction("damage.isabsolute", (sc, in) -> ((DamageSource) in[0].get(sc)).isDamageAbsolute());
|
|
|
sm.registerFunction("damage.isdifficultyscaled", (sc, in) -> ((DamageSource) in[0].get(sc)).isDifficultyScaled());
|
|
|
sm.registerFunction("damage.isexplosion", (sc, in) -> ((DamageSource) in[0].get(sc)).isExplosion());
|
|
|
- sm.registerFunction("damage.isfireDamage", (sc, in) -> ((DamageSource) in[0].get(sc)).isFireDamage());
|
|
|
- sm.registerFunction("damage.isunblockable", (sc, in) -> ((DamageSource) in[0].get(sc)).isMagicDamage());
|
|
|
- sm.registerFunction("damage.ismagic", (sc, in) -> ((DamageSource) in[0].get(sc)).isProjectile());
|
|
|
+ sm.registerFunction("damage.isfire", (sc, in) -> ((DamageSource) in[0].get(sc)).isFireDamage());
|
|
|
+ sm.registerFunction("damage.ismagic", (sc, in) -> ((DamageSource) in[0].get(sc)).isMagicDamage());
|
|
|
+ sm.registerFunction("damage.isprojectile", (sc, in) -> ((DamageSource) in[0].get(sc)).isProjectile());
|
|
|
sm.registerFunction("damage.isunblockable", (sc, in) -> ((DamageSource) in[0].get(sc)).isUnblockable());
|
|
|
sm.registerFunction("damage.gettype", (sc, in) -> ((DamageSource) in[0].get(sc)).getDamageType());
|
|
|
sm.registerFunction("damage.get", (sc, in) ->
|
|
@@ -1230,6 +1370,14 @@ public class MinecraftFunctions
|
|
|
|
|
|
|
|
|
|
|
|
+ sm.registerFunction("entity.setnopickup", (sc, in) ->
|
|
|
+ {
|
|
|
+ ((AbstractArrowEntity) in[0].get(sc)).pickupStatus = AbstractArrowEntity.PickupStatus.DISALLOWED;
|
|
|
+ return Void.TYPE;
|
|
|
+ });
|
|
|
+ sm.registerFunction("entity.shootprojectile", (sc, in) -> launchProjectile((LivingEntity) in[0].get(sc),
|
|
|
+ getClass(in[1].getString(sc)), in[2].getDouble(sc), in.length >= 4 ? in[3].get(sc) : null));
|
|
|
+ sm.registerFunction("entity.isblocking", (sc, in) -> ((LivingEntity) in[0].get(sc)).isActiveItemStackBlocking());
|
|
|
sm.registerFunction("entity.getarmorthoughness", (sc, in) -> ((LivingEntity) in[0].get(sc)).getAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS).getValue());
|
|
|
sm.registerFunction("entity.getarmor", (sc, in) -> (double) ((LivingEntity) in[0].get(sc)).getTotalArmorValue());
|
|
|
sm.registerFunction("entity.getmagicarmor", (sc, in) ->
|
|
@@ -2508,7 +2656,7 @@ public class MinecraftFunctions
|
|
|
sm.registerFunction("command", (sc, in) ->
|
|
|
{
|
|
|
final String s = SnuviUtils.connect(sc, in, 0);
|
|
|
- scheduler.scheduleTask(() -> Server.executeCommand(s));
|
|
|
+ scheduler.scheduleTask(() -> commands.handleCommand(server.getCommandSource(), s));
|
|
|
return Void.TYPE;
|
|
|
});
|
|
|
sm.registerFunction("isplayer", (sc, in) ->
|
|
@@ -2638,7 +2786,7 @@ public class MinecraftFunctions
|
|
|
return text;
|
|
|
}
|
|
|
|
|
|
- private static <T> T launchProjectile(PlayerEntity p, Class<? extends T> projectile, double scale, Object data)
|
|
|
+ private static <T> T launchProjectile(LivingEntity p, Class<? extends T> projectile, double scale, Object data)
|
|
|
{
|
|
|
World w = p.world;
|
|
|
Entity launch = null;
|