Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.YourMCAdmin.LegitLandPotionEffects;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.event.player.PlayerRespawnEvent;
- import org.bukkit.event.player.PlayerToggleSneakEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.potion.PotionEffect;
- import org.bukkit.potion.PotionEffectType;
- public class LLPotionEffects extends JavaPlugin implements Listener{
- @Override
- public void onEnable() {
- getLogger().info("[LegitLand Potion Effects] has been enabled.");
- initialiseConfig(); // initialise the config
- Bukkit.getPluginManager().registerEvents(this, this);
- }
- private void initialiseConfig() {
- FileConfiguration config = getConfig(); // creates variable "config" for
- // getConfig.
- config.addDefault("Jump Boost.Enabled", false);
- config.addDefault("Night Vision.Enabled", false);
- config.addDefault("Haste.Enabled", false);
- config.addDefault("Speed.Enabled", false);
- config.addDefault("Regeneration.Enabled", false);
- config.addDefault("Health Boost.Enabled", false);
- config.addDefault("Water Breathing.Enabled", false);
- config.options().copyDefaults(true); // If true then the values will be
- // added to the config if they
- // weren't already
- saveConfig(); // Creates the config
- }
- public void onDisable() {
- saveConfig();
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label,
- String[] args) {
- if (sender.hasPermission("potioneffects.toggle")) {
- if (cmd.getName().equalsIgnoreCase("LLPotion")) {
- if (args.length > 1) {
- sender.sendMessage(ChatColor.RED + "Too many arguments!");
- return true;
- }
- if (args.length < 1) {
- sender.sendMessage(ChatColor.RED + "Proper use: /LLPotion (JumpBoost, HealthBoost, Haste, Regeneration, Speed, NightVision");
- return true;
- }
- if (args.length == 1) {
- //List which ones are enabled
- if (args[0].equalsIgnoreCase("list")) {
- if (getConfig().getBoolean("Jump Boost.Enabled") == true) {
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Jump Boost Enabled");
- }
- if (getConfig().getBoolean("Health Boost.Enabled") == true) {
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Health Boost Enabled");
- }
- if (getConfig().getBoolean("Regeneration.Enabled") == true) {
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Regeneration Enabled");
- }
- if (getConfig().getBoolean("Haste.Enabled") == true) {
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Haste Enabled");
- }
- if (getConfig().getBoolean("Speed.Enabled") == true) {
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Speed Enabled");
- }
- if (getConfig().getBoolean("Night Vision.Enabled") == true) {
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Night Vision Enabled");
- }
- if (getConfig().getBoolean("Water Breathing.Enabled") == true) {
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Water Breathing Enabled");
- }else{
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "No potion effects currently enabled!");
- }
- return true;
- }
- //jump boost toggle
- if (args[0].equalsIgnoreCase("JumpBoost")) {
- if (getConfig().getBoolean("Jump Boost.Enabled") == true) {
- getConfig().set("Jump Boost.Enabled", false);
- saveConfig();
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Jump Boost Disabled");
- } else if (getConfig().getBoolean("Jump Boost.Enabled") == false) {
- getConfig().set("Jump Boost.Enabled", true);
- saveConfig();
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Jump Boost Enabled");
- }
- //health boost toggle
- }else if (args[0].equalsIgnoreCase("HealthBoost")) {
- if (getConfig().getBoolean("Health Boost.Enabled") == true) {
- getConfig().set("Health Boost.Enabled", false);
- saveConfig();
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Health Boost Disabled");
- } else if (getConfig().getBoolean("Health Boost.Enabled") == false) {
- getConfig().set("Health Boost.Enabled", true);
- saveConfig();
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Health Boost Enabled");
- }
- //speed toggle
- }else if (args[0].equalsIgnoreCase("Speed")) {
- if (getConfig().getBoolean("Speed.Enabled") == true) {
- getConfig().set("Speed.Enabled", false);
- saveConfig();
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Speed Disabled");
- } else if (getConfig().getBoolean("Speed.Enabled") == false) {
- getConfig().set("Speed.Enabled", true);
- saveConfig();
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Speed Enabled");
- }
- //nightvision toggle
- }else if (args[0].equalsIgnoreCase("Nightvision")) {
- if (getConfig().getBoolean("Night Vision.Enabled") == true) {
- getConfig().set("Night Vision.Enabled", false);
- saveConfig();
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Night Vision Disabled");
- } else if (getConfig().getBoolean("Night Vision.Enabled") == false) {
- getConfig().set("Night Vision.Enabled", true);
- saveConfig();
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Night Vision Enabled");
- }
- //regen toggle
- }else if (args[0].equalsIgnoreCase("Regeneration")) {
- if (getConfig().getBoolean("Regeneration.Enabled") == true) {
- getConfig().set("Regeneration.Enabled", false);
- saveConfig();
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Regeneration Disabled");
- } else if (getConfig().getBoolean("Regeneration.Enabled") == false) {
- getConfig().set("Regeneration.Enabled", true);
- saveConfig();
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Regeneration Enabled");
- }
- //waterbreathing toggle
- }else if (args[0].equalsIgnoreCase("WaterBreathing")) {
- if (getConfig().getBoolean("Water Breathing.Enabled") == true) {
- getConfig().set("Water Breathing.Enabled", false);
- saveConfig();
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Water Breathing Disabled");
- } else if (getConfig().getBoolean("Water Breathing.Enabled") == false) {
- getConfig().set("Water Breathing.Enabled", true);
- saveConfig();
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Water Breathing Enabled");
- }
- //haste toggle
- }else if (args[0].equalsIgnoreCase("Haste")) {
- if (getConfig().getBoolean("Haste.Enabled") == true) {
- getConfig().set("Haste.Enabled", false);
- saveConfig();
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Haste Disabled");
- } else if (getConfig().getBoolean("Haste.Enabled") == false) {
- getConfig().set("Haste.Enabled", true);
- saveConfig();
- sender.sendMessage(ChatColor.GREEN
- + "[LegitPotionEffects] " + ChatColor.RED
- + "Haste Enabled");
- }
- }else{
- sender.sendMessage(ChatColor.GREEN + "[LegitPotionEffects] " + ChatColor.RED + "Incorrect Potion Effect");
- }
- return true;
- }
- }
- }
- Player p = (Player) sender;
- if (cmd.getName().equalsIgnoreCase("pot")) {
- if (args.length > 1) {
- sender.sendMessage(ChatColor.RED + "Too many arguments, maaan! Chill out, dude. Are you a cop?");
- return true;
- }
- if (args.length == 0) {
- p.removePotionEffect(PotionEffectType.CONFUSION);
- p.addPotionEffect(new PotionEffect(
- PotionEffectType.CONFUSION, 600, 0));
- sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Wooaaaaaah... Duuuude... I'm sooooo high right now....");
- return true;
- }
- }
- return true;
- }
- @EventHandler
- // player joins and gets potion effects
- public void onJoin(PlayerJoinEvent event) {
- Player p = event.getPlayer();
- if (getConfig().getBoolean("Jump Boost.Enabled")) {
- if (p.hasPermission("potioneffects.jumpboost")) {
- p.removePotionEffect(PotionEffectType.JUMP);
- p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP,
- 288000, 3));
- }
- } else {
- if (p.hasPermission("potioneffects.jumpboost")) {
- p.removePotionEffect(PotionEffectType.JUMP);
- }
- }
- if (getConfig().getBoolean("Haste.Enabled")) {
- if (p.hasPermission("potioneffects.haste")) {
- p.removePotionEffect(PotionEffectType.FAST_DIGGING);
- p.addPotionEffect(new PotionEffect(
- PotionEffectType.FAST_DIGGING, 288000, 2));
- }
- } else {
- if (p.hasPermission("potioneffects.haste")) {
- p.removePotionEffect(PotionEffectType.FAST_DIGGING);
- }
- }
- if (getConfig().getBoolean("Speed.Enabled")) {
- if (p.hasPermission("potioneffects.speed")) {
- p.removePotionEffect(PotionEffectType.SPEED);
- p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,
- 288000, 2));
- }
- } else {
- if (p.hasPermission("potioneffects.speed")) {
- p.removePotionEffect(PotionEffectType.SPEED);
- }
- }
- if (getConfig().getBoolean("Night Vision.Enabled")) {
- if (p.hasPermission("potioneffects.nightvision")) {
- p.removePotionEffect(PotionEffectType.NIGHT_VISION);
- p.addPotionEffect(new PotionEffect(
- PotionEffectType.NIGHT_VISION, 288000, 0));
- }
- } else {
- if (p.hasPermission("potioneffects.nightvision")) {
- p.removePotionEffect(PotionEffectType.NIGHT_VISION);
- }
- }
- if (getConfig().getBoolean("Regeneration.Enabled")) {
- if (p.hasPermission("potioneffects.regeneration")) {
- p.removePotionEffect(PotionEffectType.REGENERATION);
- p.addPotionEffect(new PotionEffect(
- PotionEffectType.REGENERATION, 288000, 0));
- }
- } else {
- if (p.hasPermission("potioneffects.regeneration")) {
- p.removePotionEffect(PotionEffectType.REGENERATION);
- }
- }
- if (getConfig().getBoolean("Water Breathing.Enabled")) {
- if (p.hasPermission("potioneffects.waterbreathing")) {
- p.removePotionEffect(PotionEffectType.WATER_BREATHING);
- p.addPotionEffect(new PotionEffect(
- PotionEffectType.WATER_BREATHING, 288000, 0));
- }
- } else {
- if (p.hasPermission("potioneffects.regeneration")) {
- p.removePotionEffect(PotionEffectType.WATER_BREATHING);
- }
- }
- if (getConfig().getBoolean("Health Boost.Enabled")) {
- if (p.hasPermission("potioneffects.healthboost")) {
- p.removePotionEffect(PotionEffectType.HEALTH_BOOST);
- p.addPotionEffect(new PotionEffect(
- PotionEffectType.HEALTH_BOOST, 288000, 1));
- }
- } else {
- if (p.hasPermission("potioneffects.healthboost")) {
- p.removePotionEffect(PotionEffectType.HEALTH_BOOST);
- }
- }
- }
- @EventHandler
- // Player sneaks, potion effect is added/reset
- public void onPlayerSneak(PlayerToggleSneakEvent event) {
- Player p = (Player) event.getPlayer();
- if (getConfig().getBoolean("Jump Boost.Enabled")) {
- if (p.hasPermission("potioneffects.jumpboost")) {
- p.removePotionEffect(PotionEffectType.JUMP);
- p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP,
- 288000, 3));
- }
- } else {
- if (p.hasPermission("potioneffects.jumpboost")) {
- p.removePotionEffect(PotionEffectType.JUMP);
- }
- }
- if (getConfig().getBoolean("Haste.Enabled")) {
- if (p.hasPermission("potioneffects.haste")) {
- p.removePotionEffect(PotionEffectType.FAST_DIGGING);
- p.addPotionEffect(new PotionEffect(
- PotionEffectType.FAST_DIGGING, 288000, 2));
- }
- } else {
- if (p.hasPermission("potioneffects.haste")) {
- p.removePotionEffect(PotionEffectType.FAST_DIGGING);
- }
- }
- if (getConfig().getBoolean("Speed.Enabled")) {
- if (p.hasPermission("potioneffects.speed")) {
- p.removePotionEffect(PotionEffectType.SPEED);
- p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,
- 288000, 2));
- }
- } else {
- if (p.hasPermission("potioneffects.speed")) {
- p.removePotionEffect(PotionEffectType.SPEED);
- }
- }
- if (getConfig().getBoolean("Night Vision.Enabled")) {
- if (p.hasPermission("potioneffects.nightvision")) {
- p.removePotionEffect(PotionEffectType.NIGHT_VISION);
- p.addPotionEffect(new PotionEffect(
- PotionEffectType.NIGHT_VISION, 288000, 0));
- }
- } else {
- if (p.hasPermission("potioneffects.nightvision")) {
- p.removePotionEffect(PotionEffectType.NIGHT_VISION);
- }
- }
- if (getConfig().getBoolean("Regeneration.Enabled")) {
- if (p.hasPermission("potioneffects.regeneration")) {
- p.removePotionEffect(PotionEffectType.REGENERATION);
- p.addPotionEffect(new PotionEffect(
- PotionEffectType.REGENERATION, 288000, 0));
- }
- } else {
- if (p.hasPermission("potioneffects.regeneration")) {
- p.removePotionEffect(PotionEffectType.REGENERATION);
- }
- }
- if (getConfig().getBoolean("Water Breathing.Enabled")) {
- if (p.hasPermission("potioneffects.waterbreathing")) {
- p.removePotionEffect(PotionEffectType.WATER_BREATHING);
- p.addPotionEffect(new PotionEffect(
- PotionEffectType.WATER_BREATHING, 288000, 0));
- }
- } else {
- if (p.hasPermission("potioneffects.regeneration")) {
- p.removePotionEffect(PotionEffectType.WATER_BREATHING);
- }
- }
- if (getConfig().getBoolean("Health Boost.Enabled")) {
- if (p.hasPermission("potioneffects.healthboost")) {
- }
- } else {
- if (p.hasPermission("potioneffects.healthboost")) {
- p.removePotionEffect(PotionEffectType.HEALTH_BOOST);
- }
- }
- }
- @EventHandler
- // Health Boost resets on player inventory open. So they get it for 4 hours
- // on Join & Respawn
- public void onPlayerRespawn(PlayerRespawnEvent event) {
- final Player p = (Player) event.getPlayer();
- if (getConfig().getBoolean("Health Boost.Enabled")) {
- this.getServer().getScheduler()
- .scheduleSyncDelayedTask(this, new Runnable() {
- public void run(){
- if (p.hasPermission("potioneffects.healthboost")) {
- p.removePotionEffect(PotionEffectType.HEALTH_BOOST);
- p.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 288000, 1));
- }
- }
- }, 5L);
- } else {
- if (p.hasPermission("potioneffects.healthboost")) {
- p.removePotionEffect(PotionEffectType.HEALTH_BOOST);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement