Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 15.22 KB | None | 0 0
  1. package com.YourMCAdmin.LegitLandPotionEffects;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.command.Command;
  6. import org.bukkit.command.CommandSender;
  7. import org.bukkit.configuration.file.FileConfiguration;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.event.EventHandler;
  10. import org.bukkit.event.Listener;
  11. import org.bukkit.event.player.PlayerJoinEvent;
  12. import org.bukkit.event.player.PlayerRespawnEvent;
  13. import org.bukkit.event.player.PlayerToggleSneakEvent;
  14. import org.bukkit.plugin.java.JavaPlugin;
  15. import org.bukkit.potion.PotionEffect;
  16. import org.bukkit.potion.PotionEffectType;
  17.  
  18. public class LLPotionEffects extends JavaPlugin implements Listener{
  19.  
  20.     @Override
  21.     public void onEnable() {
  22.         getLogger().info("[LegitLand Potion Effects] has been enabled.");
  23.         initialiseConfig(); // initialise the config
  24.         Bukkit.getPluginManager().registerEvents(this, this);
  25.     }
  26.  
  27.     private void initialiseConfig() {
  28.         FileConfiguration config = getConfig(); // creates variable "config" for
  29.                                                 // getConfig.
  30.         config.addDefault("Jump Boost.Enabled", false);
  31.         config.addDefault("Night Vision.Enabled", false);
  32.         config.addDefault("Haste.Enabled", false);
  33.         config.addDefault("Speed.Enabled", false);
  34.         config.addDefault("Regeneration.Enabled", false);
  35.         config.addDefault("Health Boost.Enabled", false);
  36.         config.addDefault("Water Breathing.Enabled", false);
  37.         config.options().copyDefaults(true); // If true then the values will be
  38.         // added to the config if they
  39.         // weren't already
  40.         saveConfig(); // Creates the config
  41.     }
  42.  
  43.     public void onDisable() {
  44.         saveConfig();
  45.     }
  46.  
  47.     public boolean onCommand(CommandSender sender, Command cmd, String label,
  48.             String[] args) {
  49.        
  50.    
  51.         if (sender.hasPermission("potioneffects.toggle")) {
  52.         if (cmd.getName().equalsIgnoreCase("LLPotion")) {
  53.             if (args.length > 1) {
  54.                 sender.sendMessage(ChatColor.RED + "Too many arguments!");
  55.                 return true;
  56.             }
  57.            
  58.             if (args.length < 1) {
  59.                 sender.sendMessage(ChatColor.RED + "Proper use: /LLPotion (JumpBoost, HealthBoost, Haste, Regeneration, Speed, NightVision");
  60.                 return true;
  61.             }
  62.  
  63.             if (args.length == 1) {
  64.                 //List which ones are enabled
  65.                 if (args[0].equalsIgnoreCase("list")) {
  66.                     if (getConfig().getBoolean("Jump Boost.Enabled") == true) {
  67.                         sender.sendMessage(ChatColor.GREEN
  68.                                 + "[LegitPotionEffects] " + ChatColor.RED
  69.                                 + "Jump Boost Enabled");
  70.                     }
  71.                     if (getConfig().getBoolean("Health Boost.Enabled") == true) {
  72.                         sender.sendMessage(ChatColor.GREEN
  73.                                 + "[LegitPotionEffects] " + ChatColor.RED
  74.                                 + "Health Boost Enabled");
  75.                     }
  76.                     if (getConfig().getBoolean("Regeneration.Enabled") == true) {
  77.                         sender.sendMessage(ChatColor.GREEN
  78.                                 + "[LegitPotionEffects] " + ChatColor.RED
  79.                                 + "Regeneration Enabled");
  80.                     }
  81.                     if (getConfig().getBoolean("Haste.Enabled") == true) {
  82.                         sender.sendMessage(ChatColor.GREEN
  83.                                 + "[LegitPotionEffects] " + ChatColor.RED
  84.                                 + "Haste Enabled");
  85.                     }
  86.                     if (getConfig().getBoolean("Speed.Enabled") == true) {
  87.                         sender.sendMessage(ChatColor.GREEN
  88.                                 + "[LegitPotionEffects] " + ChatColor.RED
  89.                                 + "Speed Enabled");
  90.                     }
  91.                     if (getConfig().getBoolean("Night Vision.Enabled") == true) {
  92.                         sender.sendMessage(ChatColor.GREEN
  93.                                 + "[LegitPotionEffects] " + ChatColor.RED
  94.                                 + "Night Vision Enabled");
  95.                     }
  96.                     if (getConfig().getBoolean("Water Breathing.Enabled") == true) {
  97.                         sender.sendMessage(ChatColor.GREEN
  98.                                 + "[LegitPotionEffects] " + ChatColor.RED
  99.                                 + "Water Breathing Enabled");
  100.                     }else{
  101.                         sender.sendMessage(ChatColor.GREEN
  102.                                 + "[LegitPotionEffects] " + ChatColor.RED
  103.                                 + "No potion effects currently enabled!");
  104.                     }
  105.                     return true;
  106.                 }
  107.                    
  108.                 //jump boost toggle
  109.                 if (args[0].equalsIgnoreCase("JumpBoost")) {
  110.                     if (getConfig().getBoolean("Jump Boost.Enabled") == true) {
  111.                         getConfig().set("Jump Boost.Enabled", false);
  112.                         saveConfig();
  113.                         sender.sendMessage(ChatColor.GREEN
  114.                                 + "[LegitPotionEffects] " + ChatColor.RED
  115.                                 + "Jump Boost Disabled");
  116.  
  117.                     } else if (getConfig().getBoolean("Jump Boost.Enabled") == false) {
  118.                         getConfig().set("Jump Boost.Enabled", true);
  119.                         saveConfig();
  120.                         sender.sendMessage(ChatColor.GREEN
  121.                                 + "[LegitPotionEffects] " + ChatColor.RED
  122.                                 + "Jump Boost Enabled");
  123.                     }
  124.                    
  125.                 //health boost toggle
  126.                 }else if (args[0].equalsIgnoreCase("HealthBoost")) {
  127.                     if (getConfig().getBoolean("Health Boost.Enabled") == true) {
  128.                         getConfig().set("Health Boost.Enabled", false);
  129.                         saveConfig();
  130.                         sender.sendMessage(ChatColor.GREEN
  131.                                 + "[LegitPotionEffects] " + ChatColor.RED
  132.                                 + "Health Boost Disabled");
  133.  
  134.                     } else if (getConfig().getBoolean("Health Boost.Enabled") == false) {
  135.                         getConfig().set("Health Boost.Enabled", true);
  136.                         saveConfig();
  137.                         sender.sendMessage(ChatColor.GREEN
  138.                                 + "[LegitPotionEffects] " + ChatColor.RED
  139.                                 + "Health Boost Enabled");
  140.                     }
  141.                
  142.                 //speed toggle
  143.                 }else if (args[0].equalsIgnoreCase("Speed")) {
  144.                     if (getConfig().getBoolean("Speed.Enabled") == true) {
  145.                         getConfig().set("Speed.Enabled", false);
  146.                         saveConfig();
  147.                         sender.sendMessage(ChatColor.GREEN
  148.                                 + "[LegitPotionEffects] " + ChatColor.RED
  149.                                 + "Speed Disabled");
  150.  
  151.                     } else if (getConfig().getBoolean("Speed.Enabled") == false) {
  152.                         getConfig().set("Speed.Enabled", true);
  153.                         saveConfig();
  154.                         sender.sendMessage(ChatColor.GREEN
  155.                                 + "[LegitPotionEffects] " + ChatColor.RED
  156.                                 + "Speed Enabled");
  157.                     }
  158.                    
  159.                 //nightvision toggle
  160.                 }else if (args[0].equalsIgnoreCase("Nightvision")) {
  161.                     if (getConfig().getBoolean("Night Vision.Enabled") == true) {
  162.                         getConfig().set("Night Vision.Enabled", false);
  163.                         saveConfig();
  164.                         sender.sendMessage(ChatColor.GREEN
  165.                                 + "[LegitPotionEffects] " + ChatColor.RED
  166.                                 + "Night Vision Disabled");
  167.  
  168.                     } else if (getConfig().getBoolean("Night Vision.Enabled") == false) {
  169.                         getConfig().set("Night Vision.Enabled", true);
  170.                         saveConfig();
  171.                         sender.sendMessage(ChatColor.GREEN
  172.                                 + "[LegitPotionEffects] " + ChatColor.RED
  173.                                 + "Night Vision Enabled");
  174.                     }
  175.                 //regen toggle
  176.                 }else if (args[0].equalsIgnoreCase("Regeneration")) {
  177.                     if (getConfig().getBoolean("Regeneration.Enabled") == true) {
  178.                         getConfig().set("Regeneration.Enabled", false);
  179.                         saveConfig();
  180.                         sender.sendMessage(ChatColor.GREEN
  181.                                 + "[LegitPotionEffects] " + ChatColor.RED
  182.                                 + "Regeneration Disabled");
  183.  
  184.                     } else if (getConfig().getBoolean("Regeneration.Enabled") == false) {
  185.                         getConfig().set("Regeneration.Enabled", true);
  186.                         saveConfig();
  187.                         sender.sendMessage(ChatColor.GREEN
  188.                                 + "[LegitPotionEffects] " + ChatColor.RED
  189.                                 + "Regeneration Enabled");
  190.                     }
  191.                 //waterbreathing toggle
  192.                 }else if (args[0].equalsIgnoreCase("WaterBreathing")) {
  193.                     if (getConfig().getBoolean("Water Breathing.Enabled") == true) {
  194.                         getConfig().set("Water Breathing.Enabled", false);
  195.                         saveConfig();
  196.                         sender.sendMessage(ChatColor.GREEN
  197.                                 + "[LegitPotionEffects] " + ChatColor.RED
  198.                                 + "Water Breathing Disabled");
  199.  
  200.                     } else if (getConfig().getBoolean("Water Breathing.Enabled") == false) {
  201.                         getConfig().set("Water Breathing.Enabled", true);
  202.                         saveConfig();
  203.                         sender.sendMessage(ChatColor.GREEN
  204.                                 + "[LegitPotionEffects] " + ChatColor.RED
  205.                                 + "Water Breathing Enabled");
  206.                     }
  207.  
  208.                 //haste toggle
  209.                 }else if (args[0].equalsIgnoreCase("Haste")) {
  210.                     if (getConfig().getBoolean("Haste.Enabled") == true) {
  211.                         getConfig().set("Haste.Enabled", false);
  212.                         saveConfig();
  213.                         sender.sendMessage(ChatColor.GREEN
  214.                                 + "[LegitPotionEffects] " + ChatColor.RED
  215.                                 + "Haste Disabled");
  216.  
  217.                     } else if (getConfig().getBoolean("Haste.Enabled") == false) {
  218.                         getConfig().set("Haste.Enabled", true);
  219.                         saveConfig();
  220.                         sender.sendMessage(ChatColor.GREEN
  221.                                 + "[LegitPotionEffects] " + ChatColor.RED
  222.                                 + "Haste Enabled");
  223.                     }
  224.                 }else{
  225.                     sender.sendMessage(ChatColor.GREEN + "[LegitPotionEffects] " + ChatColor.RED + "Incorrect Potion Effect");
  226.                    
  227.                 }
  228.             return true;
  229.             }
  230.         }
  231.         }
  232.        
  233.         Player p = (Player) sender;
  234.  
  235.         if (cmd.getName().equalsIgnoreCase("pot")) {
  236.             if (args.length > 1) {
  237.                 sender.sendMessage(ChatColor.RED + "Too many arguments, maaan! Chill out, dude. Are you a cop?");
  238.                 return true;
  239.             }
  240.            
  241.             if (args.length == 0) {
  242.                 p.removePotionEffect(PotionEffectType.CONFUSION);
  243.                 p.addPotionEffect(new PotionEffect(
  244.                         PotionEffectType.CONFUSION, 600, 0));
  245.                 sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Wooaaaaaah... Duuuude... I'm sooooo high right now....");
  246.                 return true;
  247.             }
  248.  
  249.         }
  250.         return true;
  251.        
  252.     }
  253.                
  254.                    
  255.  
  256.  
  257.     @EventHandler
  258.     // player joins and gets potion effects
  259.     public void onJoin(PlayerJoinEvent event) {
  260.  
  261.         Player p = event.getPlayer();
  262.  
  263.         if (getConfig().getBoolean("Jump Boost.Enabled")) {
  264.             if (p.hasPermission("potioneffects.jumpboost")) {
  265.                 p.removePotionEffect(PotionEffectType.JUMP);
  266.                 p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP,
  267.                         288000, 3));
  268.             }
  269.         } else {
  270.             if (p.hasPermission("potioneffects.jumpboost")) {
  271.                 p.removePotionEffect(PotionEffectType.JUMP);
  272.             }
  273.         }
  274.         if (getConfig().getBoolean("Haste.Enabled")) {
  275.             if (p.hasPermission("potioneffects.haste")) {
  276.                 p.removePotionEffect(PotionEffectType.FAST_DIGGING);
  277.                 p.addPotionEffect(new PotionEffect(
  278.                         PotionEffectType.FAST_DIGGING, 288000, 2));
  279.             }
  280.         } else {
  281.             if (p.hasPermission("potioneffects.haste")) {
  282.                 p.removePotionEffect(PotionEffectType.FAST_DIGGING);
  283.             }
  284.         }
  285.         if (getConfig().getBoolean("Speed.Enabled")) {
  286.             if (p.hasPermission("potioneffects.speed")) {
  287.                 p.removePotionEffect(PotionEffectType.SPEED);
  288.                 p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,
  289.                         288000, 2));
  290.             }
  291.         } else {
  292.             if (p.hasPermission("potioneffects.speed")) {
  293.                 p.removePotionEffect(PotionEffectType.SPEED);
  294.             }
  295.         }
  296.         if (getConfig().getBoolean("Night Vision.Enabled")) {
  297.             if (p.hasPermission("potioneffects.nightvision")) {
  298.                 p.removePotionEffect(PotionEffectType.NIGHT_VISION);
  299.                 p.addPotionEffect(new PotionEffect(
  300.                         PotionEffectType.NIGHT_VISION, 288000, 0));
  301.             }
  302.         } else {
  303.             if (p.hasPermission("potioneffects.nightvision")) {
  304.                 p.removePotionEffect(PotionEffectType.NIGHT_VISION);
  305.             }
  306.         }
  307.         if (getConfig().getBoolean("Regeneration.Enabled")) {
  308.             if (p.hasPermission("potioneffects.regeneration")) {
  309.                 p.removePotionEffect(PotionEffectType.REGENERATION);
  310.                 p.addPotionEffect(new PotionEffect(
  311.                         PotionEffectType.REGENERATION, 288000, 0));
  312.             }
  313.         } else {
  314.             if (p.hasPermission("potioneffects.regeneration")) {
  315.                 p.removePotionEffect(PotionEffectType.REGENERATION);
  316.             }
  317.         }
  318.         if (getConfig().getBoolean("Water Breathing.Enabled")) {
  319.             if (p.hasPermission("potioneffects.waterbreathing")) {
  320.                 p.removePotionEffect(PotionEffectType.WATER_BREATHING);
  321.                 p.addPotionEffect(new PotionEffect(
  322.                         PotionEffectType.WATER_BREATHING, 288000, 0));
  323.             }
  324.         } else {
  325.             if (p.hasPermission("potioneffects.regeneration")) {
  326.                 p.removePotionEffect(PotionEffectType.WATER_BREATHING);
  327.             }
  328.         }
  329.         if (getConfig().getBoolean("Health Boost.Enabled")) {
  330.             if (p.hasPermission("potioneffects.healthboost")) {
  331.                 p.removePotionEffect(PotionEffectType.HEALTH_BOOST);
  332.                 p.addPotionEffect(new PotionEffect(
  333.                         PotionEffectType.HEALTH_BOOST, 288000, 1));
  334.             }
  335.         } else {
  336.             if (p.hasPermission("potioneffects.healthboost")) {
  337.                 p.removePotionEffect(PotionEffectType.HEALTH_BOOST);
  338.             }
  339.         }
  340.  
  341.     }
  342.  
  343.     @EventHandler
  344.     // Player sneaks, potion effect is added/reset
  345.     public void onPlayerSneak(PlayerToggleSneakEvent event) {
  346.         Player p = (Player) event.getPlayer();
  347.  
  348.         if (getConfig().getBoolean("Jump Boost.Enabled")) {
  349.             if (p.hasPermission("potioneffects.jumpboost")) {
  350.                 p.removePotionEffect(PotionEffectType.JUMP);
  351.                 p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP,
  352.                         288000, 3));
  353.             }
  354.         } else {
  355.             if (p.hasPermission("potioneffects.jumpboost")) {
  356.                 p.removePotionEffect(PotionEffectType.JUMP);
  357.             }
  358.         }
  359.         if (getConfig().getBoolean("Haste.Enabled")) {
  360.             if (p.hasPermission("potioneffects.haste")) {
  361.                 p.removePotionEffect(PotionEffectType.FAST_DIGGING);
  362.                 p.addPotionEffect(new PotionEffect(
  363.                         PotionEffectType.FAST_DIGGING, 288000, 2));
  364.             }
  365.         } else {
  366.             if (p.hasPermission("potioneffects.haste")) {
  367.                 p.removePotionEffect(PotionEffectType.FAST_DIGGING);
  368.             }
  369.         }
  370.         if (getConfig().getBoolean("Speed.Enabled")) {
  371.             if (p.hasPermission("potioneffects.speed")) {
  372.                 p.removePotionEffect(PotionEffectType.SPEED);
  373.                 p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,
  374.                         288000, 2));
  375.             }
  376.         } else {
  377.             if (p.hasPermission("potioneffects.speed")) {
  378.                 p.removePotionEffect(PotionEffectType.SPEED);
  379.             }
  380.         }
  381.         if (getConfig().getBoolean("Night Vision.Enabled")) {
  382.             if (p.hasPermission("potioneffects.nightvision")) {
  383.                 p.removePotionEffect(PotionEffectType.NIGHT_VISION);
  384.                 p.addPotionEffect(new PotionEffect(
  385.                         PotionEffectType.NIGHT_VISION, 288000, 0));
  386.             }
  387.         } else {
  388.             if (p.hasPermission("potioneffects.nightvision")) {
  389.                 p.removePotionEffect(PotionEffectType.NIGHT_VISION);
  390.             }
  391.         }
  392.         if (getConfig().getBoolean("Regeneration.Enabled")) {
  393.             if (p.hasPermission("potioneffects.regeneration")) {
  394.                 p.removePotionEffect(PotionEffectType.REGENERATION);
  395.                 p.addPotionEffect(new PotionEffect(
  396.                         PotionEffectType.REGENERATION, 288000, 0));
  397.             }
  398.         } else {
  399.             if (p.hasPermission("potioneffects.regeneration")) {
  400.                 p.removePotionEffect(PotionEffectType.REGENERATION);
  401.             }
  402.         }
  403.         if (getConfig().getBoolean("Water Breathing.Enabled")) {
  404.             if (p.hasPermission("potioneffects.waterbreathing")) {
  405.                 p.removePotionEffect(PotionEffectType.WATER_BREATHING);
  406.                 p.addPotionEffect(new PotionEffect(
  407.                         PotionEffectType.WATER_BREATHING, 288000, 0));
  408.             }
  409.         } else {
  410.             if (p.hasPermission("potioneffects.regeneration")) {
  411.                 p.removePotionEffect(PotionEffectType.WATER_BREATHING);
  412.             }
  413.         }
  414.         if (getConfig().getBoolean("Health Boost.Enabled")) {
  415.             if (p.hasPermission("potioneffects.healthboost")) {
  416.             }
  417.         } else {
  418.             if (p.hasPermission("potioneffects.healthboost")) {
  419.                 p.removePotionEffect(PotionEffectType.HEALTH_BOOST);
  420.             }
  421.         }
  422.     }
  423.  
  424.     @EventHandler
  425.     // Health Boost resets on player inventory open. So they get it for 4 hours
  426.     // on Join & Respawn
  427.     public void onPlayerRespawn(PlayerRespawnEvent event) {
  428.        
  429.         final Player p = (Player) event.getPlayer();
  430.  
  431.         if (getConfig().getBoolean("Health Boost.Enabled")) {
  432.             this.getServer().getScheduler()
  433.             .scheduleSyncDelayedTask(this, new Runnable() {
  434.                 public void run(){
  435.                     if (p.hasPermission("potioneffects.healthboost")) {
  436.                         p.removePotionEffect(PotionEffectType.HEALTH_BOOST);
  437.                         p.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 288000, 1));
  438.             }
  439.             }
  440.             }, 5L);
  441.            
  442.         } else {
  443.             if (p.hasPermission("potioneffects.healthboost")) {
  444.                 p.removePotionEffect(PotionEffectType.HEALTH_BOOST);
  445.             }
  446.         }
  447.     }
  448. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement