Skip to content
Snippets Groups Projects
Commit 4067dd62 authored by Zandor Smith's avatar Zandor Smith :computer:
Browse files

+ Added configurable potion effects in config.

parent 5ba48c08
No related branches found
No related tags found
No related merge requests found
......@@ -33,7 +33,7 @@
<groupId>com.zandor300</groupId>
<artifactId>ZSUtilities</artifactId>
<type>jar</type>
<version>1.8-1.0.4.3</version>
<version>1.8-1.0.4.4</version>
</dependency>
</dependencies>
......
......@@ -3,14 +3,17 @@ package com.zandor300.stonepotion;
import com.zandor300.stonepotion.commands.StonePotionCommand;
import com.zandor300.stonepotion.listeners.PlayerListener;
import com.zandor300.zsutilities.commandsystem.CommandManager;
import com.zandor300.zsutilities.config.Config;
import com.zandor300.zsutilities.utilities.Chat;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffectType;
import org.mcstats.Metrics;
import java.io.IOException;
import java.util.ArrayList;
/**
* Created by Zandor on 3/23/15.
......@@ -19,6 +22,9 @@ public class StonePotion extends JavaPlugin {
private static Chat chat = new Chat("StonePotion", ChatColor.GREEN);
private static StonePotion plugin;
private static Config config;
private static ArrayList<PotionEffectType> types = new ArrayList<PotionEffectType>();
public static Chat getChat() {
return chat;
......@@ -28,10 +34,15 @@ public class StonePotion extends JavaPlugin {
return plugin;
}
public static ArrayList<PotionEffectType> getTypes() {
return types;
}
@Override
public void onEnable() {
chat.sendConsoleMessage("Setting things up...");
config = new Config(this, "config.yml", true);
plugin = this;
PluginManager pm = Bukkit.getPluginManager();
......@@ -43,6 +54,17 @@ public class StonePotion extends JavaPlugin {
chat.sendConsoleMessage("Couldn't submit stats to MCStats.org...");
}
chat.sendConsoleMessage("Registering effects...");
for(Object effect : config.getConfig().getList("effects")) {
String effect1 = effect.toString();
PotionEffectType type = PotionEffectType.getByName(effect1);
if(type == null)
chat.sendConsoleMessage("ERROR: Effect " + effect1 + " doesn't exist in Bukkit. It will be skipped.");
else
types.add(type);
}
chat.sendConsoleMessage("Registered effects.");
chat.sendConsoleMessage("Registering events...");
pm.registerEvents(new PlayerListener(this), this);
chat.sendConsoleMessage("Registered events.");
......
......@@ -2,6 +2,7 @@ package com.zandor300.stonepotion.listeners;
import com.zandor300.stonepotion.StonePotion;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
......@@ -28,17 +29,11 @@ public class PlayerListener extends StonePotionListener {
return;
Player player = event.getPlayer();
Random random = new Random();
int rand = random.nextInt(3);
int rand = random.nextInt(StonePotion.getTypes().size());
int time = 60 + random.nextInt(60);
if(rand == 0) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, time * 20, 1));
StonePotion.getChat().sendMessage(player, "You have been rewarded with SPEED for " + time + " seconds.");
} else if(rand == 1) {
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, time * 20, 1));
StonePotion.getChat().sendMessage(player, "You have been rewarded with NIGHT VISION for " + time + " seconds.");
} else if(rand == 2) {
player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, time * 20, 1));
StonePotion.getChat().sendMessage(player, "You have been rewarded with FIRE RESISTANCE for " + time + " seconds.");
}
player.addPotionEffect(new PotionEffect(StonePotion.getTypes().get(rand), time * 20, 1));
player.playSound(player.getLocation(), Sound.CLICK, 1, 1);
StonePotion.getChat().sendMessage(player, "You have been rewarded with " +
StonePotion.getTypes().get(rand).getName() + " for " + time + " seconds.");
}
}
effects:
- SPEED
- NIGHT_VISION
- FIRE_RESISTANCE
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment