MinecraftFunctions.java 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610
  1. package me.km.snuviscript;
  2. import me.km.KajetansMod;
  3. import me.km.afk.AfkListener;
  4. import me.km.api.Module;
  5. import me.km.api.Utils;
  6. import me.km.environment.EnvironmentAPI;
  7. import me.km.exception.EntityNotFoundException;
  8. import me.km.exception.IllegalItemStackStringException;
  9. import me.km.exception.IllegalStringLocationException;
  10. import me.km.exception.PlayerNotFoundException;
  11. import me.km.utils.NBTUtils;
  12. import me.km.plots.ProtectionBank;
  13. import me.km.table.TableAPI;
  14. import java.util.ArrayList;
  15. import java.util.Arrays;
  16. import java.util.List;
  17. import java.util.Map;
  18. import java.util.Set;
  19. import java.util.UUID;
  20. import java.util.function.Consumer;
  21. import java.util.stream.Collectors;
  22. import me.hammerle.code.ISnuviLogger;
  23. import me.hammerle.code.Script;
  24. import me.hammerle.code.ScriptUtils;
  25. import me.km.api.Location;
  26. import me.km.api.TitleAPI;
  27. import me.km.dimensions.ModDimensions;
  28. import me.km.effects.EffectUtils;
  29. import me.km.inventory.InventoryUtils;
  30. import me.km.permissions.Permissions;
  31. import me.km.table.Table;
  32. import me.km.utils.ItemStackUtils;
  33. import me.km.utils.ReflectionUtils;
  34. import me.km.utils.SpecialBlockUtils;
  35. import net.minecraft.block.Block;
  36. import net.minecraft.block.BlockDoor;
  37. import net.minecraft.block.state.IBlockState;
  38. import net.minecraft.command.ICommandSender;
  39. import net.minecraft.enchantment.Enchantment;
  40. import net.minecraft.enchantment.EnchantmentHelper;
  41. import net.minecraft.entity.Entity;
  42. import net.minecraft.entity.EntityLiving;
  43. import net.minecraft.entity.EntityLivingBase;
  44. import net.minecraft.entity.item.EntityItemFrame;
  45. import net.minecraft.entity.monster.EntityCreeper;
  46. import net.minecraft.entity.passive.EntityVillager;
  47. import net.minecraft.entity.player.EntityPlayer;
  48. import net.minecraft.entity.player.EntityPlayerMP;
  49. import net.minecraft.entity.projectile.EntityPotion;
  50. import net.minecraft.inventory.EntityEquipmentSlot;
  51. import net.minecraft.inventory.IInventory;
  52. import net.minecraft.item.ItemStack;
  53. import net.minecraft.network.ThreadQuickExitException;
  54. import net.minecraft.network.play.client.CPacketChatMessage;
  55. import net.minecraft.network.play.client.CPacketClientStatus;
  56. import net.minecraft.network.play.server.SPacketSpawnPosition;
  57. import net.minecraft.potion.Potion;
  58. import net.minecraft.potion.PotionUtils;
  59. import net.minecraft.tileentity.TileEntity;
  60. import net.minecraft.tileentity.TileEntityChest;
  61. import net.minecraft.tileentity.TileEntitySign;
  62. import net.minecraft.util.DamageSource;
  63. import net.minecraft.util.EnumFacing;
  64. import net.minecraft.util.EnumParticleTypes;
  65. import net.minecraft.util.ResourceLocation;
  66. import net.minecraft.util.SoundCategory;
  67. import net.minecraft.util.SoundEvent;
  68. import net.minecraft.util.math.BlockPos;
  69. import net.minecraft.util.math.Vec3d;
  70. import net.minecraft.util.text.TextComponentString;
  71. import net.minecraft.world.World;
  72. import net.minecraft.world.WorldServer;
  73. import me.hammerle.exceptions.IllegalStringException;
  74. import me.hammerle.code.SnuviParser;
  75. import me.hammerle.exceptions.HoldCodeException;
  76. import me.hammerle.math.Fraction;
  77. import me.km.effects.Effect;
  78. import me.km.inventory.CustomContainer;
  79. import me.km.networking.ModPacketHandler;
  80. import me.km.pathfinder.PathfinderUtils;
  81. import me.km.skills.LeveledSkill;
  82. import me.km.skills.Skill;
  83. import net.minecraft.entity.item.EntityItem;
  84. import net.minecraft.util.math.MathHelper;
  85. import net.minecraft.util.text.ITextComponent;
  86. public class MinecraftFunctions implements ISnuviLogger
  87. {
  88. @SuppressWarnings("")
  89. public static void registerFunctions(SnuviParser parser)
  90. {
  91. // -------------------------------------------------------------
  92. // Command-Bibliothek
  93. // -------------------------------------------------------------
  94. parser.registerConsumer("command.add", (args, qd) ->
  95. KajetansMod.scripts.registerScriptCommand(args[0].toString()));
  96. parser.registerConsumer("command.remove", (args, qd) ->
  97. KajetansMod.scripts.unregisterScriptCommand(args[0].toString()));
  98. parser.registerFunction("command.exists", (args, qd) ->
  99. KajetansMod.scripts.isRegisteredScriptCommand(args[0].toString()));
  100. parser.registerConsumer("command.clear", (args, qd) ->
  101. KajetansMod.scripts.clearScriptCommands());
  102. // -------------------------------------------------------------
  103. // Permission-Bibliothek
  104. // -------------------------------------------------------------
  105. parser.registerConsumer("perm.clear", (args, qd) ->
  106. KajetansMod.perms.clear());
  107. parser.registerConsumer("perm.registergroup", (args, qd) ->
  108. KajetansMod.perms.registerGroupPermission(ScriptUtils.getInt(args[0]), args[1].toString()));
  109. parser.registerConsumer("perm.registerplayer", (args, qd) ->
  110. KajetansMod.perms.registerPlayerGroup(UUID.fromString(args[0].toString()), ScriptUtils.getInt(args[1])));
  111. parser.registerFunction("perm.get", (args, qd) ->
  112. Permissions.valueOf(args[0].toString()));
  113. parser.registerFunction("perm.has", (args, qd) ->
  114. KajetansMod.perms.has((ICommandSender) args[0], args[1]));
  115. // -------------------------------------------------------------
  116. // Title-Bibliothek
  117. // -------------------------------------------------------------
  118. parser.registerConsumer("title.settime", (args, qd) ->
  119. TitleAPI.setTitleTime((EntityPlayerMP) args[0], ScriptUtils.getInt(args[1]), ScriptUtils.getInt(args[2]), ScriptUtils.getInt(args[3])));
  120. parser.registerConsumer("title.clear", (args, qd) ->
  121. TitleAPI.clearTitle((EntityPlayerMP) args[0]));
  122. parser.registerConsumer("title.reset", (args, qd) ->
  123. TitleAPI.resetTitle((EntityPlayerMP) args[0]));
  124. parser.registerConsumer("title.send", (args, qd) ->
  125. TitleAPI.setTitle((EntityPlayerMP) args[0], ScriptUtils.connect(args, 1)));
  126. parser.registerConsumer("title.setsub", (args, qd) ->
  127. TitleAPI.setSubTitle((EntityPlayerMP) args[0], ScriptUtils.connect(args, 1)));
  128. // -------------------------------------------------------------
  129. // Villager-Bibliothek
  130. // -------------------------------------------------------------
  131. parser.registerConsumer("villager.showtrades", (args, qd) ->
  132. ((EntityPlayer) args[0]).displayVillagerTradeGui(((EntityVillager) args[1])));
  133. // -------------------------------------------------------------
  134. // Player-Bibliothek
  135. // -------------------------------------------------------------
  136. parser.registerFunction("player.getitemamount", (args, qd) ->
  137. new Fraction(InventoryUtils.searchInventoryFor(((EntityPlayer) args[0]).inventory, (ItemStack) args[2], (boolean) args[1])));
  138. parser.registerFunction("player.removeitem", (args, qd) ->
  139. removeItem(args));
  140. parser.registerFunction("player.giveitem", (args, qd) ->
  141. giveItem(args));
  142. parser.registerFunction("player.shootprojectile", (args, qd) ->
  143. EffectUtils.launchProjectile((EntityPlayer) args[0], getClass(args[1].toString()), ScriptUtils.getDouble(args[2]), args[3]));
  144. parser.registerConsumer("player.respawn", (args, qd) ->
  145. respawnPlayer(qd, args));
  146. parser.registerConsumer("player.inventorytolist", (args, qd) ->
  147. qd.setVar(args[0].toString(), ((EntityPlayer) args[1]).inventory.mainInventory));
  148. parser.registerFunction("player.getnearest", (args, qd) ->
  149. Utils.getNearestPlayer(((Location) args[0]).getWorld(), ((Location) args[0]).getPos()));
  150. parser.registerConsumer("player.say", (args, qd) ->
  151. playerSay(args));
  152. parser.registerFunction("player.isafk", (args, qd) ->
  153. KajetansMod.afkManager.getEvent(AfkListener.class).isAfk(((EntityPlayer) args[0])));
  154. parser.registerConsumer("player.speak", (args, qd) ->
  155. sendMessageToGroup(args[0], qd, NBTUtils.concat(2, "§7[§r" + args[1] + "§7]§r ", args)));
  156. parser.registerConsumer("player.setcompass", (args, qd) ->
  157. ((EntityPlayerMP) args[0]).connection.sendPacket(new SPacketSpawnPosition(((Location) args[1]).getBlockPos())));
  158. parser.registerFunction("player.gethunger", (args, qd) ->
  159. new Fraction(((EntityPlayer) args[0]).getFoodStats().getFoodLevel()));
  160. parser.registerConsumer("player.sethunger", (args, qd) ->
  161. ((EntityPlayer) args[0]).getFoodStats().setFoodLevel(ScriptUtils.getInt(args[1])));
  162. parser.registerFunction("player.getsaturation", (args, qd) ->
  163. Fraction.fromDouble(ReflectionUtils.getSaturation(((EntityPlayer) args[0]).getFoodStats())));
  164. parser.registerConsumer("player.setsaturation", (args, qd) ->
  165. ReflectionUtils.setSaturation(((EntityPlayer) args[0]).getFoodStats(), ScriptUtils.getFloat(args[1])));
  166. parser.registerFunction("player.getname", (args, qd) ->
  167. getName(args));
  168. parser.registerFunction("player.getfullname", (args, qd) ->
  169. KajetansMod.chatManager.getFullName((EntityPlayer) args[0]));
  170. parser.registerFunction("player.getuuid", (args, qd) ->
  171. getUuid(args));
  172. parser.registerFunction("player.getip", (args, qd) ->
  173. ((EntityPlayerMP) args[0]).connection.netManager.getRemoteAddress().toString());
  174. parser.registerFunction("player.iscreative", (args, qd) ->
  175. ((EntityPlayer) args[0]).isCreative());
  176. parser.registerFunction("player.isspectator", (args, qd) ->
  177. ((EntityPlayer) args[0]).isSpectator());
  178. parser.registerFunction("player.issurvival", (args, qd) ->
  179. !((EntityPlayer) args[0]).isCreative() && !((EntityPlayer) args[0]).isSpectator());
  180. parser.registerFunction("player.isadventure", (args, qd) ->
  181. !((EntityPlayer) args[0]).capabilities.allowEdit);
  182. parser.registerFunction("player.hasfly", (args, qd) ->
  183. ((EntityPlayer) args[0]).capabilities.allowFlying);
  184. parser.registerFunction("player.getlastdamager", (args, qd) ->
  185. getLastDamager(args));
  186. parser.registerConsumer("player.settag", (args, qd) ->
  187. setTag(args));
  188. parser.registerFunction("player.gettag", (args, qd) ->
  189. getTag(args));
  190. parser.registerConsumer("player.dropinventory", (args, qd) ->
  191. dropInventory(args));
  192. parser.registerFunction("player.gettarget", (args, qd) ->
  193. new Location(((EntityPlayer) args[0]).world, Utils.getPlayerTarget((EntityPlayer) args[0], ScriptUtils.getInt(args[1]))));
  194. parser.registerFunction("player.gettargetentity", (args, qd) ->
  195. Utils.getTargetedEntity((EntityPlayer) args[0], ScriptUtils.getDouble(args[1]), getClass(args[2].toString())));
  196. parser.registerFunction("player.hasquest", (args, qd) ->
  197. KajetansMod.scripts.hasScript((EntityPlayer) args[0]));
  198. parser.registerConsumer("player.action", (args, qd) ->
  199. sendToActionBar(args, qd));
  200. parser.registerConsumer("player.kick", (args, qd) ->
  201. kickPlayerFromQuest(args, qd));
  202. parser.registerConsumer("player.playsound", (args, qd) ->
  203. playSoundPlayer(args));
  204. parser.registerFunction("player.getbedspawn", (args, qd) ->
  205. getBedLocation(args));
  206. parser.registerConsumer("player.setbedspawn", (args, qd) ->
  207. ((EntityPlayer) args[0]).bedLocation = ((Location) args[1]).getBlockPos());
  208. parser.registerConsumer("player.damageitem", (args, qd) ->
  209. ((EntityPlayer) args[0]).getHeldItemMainhand().damageItem(ScriptUtils.getInt(args[1]), (EntityPlayer) args[0]));
  210. // -------------------------------------------------------------
  211. // Players-Bibliothek
  212. // -------------------------------------------------------------
  213. parser.registerFunction("players.getamount", (args, qd) ->
  214. new Fraction(KajetansMod.server.getCurrentPlayerCount()));
  215. parser.registerConsumer("players.tolist", (args, qd) ->
  216. qd.setVar(args[0].toString(), new ArrayList(KajetansMod.server.getPlayerList().getPlayers())));
  217. parser.registerConsumer("players.toworldlist", (args, qd) ->
  218. qd.setVar(args[0].toString(), new ArrayList(ModDimensions.getWorldFromName(args[1].toString()).playerEntities)));
  219. parser.registerConsumer("players.near", (args, qd) ->
  220. nearPlayers(args, qd));
  221. // -------------------------------------------------------------
  222. // Rank-Bibliothek
  223. // -------------------------------------------------------------
  224. parser.registerConsumer("rank.get", (args, qd) ->
  225. qd.setVar(args[0].toString(), KajetansMod.chatManager.getRanks((EntityPlayer) args[1])));
  226. parser.registerConsumer("rank.register", (args, qd) ->
  227. KajetansMod.chatManager.registerRank(args[0].toString(), ScriptUtils.getInt(args[1]), args[2].toString()));
  228. parser.registerConsumer("rank.player", (args, qd) ->
  229. KajetansMod.chatManager.registerPlayerRank(UUID.fromString(args[0].toString()), args[1].toString()));
  230. parser.registerConsumer("rank.clear", (args, qd) ->
  231. KajetansMod.chatManager.clearRanks());
  232. // -------------------------------------------------------------
  233. // Custom-Bibliothek
  234. // -------------------------------------------------------------
  235. /*parser.registerConsumer("custom.registershapelessrecipe", (args, qd) ->
  236. registerShapelessRecipe(args));
  237. parser.registerConsumer("custom.registershapedrecipe", (args, qd) ->
  238. registerShapedRecipe(args));
  239. parser.registerConsumer("custom.registerfurnacerecipe", (args, qd) ->
  240. RecipeUtils.registerFurnaceRecipe((ItemStack) args[0], (ItemStack) args[1]));
  241. parser.registerConsumer("custom.clearrecipes", (args, qd) ->
  242. RecipeUtils.clearRecipes());*/
  243. // -------------------------------------------------------------
  244. // World-Bibliothek
  245. // -------------------------------------------------------------
  246. parser.registerAlias("world.getplayers", "players.toworldlist");
  247. parser.registerConsumer("world.setskills", (args, qd) ->
  248. KajetansMod.worldManager.getWorldPreferences(ModDimensions.getWorldFromName(args[0].toString())).skills = (boolean) args[1]);
  249. parser.registerConsumer("world.setblockprotections", (args, qd) ->
  250. KajetansMod.worldManager.getWorldPreferences(ModDimensions.getWorldFromName(args[0].toString())).blockProtection = (boolean) args[1]);
  251. parser.registerConsumer("world.setdefaultenchanting", (args, qd) ->
  252. KajetansMod.worldManager.getWorldPreferences(ModDimensions.getWorldFromName(args[0].toString())).defaultEnchanting = (boolean) args[1]);
  253. parser.registerConsumer("world.setpvpprotection", (args, qd) ->
  254. KajetansMod.worldManager.getWorldPreferences(ModDimensions.getWorldFromName(args[0].toString())).pvpProtection = (boolean) args[1]);
  255. parser.registerConsumer("world.setstatuseffects", (args, qd) ->
  256. KajetansMod.worldManager.getWorldPreferences(ModDimensions.getWorldFromName(args[0].toString())).statusEffects = (boolean) args[1]);
  257. parser.registerConsumer("world.setmanabar", (args, qd) ->
  258. KajetansMod.worldManager.getWorldPreferences(ModDimensions.getWorldFromName(args[0].toString())).manabar = (boolean) args[1]);
  259. parser.registerConsumer("world.setscrolls", (args, qd) ->
  260. KajetansMod.worldManager.getWorldPreferences(ModDimensions.getWorldFromName(args[0].toString())).scrolls = (boolean) args[1]);
  261. parser.registerConsumer("world.setdefaultproducing", (args, qd) ->
  262. KajetansMod.worldManager.getWorldPreferences(ModDimensions.getWorldFromName(args[0].toString())).defaultProducing = (boolean) args[1]);
  263. // -------------------------------------------------------------
  264. // Item-Bibliothek
  265. // -------------------------------------------------------------
  266. parser.registerConsumer("item.drop", (args, qd) ->
  267. dropItem(args));
  268. parser.registerFunction("item.gettype", (args, qd) ->
  269. ((ItemStack) args[0]).getItem().getRegistryName().toString());
  270. parser.registerFunction("item.getdata", (args, qd) ->
  271. new Fraction(((ItemStack) args[0]).getMetadata()));
  272. parser.registerConsumer("item.setdata", (args, qd) ->
  273. ((ItemStack) args[0]).setItemDamage(ScriptUtils.getInt(args[1])));
  274. parser.registerFunction("item.getamount", (args, qd) ->
  275. new Fraction(((ItemStack) args[0]).getCount()));
  276. parser.registerConsumer("item.setamount", (args, qd) ->
  277. ((ItemStack) args[0]).setCount(ScriptUtils.getInt(args[1])));
  278. parser.registerFunction("item.getname", (args, qd) ->
  279. ((ItemStack) args[0]).getDisplayName());
  280. parser.registerConsumer("item.setname", (args, qd) ->
  281. ((ItemStack) args[0]).setStackDisplayName(ScriptUtils.connect(args, 1)));
  282. parser.registerConsumer("item.getlore", (args, qd) ->
  283. qd.setVar(args[0].toString(), ItemStackUtils.getLore((ItemStack) args[1])));
  284. parser.registerConsumer("item.setlore", (args, qd) ->
  285. ItemStackUtils.setLore((ItemStack) args[0], (List<String>) args[1]));
  286. parser.registerConsumer("item.addlore", (args, qd) ->
  287. ItemStackUtils.addLore((ItemStack) args[0], ScriptUtils.connect(args, 2), ScriptUtils.getInt(args[1])));
  288. parser.registerFunction("item.getenchantlevel", (args, qd) ->
  289. new Fraction(EnchantmentHelper.getEnchantmentLevel(Enchantment.getEnchantmentByLocation(args[1].toString()), (ItemStack) args[0])));
  290. parser.registerConsumer("item.setcooldown", (args, qd) ->
  291. ((EntityPlayer) args[0]).getCooldownTracker().setCooldown(((ItemStack) args[1]).getItem(), ScriptUtils.getInt(args[2])));
  292. parser.registerFunction("item.gettooltype", (args, qd) ->
  293. Utils.getToolType((ItemStack) args[0]));
  294. // -------------------------------------------------------------
  295. // Location-Bibliothek
  296. // -------------------------------------------------------------
  297. parser.registerFunction("loc.distance", (args, qd) ->
  298. Fraction.fromDouble(((Location) args[0]).getPos().distanceTo(((Location) args[1]).getPos())));
  299. parser.registerConsumer("loc.setyaw", (args, qd) ->
  300. ((Location) args[0]).setYaw(ScriptUtils.getFloat(args[1])));
  301. parser.registerConsumer("loc.setpitch", (args, qd) ->
  302. ((Location) args[0]).setPitch(ScriptUtils.getFloat(args[1])));
  303. parser.registerFunction("loc.mod", (args, qd) ->
  304. ((Location) args[0]).copyAdd(ScriptUtils.getDouble(args[1]), ScriptUtils.getDouble(args[2]), ScriptUtils.getDouble(args[3])));
  305. parser.registerFunction("loc.getcoord", (args, qd) ->
  306. getCoordOfLocation(args));
  307. parser.registerFunction("loc.gettime", (args, qd) ->
  308. new Fraction(((Location) args[0]).getWorld().getWorldTime()));
  309. parser.registerFunction("loc.hasstorm", (args, qd) ->
  310. ((Location) args[0]).getWorld().isRaining());
  311. parser.registerFunction("loc.isbetween", (args, qd) ->
  312. isBetween(args));
  313. // -------------------------------------------------------------
  314. // Block-Bibliothek
  315. // -------------------------------------------------------------
  316. parser.registerFunction("block.gettype", (args, qd) ->
  317. ((Location) args[0]).getWorld().getBlockState(((Location) args[0]).getBlockPos()).getBlock().getRegistryName().toString());
  318. parser.registerFunction("block.getdata", (args, qd) ->
  319. getBlockData((Location) args[0]));
  320. parser.registerConsumer("block.clone", (args, qd) ->
  321. cloneBlock(args));
  322. parser.registerConsumer("block.set", (args, qd) ->
  323. setBlock(args, qd));
  324. parser.registerConsumer("block.set2", (args, qd) ->
  325. setBlockWithData(args, qd));
  326. parser.registerConsumer("block.setsign", (args, qd) ->
  327. setSign(args));
  328. parser.registerFunction("block.getsign", (args, qd) ->
  329. getSign(args));
  330. parser.registerConsumer("block.setdoorstatus", (args, qd) ->
  331. setDoorStatus(args));
  332. parser.registerFunction("block.getdoorstatus", (args, qd) ->
  333. getDoorStatus(args));
  334. parser.registerFunction("block.isdoor", (args, qd) ->
  335. isDoor(args));
  336. parser.registerFunction("block.issolid", (args, qd) ->
  337. isSolid(args));
  338. parser.registerFunction("block.tostack", (args, qd) ->
  339. getStackFromBlock((Location) args[0]));
  340. parser.registerFunction("block.getitemamount", (args, qd) ->
  341. getItemAmountChest(args));
  342. parser.registerFunction("block.additem", (args, qd) ->
  343. addItemAmountChest(args));
  344. parser.registerFunction("block.subitem", (args, qd) ->
  345. removeItemAmountChest(args));
  346. // -------------------------------------------------------------
  347. // Event-Bibliothek
  348. // -------------------------------------------------------------
  349. parser.registerConsumer("event.addloc", (args, qd) ->
  350. ((MinecraftScript) qd).addLocation((Location) args[0]));
  351. parser.registerConsumer("event.removeloc", (args, qd) ->
  352. ((MinecraftScript) qd).removeLocation((Location) args[0]));
  353. parser.registerConsumer("event.clearlocs", (args, qd) ->
  354. ((MinecraftScript) qd).clearLocations());
  355. // -------------------------------------------------------------
  356. // Skill-Bibliothek
  357. // -------------------------------------------------------------
  358. parser.registerConsumer("skill.register", (args, qd) ->
  359. registerSkill(args));
  360. parser.registerConsumer("skill.clear", (args, qd) ->
  361. KajetansMod.skills.clearSkills());
  362. parser.registerConsumer("skill.getactive", (args, qd) ->
  363. qd.setVar(args[0].toString(), KajetansMod.jobs.getActiveSkills((EntityPlayer) args[1])));
  364. parser.registerFunction("skill.getid", (args, qd) ->
  365. ((LeveledSkill) args[0]).getId());
  366. parser.registerFunction("skill.fromid", (args, qd) ->
  367. getSkillFromId(args));
  368. parser.registerFunction("skill.getstack", (args, qd) ->
  369. ((LeveledSkill) args[0]).getItemStack());
  370. parser.registerFunction("skill.use", (args, qd) ->
  371. ((LeveledSkill) args[0]).useEffect((EntityPlayerMP) args[1]));
  372. // -------------------------------------------------------------
  373. // Job-Bibliothek
  374. // -------------------------------------------------------------
  375. parser.registerFunction("job.getlevel", (args, qd) ->
  376. new Fraction(KajetansMod.jobs.getLevel((EntityPlayer) args[0], ScriptUtils.getByte(args[1]))));
  377. parser.registerConsumer("job.addlevel", (args, qd) ->
  378. KajetansMod.jobs.addLevel((EntityPlayer) args[0], ScriptUtils.getByte(args[1]), ScriptUtils.getByte(args[2])));
  379. parser.registerConsumer("job.setlevel", (args, qd) ->
  380. KajetansMod.jobs.setLevel((EntityPlayer) args[0], ScriptUtils.getByte(args[1]), ScriptUtils.getByte(args[2])));
  381. parser.registerFunction("job.getxp", (args, qd) ->
  382. new Fraction(KajetansMod.jobs.getXP((EntityPlayer) args[0], ScriptUtils.getByte(args[1]))));
  383. parser.registerConsumer("job.addxp", (args, qd) ->
  384. KajetansMod.jobs.addXP((EntityPlayer) args[0], ScriptUtils.getByte(args[1]), ScriptUtils.getByte(args[2])));
  385. parser.registerConsumer("job.setxp", (args, qd) ->
  386. KajetansMod.jobs.setXP((EntityPlayer) args[0], ScriptUtils.getByte(args[1]), ScriptUtils.getByte(args[2])));
  387. parser.registerConsumer("job.registerjob", (args, qd) ->
  388. KajetansMod.jobs.registerJob(ScriptUtils.getByte(args[0]), ScriptUtils.connect(args, 1)));
  389. parser.registerConsumer("job.registerrecipe", (args, qd) ->
  390. KajetansMod.jobs.registerRecipe(ScriptUtils.getByte(args[0]), ScriptHelper.getItem(args[1].toString()), ScriptUtils.getByte(args[2])));
  391. parser.registerConsumer("job.registermaterial", (args, qd) ->
  392. KajetansMod.jobs.registerPreferedBlock(ScriptUtils.getByte(args[0]), Block.getBlockFromName(args[1].toString())));
  393. parser.registerConsumer("job.registerskill", (args, qd) ->
  394. KajetansMod.jobs.registerSkill(ScriptUtils.getByte(args[0]), KajetansMod.skills.getSkill(ScriptUtils.getInt(args[1])), ScriptUtils.getByte(args[2]), ScriptUtils.getByte(args[3])));
  395. parser.registerFunction("job.getamount", (args, qd) ->
  396. new Fraction(KajetansMod.jobs.getNumberOfJobs()));
  397. parser.registerFunction("job.getname", (args, qd) ->
  398. KajetansMod.jobs.getJobName(ScriptUtils.getByte(args[0])));
  399. parser.registerFunction("job.geteffectlevel", (args, qd) ->
  400. new Fraction(EffectUtils.getEffectLevel((EntityPlayer) args[0], me.km.effects.Effect.valueOf(args[1].toString()))));
  401. parser.registerFunction("job.hasjob", (args, qd) ->
  402. KajetansMod.jobs.hasJob((EntityPlayer) args[0], ScriptUtils.getByte(args[1])));
  403. parser.registerFunction("job.hasrecipe", (args, qd) ->
  404. KajetansMod.jobs.hasRecipe((EntityPlayer) args[0], ScriptHelper.getItem(args[1].toString())));
  405. parser.registerConsumer("job.getjobs", (args, qd) ->
  406. qd.setVar(args[0].toString(), KajetansMod.jobs.getJobs((EntityPlayer) args[1]).stream().map(b -> new Fraction(b)).collect(Collectors.toList())));
  407. parser.registerFunction("job.isregmaterial", (args, qd) ->
  408. KajetansMod.jobs.isPreferedMaterial((EntityPlayer) args[0],Block.getBlockFromName(args[1].toString())));
  409. parser.registerConsumer("job.setjob", (args, qd) ->
  410. KajetansMod.jobs.setJob((EntityPlayer) args[0], ScriptUtils.getByte(args[1]), (boolean) args[2]));
  411. parser.registerConsumer("job.reset", (args, qd) ->
  412. KajetansMod.jobs.resetAll());
  413. // -------------------------------------------------------------
  414. // Entity - Befehle
  415. // -------------------------------------------------------------
  416. parser.registerFunction("entity.getlocation", (args, qd) ->
  417. new Location(((Entity) args[0])));
  418. parser.registerConsumer("entity.damage", (args, qd) ->
  419. damageEntity(args));
  420. parser.registerConsumer("entity.getdamagesource", (args, qd) ->
  421. getDamageSource(args));
  422. parser.registerFunction("entity.gethealth", (args, qd) ->
  423. Fraction.fromDouble(((EntityLivingBase) args[0]).getHealth()));
  424. parser.registerConsumer("entity.sethealth", (args, qd) ->
  425. ((EntityLivingBase) args[0]).setHealth(ScriptUtils.getFloat(args[1])));
  426. parser.registerConsumer("entity.setname", (args, qd) ->
  427. nameEntity(args));
  428. parser.registerFunction("entity.getname", (args, qd) ->
  429. ((Entity) args[0]).getDisplayName().getUnformattedText());
  430. parser.registerConsumer("entity.throw", (args, qd) ->
  431. Utils.setVelocity((Entity) args[0], ScriptUtils.getDouble(args[1]), ScriptUtils.getDouble(args[2]), ScriptUtils.getDouble(args[3])));
  432. parser.registerConsumer("entity.teleport", (args, qd) ->
  433. Utils.teleportEntity((Entity) args[0], (Location) args[1]));
  434. parser.registerConsumer("entity.setequip", (args, qd) ->
  435. setEntityEquip(args));
  436. parser.registerFunction("entity.getequip", (args, qd) ->
  437. getEntityEquip(args));
  438. parser.registerConsumer("entity.removeall", (args, qd) ->
  439. removeEntities(args));
  440. parser.registerConsumer("entity.remove", (args, qd) ->
  441. ((Entity) args[0]).setDead());
  442. parser.registerConsumer("entity.setinvulnerable", (args, qd) ->
  443. ((Entity) args[0]).setEntityInvulnerable((boolean) args[1]));
  444. parser.registerConsumer("entity.setsilent", (args, qd) ->
  445. ((Entity) args[0]).setSilent((boolean) args[1]));
  446. parser.registerConsumer("entity.hide", (args, qd) ->
  447. ((Entity) args[0]).setInvisible(true));
  448. parser.registerConsumer("entity.show", (args, qd) ->
  449. ((Entity) args[0]).setInvisible(false));
  450. parser.registerConsumer("entity.ride", (args, qd) ->
  451. ((Entity) args[0]).startRiding(((Entity) args[1])));
  452. parser.registerConsumer("entity.addeffect", (args, qd) ->
  453. addEffect(args));
  454. parser.registerFunction("entity.haseffect", (args, qd) ->
  455. ((EntityLivingBase) args[0]).isPotionActive(Potion.getPotionFromResourceLocation(args[1].toString())));
  456. parser.registerConsumer("entity.goto", (args, qd) ->
  457. walkTo(args));
  458. parser.registerConsumer("entity.explode", (args, qd) ->
  459. ((EntityCreeper) args[0]).ignite());
  460. parser.registerConsumer("entity.spawnitemframe", (args, qd) ->
  461. spawnItemFrame(args));
  462. parser.registerFunction("entity.getitemframe", (args, qd) ->
  463. ((EntityItemFrame) args[0]).getDisplayedItem());
  464. parser.registerFunction("entity.get", (args, qd) ->
  465. getEntity(args));
  466. parser.registerFunction("entity.getpotiontype", (args, qd) ->
  467. getPotionType(args));
  468. parser.registerConsumer("entity.setgravity", (args, qd) ->
  469. ((Entity) args[0]).setNoGravity(!(boolean) args[1]));
  470. parser.registerConsumer("entity.iswet", (args, qd) ->
  471. ((Entity) args[0]).isWet());
  472. parser.registerConsumer("entity.setpickupdelay", (args, qd) ->
  473. ((EntityItem) args[0]).setPickupDelay(ScriptUtils.getInt(args[1])));
  474. parser.registerConsumer("entity.setage", (args, qd) ->
  475. ReflectionUtils.setAge((EntityItem) args[0], ScriptUtils.getInt(args[1])));
  476. // -------------------------------------------------------------
  477. // Status-Bibliothek
  478. // -------------------------------------------------------------
  479. parser.registerFunction("status.getmana", (args, qd) ->
  480. new Fraction(EnvironmentAPI.getMana(((EntityPlayer) args[0]))));
  481. parser.registerFunction("status.getcold", (args, qd) ->
  482. new Fraction(EnvironmentAPI.getCold(((EntityPlayer) args[0]))));
  483. parser.registerFunction("status.getenergy", (args, qd) ->
  484. new Fraction(EnvironmentAPI.getEnergy(((EntityPlayer) args[0]))));
  485. parser.registerFunction("status.getthirst", (args, qd) ->
  486. new Fraction(EnvironmentAPI.getThirst(((EntityPlayer) args[0]))));
  487. parser.registerConsumer("status.changemange", (args, qd) ->
  488. EnvironmentAPI.changeMana(((EntityPlayer) args[0]), ScriptUtils.getInt(args[1])));
  489. parser.registerConsumer("status.changecold", (args, qd) ->
  490. EnvironmentAPI.changeCold(((EntityPlayer) args[0]), ScriptUtils.getInt(args[1])));
  491. parser.registerConsumer("status.changeenergie", (args, qd) ->
  492. EnvironmentAPI.changeEnergy(((EntityPlayer) args[0]), ScriptUtils.getInt(args[1])));
  493. parser.registerConsumer("status.changethirst", (args, qd) ->
  494. EnvironmentAPI.changeThirst(((EntityPlayer) args[0]), ScriptUtils.getInt(args[1])));
  495. parser.registerConsumer("status.resetmana", (args, qd) ->
  496. EnvironmentAPI.resetMana(((EntityPlayer) args[0])));
  497. parser.registerConsumer("status.resetcold", (args, qd) ->
  498. EnvironmentAPI.resetCold(((EntityPlayer) args[0])));
  499. parser.registerConsumer("status.resetenergy", (args, qd) ->
  500. EnvironmentAPI.resetEnergy(((EntityPlayer) args[0])));
  501. parser.registerConsumer("status.resetthirst", (args, qd) ->
  502. EnvironmentAPI.resetThirst(((EntityPlayer) args[0])));
  503. parser.registerFunction("status.gettemperature", (args, qd) ->
  504. new Fraction(EnvironmentAPI.getTemperature(((Location) args[0]).getWorld(), ((Location) args[0]).getBlockPos())));
  505. // -------------------------------------------------------------
  506. // GMap-Bibliothek
  507. // -------------------------------------------------------------
  508. parser.registerConsumer("gmap.removeall", (args, qd) ->
  509. KajetansMod.scripts.getDataBank(ScriptBank.class).removeMap(args[0].toString()));
  510. parser.registerConsumer("gmap.add", (args, qd) ->
  511. KajetansMod.scripts.getDataBank(ScriptBank.class).addMapElement(args[0].toString(), args[1].toString(), args[2].toString()));
  512. parser.registerConsumer("gmap.remove", (args, qd) ->
  513. KajetansMod.scripts.getDataBank(ScriptBank.class).removeMapElement(args[0].toString(), args[1].toString()));
  514. parser.registerConsumer("gmap.totable", (args, qd) ->
  515. qd.setVar(args[0].toString(), KajetansMod.scripts.getDataBank(ScriptBank.class).getGlobalMapAsTable(args[1].toString())));
  516. parser.registerFunction("gmap.get", (args, qd) ->
  517. KajetansMod.scripts.getDataBank(ScriptBank.class).getMapValue(args[0].toString(), args[1].toString()));
  518. // -------------------------------------------------------------
  519. // GDMap-Bibliothek
  520. // -------------------------------------------------------------
  521. parser.registerConsumer("gdmap.removeall", (args, qd) ->
  522. KajetansMod.scripts.getDataBank(ScriptBank.class).removeDualMap(args[0].toString()));
  523. parser.registerConsumer("gdmap.add", (args, qd) ->
  524. KajetansMod.scripts.getDataBank(ScriptBank.class).addDualMapElement(args[0].toString(), args[1].toString(), args[2].toString(), args[3].toString()));
  525. parser.registerConsumer("gdmap.remove", (args, qd) ->
  526. KajetansMod.scripts.getDataBank(ScriptBank.class).removeDualMapElement(args[0].toString(), args[1].toString(), args[2].toString()));
  527. parser.registerConsumer("gdmap.totable", (args, qd) ->
  528. qd.setVar(args[0].toString(), KajetansMod.scripts.getDataBank(ScriptBank.class).getGlobalDualMapAsTable(args[1].toString(), args[2].toString())));
  529. parser.registerFunction("gdmap.get", (args, qd) ->
  530. KajetansMod.scripts.getDataBank(ScriptBank.class).getDualMapValue(args[0].toString(), args[1].toString(), args[2].toString()));
  531. // -------------------------------------------------------------
  532. // Table-Bibliothek
  533. // -------------------------------------------------------------
  534. parser.registerConsumer("table.print", (args, qd) ->
  535. printTable(args, qd));
  536. parser.registerConsumer("table.new", (args, qd) ->
  537. qd.setVar(args[0].toString(), new Table(ScriptUtils.getInt(args[1]))));
  538. parser.registerConsumer("table.frommap", (args, qd) ->
  539. qd.setVar(args[0].toString(), new Table((Map<Object, Object>) args[1])));
  540. parser.registerConsumer("table.sort", (args, qd) ->
  541. ((Table) args[0]).sort());
  542. parser.registerConsumer("table.reverse", (args, qd) ->
  543. ((Table) args[0]).reverse());
  544. parser.registerConsumer("table.shuffle", (args, qd) ->
  545. ((Table) args[0]).shuffle());
  546. parser.registerConsumer("table.clear", (args, qd) ->
  547. ((Table) args[0]).clear());
  548. parser.registerConsumer("table.addrow", (args, qd) ->
  549. ((Table) args[0]).addRow(Arrays.copyOfRange(args, 1, args.length)));
  550. parser.registerConsumer("table.removerow", (args, qd) ->
  551. ((Table) args[0]).removeRow(ScriptUtils.getInt(args[1])));
  552. parser.registerFunction("table.get", (args, qd) ->
  553. ((Table) args[0]).getElement(ScriptUtils.getInt(args[1]), ScriptUtils.getInt(args[2])));
  554. parser.registerFunction("table.getindexof", (args, qd) ->
  555. new Fraction(((Table) args[0]).getIndexOf(args[1])));
  556. parser.registerConsumer("table.setsortcolumn", (args, qd) ->
  557. ((Table) args[0]).setSortColumn(ScriptUtils.getInt(args[1])));
  558. parser.registerFunction("table.getsize", (args, qd) ->
  559. new Fraction(((Table) args[0]).getSize()));
  560. // -------------------------------------------------------------
  561. // Plot-Bibliothek
  562. // -------------------------------------------------------------
  563. parser.registerFunction("plot.hastag", (args, qd) ->
  564. KajetansMod.plots.getDataBank(ProtectionBank.class).hasTag(((Location) args[0]).getWorld(), ((Location) args[0]).getBlockPos(), args[1].toString()));
  565. parser.registerConsumer("plot.add", (args, qd) ->
  566. addPlot(args));
  567. parser.registerConsumer("plot.getids", (args, qd) ->
  568. qd.setVar(args[0].toString(), getPlotIds(args)));
  569. parser.registerFunction("plot.canbuild", (args, qd) ->
  570. KajetansMod.plots.getDataBank(ProtectionBank.class).canBuild(((Location) args[0]).getWorld(), ((Location) args[0]).getBlockPos(), (EntityPlayer) args[1]));
  571. parser.registerFunction("plot.getname", (args, qd) ->
  572. KajetansMod.plots.getDataBank(ProtectionBank.class).getFirstRegionName(((Location) args[0]).getWorld(), ((Location) args[0]).getBlockPos()));
  573. parser.registerFunction("plot.doesintersect", (args, qd) ->
  574. doesIntersect(args));
  575. // -------------------------------------------------------------
  576. // Quest-Bibliothek
  577. // -------------------------------------------------------------
  578. parser.registerConsumer("quest.end", (args, qd) ->
  579. endPlayerScript(args, qd));
  580. parser.registerConsumer("quest.playerstolist", (args, qd) ->
  581. qd.setVar(args[0].toString(), new ArrayList<>(((PlayerScript) qd).getPlayers())));
  582. parser.registerFunction("quest.getplayeramount", (args, qd) ->
  583. new Fraction(((PlayerScript) qd).getPlayers().size()));
  584. parser.registerConsumer("quest.start", (args, qd) ->
  585. startPlayerScript(args, qd));
  586. parser.registerFunction("quest.isactive", (args, qd) ->
  587. KajetansMod.scripts.isActive(args[0].toString()));
  588. parser.registerFunction("quest.getleader", (args, qd) ->
  589. getPlayerScriptLeader(qd));
  590. // -------------------------------------------------------------
  591. // Scoreboard-Bibliothek
  592. // -------------------------------------------------------------
  593. parser.registerConsumer("sb.add", (args, qd) ->
  594. addToScoreBoard(args, qd));
  595. parser.registerConsumer("sb.remove", (args, qd) ->
  596. removeFromScoreBoard(args, qd));
  597. parser.registerConsumer("sb.reset", (args, qd) ->
  598. doForGroup(args[0], qd, p -> KajetansMod.scoreboard.resetScoreboard((EntityPlayerMP) p)));
  599. // -------------------------------------------------------------
  600. // Display-Bibliothek
  601. // -------------------------------------------------------------
  602. parser.registerConsumer("display.add", (args, qd) ->
  603. addToDisplay(args, qd));
  604. parser.registerConsumer("display.remove", (args, qd) ->
  605. removeFromDisplay(args, qd));
  606. parser.registerConsumer("display.reset", (args, qd) ->
  607. doForGroup(args[0], qd, p -> ModPacketHandler.sendStats((EntityPlayerMP) p, (byte) 3, (byte) -1, "")));
  608. // -------------------------------------------------------------
  609. // Effect-Bibliothek
  610. // -------------------------------------------------------------
  611. parser.registerConsumer("effect.playsound", (args, qd) ->
  612. playSound(args));
  613. parser.registerConsumer("effect.play", (args, qd) ->
  614. playParticle(args));
  615. // -------------------------------------------------------------
  616. // Inventory-Bibliothek
  617. // -------------------------------------------------------------
  618. parser.registerConsumer("inv.new", (args, qd) ->
  619. qd.setVar(args[0].toString(), new SnuviInventory(args[2].toString(), ScriptUtils.getInt(args[1]), ((MinecraftScript) qd).getNewId())));
  620. parser.registerConsumer("inv.newdynamic", (args, qd) ->
  621. qd.setVar(args[0].toString(), new SnuviInventory(args[2].toString(), args[1].toString(), ((MinecraftScript) qd).getNewId())));
  622. parser.registerConsumer("inv.loadblock", (args, qd) ->
  623. qd.setVar(args[0].toString(), newInventory((Location) args[1], (MinecraftScript) qd, args[2].toString())));
  624. parser.registerConsumer("inv.setitem", (args, qd) ->
  625. ((IInventory) args[0]).setInventorySlotContents(ScriptUtils.getInt(args[1]), (ItemStack) args[2]));
  626. parser.registerFunction("inv.getitem", (args, qd) ->
  627. ((IInventory) args[0]).getStackInSlot(ScriptUtils.getInt(args[1])));
  628. parser.registerConsumer("inv.open", (args, qd) ->
  629. new ScriptInventoryHolder((SnuviInventory) args[0], (EntityPlayerMP) args[1], (MinecraftScript) qd).openForPlayer());
  630. parser.registerConsumer("inv.close", (args, qd) ->
  631. invClose(args));
  632. // -------------------------------------------------------------
  633. // Read-Bibliothek
  634. // -------------------------------------------------------------
  635. parser.registerFunction("read.player", (args, qd) ->
  636. Utils.getPlayerByName(args[0].toString()));
  637. parser.registerFunction("read.location", (args, qd) ->
  638. new Location(qd, args[0].toString()));
  639. parser.registerFunction("read.item", (args, qd) ->
  640. ScriptHelper.getItemStack(args, 0));
  641. parser.registerFunction("read.spawnmob", (args, qd) ->
  642. NBTUtils.fromString(qd, ScriptUtils.connect(args," ", 1).replace("'", "\""), (Location) args[0]));
  643. // -------------------------------------------------------------
  644. // Text-Bibliothek
  645. // -------------------------------------------------------------
  646. parser.registerFunction("text.location", (args, qd) ->
  647. ((Location) args[0]).toString());
  648. parser.registerFunction("text.locationblock", (args, qd) ->
  649. ((Location) args[0]).toBlockString());
  650. parser.registerFunction("text.item", (args, qd) ->
  651. ScriptHelper.getItemStackString((ItemStack) args[0]));
  652. parser.registerFunction("text.click", (args, qd) ->
  653. NBTUtils.getClickable(args[0], args[1].toString()));
  654. parser.registerFunction("text.hover", (args, qd) ->
  655. NBTUtils.getHoverable(args[0], args[1].toString()));
  656. // -------------------------------------------------------------
  657. // Ohne Bibliothek
  658. // -------------------------------------------------------------
  659. parser.registerConsumer("overload", (args, qd) ->
  660. qd.overload(ScriptUtils.readCode("scripts/" + args[0].toString(), ".txt")));
  661. parser.registerFunction("getglobalvar", (args, qd) ->
  662. getGlobalVar(args));
  663. parser.registerAlias("ggv", "getglobalvar");
  664. parser.registerConsumer("setglobalvar", (args, qd) ->
  665. setGlobalVar(args));
  666. parser.registerAlias("sgv", "setglobalvar");
  667. parser.registerConsumer("msg", (args, qd) ->
  668. sendMessageToGroup(args[0], qd, NBTUtils.concat(1, args)));
  669. parser.registerFunction("removeformat", (args, qd) ->
  670. ScriptUtils.connect(args, 0).replaceAll("§.", ""));
  671. parser.registerFunction("concatspace", (args, qd) ->
  672. ScriptUtils.connect(args, " ", 0));
  673. parser.registerFunction("onlyletters", (args, qd) ->
  674. onlyLetters(ScriptUtils.connect(args, 0)));
  675. parser.registerConsumer("command", (args, qd) ->
  676. KajetansMod.server.commandManager.executeCommand(KajetansMod.server, ScriptUtils.connect(args, 0)));
  677. }
  678. @Override
  679. public void printException(Exception ex, String function, String s, int line)
  680. {
  681. if(KajetansMod.debugMode || KajetansMod.scripts.getSnuviParser().printStack)
  682. {
  683. Module m = KajetansMod.scripts;
  684. m.sendWarningToConsole("Error in '" + s + "'");
  685. if(line != -1)
  686. {
  687. m.sendWarningToConsole("Zeile: " + line);
  688. }
  689. m.sendWarningToConsole("Fehler: " + ex.getClass().getSimpleName() + " - " + ex.getLocalizedMessage());
  690. if(function != null)
  691. {
  692. m.sendWarningToConsole("Funktion: " + function);
  693. }
  694. }
  695. sendToDevsWithSuffix("§cError in '" + s + "'");
  696. if(line != -1)
  697. {
  698. sendToDevsWithHelpList("§cZeile:", String.valueOf(line));
  699. }
  700. sendToDevsWithHelpList("§cFehler:", ex.getClass().getSimpleName() + " - " + ex.getLocalizedMessage());
  701. if(function != null)
  702. {
  703. sendToDevsWithHelpList("§cFunktion: ", function);
  704. }
  705. }
  706. @Override
  707. public void printException(Exception ex, String function, Script sc, int line)
  708. {
  709. printException(ex, function, sc == null ? "null" : sc.getName(), line);
  710. }
  711. @Override
  712. public void printInfo(String s)
  713. {
  714. sendToDevsWithSuffix(s);
  715. }
  716. @Override
  717. public void printWarning(String s)
  718. {
  719. sendWarningToAllDevs(s);
  720. }
  721. private static void printTable(Object[] args, Script sc)
  722. {
  723. Table t = (Table) args[1];
  724. if(t.getSize() >= 60)
  725. {
  726. throw new IllegalArgumentException("table is too big");
  727. }
  728. TableAPI.getTable(t, ScriptUtils.getInt(args[2]), args[3].toString(),
  729. args.length >= 5 ? (boolean) args[4] : false)
  730. .forEach(s -> sendMessageToGroup(args[0], sc, new TextComponentString(s)));
  731. }
  732. private static Location getBedLocation(Object[] args)
  733. {
  734. WorldServer ws = ModDimensions.getWorldFromName(args[1].toString());
  735. return new Location(ws, ((EntityPlayer) args[0]).getBedLocation(ws.provider.getDimension()));
  736. }
  737. private static boolean isDoor(Object[] args)
  738. {
  739. Location l = (Location) args[0];
  740. return l.getWorld().getBlockState(l.getBlockPos()).getBlock() instanceof BlockDoor;
  741. }
  742. private static boolean getDoorStatus(Object[] args)
  743. {
  744. Location l = (Location) args[0];
  745. return BlockDoor.isOpen(l.getWorld(), l.getBlockPos());
  746. }
  747. private static void setDoorStatus(Object[] args)
  748. {
  749. Location l = (Location) args[0];
  750. BlockPos pos = l.getBlockPos();
  751. ((BlockDoor) l.getWorld().getBlockState(pos).getBlock()).toggleDoor(l.getWorld(), pos, (boolean) args[1]);
  752. }
  753. private static void registerSkill(Object[] args)
  754. {
  755. KajetansMod.skills.registerSkill(ScriptUtils.getInt(args[0]),
  756. (ItemStack) args[1], Effect.valueOf(args[2].toString()),
  757. args[3].toString(), args[4].toString(),
  758. ScriptUtils.getInt(args[5]), ScriptUtils.getInt(args[6]),
  759. ScriptUtils.getInt(args[7]), ScriptUtils.getInt(args[8]));
  760. }
  761. private static LeveledSkill getSkillFromId(Object[] args)
  762. {
  763. Skill skill = KajetansMod.skills.getSkill(ScriptUtils.getInt(args[0]));
  764. if(skill == null)
  765. {
  766. return null;
  767. }
  768. byte level = (byte) EffectUtils.getEffectLevel((EntityPlayer) args[1], skill.getEffect());
  769. if(level <= 0)
  770. {
  771. return null;
  772. }
  773. return new LeveledSkill(skill, level);
  774. }
  775. private static void walkTo(Object[] args)
  776. {
  777. Location l = (Location) args[1];
  778. PathfinderUtils.walkTo((EntityLiving) args[0], l.getX(), l.getY(), l.getZ(), ScriptUtils.getDouble(args[2]));
  779. }
  780. private static void playerSay(Object[] args)
  781. {
  782. try
  783. {
  784. ((EntityPlayerMP) args[0]).connection.processChatMessage(new CPacketChatMessage(ScriptUtils.connect(args, 1)));
  785. }
  786. catch(ThreadQuickExitException ex)
  787. {
  788. // Minecraft needs this for canceling and queueing into main thread
  789. }
  790. }
  791. private static void respawnPlayer(Script sc, Object[] args)
  792. {
  793. KajetansMod.scheduler.scheduleTask(() ->
  794. {
  795. try
  796. {
  797. ((EntityPlayerMP) args[0]).connection.processClientStatus(new CPacketClientStatus(CPacketClientStatus.State.PERFORM_RESPAWN));
  798. }
  799. catch(ThreadQuickExitException ex)
  800. {
  801. // Minecraft needs this for canceling and queueing into main thread
  802. }
  803. });
  804. }
  805. private static Class getClass(String s)
  806. {
  807. try
  808. {
  809. return Class.forName(s);
  810. }
  811. catch(ClassNotFoundException ex)
  812. {
  813. throw new IllegalStringException(s);
  814. }
  815. }
  816. private static Fraction getItemAmountChest(Object[] args) throws IllegalStringLocationException, IllegalItemStackStringException
  817. {
  818. Location l = (Location) args[0];
  819. TileEntity te = l.getWorld().getTileEntity(l.getBlockPos());
  820. if(te == null || !(te instanceof TileEntityChest))
  821. {
  822. return new Fraction(0);
  823. }
  824. return new Fraction(InventoryUtils.searchInventoryFor(((TileEntityChest) te), (ItemStack) args[2], (boolean) args[1]));
  825. }
  826. private static ItemStack addItemAmountChest(Object[] args) throws IllegalStringLocationException, IllegalItemStackStringException
  827. {
  828. Location l = (Location) args[0];
  829. ItemStack stack = ((ItemStack) args[1]);
  830. TileEntity te = l.getWorld().getTileEntity(l.getBlockPos());
  831. if(te == null || !(te instanceof TileEntityChest))
  832. {
  833. return stack;
  834. }
  835. stack.setCount(InventoryUtils.addToInventory((TileEntityChest) te, stack));
  836. return stack;
  837. }
  838. private static ItemStack removeItemAmountChest(Object[] args) throws IllegalStringLocationException, IllegalItemStackStringException
  839. {
  840. Location l = (Location) args[0];
  841. ItemStack stack = ((ItemStack) args[1]);
  842. TileEntity te = l.getWorld().getTileEntity(l.getBlockPos());
  843. if(te == null || !(te instanceof TileEntityChest))
  844. {
  845. return stack;
  846. }
  847. stack.setCount(InventoryUtils.removeFromInventory((TileEntityChest) te, stack));
  848. return stack;
  849. }
  850. private static Object getCoordOfLocation(Object[] args) throws IllegalStringLocationException
  851. {
  852. Location l = (Location) args[0];
  853. switch(args[1].toString())
  854. {
  855. case "x":
  856. return Fraction.fromDouble(l.getX());
  857. case "y":
  858. return Fraction.fromDouble(l.getY());
  859. case "z":
  860. return Fraction.fromDouble(l.getZ());
  861. case "bx":
  862. return new Fraction(MathHelper.floor(l.getX()));
  863. case "by":
  864. return new Fraction(MathHelper.floor(l.getY()));
  865. case "bz":
  866. return new Fraction(MathHelper.floor(l.getZ()));
  867. case "w":
  868. return ModDimensions.getWorldName(l.getWorld());
  869. default:
  870. return null;
  871. }
  872. }
  873. private static void cloneBlock(Object[] args) throws IllegalStringLocationException
  874. {
  875. Location l = (Location) args[1];
  876. IBlockState state = getBlockState((Location) args[0]);
  877. l.getWorld().setBlockState(l.getBlockPos(), state);
  878. }
  879. private static ItemStack removeItem(Object[] args) throws PlayerNotFoundException, IllegalItemStackStringException
  880. {
  881. ItemStack stack = ((ItemStack) args[1]).copy();
  882. stack.setCount(InventoryUtils.removeFromInventory(((EntityPlayer) args[0]).inventory, stack));
  883. return stack;
  884. }
  885. private static void dropItem(Object[] args) throws IllegalStringLocationException, IllegalItemStackStringException
  886. {
  887. Location l = (Location) args[0];
  888. World w = l.getWorld();
  889. BlockPos pos = l.getBlockPos();
  890. ItemStack stack = ((ItemStack) args[1]).copy();
  891. int amount = stack.getCount();
  892. while(amount > stack.getMaxStackSize())
  893. {
  894. stack.setCount(stack.getMaxStackSize());
  895. amount -= stack.getMaxStackSize();
  896. ItemStackUtils.drop(w, pos, stack.copy());
  897. }
  898. if(amount > 0)
  899. {
  900. stack.setCount(amount);
  901. ItemStackUtils.drop(w, pos, stack);
  902. }
  903. }
  904. private static ItemStack giveItem(Object[] args) throws PlayerNotFoundException, IllegalItemStackStringException
  905. {
  906. ItemStack stack = ((ItemStack) args[1]).copy();
  907. stack.setCount(InventoryUtils.addToInventory(((EntityPlayer) args[0]).inventory, stack));
  908. return stack;
  909. }
  910. private static void endPlayerScript(Object[] args, Script qd) throws NumberFormatException, UnsupportedOperationException
  911. {
  912. if(qd.getClass() == MinecraftScript.class)
  913. {
  914. throw new UnsupportedOperationException();
  915. }
  916. ((PlayerScript) qd).getPlayers().stream().forEach((p) ->
  917. {
  918. KajetansMod.scripts.send(p, "Du hast die Quest geschafft!");
  919. });
  920. KajetansMod.scripts.getSnuviParser().termSafe(qd);
  921. throw new HoldCodeException();
  922. }
  923. private static void setBlock(Object[] args, Script qd) throws IllegalStringLocationException, IllegalItemStackStringException
  924. {
  925. Location l = (Location) args[0];
  926. ItemStack stack = (ItemStack) args[1];
  927. l.getWorld().setBlockState(l.getBlockPos(), Block.getBlockFromItem(stack.getItem()).getStateFromMeta(stack.getMetadata()));
  928. qd.incLoopCounter();
  929. }
  930. private static void setBlockWithData(Object[] args, Script qd) throws IllegalStringLocationException
  931. {
  932. Location l = (Location) args[0];
  933. if(args.length >= 4)
  934. {
  935. NBTUtils.setBlockWithData(l.getWorld(), l.getBlockPos(), ScriptUtils.getInt(args[2]), Block.getBlockFromName(args[1].toString()), ScriptUtils.connect(args, 3));
  936. }
  937. else
  938. {
  939. NBTUtils.setBlockWithData(l.getWorld(), l.getBlockPos(), ScriptUtils.getInt(args[2]), Block.getBlockFromName(args[1].toString()), null);
  940. }
  941. qd.incLoopCounter();
  942. }
  943. private static void dropInventory(Object[] args)
  944. {
  945. ((EntityPlayer) args[0]).inventory.dropAllItems();
  946. }
  947. private static void playSound(Object[] args) throws IllegalStringLocationException
  948. {
  949. Location l = ((Location) args[0]);
  950. Vec3d v = l.getPos();
  951. EffectUtils.playSound((WorldServer) l.getWorld(), SoundEvent.REGISTRY.getObject(new ResourceLocation(args[1].toString())), SoundCategory.MASTER, v.x, v.y, v.z);
  952. }
  953. private static void playSoundPlayer(Object[] args) throws IllegalStringLocationException
  954. {
  955. EffectUtils.playSound((EntityPlayerMP) args[0], SoundEvent.REGISTRY.getObject(new ResourceLocation(args[1].toString())), SoundCategory.MASTER);
  956. }
  957. private static void playParticle(Object[] args) throws IllegalStringLocationException
  958. {
  959. Location l = ((Location) args[0]);
  960. EffectUtils.spawnParticle((WorldServer) l.getWorld(), EnumParticleTypes.getByName(args[1].toString()),
  961. l.getX() + 0.5, l.getY() + 0.5, l.getZ() + 0.5, ScriptUtils.getInt(args[2]));
  962. }
  963. private static void setEntityEquip(Object[] args) throws IllegalStringLocationException, EntityNotFoundException, IllegalItemStackStringException
  964. {
  965. EntityLivingBase liv = (EntityLivingBase) args[0];
  966. ItemStack stack = ((ItemStack) args[2]).copy();
  967. switch(args[1].toString())
  968. {
  969. case "hand":
  970. liv.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, stack);
  971. return;
  972. case "head":
  973. liv.setItemStackToSlot(EntityEquipmentSlot.HEAD, stack);
  974. return;
  975. case "chest":
  976. liv.setItemStackToSlot(EntityEquipmentSlot.CHEST, stack);
  977. return;
  978. case "legs":
  979. liv.setItemStackToSlot(EntityEquipmentSlot.LEGS, stack);
  980. return;
  981. case "feet":
  982. liv.setItemStackToSlot(EntityEquipmentSlot.FEET, stack);
  983. return;
  984. case "offhand":
  985. liv.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, stack);
  986. }
  987. }
  988. private static ItemStack getEntityEquip(Object[] args) throws IllegalStringLocationException, EntityNotFoundException
  989. {
  990. EntityLivingBase liv = (EntityLivingBase) args[0];
  991. switch(args[1].toString())
  992. {
  993. case "hand":
  994. return liv.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND);
  995. case "head":
  996. return liv.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
  997. case "chest":
  998. return liv.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
  999. case "legs":
  1000. return liv.getItemStackFromSlot(EntityEquipmentSlot.LEGS);
  1001. case "feet":
  1002. return liv.getItemStackFromSlot(EntityEquipmentSlot.FEET);
  1003. case "offhand":
  1004. return liv.getItemStackFromSlot(EntityEquipmentSlot.OFFHAND);
  1005. }
  1006. return ItemStack.EMPTY;
  1007. }
  1008. private static void invClose(Object[] args)
  1009. {
  1010. EntityPlayer p = (EntityPlayer) args[0];
  1011. if(p.openContainer instanceof CustomContainer)
  1012. {
  1013. ((CustomContainer) p.openContainer).closeSafe();
  1014. }
  1015. else
  1016. {
  1017. p.closeScreen();
  1018. }
  1019. }
  1020. @SuppressWarnings("unchecked")
  1021. private static void removeEntities(Object[] args) throws IllegalStringLocationException
  1022. {
  1023. Class<? extends Entity> c = (Class<? extends Entity>) getClass(args[0].toString());
  1024. if(c == Entity.class)
  1025. {
  1026. return;
  1027. }
  1028. Location l = (Location) args[1];
  1029. Utils.getEntities(l.getWorld(), l.getX(), l.getY(), l.getZ(), ScriptUtils.getDouble(args[2]), c).stream().forEach(ent ->
  1030. {
  1031. ent.setDead();
  1032. });
  1033. }
  1034. private static void setSign(Object[] args) throws IllegalStringLocationException
  1035. {
  1036. Location l = (Location) args[0];
  1037. TileEntitySign sign = (TileEntitySign) l.getWorld().getTileEntity(l.getBlockPos());
  1038. SpecialBlockUtils.setSignLine(sign, ScriptUtils.getInt(args[1]), ScriptUtils.connect(args, 2));
  1039. }
  1040. @SuppressWarnings("")
  1041. private static String getSign(Object[] args) throws IllegalStringLocationException
  1042. {
  1043. Location l = (Location) args[0];
  1044. TileEntitySign sign = (TileEntitySign) l.getWorld().getTileEntity(l.getBlockPos());
  1045. return sign.signText[ScriptUtils.getInt(args[1])].getUnformattedText();
  1046. }
  1047. private static boolean isSolid(Object[] args)
  1048. {
  1049. IBlockState state = getBlockState((Location) args[0]);
  1050. return state.isFullBlock() && state.isOpaqueCube();
  1051. }
  1052. private static void spawnItemFrame(Object[] args) throws IllegalStringLocationException, IllegalItemStackStringException
  1053. {
  1054. Location l = ((Location) args[0]);
  1055. EntityItemFrame frame = new EntityItemFrame(l.getWorld(), l.getBlockPos(), EnumFacing.byName(args[1].toString()));
  1056. frame.setDisplayedItem(((ItemStack) args[2]).copy());
  1057. }
  1058. private static void nameEntity(Object[] args) throws EntityNotFoundException
  1059. {
  1060. Entity ent = (Entity) args[0];
  1061. ent.setCustomNameTag(ScriptUtils.connect(args, 1));
  1062. if(args.length >= 3)
  1063. {
  1064. ent.setAlwaysRenderNameTag((boolean) args[2]);
  1065. return;
  1066. }
  1067. ent.setAlwaysRenderNameTag(true);
  1068. }
  1069. private static EntityPlayer getPlayerScriptLeader(Script qd) throws PlayerNotFoundException
  1070. {
  1071. if(qd.getClass() == PlayerScript.class)
  1072. {
  1073. return((PlayerScript) qd).getPlayers().get(0);
  1074. }
  1075. throw new UnsupportedOperationException();
  1076. }
  1077. private static void startPlayerScript(Object[] args, Script qd) throws PlayerNotFoundException
  1078. {
  1079. if(qd.getClass() == MinecraftScript.class)
  1080. {
  1081. EntityPlayer p = ((EntityPlayer) args[0]);
  1082. if(!KajetansMod.scripts.hasScript(p))
  1083. {
  1084. KajetansMod.scripts.startQuest(KajetansMod.server, args[1].toString(), p);
  1085. }
  1086. return;
  1087. }
  1088. throw new UnsupportedOperationException();
  1089. }
  1090. private static void addToScoreBoard(Object[] args, Script qd) throws PlayerNotFoundException
  1091. {
  1092. int id = ScriptUtils.getInt(args[1]);
  1093. String message = ScriptUtils.connect(args, 2);
  1094. doForGroup(args[0], qd, p -> KajetansMod.scoreboard.getScoreboard((EntityPlayerMP) p).addText(id, message));
  1095. }
  1096. private static void removeFromScoreBoard(Object[] args, Script qd) throws PlayerNotFoundException
  1097. {
  1098. int id = ScriptUtils.getInt(args[1]);
  1099. doForGroup(args[0], qd, p -> KajetansMod.scoreboard.getScoreboard((EntityPlayerMP) p).removeText(id));
  1100. }
  1101. private static void addToDisplay(Object[] args, Script qd) throws PlayerNotFoundException
  1102. {
  1103. byte id = (byte) ScriptUtils.getInt(args[1]);
  1104. String message = ScriptUtils.connect(args, 2);
  1105. doForGroup(args[0], qd, p -> ModPacketHandler.sendStats((EntityPlayerMP) p, (byte) 1, id, message));
  1106. }
  1107. private static void removeFromDisplay(Object[] args, Script qd) throws PlayerNotFoundException
  1108. {
  1109. byte id = (byte) ScriptUtils.getInt(args[1]);
  1110. doForGroup(args[0], qd, p -> ModPacketHandler.sendStats((EntityPlayerMP) p, (byte) 2, id, ""));
  1111. }
  1112. private static void sendToActionBar(Object[] args, Script qd) throws PlayerNotFoundException
  1113. {
  1114. TextComponentString text = new TextComponentString(ScriptUtils.connect(args, 1));
  1115. doForGroup(args[0], qd, p -> ((EntityPlayerMP) p).sendStatusMessage(text, true));
  1116. }
  1117. private static void kickPlayerFromQuest(Object[] args, Script qd) throws PlayerNotFoundException, UnsupportedOperationException
  1118. {
  1119. if(qd.getClass() == PlayerScript.class)
  1120. {
  1121. KajetansMod.scripts.removePlayerFromScript((EntityPlayer) args[0], (PlayerScript) qd);
  1122. return;
  1123. }
  1124. throw new UnsupportedOperationException();
  1125. }
  1126. private static void damageEntity(Object[] args)
  1127. {
  1128. // entity.damage(entity, damagefloat, DamageSource);
  1129. if(args.length >= 3)
  1130. {
  1131. ((EntityLivingBase) args[0]).attackEntityFrom((DamageSource) args[2], ScriptUtils.getFloat(args[1]));
  1132. return;
  1133. }
  1134. ((EntityLivingBase) args[0]).attackEntityFrom(DamageSource.GENERIC, ScriptUtils.getFloat(args[1]));
  1135. }
  1136. private static DamageSource getDamageSource(Object[] args)
  1137. {
  1138. if(args[0] instanceof EntityLivingBase)
  1139. {
  1140. EntityLivingBase ent = (EntityLivingBase) args[0];
  1141. DamageSource ds;
  1142. if(ent instanceof EntityPlayer)
  1143. {
  1144. ds = DamageSource.causePlayerDamage((EntityPlayer) ent);
  1145. }
  1146. else
  1147. {
  1148. ds = DamageSource.causeMobDamage(ent);
  1149. }
  1150. if((boolean) args[1])
  1151. {
  1152. ds.setDamageAllowedInCreativeMode();
  1153. }
  1154. if((boolean) args[2])
  1155. {
  1156. ds.setDamageBypassesArmor();
  1157. }
  1158. if((boolean) args[3])
  1159. {
  1160. ds.setDamageIsAbsolute();
  1161. }
  1162. if((boolean) args[4])
  1163. {
  1164. ds.setExplosion();
  1165. }
  1166. if((boolean) args[5])
  1167. {
  1168. ds.setFireDamage();
  1169. }
  1170. if((boolean) args[6])
  1171. {
  1172. ds.setMagicDamage();
  1173. }
  1174. if((boolean) args[7])
  1175. {
  1176. ds.setProjectile();
  1177. }
  1178. return ds;
  1179. }
  1180. switch(args[0].toString())
  1181. {
  1182. case "IN_FIRE": return DamageSource.IN_FIRE;
  1183. case "LIGHTNING_BOLT": return DamageSource.LIGHTNING_BOLT;
  1184. case "ON_FIRE": return DamageSource.ON_FIRE;
  1185. case "LAVA": return DamageSource.LAVA;
  1186. case "HOT_FLOOR": return DamageSource.HOT_FLOOR;
  1187. case "IN_WALL": return DamageSource.IN_WALL;
  1188. case "CRAMMING": return DamageSource.CRAMMING;
  1189. case "DROWN": return DamageSource.DROWN;
  1190. case "STARVE": return DamageSource.STARVE;
  1191. case "CACTUS": return DamageSource.CACTUS;
  1192. case "FALL": return DamageSource.FALL;
  1193. case "FLY_INTO_WALL": return DamageSource.FLY_INTO_WALL;
  1194. case "OUT_OF_WORLD": return DamageSource.OUT_OF_WORLD;
  1195. case "GENERIC": return DamageSource.GENERIC;
  1196. case "MAGIC": return DamageSource.MAGIC;
  1197. case "WITHER": return DamageSource.WITHER;
  1198. case "ANVIL": return DamageSource.ANVIL;
  1199. case "FALLING_BLOCK": return DamageSource.FALLING_BLOCK;
  1200. case "DRAGON_BREATH": return DamageSource.DRAGON_BREATH;
  1201. case "FIREWORKS": return DamageSource.FIREWORKS;
  1202. case "THORNS": return DamageSource.causeThornsDamage((Entity) args[1]);
  1203. }
  1204. return DamageSource.GENERIC;
  1205. }
  1206. private static boolean doesIntersect(Object[] args)
  1207. {
  1208. Location l1 = (Location) args[0];
  1209. Location l2 = (Location) args[1];
  1210. int x1 = (int) Math.min(l1.getX(), l2.getX());
  1211. int x2 = (int) Math.max(l1.getX(), l2.getX());
  1212. int y1 = (int) Math.min(l1.getY(), l2.getY());
  1213. int y2 = (int) Math.max(l1.getY(), l2.getY());
  1214. int z1 = (int) Math.min(l1.getZ(), l2.getZ());
  1215. int z2 = (int) Math.max(l1.getZ(), l2.getZ());
  1216. return KajetansMod.plots.getDataBank(ProtectionBank.class)
  1217. .isPlotOverlapping(x1, y1, z1, x2, y2, z2, l1.getWorld());
  1218. }
  1219. private static boolean isBetween(Object[] args)
  1220. {
  1221. Location l1 = ((Location) args[0]);
  1222. Location l2 = ((Location) args[1]);
  1223. Location l3 = ((Location) args[2]);
  1224. return l1.getX() >= Math.min(l2.getX(), l3.getX()) && l1.getX() <= Math.max(l2.getX(), l3.getX()) &&
  1225. l1.getY() >= Math.min(l2.getY(), l3.getY()) && l1.getY() <= Math.max(l2.getY(), l3.getY()) &&
  1226. l1.getZ() >= Math.min(l2.getZ(), l3.getZ()) && l1.getZ() <= Math.max(l2.getZ(), l3.getZ());
  1227. }
  1228. private static void addPlot(Object[] args)
  1229. {
  1230. Location l1 = (Location) args[0];
  1231. Location l2 = (Location) args[1];
  1232. BlockPos pos1 = l1.getBlockPos();
  1233. BlockPos pos2 = l2.getBlockPos();
  1234. KajetansMod.plots.getDataBank(ProtectionBank.class).addPlot(Math.min(pos1.getX(), pos2.getX()),
  1235. Math.min(pos1.getY(), pos2.getY()),
  1236. Math.min(pos1.getZ(), pos2.getZ()),
  1237. Math.max(pos1.getX(), pos2.getX()),
  1238. Math.max(pos1.getY(), pos2.getY()),
  1239. Math.max(pos1.getZ(), pos2.getZ()),
  1240. ModDimensions.getWorldName(l1.getWorld()), null, args[2].toString());
  1241. }
  1242. private static Entity getLastDamager(Object[] args)
  1243. {
  1244. DamageSource ds = ((EntityPlayer) args[0]).getLastDamageSource();
  1245. if(ds == null)
  1246. {
  1247. return null;
  1248. }
  1249. return ds.getImmediateSource();
  1250. }
  1251. private static void nearPlayers(Object[] args, Script sc)
  1252. {
  1253. Location l = (Location) args[1];
  1254. sc.setVar(args[0].toString(), Utils.getPlayers(l.getWorld(), l.getX(), l.getY(), l.getZ(), ScriptUtils.getDouble(args[2])));
  1255. }
  1256. @SuppressWarnings("")
  1257. private static SnuviInventory newInventory(Location l, MinecraftScript qd, String s)
  1258. {
  1259. TileEntityChest chest = (TileEntityChest) l.getWorld().getTileEntity(l.getBlockPos());
  1260. int size = chest.getSizeInventory();
  1261. if(size % 9 != 0)
  1262. {
  1263. size /= 9;
  1264. size++;
  1265. size *= 9;
  1266. }
  1267. SnuviInventory inv = new SnuviInventory(s, size, qd.getNewId());
  1268. for(int i = 0; i < chest.getSizeInventory(); i++)
  1269. {
  1270. inv.setInventorySlotContents(i, chest.getStackInSlot(i).copy());
  1271. }
  1272. return inv;
  1273. }
  1274. private static boolean onlyLetters(String s)
  1275. {
  1276. for(char c : s.toCharArray())
  1277. {
  1278. if(!Character.isLetter(c))
  1279. {
  1280. return false;
  1281. }
  1282. }
  1283. return true;
  1284. }
  1285. private static Entity getEntity(Object[] args)
  1286. {
  1287. Location l = (Location) args[0];
  1288. return Utils.getEntity(l.getWorld(), l.getX(), l.getY(), l.getZ(), ScriptUtils.getDouble(args[1]), getClass(args[2].toString()));
  1289. }
  1290. private static String getName(Object[] args)
  1291. {
  1292. Object o = args[0];
  1293. if(o instanceof EntityPlayer)
  1294. {
  1295. return ((EntityPlayer) o).getName();
  1296. }
  1297. return KajetansMod.playerbank.getDataBank().getName(o.toString());
  1298. }
  1299. private static String getUuid(Object[] args)
  1300. {
  1301. Object o = args[0];
  1302. if(o instanceof EntityPlayer)
  1303. {
  1304. return ((EntityPlayer) o).getUniqueID().toString();
  1305. }
  1306. return KajetansMod.playerbank.getDataBank().getUUID(o.toString());
  1307. }
  1308. private static Set<Fraction> getPlotIds(Object[] args)
  1309. {
  1310. return KajetansMod.plots.getDataBank(ProtectionBank.class).getRegionIds(
  1311. ((Location) args[1]).getWorld(),
  1312. ((Location) args[1]).getBlockPos()).stream()
  1313. .map(o -> new Fraction(Integer.parseInt(o.toString())))
  1314. .collect(Collectors.toSet());
  1315. }
  1316. @SuppressWarnings("")
  1317. private static String getPotionType(Object[] args)
  1318. {
  1319. return PotionUtils.getPotionFromItem(((EntityPotion) args[0]).getPotion()).getRegistryName().toString();
  1320. }
  1321. private static void setTag(Object[] args)
  1322. {
  1323. if(args[0] instanceof EntityPlayer)
  1324. {
  1325. KajetansMod.playerbank.getDataBank().setTag((EntityPlayer) args[0], args[1].toString(), ScriptUtils.getInt(args[2]));
  1326. return;
  1327. }
  1328. KajetansMod.playerbank.getDataBank().setTag(KajetansMod.playerbank.getDataBank().getUUID(args[0].toString()), args[1].toString(), ScriptUtils.getInt(args[2]));
  1329. }
  1330. private static Fraction getTag(Object[] args)
  1331. {
  1332. if(args[0] instanceof EntityPlayer)
  1333. {
  1334. return new Fraction(KajetansMod.playerbank.getDataBank().getTag((EntityPlayer) args[0], args[1].toString()));
  1335. }
  1336. return new Fraction(KajetansMod.playerbank.getDataBank().getTag(KajetansMod.playerbank.getDataBank().getUUID(args[0].toString()), args[1].toString()));
  1337. }
  1338. private static void setGlobalVar(Object[] args)
  1339. {
  1340. if(args[0] instanceof EntityPlayer)
  1341. {
  1342. KajetansMod.scripts.getDataBank(ScriptBank.class).setVar(args[2].toString(), args[1].toString(), ((EntityPlayer) args[0]).getUniqueID().toString());
  1343. return;
  1344. }
  1345. KajetansMod.scripts.getDataBank(ScriptBank.class).setVar(args[2].toString(), args[1].toString(), KajetansMod.playerbank.getDataBank().getUUID(args[0].toString()));
  1346. }
  1347. private static Object getGlobalVar(Object[] args)
  1348. {
  1349. if(args[0] instanceof EntityPlayer)
  1350. {
  1351. return KajetansMod.scripts.getDataBank(ScriptBank.class).getVar(args[1].toString(), ((EntityPlayer) args[0]).getUniqueID().toString());
  1352. }
  1353. return KajetansMod.scripts.getDataBank(ScriptBank.class).getVar(args[1].toString(), KajetansMod.playerbank.getDataBank().getUUID(args[0].toString()));
  1354. }
  1355. // -------------------------------------------------------------------------
  1356. // Potion
  1357. // -------------------------------------------------------------------------
  1358. private static void addEffect(Object[] args)
  1359. {
  1360. EntityLivingBase base = (EntityLivingBase) args[0];
  1361. Potion potion = Potion.getPotionFromResourceLocation(args[1].toString());
  1362. if(base == null) // doing this only to prevent EffectUtils.addPotionTo doing shit
  1363. {
  1364. throw new NullPointerException("null not allowed for entity");
  1365. }
  1366. else if(potion == null)
  1367. {
  1368. throw new NullPointerException("potion does not exist");
  1369. }
  1370. EffectUtils.addPotionTo(base, potion, ScriptUtils.getInt(args[2]), ScriptUtils.getInt(args[3]));
  1371. }
  1372. // -------------------------------------------------------------------------
  1373. // Block
  1374. // -------------------------------------------------------------------------
  1375. private static Fraction getBlockData(Location l)
  1376. {
  1377. IBlockState state = l.getWorld().getBlockState(l.getBlockPos());
  1378. return new Fraction(state.getBlock().getMetaFromState(state));
  1379. }
  1380. private static IBlockState getBlockState(Location l)
  1381. {
  1382. return l.getWorld().getBlockState(l.getBlockPos());
  1383. }
  1384. private static ItemStack getStackFromBlock(Location l)
  1385. {
  1386. World w = l.getWorld();
  1387. BlockPos pos = l.getBlockPos();
  1388. IBlockState state = w.getBlockState(pos);
  1389. return state.getBlock().getItem(w, pos, state);
  1390. }
  1391. // -------------------------------------------------------------------------
  1392. // Custom-Handler
  1393. // -------------------------------------------------------------------------
  1394. /*private static void registerShapelessRecipe(Object[] args)
  1395. {
  1396. ItemStack[] stacks = new ItemStack[args.length - 1];
  1397. for(int i = 0; i < stacks.length; i++)
  1398. {
  1399. stacks[i] = (ItemStack) args[i + 1];
  1400. }
  1401. RecipeUtils.registerShapelessRecipe((ItemStack) args[0], stacks);
  1402. }
  1403. private static void registerShapedRecipe(Object[] args)
  1404. {
  1405. int counter = 0;
  1406. while(args[counter + 1].getClass() == String.class)
  1407. {
  1408. counter++;
  1409. }
  1410. String[] s = new String[counter];
  1411. for(int i = 0; i < s.length; i++)
  1412. {
  1413. s[i] = args[i + 1].toString();
  1414. }
  1415. ItemStack[] stacks = new ItemStack[args.length - 1 - s.length];
  1416. for(int i = 0; i < stacks.length; i++)
  1417. {
  1418. stacks[i] = (ItemStack) args[i + 1 + counter];
  1419. }
  1420. RecipeUtils.registerShapedRecipe((ItemStack) args[0], s, stacks);
  1421. }*/
  1422. // -------------------------------------------------------------------------
  1423. // Gruppen-Handler
  1424. // -------------------------------------------------------------------------
  1425. private static void doForGroup(Object group, Script qd, Consumer<ICommandSender> c) throws UnsupportedOperationException, PlayerNotFoundException
  1426. {
  1427. if(group instanceof String)
  1428. {
  1429. switch(group.toString())
  1430. {
  1431. case "all":
  1432. if(qd.getClass() == MinecraftScript.class)
  1433. {
  1434. throw new UnsupportedOperationException();
  1435. }
  1436. ((PlayerScript) qd).getPlayers().forEach(p -> c.accept(p));
  1437. break;
  1438. case "online":
  1439. KajetansMod.server.getPlayerList().getPlayers().forEach(p -> c.accept(p));
  1440. break;
  1441. case "dev":
  1442. if(qd != null && qd.getClass() == PlayerScript.class)
  1443. {
  1444. ((PlayerScript) qd).getPlayers().stream().filter(p -> KajetansMod.perms.has(p, Permissions.SCRIPT_ERROR)).forEach(p -> c.accept(p));
  1445. return;
  1446. }
  1447. KajetansMod.server.getPlayerList().getPlayers().stream().filter(p -> KajetansMod.perms.has(p, Permissions.SCRIPT_ERROR)).forEach(p -> c.accept(p));
  1448. break;
  1449. case "server":
  1450. c.accept(KajetansMod.server);
  1451. break;
  1452. default:
  1453. c.accept(Utils.getPlayerByName(group.toString()));
  1454. break;
  1455. }
  1456. return;
  1457. }
  1458. c.accept((EntityPlayer) group);
  1459. }
  1460. private static void sendMessageToGroup(Object group, Script sc, ITextComponent text)
  1461. {
  1462. doForGroup(group, sc, p ->
  1463. {
  1464. p.sendMessage(text);
  1465. });
  1466. }
  1467. public static void sendMessageWithSuffix(Script sc, String message)
  1468. {
  1469. Module m = KajetansMod.scripts;
  1470. doForGroup("all", sc, p -> m.send(p, message));
  1471. }
  1472. private static void sendToDevsWithSuffix(String message)
  1473. {
  1474. Module m = KajetansMod.scripts;
  1475. doForGroup("dev", null, p -> m.send(p, message));
  1476. }
  1477. public static void sendWarningToAllDevs(String message)
  1478. {
  1479. Module m = KajetansMod.scripts;
  1480. String warnMessage = "§4" + message;
  1481. doForGroup("dev", null, p -> m.send(p, warnMessage));
  1482. }
  1483. private static void sendToDevsWithList(String message)
  1484. {
  1485. Module m = KajetansMod.scripts;
  1486. doForGroup("dev", null, p -> m.sendListElement(p, message));
  1487. }
  1488. private static void sendToDevsWithHelpList(String message, String message2)
  1489. {
  1490. Module m = KajetansMod.scripts;
  1491. doForGroup("dev", null, p -> m.sendHelpListElement(p, message, message2));
  1492. }
  1493. }