123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752 |
- 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.utils.NBTUtils;
- 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.Set;
- 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.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.EntityLiving;
- import net.minecraft.entity.EntityLivingBase;
- 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.IllegalStringException;
- import me.hammerle.code.SnuviParser;
- import me.hammerle.exceptions.HoldCodeException;
- import me.hammerle.math.Fraction;
- import me.km.effects.Effect;
- import me.km.inventory.CustomContainer;
- import me.km.networking.ModPacketHandler;
- import me.km.pathfinder.PathfinderUtils;
- import me.km.skills.LeveledSkill;
- import me.km.skills.Skill;
- import net.minecraft.block.BlockCrops;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.util.NonNullList;
- import net.minecraft.util.math.MathHelper;
- import net.minecraft.util.text.ITextComponent;
- 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])));
- parser.registerFunction("perm.get", (args, qd) ->
- Permissions.valueOf(args[0].toString()));
- parser.registerFunction("perm.has", (args, qd) ->
- KajetansMod.perms.has((ICommandSender) args[0], 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) ->
- new Fraction(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.registerFunction("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(qd, 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, NBTUtils.concat(2, "§7[§r" + args[1] + "§7]§r ", args)));
- parser.registerConsumer("player.setcompass", (args, qd) ->
- ((EntityPlayerMP) args[0]).connection.sendPacket(new SPacketSpawnPosition(((Location) args[1]).getBlockPos())));
- parser.registerFunction("player.gethunger", (args, qd) ->
- new Fraction(((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) ->
- Fraction.fromDouble(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) ->
- getTag(args));
- parser.registerConsumer("player.setguild", (args, qd) ->
- {
- if(args[0] instanceof EntityPlayer)
- {
- KajetansMod.playerbank.setGuildId((EntityPlayer) args[0], ScriptUtils.getInt(args[1]));
- return;
- }
- KajetansMod.playerbank.setGuildId(args[0].toString(), ScriptUtils.getInt(args[1]));
- });
- parser.registerFunction("player.getguild", (args, qd) ->
- {
- if(args[0] instanceof EntityPlayer)
- {
- return new Fraction(KajetansMod.playerbank.getGuildId((EntityPlayer) args[0]));
- }
- return new Fraction(KajetansMod.playerbank.getGuildId(args[0].toString()));
- });
-
- parser.registerConsumer("player.dropinventory", (args, qd) ->
- dropInventory(args));
- parser.registerFunction("player.gettarget", (args, qd) ->
- {
- if(args.length > 2)
- {
- return new Location(((EntityPlayer) args[0]).world,
- Utils.getPlayerTarget((EntityPlayer) args[0], ScriptUtils.getInt(args[1]), (boolean) args[2]));
- }
- return new Location(((EntityPlayer) args[0]).world, Utils.getPlayerTarget((EntityPlayer) args[0], ScriptUtils.getInt(args[1])));
- });
-
- parser.registerFunction("player.gettargetentity", (args, qd) ->
- Utils.getTargetedEntity((EntityPlayer) args[0], ScriptUtils.getDouble(args[1]), getClass(args[2].toString())));
- 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) ->
- new Fraction(KajetansMod.server.getCurrentPlayerCount()));
- parser.registerConsumer("players.tolist", (args, qd) ->
- qd.setVar(args[0].toString(), new ArrayList(KajetansMod.server.getPlayerList().getPlayers())));
- 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) ->
- nearPlayers(args, qd));
- // -------------------------------------------------------------
- // 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) ->
- new Fraction(((ItemStack) args[0]).getMetadata()));
- parser.registerConsumer("item.setdata", (args, qd) ->
- ((ItemStack) args[0]).setItemDamage(ScriptUtils.getInt(args[1])));
- parser.registerFunction("item.getamount", (args, qd) ->
- new Fraction(((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) ->
- new Fraction(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.new", (args, qd) ->
- {
- if(args.length >= 6)
- {
- return new Location(ModDimensions.getWorldFromName(args[0].toString()),
- ScriptUtils.getDouble(args[0]), ScriptUtils.getDouble(args[1]), ScriptUtils.getDouble(args[2]),
- ScriptUtils.getFloat(args[3]), ScriptUtils.getFloat(args[4]));
- }
- return new Location(ModDimensions.getWorldFromName(args[0].toString()),
- ScriptUtils.getDouble(args[0]), ScriptUtils.getDouble(args[1]), ScriptUtils.getDouble(args[2]), 0, 0);
- });
-
- parser.registerFunction("loc.getx", (args, qd) ->
- Fraction.fromDouble(((Location) args[0]).getX()));
- parser.registerFunction("loc.gety", (args, qd) ->
- Fraction.fromDouble(((Location) args[0]).getY()));
- parser.registerFunction("loc.getz", (args, qd) ->
- Fraction.fromDouble(((Location) args[0]).getZ()));
-
- parser.registerConsumer("loc.setx", (args, qd) ->
- ((Location) args[0]).setX(ScriptUtils.getDouble(args[1])));
- parser.registerConsumer("loc.sety", (args, qd) ->
- ((Location) args[0]).setY(ScriptUtils.getDouble(args[1])));
- parser.registerConsumer("loc.setz", (args, qd) ->
- ((Location) args[0]).setZ(ScriptUtils.getDouble(args[1])));
-
- parser.registerConsumer("loc.addx", (args, qd) ->
- ((Location) args[0]).addX(ScriptUtils.getDouble(args[1])));
- parser.registerConsumer("loc.addy", (args, qd) ->
- ((Location) args[0]).addY(ScriptUtils.getDouble(args[1])));
- parser.registerConsumer("loc.addz", (args, qd) ->
- ((Location) args[0]).addZ(ScriptUtils.getDouble(args[1])));
-
- 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.distance", (args, qd) ->
- Fraction.fromDouble(((Location) args[0]).getPos().distanceTo(((Location) args[1]).getPos())));
- 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) ->
- new Fraction(((Location) args[0]).getWorld().getWorldTime()));
- 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) ->
- 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));
- parser.registerConsumer("block.grow", (args, qd) ->
- {
- World w = ((Location) args[0]).getWorld();
- BlockPos pos1 = ((Location) args[0]).getBlockPos();
- BlockPos pos2 = ((Location) args[1]).getBlockPos();
-
- int x = Math.min(pos1.getX(), pos2.getX());
- int endX = Math.max(pos1.getX(), pos2.getX());
-
- int y = Math.min(pos1.getY(), pos2.getY());
- int endY = Math.max(pos1.getY(), pos2.getY());
-
- int z = Math.min(pos1.getZ(), pos2.getZ());
- int endZ = Math.max(pos1.getZ(), pos2.getZ());
-
- if(endX - x > 50 || endY - y > 50 || endZ - z > 50)
- {
- throw new IllegalArgumentException("uhh, that area seems way to big for growing plants");
- }
-
- BlockPos relative;
- IBlockState state;
- for(; x <= endX; x++)
- {
- for(; y <= endY; y++)
- {
- for(; z <= endZ; z++)
- {
- relative = new BlockPos(x, y, z);
- state = w.getBlockState(relative);
- if(state.getBlock() instanceof BlockCrops)
- {
- w.setBlockState(relative, state.withProperty(BlockCrops.AGE, 7));
- }
- }
- }
- }
- });
- // -------------------------------------------------------------
- // 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) ->
- registerSkill(args));
- parser.registerConsumer("skill.clear", (args, qd) ->
- KajetansMod.skills.clearSkills());
- parser.registerConsumer("skill.getactive", (args, qd) ->
- qd.setVar(args[0].toString(), KajetansMod.jobs.getActiveSkills((EntityPlayer) args[1])));
- parser.registerFunction("skill.getid", (args, qd) ->
- ((LeveledSkill) args[0]).getId());
- parser.registerFunction("skill.fromid", (args, qd) ->
- getSkillFromId(args));
- parser.registerFunction("skill.getstack", (args, qd) ->
- ((LeveledSkill) args[0]).getItemStack());
- parser.registerFunction("skill.use", (args, qd) ->
- ((LeveledSkill) args[0]).useEffect((EntityPlayerMP) args[1]));
-
- // -------------------------------------------------------------
- // Job-Bibliothek
- // -------------------------------------------------------------
- parser.registerFunction("job.getlevel", (args, qd) ->
- new Fraction(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) ->
- new Fraction(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.getInt(args[2])));
- parser.registerConsumer("job.setxp", (args, qd) ->
- KajetansMod.jobs.setXP((EntityPlayer) args[0], ScriptUtils.getByte(args[1]), ScriptUtils.getInt(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) ->
- new Fraction(KajetansMod.jobs.getNumberOfJobs()));
- parser.registerFunction("job.getname", (args, qd) ->
- KajetansMod.jobs.getJobName(ScriptUtils.getByte(args[0])));
- parser.registerFunction("job.geteffectlevel", (args, qd) ->
- new Fraction(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 -> new Fraction(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.registerConsumer("entity.getdamagesource", (args, qd) ->
- getDamageSource(args));
- parser.registerFunction("entity.gethealth", (args, qd) ->
- Fraction.fromDouble(((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.registerFunction("entity.getname", (args, qd) ->
- ((Entity) args[0]).getDisplayName().getUnformattedText());
- 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.addeffect", (args, qd) ->
- addEffect(args));
- parser.registerFunction("entity.haseffect", (args, qd) ->
- ((EntityLivingBase) args[0]).isPotionActive(Potion.getPotionFromResourceLocation(args[1].toString())));
- parser.registerConsumer("entity.goto", (args, qd) ->
- walkTo(args));
- parser.registerConsumer("entity.explode", (args, qd) ->
- ((EntityCreeper) args[0]).ignite());
- parser.registerConsumer("entity.spawnitemframe", (args, qd) ->
- spawnItemFrame(args));
- parser.registerFunction("entity.getitemframe", (args, qd) ->
- ((EntityItemFrame) args[0]).getDisplayedItem());
- parser.registerFunction("entity.get", (args, qd) ->
- getEntity(args));
- 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());
- parser.registerConsumer("entity.setpickupdelay", (args, qd) ->
- ((EntityItem) args[0]).setPickupDelay(ScriptUtils.getInt(args[1])));
- parser.registerConsumer("entity.setage", (args, qd) ->
- ReflectionUtils.setAge((EntityItem) args[0], ScriptUtils.getInt(args[1])));
- // -------------------------------------------------------------
- // Status-Bibliothek
- // -------------------------------------------------------------
- parser.registerFunction("status.getmana", (args, qd) ->
- new Fraction(EnvironmentAPI.getMana(((EntityPlayer) args[0]))));
- parser.registerFunction("status.getcold", (args, qd) ->
- new Fraction(EnvironmentAPI.getCold(((EntityPlayer) args[0]))));
- parser.registerFunction("status.getenergy", (args, qd) ->
- new Fraction(EnvironmentAPI.getEnergy(((EntityPlayer) args[0]))));
- parser.registerFunction("status.getthirst", (args, qd) ->
- new Fraction(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) ->
- new Fraction(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()));
- parser.registerFunction("gmap.getordefault", (args, qd) ->
- {
- Object o = KajetansMod.scripts.getDataBank(ScriptBank.class).getMapValue(args[0].toString(), args[1].toString());
- if(o == null)
- {
- return args[2];
- }
- return o;
- });
-
- // -------------------------------------------------------------
- // 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()));
- parser.registerFunction("gdmap.getordefault", (args, qd) ->
- {
- Object o = KajetansMod.scripts.getDataBank(ScriptBank.class).getDualMapValue(args[0].toString(), args[1].toString(), args[2].toString());
- if(o == null)
- {
- return args[3];
- }
- return o;
- });
- // -------------------------------------------------------------
- // 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.registerConsumer("table.set", (args, qd) ->
- ((Table) args[0]).setElement(ScriptUtils.getInt(args[1]), ScriptUtils.getInt(args[2]), args[3]));
- parser.registerFunction("table.getindexof", (args, qd) ->
- new Fraction(((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) ->
- new Fraction(((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.registerConsumer("plot.getids", (args, qd) ->
- qd.setVar(args[0].toString(), getPlotIds(args)));
- 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) ->
- new Fraction(((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)));
-
- // -------------------------------------------------------------
- // Display-Bibliothek
- // -------------------------------------------------------------
- parser.registerConsumer("display.add", (args, qd) ->
- addToDisplay(args, qd));
- parser.registerConsumer("display.remove", (args, qd) ->
- removeFromDisplay(args, qd));
- parser.registerConsumer("display.reset", (args, qd) ->
- doForGroup(args[0], qd, p -> ModPacketHandler.sendToDisplay((EntityPlayerMP) p, (byte) 3, (byte) -1, "")));
- // -------------------------------------------------------------
- // 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.newdynamic", (args, qd) ->
- qd.setVar(args[0].toString(), new SnuviInventory(args[2].toString(), args[1].toString(), ((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());
- parser.registerConsumer("inv.close", (args, qd) ->
- invClose(args));
- parser.registerConsumer("inv.update", (args, qd) ->
- {
- EntityPlayerMP p = (EntityPlayerMP) args[0];
- NonNullList<ItemStack> list = NonNullList.<ItemStack>create();
- int size = p.openContainer.inventorySlots.size();
- for(int j = 0; j < size; j++)
- {
- ItemStack itemstack = p.openContainer.inventorySlots.get(j).getStack();
- list.add(itemstack.isEmpty() ? ItemStack.EMPTY : itemstack);
- }
- p.sendAllContents(p.openContainer, list);
- });
- // -------------------------------------------------------------
- // 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) ->
- NBTUtils.fromString(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]));
- parser.registerFunction("text.click", (args, qd) ->
- NBTUtils.getClickable(args[0], args[1].toString()));
- parser.registerFunction("text.hover", (args, qd) ->
- NBTUtils.getHoverable(args[0], args[1].toString()));
- // -------------------------------------------------------------
- // 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, NBTUtils.concat(1, args)));
- 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.scheduler.scheduleTask(() -> KajetansMod.server.commandManager.executeCommand(KajetansMod.server, ScriptUtils.connect(args, 0))));
- }
-
- @Override
- public void printException(Exception ex, String function, String s, int line)
- {
- if(KajetansMod.debugMode || KajetansMod.scripts.getSnuviParser().printStack)
- {
- Module m = KajetansMod.scripts;
- m.sendWarningToConsole("Error in '" + s + "'");
- if(line != -1)
- {
- m.sendWarningToConsole("Zeile: " + line);
- }
- m.sendWarningToConsole("Fehler: " + ex.getClass().getSimpleName() + " - " + ex.getLocalizedMessage());
- if(function != null)
- {
- m.sendWarningToConsole("Funktion: " + function);
- }
- }
- sendToDevsWithSuffix("§cError in '" + s + "'");
- if(line != -1)
- {
- sendToDevsWithHelpList("§cZeile:", String.valueOf(line));
- }
- sendToDevsWithHelpList("§cFehler:", ex.getClass().getSimpleName() + " - " + ex.getLocalizedMessage());
- if(function != null)
- {
- sendToDevsWithHelpList("§cFunktion: ", function);
- }
- }
-
- @Override
- public void printException(Exception ex, String function, Script sc, int line)
- {
- printException(ex, function, sc == null ? "null" : sc.getName(), line);
- }
-
- @Override
- public void printInfo(String s)
- {
- sendToDevsWithSuffix(s);
- }
-
- @Override
- public void printWarning(String s)
- {
- sendWarningToAllDevs(s);
- }
- 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, new TextComponentString(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 registerSkill(Object[] args)
- {
- KajetansMod.skills.registerSkill(ScriptUtils.getInt(args[0]),
- (ItemStack) args[1], Effect.valueOf(args[2].toString()),
- args[3].toString(), args[4].toString(),
- ScriptUtils.getInt(args[5]), ScriptUtils.getInt(args[6]),
- ScriptUtils.getInt(args[7]), ScriptUtils.getInt(args[8]));
- }
-
- private static LeveledSkill getSkillFromId(Object[] args)
- {
- Skill skill = KajetansMod.skills.getSkill(ScriptUtils.getInt(args[0]));
- if(skill == null)
- {
- return null;
- }
- byte level = (byte) EffectUtils.getEffectLevel((EntityPlayer) args[1], skill.getEffect());
- if(level <= 0)
- {
- return null;
- }
- return new LeveledSkill(skill, level);
- }
-
- private static void walkTo(Object[] args)
- {
- Location l = (Location) args[1];
- PathfinderUtils.walkTo((EntityLiving) args[0], l.getX(), l.getY(), l.getZ(), ScriptUtils.getDouble(args[2]));
- }
-
- 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(Script sc, Object[] args)
- {
- KajetansMod.scheduler.scheduleTask(() ->
- {
- 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 Fraction 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 new Fraction(0);
- }
- return new Fraction(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 Fraction.fromDouble(l.getX());
- case "y":
- return Fraction.fromDouble(l.getY());
- case "z":
- return Fraction.fromDouble(l.getZ());
- case "bx":
- return new Fraction(MathHelper.floor(l.getX()));
- case "by":
- return new Fraction(MathHelper.floor(l.getY()));
- case "bz":
- return new Fraction(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)
- {
- NBTUtils.setBlockWithData(l.getWorld(), l.getBlockPos(), ScriptUtils.getInt(args[2]), Block.getBlockFromName(args[1].toString()), ScriptUtils.connect(args, 3));
- }
- else
- {
- NBTUtils.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]);
- EffectUtils.spawnParticle((WorldServer) l.getWorld(), EnumParticleTypes.getByName(args[1].toString()),
- l.getX() + 0.5, l.getY() + 0.5, l.getZ() + 0.5, 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;
- }
-
- private static void invClose(Object[] args)
- {
- EntityPlayer p = (EntityPlayer) args[0];
- if(p.openContainer instanceof CustomContainer)
- {
- ((CustomContainer) p.openContainer).closeSafe();
- }
- else
- {
- p.closeScreen();
- }
- }
-
- @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)
- {
- return;
- }
- Location l = (Location) args[1];
- Utils.getEntities(l.getWorld(), l.getX(), l.getY(), l.getZ(), 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 addToDisplay(Object[] args, Script qd) throws PlayerNotFoundException
- {
- byte id = (byte) ScriptUtils.getInt(args[1]);
- String message = ScriptUtils.connect(args, 2);
- doForGroup(args[0], qd, p -> ModPacketHandler.sendToDisplay((EntityPlayerMP) p, (byte) 1, id, message));
- }
-
- private static void removeFromDisplay(Object[] args, Script qd) throws PlayerNotFoundException
- {
- byte id = (byte) ScriptUtils.getInt(args[1]);
- doForGroup(args[0], qd, p -> ModPacketHandler.sendToDisplay((EntityPlayerMP) p, (byte) 2, id, ""));
- }
- private static void sendToActionBar(Object[] args, Script qd) throws PlayerNotFoundException
- {
- TextComponentString text = new TextComponentString(ScriptUtils.connect(args, 1));
- doForGroup(args[0], qd, p -> ((EntityPlayerMP) p).sendStatusMessage(text, true));
- }
- 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)
- {
- // entity.damage(entity, damagefloat, DamageSource);
- if(args.length >= 3)
- {
- ((EntityLivingBase) args[0]).attackEntityFrom((DamageSource) args[2], ScriptUtils.getFloat(args[1]));
- return;
- }
- ((EntityLivingBase) args[0]).attackEntityFrom(DamageSource.GENERIC, ScriptUtils.getFloat(args[1]));
- }
-
- private static DamageSource getDamageSource(Object[] args)
- {
- if(args[0] instanceof EntityLivingBase)
- {
- EntityLivingBase ent = (EntityLivingBase) args[0];
- DamageSource ds;
- if(ent instanceof EntityPlayer)
- {
- ds = DamageSource.causePlayerDamage((EntityPlayer) ent);
- }
- else
- {
- ds = DamageSource.causeMobDamage(ent);
- }
-
- if((boolean) args[1])
- {
- ds.setDamageAllowedInCreativeMode();
- }
- if((boolean) args[2])
- {
- ds.setDamageBypassesArmor();
- }
- if((boolean) args[3])
- {
- ds.setDamageIsAbsolute();
- }
- if((boolean) args[4])
- {
- ds.setExplosion();
- }
- if((boolean) args[5])
- {
- ds.setFireDamage();
- }
- if((boolean) args[6])
- {
- ds.setMagicDamage();
- }
- if((boolean) args[7])
- {
- ds.setProjectile();
- }
- return ds;
- }
-
- switch(args[0].toString())
- {
- case "IN_FIRE": return DamageSource.IN_FIRE;
- case "LIGHTNING_BOLT": return DamageSource.LIGHTNING_BOLT;
- case "ON_FIRE": return DamageSource.ON_FIRE;
- case "LAVA": return DamageSource.LAVA;
- case "HOT_FLOOR": return DamageSource.HOT_FLOOR;
- case "IN_WALL": return DamageSource.IN_WALL;
- case "CRAMMING": return DamageSource.CRAMMING;
- case "DROWN": return DamageSource.DROWN;
- case "STARVE": return DamageSource.STARVE;
- case "CACTUS": return DamageSource.CACTUS;
- case "FALL": return DamageSource.FALL;
- case "FLY_INTO_WALL": return DamageSource.FLY_INTO_WALL;
- case "OUT_OF_WORLD": return DamageSource.OUT_OF_WORLD;
- case "GENERIC": return DamageSource.GENERIC;
- case "MAGIC": return DamageSource.MAGIC;
- case "WITHER": return DamageSource.WITHER;
- case "ANVIL": return DamageSource.ANVIL;
- case "FALLING_BLOCK": return DamageSource.FALLING_BLOCK;
- case "DRAGON_BREATH": return DamageSource.DRAGON_BREATH;
- case "FIREWORKS": return DamageSource.FIREWORKS;
- case "THORNS": return DamageSource.causeThornsDamage((Entity) args[1]);
- }
- return DamageSource.GENERIC;
- }
-
- 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();
- }
-
- private static void nearPlayers(Object[] args, Script sc)
- {
- Location l = (Location) args[1];
- sc.setVar(args[0].toString(), Utils.getPlayers(l.getWorld(), l.getX(), l.getY(), l.getZ(), ScriptUtils.getDouble(args[2])));
- }
-
- @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 Entity getEntity(Object[] args)
- {
- Location l = (Location) args[0];
- return Utils.getEntity(l.getWorld(), l.getX(), l.getY(), l.getZ(), ScriptUtils.getDouble(args[1]), getClass(args[2].toString()));
- }
-
- 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());
- }
-
- private static Set<Fraction> getPlotIds(Object[] args)
- {
- return KajetansMod.plots.getDataBank(ProtectionBank.class).getRegionIds(
- ((Location) args[1]).getWorld(),
- ((Location) args[1]).getBlockPos()).stream()
- .map(o -> new Fraction(Integer.parseInt(o.toString())))
- .collect(Collectors.toSet());
- }
-
- @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(args[0].toString(), args[1].toString(), ScriptUtils.getInt(args[2]));
- }
-
- private static Fraction getTag(Object[] args)
- {
- if(args[0] instanceof EntityPlayer)
- {
- return new Fraction(KajetansMod.playerbank.getDataBank().getTag((EntityPlayer) args[0], args[1].toString()));
- }
- return new Fraction(KajetansMod.playerbank.getDataBank().getTag(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());
- }
- else if(args[0].equals("SERVER"))
- {
- KajetansMod.scripts.getDataBank(ScriptBank.class).setVar(args[2].toString(), args[1].toString(), "-1");
- }
- else
- {
- KajetansMod.scripts.getDataBank(ScriptBank.class).setVar(args[2].toString(), args[1].toString(), 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());
- }
- else if(args[0].equals("SERVER"))
- {
- return KajetansMod.scripts.getDataBank(ScriptBank.class).getVar(args[1].toString(), "-1");
- }
- return KajetansMod.scripts.getDataBank(ScriptBank.class).getVar(args[1].toString(), args[0].toString());
- }
-
- // -------------------------------------------------------------------------
- // Potion
- // -------------------------------------------------------------------------
-
- private static void addEffect(Object[] args)
- {
- EntityLivingBase base = (EntityLivingBase) args[0];
- Potion potion = Potion.getPotionFromResourceLocation(args[1].toString());
- if(base == null) // doing this only to prevent EffectUtils.addPotionTo doing shit
- {
- throw new NullPointerException("null not allowed for entity");
- }
- else if(potion == null)
- {
- throw new NullPointerException("potion does not exist");
- }
- EffectUtils.addPotionTo(base, potion, ScriptUtils.getInt(args[2]), ScriptUtils.getInt(args[3]));
- }
-
- // -------------------------------------------------------------------------
- // Block
- // -------------------------------------------------------------------------
-
- private static Fraction getBlockData(Location l)
- {
- IBlockState state = l.getWorld().getBlockState(l.getBlockPos());
- return new Fraction(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, ITextComponent text)
- {
- doForGroup(group, sc, p ->
- {
- p.sendMessage(text);
- });
- }
-
- 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));
- }
- }
|