12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610 |
- 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.entity.item.EntityItem;
- 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.dropinventory", (args, qd) ->
- dropInventory(args));
- parser.registerFunction("player.gettarget", (args, qd) ->
- 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.distance", (args, qd) ->
- Fraction.fromDouble(((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) ->
- 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));
- // -------------------------------------------------------------
- // 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.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) ->
- 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()));
-
- // -------------------------------------------------------------
- // 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) ->
- 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.sendStats((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));
- // -------------------------------------------------------------
- // 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.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.sendStats((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.sendStats((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(KajetansMod.playerbank.getDataBank().getUUID(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(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()));
- }
-
- // -------------------------------------------------------------------------
- // 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));
- }
- }
|