Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.vilsol.challenge;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.scheduler.BukkitScheduler;
- public class Challenge extends JavaPlugin {
- private String prefix = "[" + ChatColor.RED + "Challenge" + ChatColor.WHITE + "] ";
- public void loadConfiguration(){
- this.getConfig().addDefault("Challenge.BroadcastTime", 300);
- this.getConfig().options().copyDefaults(true);
- this.saveConfig();
- }
- public void onEnable() {
- getLogger().info("Challenge by Vilsol Loaded!");
- getServer().getPluginManager().registerEvents(new ChallengeListener(), this);
- BukkitScheduler sch = Bukkit.getServer().getScheduler();
- loadConfiguration();
- int time = getConfig().getInt("Challenge.BroadcastTime");
- sch.scheduleSyncRepeatingTask(this, new Runnable(){
- @Override
- public void run() {
- ChallengeAdmin ch = new ChallengeAdmin();
- Bukkit.getServer().broadcastMessage(prefix + ch.get());
- } }, time*20, time*20);
- }
- public void onDisable() {
- getLogger().info("Challenge Unloaded!");
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
- String cmdn = cmd.getName();
- if(cmdn.equalsIgnoreCase("challenge")){
- ChallengeAdmin cha = new ChallengeAdmin();
- if(args.length >= 1){
- String sub = args[0];
- if(sub.equalsIgnoreCase("help")){
- sendHelp(sender);
- } else if(sub.equalsIgnoreCase("list") && sender.hasPermission("challenge.list")){
- cha.list(sender);
- } else if(sub.equalsIgnoreCase("suggestions") && sender.hasPermission("challenge.suggestions")){
- cha.listSuggestions(sender);
- }
- if(args.length >= 2){
- if(sub.equalsIgnoreCase("del") && sender.hasPermission("challenge.del")){
- cha.delete(args[1]);
- sender.sendMessage("Challenge deleted!");
- } else if(sub.equalsIgnoreCase("add") && sender.hasPermission("challenge.add")){
- String challenge = "";
- boolean first = true;
- for(int cz = 1; cz < args.length; cz ++){
- if(!first){
- challenge += " ";
- }
- challenge += args[cz];
- first = false;
- }
- cha.add(challenge);
- sender.sendMessage(prefix + "Challenge succesfully set!");
- } else if(sub.equalsIgnoreCase("suggest") && sender.hasPermission("challenge.suggest")){
- String suggestion = "";
- boolean first = true;
- for(int cz = 1; cz < args.length; cz ++){
- if(!first){
- suggestion += " ";
- }
- suggestion += args[cz];
- first = false;
- }
- cha.suggest(suggestion);
- sender.sendMessage(prefix + "Suggestion added!");
- } else if(sub.equalsIgnoreCase("accept") && sender.hasPermission("challenge.accept")){
- cha.accept(args[1]);
- sender.sendMessage(prefix + "Challenge has been accepted!");
- } else if(sub.equalsIgnoreCase("deny") && sender.hasPermission("challenge.deny")){
- cha.deny(args[1]);
- sender.sendMessage(prefix + "Challenge has been denied!");
- }
- }
- }else{
- sender.sendMessage(prefix + cha.get());
- }
- return true;
- }
- return false;
- }
- private void sendHelp(CommandSender sender) {
- sender.sendMessage(ChatColor.AQUA + "------------------- User Commands -------------------");
- sender.sendMessage(prefix + ChatColor.GOLD + "suggest" + ChatColor.WHITE +": Suggest a challenge!");
- sender.sendMessage(prefix + ChatColor.GOLD + "suggestions" + ChatColor.WHITE +": List all suggestions!");
- sender.sendMessage(ChatColor.AQUA + "------------------- Admin Commands ------------------");
- sender.sendMessage(prefix + ChatColor.GOLD + "add" + ChatColor.WHITE +": Adds a challenge!");
- sender.sendMessage(prefix + ChatColor.GOLD + "del" + ChatColor.WHITE +": Deletes a challenge!");
- sender.sendMessage(prefix + ChatColor.GOLD + "list" + ChatColor.WHITE +": List all challenges!");
- sender.sendMessage(prefix + ChatColor.GOLD + "accept" + ChatColor.WHITE +": Accept a suggestion!");
- sender.sendMessage(prefix + ChatColor.GOLD + "deny" + ChatColor.WHITE +": Deny a suggestion!");
- sender.sendMessage(prefix + "Example: /" + ChatColor.RED + "challenge " + ChatColor.GOLD + "add " + ChatColor.WHITE +"Make 2x2 jebdoor!");
- sender.sendMessage(ChatColor.AQUA + "-----------------------------------------------------");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement