Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.96 KB | None | 0 0
  1. package me.Ahmet094.DrugsFTW;
  2.  
  3. import org.bukkit.event.block.*;
  4. import org.bukkit.potion.*;
  5. import org.bukkit.inventory.*;
  6. import org.bukkit.entity.*;
  7. import org.bukkit.event.*;
  8. import org.bukkit.event.entity.*;
  9. import org.bukkit.event.player.*;
  10. import org.bukkit.*;
  11.  
  12. public class DrugsListener implements Listener
  13. {
  14. private DrugsFTW plugin;
  15.  
  16. public DrugsListener(final DrugsFTW instance) {
  17. this.plugin = instance;
  18. }
  19.  
  20. @EventHandler
  21. public void DrogenNehmen(final PlayerInteractEvent event) {
  22. final Player spieler = event.getPlayer();
  23. final ItemStack item = spieler.getItemInHand();
  24. final int duration = this.plugin.getConfig().getInt("options.EffectDuration") * 20;
  25. final String prefix = this.plugin.getConfig().getString("messages.ChatPrefix").replaceAll("&", "§");
  26. final int amountNeeded = this.plugin.getConfig().getInt("options.amountNeeded");
  27. if (spieler.hasPermission("drugsftw.takeDrugs") || spieler.isOp()) {
  28. final Action action = event.getAction();
  29. event.getAction();
  30. if (action == Action.RIGHT_CLICK_AIR && item.getType() == Material.RED_MUSHROOM && item.getAmount() >= amountNeeded) {
  31. if (spieler.hasPotionEffect(PotionEffectType.CONFUSION)) {
  32. spieler.sendMessage(prefix + this.plugin.getConfig().getString("messages.MyselfAlreadyOnDrugs").replaceAll("&", "§"));
  33. }
  34. else {
  35. spieler.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, duration, 3));
  36. if (item.getAmount() == amountNeeded) {
  37. spieler.setItemInHand((ItemStack)null);
  38. spieler.sendMessage(prefix + this.plugin.getConfig().getString("messages.MyselfNowOnDrugs").replaceAll("&", "§"));
  39. }
  40. else {
  41. item.setAmount(item.getAmount() - amountNeeded);
  42. spieler.sendMessage(prefix + this.plugin.getConfig().getString("messages.MyselfNowOnDrugs").replaceAll("&", "§"));
  43. }
  44. }
  45. }
  46. final Action action2 = event.getAction();
  47. event.getAction();
  48. if (action2 == Action.RIGHT_CLICK_AIR && item.getType() == Material.SUGAR && item.getAmount() >= amountNeeded) {
  49. if (spieler.hasPotionEffect(PotionEffectType.BLINDNESS)) {
  50. spieler.sendMessage(prefix + this.plugin.getConfig().getString("messages.MyselfAlreadyOnDrugs").replaceAll("&", "§"));
  51. }
  52. else {
  53. spieler.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, duration, 5));
  54. if (item.getAmount() == amountNeeded) {
  55. spieler.setItemInHand((ItemStack)null);
  56. spieler.sendMessage(prefix + this.plugin.getConfig().getString("messages.MyselfNowOnDrugs").replaceAll("&", "§"));
  57. }
  58. else {
  59. item.setAmount(item.getAmount() - amountNeeded);
  60. spieler.sendMessage(prefix + this.plugin.getConfig().getString("messages.MyselfNowOnDrugs").replaceAll("&", "§"));
  61. }
  62. }
  63. }
  64. final Action action3 = event.getAction();
  65. event.getAction();
  66. if (action3 == Action.RIGHT_CLICK_AIR && item.getType() == Material.WHEAT && item.getAmount() >= amountNeeded && this.plugin.getConfig().getBoolean("options.enableWheat")) {
  67. if (spieler.hasPotionEffect(PotionEffectType.WEAKNESS)) {
  68. spieler.sendMessage(prefix + this.plugin.getConfig().getString("messages.MyselfAlreadyOnDrugs").replaceAll("&", "§"));
  69. }
  70. else {
  71. spieler.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, duration, amountNeeded));
  72. if (item.getAmount() == amountNeeded) {
  73. spieler.setItemInHand((ItemStack)null);
  74. spieler.sendMessage(prefix + this.plugin.getConfig().getString("messages.MyselfNowOnDrugs").replaceAll("&", "§"));
  75. }
  76. else {
  77. item.setAmount(item.getAmount() - amountNeeded);
  78. spieler.sendMessage(prefix + this.plugin.getConfig().getString("messages.MyselfNowOnDrugs").replaceAll("&", "§"));
  79. }
  80. }
  81. }
  82. final Action action4 = event.getAction();
  83. event.getAction();
  84. if (action4 == Action.RIGHT_CLICK_AIR && item.getType() == Material.BROWN_MUSHROOM && item.getAmount() >= amountNeeded) {
  85. if (spieler.hasPotionEffect(PotionEffectType.POISON)) {
  86. spieler.sendMessage(prefix + this.plugin.getConfig().getString("messages.MyselfAlreadyOnDrugs").replaceAll("&", "§"));
  87. }
  88. else {
  89. spieler.addPotionEffect(new PotionEffect(PotionEffectType.POISON, duration, amountNeeded));
  90. if (item.getAmount() == amountNeeded) {
  91. spieler.setItemInHand((ItemStack)null);
  92. spieler.sendMessage(prefix + this.plugin.getConfig().getString("messages.MyselfNowOnDrugs").replaceAll("&", "§"));
  93. }
  94. else {
  95. item.setAmount(item.getAmount() - amountNeeded);
  96. spieler.sendMessage(prefix + this.plugin.getConfig().getString("messages.MyselfNowOnDrugs").replaceAll("&", "§"));
  97. }
  98. }
  99. }
  100. final Action action5 = event.getAction();
  101. event.getAction();
  102. if (action5 == Action.RIGHT_CLICK_AIR && item.getType() == Material.SULPHUR && item.getAmount() >= amountNeeded) {
  103. if (spieler.hasPotionEffect(PotionEffectType.NIGHT_VISION)) {
  104. spieler.sendMessage(prefix + this.plugin.getConfig().getString("messages.MyselfAlreadyOnDrugs").replaceAll("&", "§"));
  105. }
  106. else {
  107. spieler.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, duration, amountNeeded));
  108. spieler.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, duration, amountNeeded));
  109. if (item.getAmount() == amountNeeded) {
  110. spieler.setItemInHand((ItemStack)null);
  111. spieler.sendMessage(prefix + this.plugin.getConfig().getString("messages.MyselfNowOnDrugs").replaceAll("&", "§"));
  112. }
  113. else {
  114. item.setAmount(item.getAmount() - amountNeeded);
  115. spieler.sendMessage(prefix + this.plugin.getConfig().getString("messages.MyselfNowOnDrugs").replaceAll("&", "§"));
  116. }
  117. }
  118. }
  119. }
  120. }
  121.  
  122. @EventHandler
  123. public void OpferAufDrogenSetzen(final EntityDamageByEntityEvent event) {
  124. if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
  125. final Player opfer = (Player)event.getEntity();
  126. final Player schlingel = (Player)event.getDamager();
  127. final ItemStack item = schlingel.getItemInHand();
  128. final int duration = this.plugin.getConfig().getInt("options.EffectDuration") * 20;
  129. final String prefix = this.plugin.getConfig().getString("messages.ChatPrefix").replaceAll("&", "§");
  130. final int amountNeeded = this.plugin.getConfig().getInt("options.amountNeeded");
  131. if (schlingel.hasPermission("drugsftw.setonDrugs") || schlingel.isOp()) {
  132. if (!opfer.hasPermission("drugsftw.immune") && item.getType() == Material.RED_MUSHROOM && item.getAmount() >= amountNeeded) {
  133. if (opfer.hasPotionEffect(PotionEffectType.CONFUSION)) {
  134. schlingel.sendMessage(prefix + this.plugin.getConfig().getString("messages.VictimAlreadyOnDrugs").replaceAll("&", "§").replaceAll("<target>", opfer.getDisplayName()));
  135. }
  136. else {
  137. opfer.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, duration, 1));
  138. opfer.sendMessage(prefix + this.plugin.getConfig().getString("messages.GotSetOnDrugs").replaceAll("&", "§").replaceAll("<player>", schlingel.getDisplayName()));
  139. schlingel.sendMessage(prefix + this.plugin.getConfig().getString("messages.VictimNowOnDrugs").replaceAll("&", "§").replaceAll("<target>", opfer.getDisplayName()));
  140. if (item.getAmount() == amountNeeded) {
  141. schlingel.setItemInHand((ItemStack)null);
  142. }
  143. else {
  144. item.setAmount(item.getAmount() - amountNeeded);
  145. }
  146. }
  147. }
  148. if (item.getType() == Material.SUGAR && item.getAmount() >= amountNeeded) {
  149. if (opfer.hasPotionEffect(PotionEffectType.BLINDNESS)) {
  150. schlingel.sendMessage(prefix + this.plugin.getConfig().getString("messages.VictimAlreadyOnDrugs").replaceAll("&", "§").replaceAll("<target>", opfer.getDisplayName()));
  151. }
  152. else {
  153. opfer.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, duration, 1));
  154. opfer.sendMessage(prefix + this.plugin.getConfig().getString("messages.GotSetOnDrugs").replaceAll("&", "§").replaceAll("<player>", schlingel.getDisplayName()));
  155. schlingel.sendMessage(prefix + this.plugin.getConfig().getString("messages.VictimNowOnDrugs").replaceAll("&", "§").replaceAll("<target>", opfer.getDisplayName()));
  156. if (item.getAmount() == amountNeeded) {
  157. schlingel.setItemInHand((ItemStack)null);
  158. }
  159. else {
  160. item.setAmount(item.getAmount() - amountNeeded);
  161. }
  162. }
  163. }
  164. if (item.getType() == Material.WHEAT && item.getAmount() >= amountNeeded) {
  165. if (opfer.hasPotionEffect(PotionEffectType.WEAKNESS)) {
  166. schlingel.sendMessage(prefix + this.plugin.getConfig().getString("messages.VictimAlreadyOnDrugs").replaceAll("&", "§").replaceAll("<target>", opfer.getDisplayName()));
  167. }
  168. else {
  169. opfer.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, duration, 1));
  170. opfer.sendMessage(prefix + this.plugin.getConfig().getString("messages.GotSetOnDrugs").replaceAll("&", "§").replaceAll("<player>", schlingel.getDisplayName()));
  171. schlingel.sendMessage(prefix + this.plugin.getConfig().getString("messages.VictimNowOnDrugs").replaceAll("&", "§").replaceAll("<target>", opfer.getDisplayName()));
  172. if (item.getAmount() == amountNeeded) {
  173. schlingel.setItemInHand((ItemStack)null);
  174. }
  175. else {
  176. item.setAmount(item.getAmount() - amountNeeded);
  177. }
  178. }
  179. }
  180. if (item.getType() == Material.BROWN_MUSHROOM && item.getAmount() >= amountNeeded) {
  181. if (opfer.hasPotionEffect(PotionEffectType.POISON)) {
  182. schlingel.sendMessage(prefix + this.plugin.getConfig().getString("messages.VictimAlreadyOnDrugs").replaceAll("&", "§").replaceAll("<target>", opfer.getDisplayName()));
  183. }
  184. else {
  185. opfer.addPotionEffect(new PotionEffect(PotionEffectType.POISON, duration, 1));
  186. opfer.sendMessage(prefix + this.plugin.getConfig().getString("messages.GotSetOnDrugs").replaceAll("&", "§").replaceAll("<player>", schlingel.getDisplayName()));
  187. schlingel.sendMessage(prefix + this.plugin.getConfig().getString("messages.VictimNowOnDrugs").replaceAll("&", "§").replaceAll("<target>", opfer.getDisplayName()));
  188. if (item.getAmount() == amountNeeded) {
  189. schlingel.setItemInHand((ItemStack)null);
  190. }
  191. else {
  192. item.setAmount(item.getAmount() - amountNeeded);
  193. }
  194. }
  195. }
  196. }
  197. }
  198. }
  199.  
  200. @EventHandler
  201. public void onPlayerChat(final AsyncPlayerChatEvent event) {
  202. if (event.getPlayer().hasPermission("drugsftw.chatcolor")) {
  203. final String nachricht = ChatColor.translateAlternateColorCodes('&', event.getMessage());
  204. event.setMessage(nachricht);
  205. }
  206. }
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement