Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.voxelmc.donorvote;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Random;
- import org.bukkit.Bukkit;
- import org.bukkit.World;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.java.JavaPlugin;
- public class DonorVote extends JavaPlugin {
- public void onEnable() {
- loadConfiguration();
- }
- public boolean onCommand(CommandSender sender, Command cmd,
- String label, String[] args) {
- if (cmd.getLabel().equalsIgnoreCase("startvote")) {
- if (sender.hasPermission("donorvote.startvote")) {
- String type = "type";
- if (args[1] == "weather") {
- this.getConfig().addDefault(type, "weather");
- this.getConfig().addDefault("sun", 0);
- this.getConfig().addDefault("rain", 0);
- String[] players = { };
- this.getConfig().addDefault("players", Arrays.asList(players));
- sender.sendMessage("§3Vote started for weather.");
- Bukkit.broadcast("§5There is now a vote for weather. Use the /donorvote command and then sun or rain to vote.", "donorvote.vote");
- this.getConfig().options().copyDefaults(true);
- this.saveConfig();
- try {
- Thread.sleep(60000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- Bukkit.broadcast("§5The vote for weather has now stopped.", "donorvote.vote");
- int sun = this.getConfig().getInt("sun");
- int rain = this.getConfig().getInt("rain");
- if (sun > rain) {
- World w = ((Player) sender).getWorld();
- w.setThundering(false);
- w.setStorm(false);
- Random rand = new Random();
- w.setWeatherDuration(rand.nextInt(100000));
- } else {
- World w = ((Player) sender).getWorld();
- w.setThundering(true);
- w.setStorm(true);
- }
- return true;
- } else if (args[1] == "time") {
- this.getConfig().addDefault(type, args[1]);
- this.getConfig().addDefault("day", 0);
- this.getConfig().addDefault("night", 0);
- String[] players = { };
- this.getConfig().addDefault("players", Arrays.asList(players));
- sender.sendMessage("§3Vote started for time.");
- Bukkit.broadcast("§5There is now a vote for time. Use the /donorvote command, and then day or night to vote.", "donorvote.vote");
- this.getConfig().options().copyDefaults(true);
- this.saveConfig();
- try {
- Thread.sleep(60000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- Bukkit.broadcast("§5The vote for time has now stopped.", "donorvote.vote");
- int day = this.getConfig().getInt("day");
- int night = this.getConfig().getInt("night");
- World w = ((Player) sender).getWorld();
- if (day > night) {
- w.setTime(1000);
- } else {
- w.setTime(12000);
- }
- return true;
- } else {
- sender.sendMessage("§4Please enter a valid vote type.");
- return false;
- }
- } else {
- sender.sendMessage("§4Sorry, you do not have permission to run this command.");
- return false;
- }
- } else if (cmd.getLabel().equalsIgnoreCase("donorvote")) {
- if (sender.hasPermission("donorvote.vote")) {
- if (sender instanceof Player) {
- String strSender = sender.getName();
- List playersList = this.getConfig().getStringList("players");
- String[] playerArray = new String[playersList.size()];
- playersList.toArray(playerArray);
- String userName = "";
- int i = 0;
- while (userName != null) {
- userName = playerArray[i];
- if (userName == sender.getName()) {
- sender.sendMessage("§4Sorry, you already voted for this.");
- return false;
- }
- i = i + 1;
- }
- String type = this.getConfig().getString("type");
- if (type == "weather") {
- if (args[1] == "sun") {
- int pastSun = this.getConfig().getInt("sun");
- int nowSun = pastSun + 1;
- this.getConfig().set("sun", nowSun);
- String name = sender.getName();
- List playerList = this.getConfig().getStringList("players");
- playerList.add(name);
- this.getConfig().set("players", playerList);
- sender.sendMessage("§2Your vote has been casted!");
- return true;
- } else if (args[1] == "rain") {
- int pastRain = this.getConfig().getInt("rain");
- int nowRain = pastRain + 1;
- this.getConfig().set("rain", nowRain);
- String name = sender.getName();
- List playerList = this.getConfig().getStringList("players");
- playerList.add(name);
- this.getConfig().set("players", playerList);
- sender.sendMessage("§2Your vote has been casted!");
- return true;
- } else {
- sender.sendMessage("§4" + args[1] + " is not a valid vote.");
- return false;
- }
- } else {
- if (args[1] == "day") {
- int pastDay = this.getConfig().getInt("day");
- int nowDay = pastDay + 1;
- this.getConfig().set("day", nowDay);
- String name = sender.getName();
- List playerList = this.getConfig().getStringList("players");
- playerList.add(name);
- this.getConfig().set("players", playerList);
- sender.sendMessage("§2Your vote has been casted!");
- return true;
- } else if (args[1] == "night") {
- int pastNight = this.getConfig().getInt("night");
- int nowNight = pastNight + 1;
- this.getConfig().set("night", nowNight);
- String name = sender.getName();
- List playerList = this.getConfig().getStringList("players");
- playerList.add(name);
- this.getConfig().set("players", playerList);
- sender.sendMessage("§2Your vote has been casted!");
- return true;
- } else {
- sender.sendMessage("§4" + args[1] + " is not a valid argument.");
- return false;
- }
- }
- } else {
- return false;
- }
- } else {
- sender.sendMessage("§4Sorry, you do not have permission to use this command.");
- return false;
- }
- } else {
- return false;
- }
- }
- public void loadConfiguration() {
- this.getConfig().options().copyDefaults(true);
- this.saveConfig();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement