MinecraftFunctions.java 72 KB

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