MinecraftFunctions.java 85 KB

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