123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464 |
- package me.km.snuviscript;
- import me.km.KajetansMod;
- import me.km.afk.AfkListener;
- import me.km.api.Module;
- import me.km.api.Utils;
- import me.km.environment.EnvironmentAPI;
- import me.km.exception.EntityNotFoundException;
- import me.km.exception.IllegalItemStackStringException;
- import me.km.exception.IllegalStringLocationException;
- import me.km.exception.PlayerNotFoundException;
- import me.km.nms.NmsUtilities;
- import me.km.plots.ProtectionBank;
- import me.km.table.TableAPI;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- import java.util.function.Consumer;
- import java.util.stream.Collectors;
- import me.hammerle.code.ISnuviLogger;
- import me.hammerle.code.Script;
- import me.hammerle.code.ScriptUtils;
- import me.hammerle.exceptions.SnuviException;
- import me.km.api.Location;
- import me.km.api.TitleAPI;
- import me.km.dimensions.ModDimensions;
- import me.km.effects.EffectUtils;
- import me.km.inventory.InventoryUtils;
- import me.km.permissions.Permissions;
- import me.km.table.Table;
- import me.km.utils.ItemStackUtils;
- import me.km.utils.ReflectionUtils;
- import me.km.utils.SpecialBlockUtils;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockDoor;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.command.ICommandSender;
- import net.minecraft.enchantment.Enchantment;
- import net.minecraft.enchantment.EnchantmentHelper;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityHanging;
- import net.minecraft.entity.EntityLiving;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.item.EntityArmorStand;
- import net.minecraft.entity.item.EntityItemFrame;
- import net.minecraft.entity.monster.EntityCreeper;
- import net.minecraft.entity.passive.EntityVillager;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.EntityPlayerMP;
- import net.minecraft.entity.projectile.EntityPotion;
- import net.minecraft.inventory.EntityEquipmentSlot;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.item.ItemStack;
- import net.minecraft.network.ThreadQuickExitException;
- import net.minecraft.network.play.client.CPacketChatMessage;
- import net.minecraft.network.play.client.CPacketClientStatus;
- import net.minecraft.network.play.server.SPacketSpawnPosition;
- import net.minecraft.potion.Potion;
- import net.minecraft.potion.PotionUtils;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.tileentity.TileEntityChest;
- import net.minecraft.tileentity.TileEntitySign;
- import net.minecraft.util.DamageSource;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.EnumParticleTypes;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.util.SoundCategory;
- import net.minecraft.util.SoundEvent;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.math.Vec3d;
- import net.minecraft.util.text.TextComponentString;
- import net.minecraft.world.World;
- import net.minecraft.world.WorldServer;
- import me.hammerle.exceptions.PreScriptException;
- import me.hammerle.exceptions.IllegalStringException;
- import me.hammerle.code.SnuviParser;
- import me.hammerle.exceptions.HoldCodeException;
- import net.minecraft.util.math.MathHelper;
- public class MinecraftFunctions implements ISnuviLogger
- {
- @SuppressWarnings("")
- public static void registerFunctions(SnuviParser parser)
- {
- // -------------------------------------------------------------
- // Command-Bibliothek
- // -------------------------------------------------------------
- parser.registerConsumer("command.add", (args, qd) ->
- KajetansMod.scripts.registerScriptCommand(args[0].toString()));
- parser.registerConsumer("command.remove", (args, qd) ->
- KajetansMod.scripts.unregisterScriptCommand(args[0].toString()));
- parser.registerFunction("command.exists", (args, qd) ->
- KajetansMod.scripts.isRegisteredScriptCommand(args[0].toString()));
- parser.registerConsumer("command.clear", (args, qd) ->
- KajetansMod.scripts.clearScriptCommands());
-
- // -------------------------------------------------------------
- // Permission-Bibliothek
- // -------------------------------------------------------------
- parser.registerConsumer("perm.clear", (args, qd) ->
- KajetansMod.perms.clear());
- parser.registerConsumer("perm.registergroup", (args, qd) ->
- KajetansMod.perms.registerGroupPermission(ScriptUtils.getInt(args[0]), args[1].toString()));
- parser.registerConsumer("perm.registerplayer", (args, qd) ->
- KajetansMod.perms.registerPlayerGroup(UUID.fromString(args[0].toString()), ScriptUtils.getInt(args[1])));
-
- // -------------------------------------------------------------
- // Title-Bibliothek
- // -------------------------------------------------------------
- parser.registerConsumer("title.settime", (args, qd) ->
- TitleAPI.setTitleTime((EntityPlayerMP) args[0], ScriptUtils.getInt(args[1]), ScriptUtils.getInt(args[2]), ScriptUtils.getInt(args[3])));
- parser.registerConsumer("title.clear", (args, qd) ->
- TitleAPI.clearTitle((EntityPlayerMP) args[0]));
- parser.registerConsumer("title.reset", (args, qd) ->
- TitleAPI.resetTitle((EntityPlayerMP) args[0]));
- parser.registerConsumer("title.send", (args, qd) ->
- TitleAPI.setTitle((EntityPlayerMP) args[0], ScriptUtils.connect(args, 1)));
- parser.registerConsumer("title.setsub", (args, qd) ->
- TitleAPI.setSubTitle((EntityPlayerMP) args[0], ScriptUtils.connect(args, 1)));
-
- // -------------------------------------------------------------
- // Villager-Bibliothek
- // -------------------------------------------------------------
- parser.registerConsumer("villager.showtrades", (args, qd) ->
- ((EntityPlayer) args[0]).displayVillagerTradeGui(((EntityVillager) args[1])));
-
- // -------------------------------------------------------------
- // Player-Bibliothek
- // -------------------------------------------------------------
- parser.registerFunction("player.getitemamount", (args, qd) ->
- InventoryUtils.searchInventoryFor(((EntityPlayer) args[0]).inventory, (ItemStack) args[2], (boolean) args[1]));
- parser.registerFunction("player.removeitem", (args, qd) ->
- removeItem(args));
- parser.registerFunction("player.giveitem", (args, qd) ->
- giveItem(args));
- parser.registerConsumer("player.shootprojectile", (args, qd) ->
- EffectUtils.launchProjectile((EntityPlayer) args[0], getClass(args[1].toString()), ScriptUtils.getDouble(args[2]), args[3]));
- parser.registerConsumer("player.respawn", (args, qd) ->
- respawnPlayer(args));
- parser.registerConsumer("player.inventorytolist", (args, qd) ->
- qd.setVar(args[0].toString(), ((EntityPlayer) args[1]).inventory.mainInventory));
- parser.registerFunction("player.getnearest", (args, qd) ->
- Utils.getNearestPlayer(((Location) args[0]).getWorld(), ((Location) args[0]).getPos()));
- parser.registerConsumer("player.say", (args, qd) ->
- playerSay(args));
- parser.registerFunction("player.isafk", (args, qd) ->
- KajetansMod.afkManager.getEvent(AfkListener.class).isAfk(((EntityPlayer) args[0])));
- parser.registerConsumer("player.speak", (args, qd) ->
- sendMessageToGroup(args[0], qd, "§7[§r" + args[1] + "§7] " + ScriptUtils.connect(args, 2)));
- parser.registerConsumer("player.setcompass", (args, qd) ->
- ((EntityPlayerMP) args[0]).connection.sendPacket(new SPacketSpawnPosition(((Location) args[1]).getBlockPos())));
- parser.registerFunction("player.gethunger", (args, qd) ->
- ((EntityPlayer) args[0]).getFoodStats().getFoodLevel());
- parser.registerConsumer("player.sethunger", (args, qd) ->
- ((EntityPlayer) args[0]).getFoodStats().setFoodLevel(ScriptUtils.getInt(args[1])));
- parser.registerFunction("player.getsaturation", (args, qd) ->
- ReflectionUtils.getSaturation(((EntityPlayer) args[0]).getFoodStats()));
- parser.registerConsumer("player.setsaturation", (args, qd) ->
- ReflectionUtils.setSaturation(((EntityPlayer) args[0]).getFoodStats(), ScriptUtils.getFloat(args[1])));
- parser.registerFunction("player.getname", (args, qd) ->
- getName(args));
- parser.registerFunction("player.getfullname", (args, qd) ->
- KajetansMod.chatManager.getFullName((EntityPlayer) args[0]));
- parser.registerFunction("player.getuuid", (args, qd) ->
- getUuid(args));
- parser.registerFunction("player.getip", (args, qd) ->
- ((EntityPlayerMP) args[0]).connection.netManager.getRemoteAddress().toString());
- parser.registerFunction("player.iscreative", (args, qd) ->
- ((EntityPlayer) args[0]).isCreative());
- parser.registerFunction("player.isspectator", (args, qd) ->
- ((EntityPlayer) args[0]).isSpectator());
- parser.registerFunction("player.issurvival", (args, qd) ->
- !((EntityPlayer) args[0]).isCreative() && !((EntityPlayer) args[0]).isSpectator());
- parser.registerFunction("player.isadventure", (args, qd) ->
- !((EntityPlayer) args[0]).capabilities.allowEdit);
- parser.registerFunction("player.hasfly", (args, qd) ->
- ((EntityPlayer) args[0]).capabilities.allowFlying);
- parser.registerFunction("player.getlastdamager", (args, qd) ->
- getLastDamager(args));
- parser.registerConsumer("player.settag", (args, qd) ->
- setTag(args));
- parser.registerFunction("player.gettag", (args, qd) ->
- (double) getTag(args));
- parser.registerConsumer("player.dropinventory", (args, qd) ->
- dropInventory(args));
- parser.registerFunction("player.gettarget", (args, qd) ->
- Utils.getPlayerTarget((EntityPlayer) args[0], ScriptUtils.getInt(args[1])));
- parser.registerFunction("player.hasquest", (args, qd) ->
- KajetansMod.scripts.hasScript((EntityPlayer) args[0]));
- parser.registerConsumer("player.action", (args, qd) ->
- sendToActionBar(args, qd));
- parser.registerConsumer("player.kick", (args, qd) ->
- kickPlayerFromQuest(args, qd));
- parser.registerConsumer("player.playsound", (args, qd) ->
- playSoundPlayer(args));
- parser.registerFunction("player.getbedspawn", (args, qd) ->
- getBedLocation(args));
- parser.registerConsumer("player.setbedspawn", (args, qd) ->
- ((EntityPlayer) args[0]).bedLocation = ((Location) args[1]).getBlockPos());
- parser.registerConsumer("player.damageitem", (args, qd) ->
- ((EntityPlayer) args[0]).getHeldItemMainhand().damageItem(ScriptUtils.getInt(args[1]), (EntityPlayer) args[0]));
- // -------------------------------------------------------------
- // Players-Bibliothek
- // -------------------------------------------------------------
- parser.registerFunction("players.getamount", (args, qd) ->
- KajetansMod.server.getCurrentPlayerCount());
- parser.registerConsumer("players.tolist", (args, qd) ->
- qd.setVar(args[0].toString(), Arrays.asList(KajetansMod.server.getOnlinePlayerNames())));
- parser.registerConsumer("players.toworldlist", (args, qd) ->
- qd.setVar(args[0].toString(), new ArrayList(ModDimensions.getWorldFromName(args[1].toString()).playerEntities)));
- parser.registerConsumer("players.near", (args, qd) ->
- qd.setVar(args[0].toString(), Utils.getNearbyEntities(((Location) args[1]).getWorld(), ((Location) args[1]).getPos(), ScriptUtils.getDouble(args[2]), EntityPlayer.class).stream().map(p -> p.getName()).collect(Collectors.toList())));
- // -------------------------------------------------------------
- // Rank-Bibliothek
- // -------------------------------------------------------------
- parser.registerConsumer("rank.get", (args, qd) ->
- qd.setVar(args[0].toString(), KajetansMod.chatManager.getRanks((EntityPlayer) args[1])));
- parser.registerConsumer("rank.register", (args, qd) ->
- KajetansMod.chatManager.registerRank(args[0].toString(), ScriptUtils.getInt(args[1]), args[2].toString()));
- parser.registerConsumer("rank.player", (args, qd) ->
- KajetansMod.chatManager.registerPlayerRank(UUID.fromString(args[0].toString()), args[1].toString()));
- parser.registerConsumer("rank.clear", (args, qd) ->
- KajetansMod.chatManager.clearRanks());
-
- // -------------------------------------------------------------
- // Custom-Bibliothek
- // -------------------------------------------------------------
- /*parser.registerConsumer("custom.registershapelessrecipe", (args, qd) ->
- registerShapelessRecipe(args));
- parser.registerConsumer("custom.registershapedrecipe", (args, qd) ->
- registerShapedRecipe(args));
- parser.registerConsumer("custom.registerfurnacerecipe", (args, qd) ->
- RecipeUtils.registerFurnaceRecipe((ItemStack) args[0], (ItemStack) args[1]));
- parser.registerConsumer("custom.clearrecipes", (args, qd) ->
- RecipeUtils.clearRecipes());*/
-
-
- // -------------------------------------------------------------
- // World-Bibliothek
- // -------------------------------------------------------------
-
- parser.registerAlias("world.getplayers", "players.toworldlist");
- parser.registerConsumer("world.setskills", (args, qd) ->
- KajetansMod.worldManager.getWorldPreferences(ModDimensions.getWorldFromName(args[0].toString())).skills = (boolean) args[1]);
- parser.registerConsumer("world.setblockprotections", (args, qd) ->
- KajetansMod.worldManager.getWorldPreferences(ModDimensions.getWorldFromName(args[0].toString())).blockProtection = (boolean) args[1]);
- parser.registerConsumer("world.setdefaultenchanting", (args, qd) ->
- KajetansMod.worldManager.getWorldPreferences(ModDimensions.getWorldFromName(args[0].toString())).defaultEnchanting = (boolean) args[1]);
- parser.registerConsumer("world.setpvpprotection", (args, qd) ->
- KajetansMod.worldManager.getWorldPreferences(ModDimensions.getWorldFromName(args[0].toString())).pvpProtection = (boolean) args[1]);
- parser.registerConsumer("world.setstatuseffects", (args, qd) ->
- KajetansMod.worldManager.getWorldPreferences(ModDimensions.getWorldFromName(args[0].toString())).statusEffects = (boolean) args[1]);
- parser.registerConsumer("world.setmanabar", (args, qd) ->
- KajetansMod.worldManager.getWorldPreferences(ModDimensions.getWorldFromName(args[0].toString())).manabar = (boolean) args[1]);
- parser.registerConsumer("world.setscrolls", (args, qd) ->
- KajetansMod.worldManager.getWorldPreferences(ModDimensions.getWorldFromName(args[0].toString())).scrolls = (boolean) args[1]);
- parser.registerConsumer("world.setdefaultproducing", (args, qd) ->
- KajetansMod.worldManager.getWorldPreferences(ModDimensions.getWorldFromName(args[0].toString())).defaultProducing = (boolean) args[1]);
-
- // -------------------------------------------------------------
- // Item-Bibliothek
- // -------------------------------------------------------------
- parser.registerConsumer("item.drop", (args, qd) ->
- dropItem(args));
- parser.registerFunction("item.gettype", (args, qd) ->
- ((ItemStack) args[0]).getItem().getRegistryName().toString());
- parser.registerFunction("item.getdata", (args, qd) ->
- ((ItemStack) args[0]).getMetadata());
- parser.registerConsumer("item.setdata", (args, qd) ->
- ((ItemStack) args[0]).setItemDamage(ScriptUtils.getInt(args[1])));
- parser.registerFunction("item.getamount", (args, qd) ->
- ((ItemStack) args[0]).getCount());
- parser.registerConsumer("item.setamount", (args, qd) ->
- ((ItemStack) args[0]).setCount(ScriptUtils.getInt(args[1])));
- parser.registerFunction("item.getname", (args, qd) ->
- ((ItemStack) args[0]).getDisplayName());
- parser.registerConsumer("item.setname", (args, qd) ->
- ((ItemStack) args[0]).setStackDisplayName(ScriptUtils.connect(args, 1)));
- parser.registerConsumer("item.getlore", (args, qd) ->
- qd.setVar(args[0].toString(), ItemStackUtils.getLore((ItemStack) args[1])));
- parser.registerConsumer("item.setlore", (args, qd) ->
- ItemStackUtils.setLore((ItemStack) args[0], (List<String>) args[1]));
- parser.registerConsumer("item.addlore", (args, qd) ->
- ItemStackUtils.addLore((ItemStack) args[0], ScriptUtils.connect(args, 2), ScriptUtils.getInt(args[1])));
- parser.registerFunction("item.getenchantlevel", (args, qd) ->
- EnchantmentHelper.getEnchantmentLevel(Enchantment.getEnchantmentByLocation(args[1].toString()), (ItemStack) args[0]));
- parser.registerConsumer("item.setcooldown", (args, qd) ->
- ((EntityPlayer) args[0]).getCooldownTracker().setCooldown(((ItemStack) args[1]).getItem(), ScriptUtils.getInt(args[2])));
- parser.registerFunction("item.gettooltype", (args, qd) ->
- Utils.getToolType((ItemStack) args[0]));
- // -------------------------------------------------------------
- // Location-Bibliothek
- // -------------------------------------------------------------
- parser.registerFunction("loc.distance", (args, qd) ->
- ((Location) args[0]).getPos().distanceTo(((Location) args[1]).getPos()));
- parser.registerConsumer("loc.setyaw", (args, qd) ->
- ((Location) args[0]).setYaw(ScriptUtils.getFloat(args[1])));
- parser.registerConsumer("loc.setpitch", (args, qd) ->
- ((Location) args[0]).setPitch(ScriptUtils.getFloat(args[1])));
- parser.registerFunction("loc.mod", (args, qd) ->
- ((Location) args[0]).copyAdd(ScriptUtils.getDouble(args[1]), ScriptUtils.getDouble(args[2]), ScriptUtils.getDouble(args[3])));
- parser.registerFunction("loc.getcoord", (args, qd) ->
- getCoordOfLocation(args));
- parser.registerFunction("loc.gettime", (args, qd) ->
- ((Long) ((Location) args[0]).getWorld().getWorldTime()).doubleValue());
- parser.registerFunction("loc.hasstorm", (args, qd) ->
- ((Location) args[0]).getWorld().isRaining());
- parser.registerFunction("loc.isbetween", (args, qd) ->
- isBetween(args));
- // -------------------------------------------------------------
- // Block-Bibliothek
- // -------------------------------------------------------------
- parser.registerFunction("block.gettype", (args, qd) ->
- ((Location) args[0]).getWorld().getBlockState(((Location) args[0]).getBlockPos()).getBlock().getRegistryName().toString());
- parser.registerFunction("block.getdata", (args, qd) ->
- (double) getBlockData((Location) args[0]));
- parser.registerConsumer("block.clone", (args, qd) ->
- cloneBlock(args));
- parser.registerConsumer("block.set", (args, qd) ->
- setBlock(args, qd));
- parser.registerConsumer("block.set2", (args, qd) ->
- setBlockWithData(args, qd));
- parser.registerConsumer("block.setsign", (args, qd) ->
- setSign(args));
- parser.registerFunction("block.getsign", (args, qd) ->
- getSign(args));
- parser.registerConsumer("block.setdoorstatus", (args, qd) ->
- setDoorStatus(args));
- parser.registerFunction("block.getdoorstatus", (args, qd) ->
- getDoorStatus(args));
- parser.registerFunction("block.isdoor", (args, qd) ->
- isDoor(args));
- parser.registerFunction("block.issolid", (args, qd) ->
- isSolid(args));
- parser.registerFunction("block.tostack", (args, qd) ->
- getStackFromBlock((Location) args[0]));
- parser.registerFunction("block.getitemamount", (args, qd) ->
- getItemAmountChest(args));
- parser.registerFunction("block.additem", (args, qd) ->
- addItemAmountChest(args));
- parser.registerFunction("block.subitem", (args, qd) ->
- removeItemAmountChest(args));
- // -------------------------------------------------------------
- // Event-Bibliothek
- // -------------------------------------------------------------
- parser.registerConsumer("event.addloc", (args, qd) ->
- ((MinecraftScript) qd).addLocation((Location) args[0]));
- parser.registerConsumer("event.removeloc", (args, qd) ->
- ((MinecraftScript) qd).removeLocation((Location) args[0]));
- parser.registerConsumer("event.clearlocs", (args, qd) ->
- ((MinecraftScript) qd).clearLocations());
- // -------------------------------------------------------------
- // Skill-Bibliothek
- // -------------------------------------------------------------
- parser.registerConsumer("skill.register", (args, qd) ->
- KajetansMod.skills.registerSkill(ScriptUtils.getInt(args[0]), (ItemStack) args[1], me.km.effects.Effect.valueOf(args[2].toString()), args[3].toString(), args[4].toString()));
- parser.registerConsumer("skill.clear", (args, qd) ->
- KajetansMod.skills.clearSkills());
-
- // -------------------------------------------------------------
- // Job-Bibliothek
- // -------------------------------------------------------------
- parser.registerFunction("job.getlevel", (args, qd) ->
- (double) KajetansMod.jobs.getLevel((EntityPlayer) args[0], ScriptUtils.getByte(args[1])));
- parser.registerConsumer("job.addlevel", (args, qd) ->
- KajetansMod.jobs.addLevel((EntityPlayer) args[0], ScriptUtils.getByte(args[1]), ScriptUtils.getByte(args[2])));
- parser.registerConsumer("job.setlevel", (args, qd) ->
- KajetansMod.jobs.setLevel((EntityPlayer) args[0], ScriptUtils.getByte(args[1]), ScriptUtils.getByte(args[2])));
- parser.registerFunction("job.getxp", (args, qd) ->
- (double) KajetansMod.jobs.getXP((EntityPlayer) args[0], ScriptUtils.getByte(args[1])));
- parser.registerConsumer("job.addxp", (args, qd) ->
- KajetansMod.jobs.addXP((EntityPlayer) args[0], ScriptUtils.getByte(args[1]), ScriptUtils.getByte(args[2])));
- parser.registerConsumer("job.setxp", (args, qd) ->
- KajetansMod.jobs.setXP((EntityPlayer) args[0], ScriptUtils.getByte(args[1]), ScriptUtils.getByte(args[2])));
- parser.registerConsumer("job.registerjob", (args, qd) ->
- KajetansMod.jobs.registerJob(ScriptUtils.getByte(args[0]), ScriptUtils.connect(args, 1)));
- parser.registerConsumer("job.registerrecipe", (args, qd) ->
- KajetansMod.jobs.registerRecipe(ScriptUtils.getByte(args[0]), ScriptHelper.getItem(args[1].toString()), ScriptUtils.getByte(args[2])));
- parser.registerConsumer("job.registermaterial", (args, qd) ->
- KajetansMod.jobs.registerPreferedBlock(ScriptUtils.getByte(args[0]), Block.getBlockFromName(args[1].toString())));
- parser.registerConsumer("job.registerskill", (args, qd) ->
- KajetansMod.jobs.registerSkill(ScriptUtils.getByte(args[0]), KajetansMod.skills.getSkill(ScriptUtils.getInt(args[1])), ScriptUtils.getByte(args[2]), ScriptUtils.getByte(args[3])));
- parser.registerFunction("job.getamount", (args, qd) ->
- (double) KajetansMod.jobs.getNumberOfJobs());
- parser.registerFunction("job.getname", (args, qd) ->
- KajetansMod.jobs.getJobName(ScriptUtils.getByte(args[0])));
- parser.registerFunction("job.geteffectlevel", (args, qd) ->
- (double) EffectUtils.getEffectLevel((EntityPlayer) args[0], me.km.effects.Effect.valueOf(args[1].toString())));
- parser.registerFunction("job.hasjob", (args, qd) ->
- KajetansMod.jobs.hasJob((EntityPlayer) args[0], ScriptUtils.getByte(args[1])));
- parser.registerFunction("job.hasrecipe", (args, qd) ->
- KajetansMod.jobs.hasRecipe((EntityPlayer) args[0], ScriptHelper.getItem(args[1].toString())));
- parser.registerConsumer("job.getjobs", (args, qd) ->
- qd.setVar(args[0].toString(), KajetansMod.jobs.getJobs((EntityPlayer) args[1]).stream().map(b -> (double) b).collect(Collectors.toList())));
- parser.registerFunction("job.isregmaterial", (args, qd) ->
- KajetansMod.jobs.isPreferedMaterial((EntityPlayer) args[0],Block.getBlockFromName(args[1].toString())));
- parser.registerConsumer("job.setjob", (args, qd) ->
- KajetansMod.jobs.setJob((EntityPlayer) args[0], ScriptUtils.getByte(args[1]), (boolean) args[2]));
- parser.registerConsumer("job.reset", (args, qd) ->
- KajetansMod.jobs.resetAll());
- // -------------------------------------------------------------
- // Entity - Befehle
- // -------------------------------------------------------------
- parser.registerFunction("entity.getlocation", (args, qd) ->
- new Location(((Entity) args[0])));
- parser.registerConsumer("entity.damage", (args, qd) ->
- damageEntity(args));
- parser.registerFunction("entity.gethealth", (args, qd) ->
- ((EntityLivingBase) args[0]).getHealth());
- parser.registerConsumer("entity.sethealth", (args, qd) ->
- ((EntityLivingBase) args[0]).setHealth(ScriptUtils.getFloat(args[1])));
- parser.registerConsumer("entity.setname", (args, qd) ->
- nameEntity(args));
- parser.registerConsumer("entity.throw", (args, qd) ->
- Utils.setVelocity((Entity) args[0], ScriptUtils.getDouble(args[1]), ScriptUtils.getDouble(args[2]), ScriptUtils.getDouble(args[3])));
- parser.registerConsumer("entity.teleport", (args, qd) ->
- Utils.teleportEntity((Entity) args[0], (Location) args[1]));
- parser.registerConsumer("entity.setequip", (args, qd) ->
- setEntityEquip(args));
- parser.registerFunction("entity.getequip", (args, qd) ->
- getEntityEquip(args));
- parser.registerConsumer("entity.removeall", (args, qd) ->
- removeEntities(args));
- parser.registerConsumer("entity.remove", (args, qd) ->
- ((Entity) args[0]).setDead());
- parser.registerConsumer("entity.setinvulnerable", (args, qd) ->
- ((Entity) args[0]).setEntityInvulnerable((boolean) args[1]));
- parser.registerConsumer("entity.setsilent", (args, qd) ->
- ((Entity) args[0]).setSilent((boolean) args[1]));
- parser.registerConsumer("entity.hide", (args, qd) ->
- ((Entity) args[0]).setInvisible(true));
- parser.registerConsumer("entity.show", (args, qd) ->
- ((Entity) args[0]).setInvisible(false));
- parser.registerConsumer("entity.ride", (args, qd) ->
- ((Entity) args[0]).startRiding(((Entity) args[1])));
- parser.registerConsumer("entity.setvars", (args, qd) ->
- ScriptVars.setEntityVars(qd, Utils.getNearestEntity(((Location) args[0]).getWorld(), ((Location) args[0]).getPos(), 3, (Class<? extends Entity>) getClass("net.minecraft.entity." + args[1]))));
- parser.registerConsumer("entity.addeffect", (args, qd) ->
- EffectUtils.addPotionTo((EntityLivingBase) args[0], Potion.getPotionFromResourceLocation(args[1].toString()), ScriptUtils.getInt(args[2]), ScriptUtils.getInt(args[3])));
- parser.registerFunction("entity.haseffect", (args, qd) ->
- ((EntityLivingBase) args[0]).isPotionActive(Potion.getPotionFromResourceLocation(args[1].toString())));
- parser.registerConsumer("entity.goto", (args, qd) ->
- NmsUtilities.walkTo((EntityLiving) args[0], ((Location) args[1]).getPos(), ScriptUtils.getDouble(args[2])));
- parser.registerConsumer("entity.explode", (args, qd) ->
- ((EntityCreeper) args[0]).ignite());
- parser.registerConsumer("entity.spawnitemframe", (args, qd) ->
- spawnItemFrame(args));
- parser.registerFunction("entity.getitemframe", (args, qd) ->
- Utils.getNearestEntity(((Location) args[0]).getWorld(), ((Location) args[0]).getPos().addVector(0.5, 0, 0.5), 1, EntityItemFrame.class).getDisplayedItem());
- parser.registerFunction("entity.getpotiontype", (args, qd) ->
- getPotionType(args));
- parser.registerConsumer("entity.setgravity", (args, qd) ->
- ((Entity) args[0]).setNoGravity(!(boolean) args[1]));
- parser.registerConsumer("entity.iswet", (args, qd) ->
- ((Entity) args[0]).isWet());
- // -------------------------------------------------------------
- // Status-Bibliothek
- // -------------------------------------------------------------
- parser.registerFunction("status.getmana", (args, qd) ->
- (double) EnvironmentAPI.getMana(((EntityPlayer) args[0])));
- parser.registerFunction("status.getcold", (args, qd) ->
- (double) EnvironmentAPI.getCold(((EntityPlayer) args[0])));
- parser.registerFunction("status.getenergy", (args, qd) ->
- (double) EnvironmentAPI.getEnergy(((EntityPlayer) args[0])));
- parser.registerFunction("status.getthirst", (args, qd) ->
- (double) EnvironmentAPI.getThirst(((EntityPlayer) args[0])));
- parser.registerConsumer("status.changemange", (args, qd) ->
- EnvironmentAPI.changeMana(((EntityPlayer) args[0]), ScriptUtils.getInt(args[1])));
- parser.registerConsumer("status.changecold", (args, qd) ->
- EnvironmentAPI.changeCold(((EntityPlayer) args[0]), ScriptUtils.getInt(args[1])));
- parser.registerConsumer("status.changeenergie", (args, qd) ->
- EnvironmentAPI.changeEnergy(((EntityPlayer) args[0]), ScriptUtils.getInt(args[1])));
- parser.registerConsumer("status.changethirst", (args, qd) ->
- EnvironmentAPI.changeThirst(((EntityPlayer) args[0]), ScriptUtils.getInt(args[1])));
- parser.registerConsumer("status.resetmana", (args, qd) ->
- EnvironmentAPI.resetMana(((EntityPlayer) args[0])));
- parser.registerConsumer("status.resetcold", (args, qd) ->
- EnvironmentAPI.resetCold(((EntityPlayer) args[0])));
- parser.registerConsumer("status.resetenergy", (args, qd) ->
- EnvironmentAPI.resetEnergy(((EntityPlayer) args[0])));
- parser.registerConsumer("status.resetthirst", (args, qd) ->
- EnvironmentAPI.resetThirst(((EntityPlayer) args[0])));
- parser.registerFunction("status.gettemperature", (args, qd) ->
- (double) EnvironmentAPI.getTemperature(((Location) args[0]).getWorld(), ((Location) args[0]).getBlockPos()));
- // -------------------------------------------------------------
- // GMap-Bibliothek
- // -------------------------------------------------------------
- parser.registerConsumer("gmap.removeall", (args, qd) ->
- KajetansMod.scripts.getDataBank(ScriptBank.class).removeMap(args[0].toString()));
- parser.registerConsumer("gmap.add", (args, qd) ->
- KajetansMod.scripts.getDataBank(ScriptBank.class).addMapElement(args[0].toString(), args[1].toString(), args[2].toString()));
- parser.registerConsumer("gmap.remove", (args, qd) ->
- KajetansMod.scripts.getDataBank(ScriptBank.class).removeMapElement(args[0].toString(), args[1].toString()));
- parser.registerConsumer("gmap.totable", (args, qd) ->
- qd.setVar(args[0].toString(), KajetansMod.scripts.getDataBank(ScriptBank.class).getGlobalMapAsTable(args[1].toString())));
- parser.registerFunction("gmap.get", (args, qd) ->
- KajetansMod.scripts.getDataBank(ScriptBank.class).getMapValue(args[0].toString(), args[1].toString()));
-
- // -------------------------------------------------------------
- // GDMap-Bibliothek
- // -------------------------------------------------------------
- parser.registerConsumer("gdmap.removeall", (args, qd) ->
- KajetansMod.scripts.getDataBank(ScriptBank.class).removeDualMap(args[0].toString()));
- parser.registerConsumer("gdmap.add", (args, qd) ->
- KajetansMod.scripts.getDataBank(ScriptBank.class).addDualMapElement(args[0].toString(), args[1].toString(), args[2].toString(), args[3].toString()));
- parser.registerConsumer("gdmap.remove", (args, qd) ->
- KajetansMod.scripts.getDataBank(ScriptBank.class).removeDualMapElement(args[0].toString(), args[1].toString(), args[2].toString()));
- parser.registerConsumer("gdmap.totable", (args, qd) ->
- qd.setVar(args[0].toString(), KajetansMod.scripts.getDataBank(ScriptBank.class).getGlobalDualMapAsTable(args[1].toString(), args[2].toString())));
- parser.registerFunction("gdmap.get", (args, qd) ->
- KajetansMod.scripts.getDataBank(ScriptBank.class).getDualMapValue(args[0].toString(), args[1].toString(), args[2].toString()));
- // -------------------------------------------------------------
- // Table-Bibliothek
- // -------------------------------------------------------------
- parser.registerConsumer("table.print", (args, qd) ->
- printTable(args, qd));
- parser.registerConsumer("table.new", (args, qd) ->
- qd.setVar(args[0].toString(), new Table(ScriptUtils.getInt(args[1]))));
- parser.registerConsumer("table.frommap", (args, qd) ->
- qd.setVar(args[0].toString(), new Table((Map<Object, Object>) args[1])));
- parser.registerConsumer("table.sort", (args, qd) ->
- ((Table) args[0]).sort());
- parser.registerConsumer("table.reverse", (args, qd) ->
- ((Table) args[0]).reverse());
- parser.registerConsumer("table.shuffle", (args, qd) ->
- ((Table) args[0]).shuffle());
- parser.registerConsumer("table.clear", (args, qd) ->
- ((Table) args[0]).clear());
- parser.registerConsumer("table.addrow", (args, qd) ->
- ((Table) args[0]).addRow(Arrays.copyOfRange(args, 1, args.length)));
- parser.registerConsumer("table.removerow", (args, qd) ->
- ((Table) args[0]).removeRow(ScriptUtils.getInt(args[1])));
- parser.registerFunction("table.get", (args, qd) ->
- ((Table) args[0]).getElement(ScriptUtils.getInt(args[1]), ScriptUtils.getInt(args[2])));
- parser.registerFunction("table.getindexof", (args, qd) ->
- (double) ((Table) args[0]).getIndexOf(args[1]));
- parser.registerConsumer("table.setsortcolumn", (args, qd) ->
- ((Table) args[0]).setSortColumn(ScriptUtils.getInt(args[1])));
- parser.registerFunction("table.getsize", (args, qd) ->
- (double) ((Table) args[0]).getSize());
- // -------------------------------------------------------------
- // Plot-Bibliothek
- // -------------------------------------------------------------
- parser.registerFunction("plot.hastag", (args, qd) ->
- KajetansMod.plots.getDataBank(ProtectionBank.class).hasTag(((Location) args[0]).getWorld(), ((Location) args[0]).getBlockPos(), args[1].toString()));
- parser.registerConsumer("plot.add", (args, qd) ->
- addPlot(args));
- parser.registerFunction("plot.getid", (args, qd) ->
- KajetansMod.plots.getDataBank(ProtectionBank.class).getFirstRegionId(((Location) args[0]).getWorld(), ((Location) args[0]).getBlockPos()));
- parser.registerFunction("plot.canbuild", (args, qd) ->
- KajetansMod.plots.getDataBank(ProtectionBank.class).canBuild(((Location) args[0]).getWorld(), ((Location) args[0]).getBlockPos(), (EntityPlayer) args[1]));
- parser.registerFunction("plot.getname", (args, qd) ->
- KajetansMod.plots.getDataBank(ProtectionBank.class).getFirstRegionName(((Location) args[0]).getWorld(), ((Location) args[0]).getBlockPos()));
- parser.registerFunction("plot.doesintersect", (args, qd) ->
- doesIntersect(args));
-
- // -------------------------------------------------------------
- // Quest-Bibliothek
- // -------------------------------------------------------------
- parser.registerConsumer("quest.end", (args, qd) ->
- endPlayerScript(args, qd));
- parser.registerConsumer("quest.playerstolist", (args, qd) ->
- qd.setVar(args[0].toString(), new ArrayList<>(((PlayerScript) qd).getPlayers())));
- parser.registerFunction("quest.getplayeramount", (args, qd) ->
- ((PlayerScript) qd).getPlayers().size());
- parser.registerConsumer("quest.start", (args, qd) ->
- startPlayerScript(args, qd));
- parser.registerFunction("quest.isactive", (args, qd) ->
- KajetansMod.scripts.isActive(args[0].toString()));
- parser.registerFunction("quest.getleader", (args, qd) ->
- getPlayerScriptLeader(qd));
- // -------------------------------------------------------------
- // Scoreboard-Bibliothek
- // -------------------------------------------------------------
- parser.registerConsumer("sb.add", (args, qd) ->
- addToScoreBoard(args, qd));
- parser.registerConsumer("sb.remove", (args, qd) ->
- removeFromScoreBoard(args, qd));
- parser.registerConsumer("sb.reset", (args, qd) ->
- doForGroup(args[0], qd, p -> KajetansMod.scoreboard.resetScoreboard((EntityPlayerMP) p)));
- // -------------------------------------------------------------
- // Effect-Bibliothek
- // -------------------------------------------------------------
- parser.registerConsumer("effect.playsound", (args, qd) ->
- playSound(args));
- parser.registerConsumer("effect.play", (args, qd) ->
- playParticle(args));
- // -------------------------------------------------------------
- // Inventory-Bibliothek
- // -------------------------------------------------------------
- parser.registerConsumer("inv.new", (args, qd) ->
- qd.setVar(args[0].toString(), new SnuviInventory(args[2].toString(), ScriptUtils.getInt(args[1]), ((MinecraftScript) qd).getNewId())));
- parser.registerConsumer("inv.loadblock", (args, qd) ->
- qd.setVar(args[0].toString(), newInventory((Location) args[1], (MinecraftScript) qd, args[2].toString())));
- parser.registerConsumer("inv.setitem", (args, qd) ->
- ((IInventory) args[0]).setInventorySlotContents(ScriptUtils.getInt(args[1]), (ItemStack) args[2]));
- parser.registerFunction("inv.getitem", (args, qd) ->
- ((IInventory) args[0]).getStackInSlot(ScriptUtils.getInt(args[1])));
- parser.registerConsumer("inv.open", (args, qd) ->
- new ScriptInventoryHolder((SnuviInventory) args[0], (EntityPlayerMP) args[1], (MinecraftScript) qd).openForPlayer((EntityPlayerMP) args[1]));
- parser.registerConsumer("inv.close", (args, qd) ->
- ((EntityPlayer) args[0]).closeScreen());
- // -------------------------------------------------------------
- // Read-Bibliothek
- // -------------------------------------------------------------
- parser.registerFunction("read.player", (args, qd) ->
- Utils.getPlayerByName(args[0].toString()));
- parser.registerFunction("read.location", (args, qd) ->
- new Location(qd, args[0].toString()));
- parser.registerFunction("read.item", (args, qd) ->
- ScriptHelper.getItemStack(args, 0));
- parser.registerFunction("read.spawnmob", (args, qd) ->
- NmsUtilities.getEntityFromNbtString(qd, ScriptUtils.connect(args," ", 1).replace("'", "\""), (Location) args[0]));
- // -------------------------------------------------------------
- // Text-Bibliothek
- // -------------------------------------------------------------
- parser.registerFunction("text.location", (args, qd) ->
- ((Location) args[0]).toString());
- parser.registerFunction("text.locationblock", (args, qd) ->
- ((Location) args[0]).toBlockString());
- parser.registerFunction("text.item", (args, qd) ->
- ScriptHelper.getItemStackString((ItemStack) args[0]));
- // -------------------------------------------------------------
- // Ohne Bibliothek
- // -------------------------------------------------------------
- parser.registerConsumer("overload", (args, qd) ->
- qd.overload(ScriptUtils.readCode("scripts/" + args[0].toString(), ".txt")));
- parser.registerFunction("getglobalvar", (args, qd) ->
- getGlobalVar(args));
- parser.registerAlias("ggv", "getglobalvar");
- parser.registerConsumer("setglobalvar", (args, qd) ->
- setGlobalVar(args));
- parser.registerAlias("sgv", "setglobalvar");
- parser.registerConsumer("msg", (args, qd) ->
- sendMessageToGroup(args[0], qd, ScriptUtils.connect(args, 1)));
- parser.registerFunction("removeformat", (args, qd) ->
- ScriptUtils.connect(args, 0).replaceAll("§.", ""));
- parser.registerFunction("concatspace", (args, qd) ->
- ScriptUtils.connect(args, " ", 0));
- parser.registerFunction("onlyletters", (args, qd) ->
- onlyLetters(ScriptUtils.connect(args, 0)));
- parser.registerConsumer("command", (args, qd) ->
- KajetansMod.server.commandManager.executeCommand(KajetansMod.server, ScriptUtils.connect(args, 0)));
- }
-
- @Override
- public void printException(SnuviException ex)
- {
- if(KajetansMod.debugMode || KajetansMod.scripts.getSnuviParser().printStack)
- {
- printConsoleException(ex, null);
- }
- sendToDevsWithSuffix("§cError in '" + ex.getScriptName() + "'");
- printGeneralException(ex);
- }
-
- @Override
- public void printException(SnuviException ex, Script sc)
- {
- if(KajetansMod.debugMode || KajetansMod.scripts.getSnuviParser().printStack)
- {
- printConsoleException(ex, sc);
- }
- sendToDevsWithSuffix("§cError in '" + sc.getName()+ "'");
- printGeneralException(ex);
- }
-
- @Override
- public void printInfo(String s)
- {
- sendToDevsWithSuffix(s);
- }
-
- @Override
- public void printWarning(String s)
- {
- sendWarningToAllDevs(s);
- }
-
- private void printGeneralException(SnuviException ex)
- {
- if(ex.getCode() != null)
- {
- ArrayList<String> list = ex.getWholeCode();
- for(int i = 1; i <= list.size(); i++)
- {
- sendToDevsWithHelpList("§cZeile " + i + ":", list.get(i - 1));
- }
- }
- if(ex.getLine() != -1)
- {
- sendToDevsWithHelpList("§cZeilennummer:", String.valueOf(ex.getLine()));
- }
-
- if(ex.getOriginalException() != null)
- {
- Exception another = ex.getOriginalException();
- if(another.getLocalizedMessage() == null)
- {
- sendToDevsWithHelpList("§cFehler:", another.getClass().getSimpleName());
- }
- else
- {
- sendToDevsWithHelpList("§cFehler:", another.getClass().getSimpleName() + " - " + another.getLocalizedMessage());
- }
- }
- else
- {
- sendToDevsWithHelpList("§cFehler:", ex.getClass().getSimpleName());
- if(ex instanceof PreScriptException)
- {
- sendToDevsWithList("§c" + ((PreScriptException) ex).getException());
- return;
- }
- }
- if(ex instanceof IllegalStringException)
- {
- sendToDevsWithHelpList("§cUngültiger Wert:", ((IllegalStringException) ex).getBadString());
- }
- }
-
- public void printConsoleException(SnuviException ex, Script sc)
- {
- Module m = KajetansMod.scripts;
- m.sendWarningToConsole("Error in '" + (sc == null ? ex.getScriptName() : sc.getName()) + "'");
- if(ex.getCode() != null)
- {
- ArrayList<String> list = ex.getWholeCode();
- for(int i = 1; i <= list.size(); i++)
- {
- m.sendWarningToConsole("Zeile " + i + ": " + list.get(i - 1));
- }
- }
- if(ex.getLine() != -1)
- {
- m.sendWarningToConsole("Zeilennummer: " + ex.getLine());
- }
-
- if(ex.getOriginalException() != null)
- {
- Exception another = ex.getOriginalException();
- if(another.getLocalizedMessage() == null)
- {
- m.sendWarningToConsole("Fehler: " + another.getClass().getSimpleName());
- }
- else
- {
- m.sendWarningToConsole("Fehler: " + another.getClass().getSimpleName() + " - " + another.getLocalizedMessage());
- }
- }
- else
- {
- m.sendWarningToConsole("Fehler: " + ex.getClass().getSimpleName());
- if(ex instanceof PreScriptException)
- {
- m.sendWarningToConsole(((PreScriptException) ex).getException());
- return;
- }
- }
- if(ex instanceof IllegalStringException)
- {
- m.sendWarningToConsole("Ungültiger Wert: " + ((IllegalStringException) ex).getBadString());
- }
- }
-
- private static void printTable(Object[] args, Script sc)
- {
- Table t = (Table) args[1];
- if(t.getSize() >= 60)
- {
- throw new IllegalArgumentException("table is too big");
- }
- TableAPI.getTable(t, ScriptUtils.getInt(args[2]), args[3].toString(),
- args.length >= 5 ? (boolean) args[4] : false)
- .forEach(s -> sendMessageToGroup(args[0], sc, s));
- }
-
- private static Location getBedLocation(Object[] args)
- {
- WorldServer ws = ModDimensions.getWorldFromName(args[1].toString());
- return new Location(ws, ((EntityPlayer) args[0]).getBedLocation(ws.provider.getDimension()));
- }
-
- private static boolean isDoor(Object[] args)
- {
- Location l = (Location) args[0];
- return l.getWorld().getBlockState(l.getBlockPos()).getBlock() instanceof BlockDoor;
- }
-
- private static boolean getDoorStatus(Object[] args)
- {
- Location l = (Location) args[0];
- return BlockDoor.isOpen(l.getWorld(), l.getBlockPos());
- }
-
- private static void setDoorStatus(Object[] args)
- {
- Location l = (Location) args[0];
- BlockPos pos = l.getBlockPos();
- ((BlockDoor) l.getWorld().getBlockState(pos).getBlock()).toggleDoor(l.getWorld(), pos, (boolean) args[1]);
- }
-
- private static void playerSay(Object[] args)
- {
- try
- {
- ((EntityPlayerMP) args[0]).connection.processChatMessage(new CPacketChatMessage(ScriptUtils.connect(args, 1)));
- }
- catch(ThreadQuickExitException ex)
- {
- // Minecraft needs this for canceling and queueing into main thread
- }
- }
-
- private static void respawnPlayer(Object[] args)
- {
- try
- {
- ((EntityPlayerMP) args[0]).connection.processClientStatus(new CPacketClientStatus(CPacketClientStatus.State.PERFORM_RESPAWN));
- }
- catch(ThreadQuickExitException ex)
- {
- // Minecraft needs this for canceling and queueing into main thread
- }
- }
-
- private static Class getClass(String s)
- {
- try
- {
- return Class.forName(s);
- }
- catch(ClassNotFoundException ex)
- {
- throw new IllegalStringException(s);
- }
- }
-
- private static int getItemAmountChest(Object[] args) throws IllegalStringLocationException, IllegalItemStackStringException
- {
- Location l = (Location) args[0];
- TileEntity te = l.getWorld().getTileEntity(l.getBlockPos());
- if(te == null || !(te instanceof TileEntityChest))
- {
- return 0;
- }
- return InventoryUtils.searchInventoryFor(((TileEntityChest) te), (ItemStack) args[2], (boolean) args[1]);
- }
-
- private static ItemStack addItemAmountChest(Object[] args) throws IllegalStringLocationException, IllegalItemStackStringException
- {
- Location l = (Location) args[0];
- ItemStack stack = ((ItemStack) args[1]);
- TileEntity te = l.getWorld().getTileEntity(l.getBlockPos());
- if(te == null || !(te instanceof TileEntityChest))
- {
- return stack;
- }
- stack.setCount(InventoryUtils.addToInventory((TileEntityChest) te, stack));
- return stack;
- }
-
- private static ItemStack removeItemAmountChest(Object[] args) throws IllegalStringLocationException, IllegalItemStackStringException
- {
- Location l = (Location) args[0];
- ItemStack stack = ((ItemStack) args[1]);
- TileEntity te = l.getWorld().getTileEntity(l.getBlockPos());
- if(te == null || !(te instanceof TileEntityChest))
- {
- return stack;
- }
- stack.setCount(InventoryUtils.removeFromInventory((TileEntityChest) te, stack));
- return stack;
- }
-
- private static Object getCoordOfLocation(Object[] args) throws IllegalStringLocationException
- {
- Location l = (Location) args[0];
- switch(args[1].toString())
- {
- case "x":
- return l.getX();
- case "y":
- return l.getY();
- case "z":
- return l.getZ();
- case "bx":
- return (double) MathHelper.floor(l.getX());
- case "by":
- return (double) MathHelper.floor(l.getY());
- case "bz":
- return (double) MathHelper.floor(l.getZ());
- case "w":
- return ModDimensions.getWorldName(l.getWorld());
- default:
- return null;
- }
- }
-
- private static void cloneBlock(Object[] args) throws IllegalStringLocationException
- {
- Location l = (Location) args[1];
- IBlockState state = getBlockState((Location) args[0]);
- l.getWorld().setBlockState(l.getBlockPos(), state);
- }
-
- private static ItemStack removeItem(Object[] args) throws PlayerNotFoundException, IllegalItemStackStringException
- {
- ItemStack stack = ((ItemStack) args[1]).copy();
- stack.setCount(InventoryUtils.removeFromInventory(((EntityPlayer) args[0]).inventory, stack));
- return stack;
- }
-
- private static void dropItem(Object[] args) throws IllegalStringLocationException, IllegalItemStackStringException
- {
- Location l = (Location) args[0];
- World w = l.getWorld();
- BlockPos pos = l.getBlockPos();
- ItemStack stack = ((ItemStack) args[1]).copy();
- int amount = stack.getCount();
- while(amount > stack.getMaxStackSize())
- {
- stack.setCount(stack.getMaxStackSize());
- amount -= stack.getMaxStackSize();
- ItemStackUtils.drop(w, pos, stack.copy());
- }
- if(amount > 0)
- {
- stack.setCount(amount);
- ItemStackUtils.drop(w, pos, stack);
- }
- }
-
- private static ItemStack giveItem(Object[] args) throws PlayerNotFoundException, IllegalItemStackStringException
- {
- ItemStack stack = ((ItemStack) args[1]).copy();
- stack.setCount(InventoryUtils.addToInventory(((EntityPlayer) args[0]).inventory, stack));
- return stack;
- }
-
- private static void endPlayerScript(Object[] args, Script qd) throws NumberFormatException, UnsupportedOperationException
- {
- if(qd.getClass() == MinecraftScript.class)
- {
- throw new UnsupportedOperationException();
- }
- ((PlayerScript) qd).getPlayers().stream().forEach((p) ->
- {
- KajetansMod.scripts.send(p, "Du hast die Quest geschafft!");
- });
- KajetansMod.scripts.getSnuviParser().termSafe(qd);
- throw new HoldCodeException();
- }
-
- private static void setBlock(Object[] args, Script qd) throws IllegalStringLocationException, IllegalItemStackStringException
- {
- Location l = (Location) args[0];
- ItemStack stack = (ItemStack) args[1];
- l.getWorld().setBlockState(l.getBlockPos(), Block.getBlockFromItem(stack.getItem()).getStateFromMeta(stack.getMetadata()));
- qd.incLoopCounter();
- }
-
- private static void setBlockWithData(Object[] args, Script qd) throws IllegalStringLocationException
- {
- Location l = (Location) args[0];
- if(args.length >= 4)
- {
- NmsUtilities.setBlockWithData(l.getWorld(), l.getBlockPos(), ScriptUtils.getInt(args[2]), Block.getBlockFromName(args[1].toString()), ScriptUtils.connect(args, 3));
- }
- else
- {
- NmsUtilities.setBlockWithData(l.getWorld(), l.getBlockPos(), ScriptUtils.getInt(args[2]), Block.getBlockFromName(args[1].toString()), null);
- }
- qd.incLoopCounter();
- }
-
- private static void dropInventory(Object[] args)
- {
- ((EntityPlayer) args[0]).inventory.dropAllItems();
- }
-
- private static void playSound(Object[] args) throws IllegalStringLocationException
- {
- Location l = ((Location) args[0]);
- Vec3d v = l.getPos();
- EffectUtils.playSound((WorldServer) l.getWorld(), SoundEvent.REGISTRY.getObject(new ResourceLocation(args[1].toString())), SoundCategory.MASTER, v.x, v.y, v.z);
- }
-
- private static void playSoundPlayer(Object[] args) throws IllegalStringLocationException
- {
- EffectUtils.playSound((EntityPlayerMP) args[0], SoundEvent.REGISTRY.getObject(new ResourceLocation(args[1].toString())), SoundCategory.MASTER);
- }
-
- private static void playParticle(Object[] args) throws IllegalStringLocationException
- {
- Location l = ((Location) args[0]).copyAdd(0.5, 0.5, 0.5);
- EffectUtils.spawnParticle((WorldServer) l.getWorld(), EnumParticleTypes.getByName(args[1].toString()), l.getPos(), ScriptUtils.getInt(args[2]));
- }
-
- private static void setEntityEquip(Object[] args) throws IllegalStringLocationException, EntityNotFoundException, IllegalItemStackStringException
- {
- EntityLivingBase liv = (EntityLivingBase) args[0];
- ItemStack stack = ((ItemStack) args[2]).copy();
- switch(args[1].toString())
- {
- case "hand":
- liv.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, stack);
- return;
- case "head":
- liv.setItemStackToSlot(EntityEquipmentSlot.HEAD, stack);
- return;
- case "chest":
- liv.setItemStackToSlot(EntityEquipmentSlot.CHEST, stack);
- return;
- case "legs":
- liv.setItemStackToSlot(EntityEquipmentSlot.LEGS, stack);
- return;
- case "feet":
- liv.setItemStackToSlot(EntityEquipmentSlot.FEET, stack);
- return;
- case "offhand":
- liv.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, stack);
- }
- }
-
- private static ItemStack getEntityEquip(Object[] args) throws IllegalStringLocationException, EntityNotFoundException
- {
- EntityLivingBase liv = (EntityLivingBase) args[0];
- switch(args[1].toString())
- {
- case "hand":
- return liv.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND);
- case "head":
- return liv.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
- case "chest":
- return liv.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
- case "legs":
- return liv.getItemStackFromSlot(EntityEquipmentSlot.LEGS);
- case "feet":
- return liv.getItemStackFromSlot(EntityEquipmentSlot.FEET);
- case "offhand":
- return liv.getItemStackFromSlot(EntityEquipmentSlot.OFFHAND);
- }
- return ItemStack.EMPTY;
- }
-
- @SuppressWarnings("unchecked")
- private static void removeEntities(Object[] args) throws IllegalStringLocationException
- {
- Class<? extends Entity> c = (Class<? extends Entity>) getClass(args[0].toString());
- if(c == Entity.class || c == EntityVillager.class || c == EntityArmorStand.class || c == EntityItemFrame.class || c == EntityHanging.class)
- {
- return;
- }
- Location l = (Location) args[1];
- Utils.getNearbyEntities(l.getWorld(), l.getPos(), ScriptUtils.getDouble(args[2]), c).stream().forEach(ent ->
- {
- ent.setDead();
- });
- }
-
- private static void setSign(Object[] args) throws IllegalStringLocationException
- {
- Location l = (Location) args[0];
- TileEntitySign sign = (TileEntitySign) l.getWorld().getTileEntity(l.getBlockPos());
- SpecialBlockUtils.setSignLine(sign, ScriptUtils.getInt(args[1]), ScriptUtils.connect(args, 2));
- }
-
- @SuppressWarnings("")
- private static String getSign(Object[] args) throws IllegalStringLocationException
- {
- Location l = (Location) args[0];
- TileEntitySign sign = (TileEntitySign) l.getWorld().getTileEntity(l.getBlockPos());
- return sign.signText[ScriptUtils.getInt(args[1])].getUnformattedText();
- }
-
- private static boolean isSolid(Object[] args)
- {
- IBlockState state = getBlockState((Location) args[0]);
- return state.isFullBlock() && state.isOpaqueCube();
- }
- private static void spawnItemFrame(Object[] args) throws IllegalStringLocationException, IllegalItemStackStringException
- {
- Location l = ((Location) args[0]);
- EntityItemFrame frame = new EntityItemFrame(l.getWorld(), l.getBlockPos(), EnumFacing.byName(args[1].toString()));
- frame.setDisplayedItem(((ItemStack) args[2]).copy());
- }
-
- private static void nameEntity(Object[] args) throws EntityNotFoundException
- {
- Entity ent = (Entity) args[0];
- ent.setCustomNameTag(ScriptUtils.connect(args, 1));
- if(args.length >= 3)
- {
- ent.setAlwaysRenderNameTag((boolean) args[2]);
- return;
- }
- ent.setAlwaysRenderNameTag(true);
- }
-
- private static EntityPlayer getPlayerScriptLeader(Script qd) throws PlayerNotFoundException
- {
- if(qd.getClass() == PlayerScript.class)
- {
- return((PlayerScript) qd).getPlayers().get(0);
- }
- throw new UnsupportedOperationException();
- }
- private static void startPlayerScript(Object[] args, Script qd) throws PlayerNotFoundException
- {
- if(qd.getClass() == MinecraftScript.class)
- {
- EntityPlayer p = ((EntityPlayer) args[0]);
- if(!KajetansMod.scripts.hasScript(p))
- {
- KajetansMod.scripts.startQuest(KajetansMod.server, args[1].toString(), p);
- }
- return;
- }
- throw new UnsupportedOperationException();
- }
-
- private static void addToScoreBoard(Object[] args, Script qd) throws PlayerNotFoundException
- {
- int id = ScriptUtils.getInt(args[1]);
- String message = ScriptUtils.connect(args, 2);
- doForGroup(args[0], qd, p -> KajetansMod.scoreboard.getScoreboard((EntityPlayerMP) p).addText(id, message));
- }
-
- private static void removeFromScoreBoard(Object[] args, Script qd) throws PlayerNotFoundException
- {
- int id = ScriptUtils.getInt(args[1]);
- doForGroup(args[0], qd, p -> KajetansMod.scoreboard.getScoreboard((EntityPlayerMP) p).removeText(id));
- }
- private static void sendToActionBar(Object[] args, Script qd) throws PlayerNotFoundException
- {
- String text = ScriptUtils.connect(args, 1);
- doForGroup(args[0], qd, p -> NmsUtilities.sendActionBar((EntityPlayerMP) p, text));
- }
- private static void kickPlayerFromQuest(Object[] args, Script qd) throws PlayerNotFoundException, UnsupportedOperationException
- {
- if(qd.getClass() == PlayerScript.class)
- {
- KajetansMod.scripts.removePlayerFromScript((EntityPlayer) args[0], (PlayerScript) qd);
- return;
- }
- throw new UnsupportedOperationException();
- }
- private static void damageEntity(Object[] args)
- {
- if(args.length >= 4)
- {
- ((EntityLivingBase) args[0]).attackEntityFrom(DamageSource.causeMobDamage((EntityLivingBase) args[2]), ScriptUtils.getFloat(args[1]));
- return;
- }
- ((EntityLivingBase) args[0]).attackEntityFrom(DamageSource.GENERIC, ScriptUtils.getFloat(args[1]));
- }
-
- private static boolean doesIntersect(Object[] args)
- {
- Location l1 = (Location) args[0];
- Location l2 = (Location) args[1];
- int x1 = (int) Math.min(l1.getX(), l2.getX());
- int x2 = (int) Math.max(l1.getX(), l2.getX());
- int y1 = (int) Math.min(l1.getY(), l2.getY());
- int y2 = (int) Math.max(l1.getY(), l2.getY());
- int z1 = (int) Math.min(l1.getZ(), l2.getZ());
- int z2 = (int) Math.max(l1.getZ(), l2.getZ());
- return KajetansMod.plots.getDataBank(ProtectionBank.class)
- .isPlotOverlapping(x1, y1, z1, x2, y2, z2, l1.getWorld());
- }
-
- private static boolean isBetween(Object[] args)
- {
- Location l1 = ((Location) args[0]);
- Location l2 = ((Location) args[1]);
- Location l3 = ((Location) args[2]);
- return l1.getX() >= Math.min(l2.getX(), l3.getX()) && l1.getX() <= Math.max(l2.getX(), l3.getX()) &&
- l1.getY() >= Math.min(l2.getY(), l3.getY()) && l1.getY() <= Math.max(l2.getY(), l3.getY()) &&
- l1.getZ() >= Math.min(l2.getZ(), l3.getZ()) && l1.getZ() <= Math.max(l2.getZ(), l3.getZ());
- }
- private static void addPlot(Object[] args)
- {
- Location l1 = (Location) args[0];
- Location l2 = (Location) args[1];
- BlockPos pos1 = l1.getBlockPos();
- BlockPos pos2 = l2.getBlockPos();
- KajetansMod.plots.getDataBank(ProtectionBank.class).addPlot(Math.min(pos1.getX(), pos2.getX()),
- Math.min(pos1.getY(), pos2.getY()),
- Math.min(pos1.getZ(), pos2.getZ()),
- Math.max(pos1.getX(), pos2.getX()),
- Math.max(pos1.getY(), pos2.getY()),
- Math.max(pos1.getZ(), pos2.getZ()),
- ModDimensions.getWorldName(l1.getWorld()), null, args[2].toString());
- }
-
- private static Entity getLastDamager(Object[] args)
- {
- DamageSource ds = ((EntityPlayer) args[0]).getLastDamageSource();
- if(ds == null)
- {
- return null;
- }
- return ds.getImmediateSource();
- }
-
- @SuppressWarnings("")
- private static SnuviInventory newInventory(Location l, MinecraftScript qd, String s)
- {
- TileEntityChest chest = (TileEntityChest) l.getWorld().getTileEntity(l.getBlockPos());
- int size = chest.getSizeInventory();
- if(size % 9 != 0)
- {
- size /= 9;
- size++;
- size *= 9;
- }
- SnuviInventory inv = new SnuviInventory(s, size, qd.getNewId());
- for(int i = 0; i < chest.getSizeInventory(); i++)
- {
- inv.setInventorySlotContents(i, chest.getStackInSlot(i).copy());
- }
- return inv;
- }
-
- private static boolean onlyLetters(String s)
- {
- for(char c : s.toCharArray())
- {
- if(!Character.isLetter(c))
- {
- return false;
- }
- }
- return true;
- }
-
- private static String getName(Object[] args)
- {
- Object o = args[0];
- if(o instanceof EntityPlayer)
- {
- return ((EntityPlayer) o).getName();
- }
- return KajetansMod.playerbank.getDataBank().getName(o.toString());
- }
-
- private static String getUuid(Object[] args)
- {
- Object o = args[0];
- if(o instanceof EntityPlayer)
- {
- return ((EntityPlayer) o).getUniqueID().toString();
- }
- return KajetansMod.playerbank.getDataBank().getUUID(o.toString());
- }
-
- @SuppressWarnings("")
- private static String getPotionType(Object[] args)
- {
- return PotionUtils.getPotionFromItem(((EntityPotion) args[0]).getPotion()).getRegistryName().toString();
- }
-
- private static void setTag(Object[] args)
- {
- if(args[0] instanceof EntityPlayer)
- {
- KajetansMod.playerbank.getDataBank().setTag((EntityPlayer) args[0], args[1].toString(), ScriptUtils.getInt(args[2]));
- return;
- }
- KajetansMod.playerbank.getDataBank().setTag(KajetansMod.playerbank.getDataBank().getUUID(args[0].toString()), args[1].toString(), ScriptUtils.getInt(args[2]));
- }
-
- private static int getTag(Object[] args)
- {
- if(args[0] instanceof EntityPlayer)
- {
- return KajetansMod.playerbank.getDataBank().getTag((EntityPlayer) args[0], args[1].toString());
- }
- return KajetansMod.playerbank.getDataBank().getTag(KajetansMod.playerbank.getDataBank().getUUID(args[0].toString()), args[1].toString());
- }
-
- private static void setGlobalVar(Object[] args)
- {
- if(args[0] instanceof EntityPlayer)
- {
- KajetansMod.scripts.getDataBank(ScriptBank.class).setVar(args[2].toString(), args[1].toString(), ((EntityPlayer) args[0]).getUniqueID().toString());
- return;
- }
- KajetansMod.scripts.getDataBank(ScriptBank.class).setVar(args[2].toString(), args[1].toString(), KajetansMod.playerbank.getDataBank().getUUID(args[0].toString()));
- }
-
- private static Object getGlobalVar(Object[] args)
- {
- if(args[0] instanceof EntityPlayer)
- {
- return KajetansMod.scripts.getDataBank(ScriptBank.class).getVar(args[1].toString(), ((EntityPlayer) args[0]).getUniqueID().toString());
- }
- return KajetansMod.scripts.getDataBank(ScriptBank.class).getVar(args[1].toString(), KajetansMod.playerbank.getDataBank().getUUID(args[0].toString()));
- }
- // -------------------------------------------------------------------------
- // Block
- // -------------------------------------------------------------------------
-
- private static int getBlockData(Location l)
- {
- IBlockState state = l.getWorld().getBlockState(l.getBlockPos());
- return state.getBlock().getMetaFromState(state);
- }
-
- private static IBlockState getBlockState(Location l)
- {
- return l.getWorld().getBlockState(l.getBlockPos());
- }
-
- private static ItemStack getStackFromBlock(Location l)
- {
- World w = l.getWorld();
- BlockPos pos = l.getBlockPos();
- IBlockState state = w.getBlockState(pos);
- return state.getBlock().getItem(w, pos, state);
- }
-
- // -------------------------------------------------------------------------
- // Custom-Handler
- // -------------------------------------------------------------------------
-
- /*private static void registerShapelessRecipe(Object[] args)
- {
- ItemStack[] stacks = new ItemStack[args.length - 1];
- for(int i = 0; i < stacks.length; i++)
- {
- stacks[i] = (ItemStack) args[i + 1];
- }
- RecipeUtils.registerShapelessRecipe((ItemStack) args[0], stacks);
- }
-
- private static void registerShapedRecipe(Object[] args)
- {
- int counter = 0;
- while(args[counter + 1].getClass() == String.class)
- {
- counter++;
- }
- String[] s = new String[counter];
- for(int i = 0; i < s.length; i++)
- {
- s[i] = args[i + 1].toString();
- }
-
- ItemStack[] stacks = new ItemStack[args.length - 1 - s.length];
- for(int i = 0; i < stacks.length; i++)
- {
- stacks[i] = (ItemStack) args[i + 1 + counter];
- }
- RecipeUtils.registerShapedRecipe((ItemStack) args[0], s, stacks);
- }*/
-
- // -------------------------------------------------------------------------
- // Gruppen-Handler
- // -------------------------------------------------------------------------
-
- private static void doForGroup(Object group, Script qd, Consumer<ICommandSender> c) throws UnsupportedOperationException, PlayerNotFoundException
- {
- if(group instanceof String)
- {
- switch(group.toString())
- {
- case "all":
- if(qd.getClass() == MinecraftScript.class)
- {
- throw new UnsupportedOperationException();
- }
- ((PlayerScript) qd).getPlayers().forEach(p -> c.accept(p));
- break;
- case "online":
- KajetansMod.server.getPlayerList().getPlayers().forEach(p -> c.accept(p));
- break;
- case "dev":
- if(qd != null && qd.getClass() == PlayerScript.class)
- {
- ((PlayerScript) qd).getPlayers().stream().filter(p -> KajetansMod.perms.has(p, Permissions.SCRIPT_ERROR)).forEach(p -> c.accept(p));
- return;
- }
- KajetansMod.server.getPlayerList().getPlayers().stream().filter(p -> KajetansMod.perms.has(p, Permissions.SCRIPT_ERROR)).forEach(p -> c.accept(p));
- break;
- case "server":
- c.accept(KajetansMod.server);
- break;
- default:
- c.accept(Utils.getPlayerByName(group.toString()));
- break;
- }
- return;
- }
- c.accept((EntityPlayer) group);
- }
-
- private static void sendMessageToGroup(Object group, Script sc, String message)
- {
- TextComponentString comp = new TextComponentString(message);
- doForGroup(group, sc, p ->
- {
- p.sendMessage(comp);
- });
- }
-
- public static void sendMessageWithSuffix(Script sc, String message)
- {
- Module m = KajetansMod.scripts;
- doForGroup("all", sc, p -> m.send(p, message));
- }
-
- private static void sendToDevsWithSuffix(String message)
- {
- Module m = KajetansMod.scripts;
- doForGroup("dev", null, p -> m.send(p, message));
- }
-
- public static void sendWarningToAllDevs(String message)
- {
- Module m = KajetansMod.scripts;
- String warnMessage = "§4" + message;
- doForGroup("dev", null, p -> m.send(p, warnMessage));
- }
-
- private static void sendToDevsWithList(String message)
- {
- Module m = KajetansMod.scripts;
- doForGroup("dev", null, p -> m.sendListElement(p, message));
- }
-
- private static void sendToDevsWithHelpList(String message, String message2)
- {
- Module m = KajetansMod.scripts;
- doForGroup("dev", null, p -> m.sendHelpListElement(p, message, message2));
- }
- }
|