Skip to content

Instantly share code, notes, and snippets.

@AskAlice

AskAlice/commandRequest.java Secret

Created Jan 23, 2013
Embed
What would you like to do?
package org.terrorsquad.commandRequest;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import javax.net.ssl.HttpsURLConnection;
import org.bukkit.command.*;
import org.bukkit.entity.Player;
import org.bukkit.event.*;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
@SuppressWarnings("unused")
public class commandRequest extends JavaPlugin {
public List<String> commands;
public List<String> confirmed;
public String prefix = "§f[§aTerrorSquad§f]§3";
public static String commandfix;
public String welcomeMessage;
public static String apiURL;
public static Boolean apiBool = false;
public void onEnable(){
// TODO Insert logic to be performed when the plugin is enabled
getLogger().info("[TerrorSquad] Forum Confirm loading...");
this.saveDefaultConfig();
commands = this.getConfig().getStringList("commandRequest.commands");
welcomeMessage = this.getConfig().getString("commandRequest.welcomeMessage");
confirmed = this.getConfig().getStringList("commandRequest.confirmed");
apiURL = this.getConfig().getString("commandRequest.apiURL");
if(commands.isEmpty() || welcomeMessage.isEmpty()){
getLogger().info("[TerrorSquad] Please check your config file for forum confirm. One of the values(commandRequest.commands or commandRequest.welcomeMessage) is not found.");
getLogger().info("[TerrorSquad] Remember that the YML config file is case sensitive, and deleting the file will give you the default.");
}
getLogger().info("[TerrorSquad] Loading complete.");
}
@Override
public void onDisable() {
// TODO Insert logic to be performed when the plugin is disabled
this.saveConfig();
}
public static boolean apiCheck(String player, String key) throws Exception{
URL url = new URL(apiURL.replace("$p", player).replace("$k", key));
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
if(in.toString().toLowerCase().contains("confirmed")){
return true;
}else{
return false;
}
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
if(cmd.getName().equalsIgnoreCase("fconfirm")){ // If the player typed /fconfirm then do the following...
if (!(sender instanceof Player)) {
sender.sendMessage("This command can only be run by a player.");
} else {
Player player = (Player) sender;
if(args.length != 1){
sender.sendMessage(new StringBuilder().append(prefix).append("Not enough or too many aruments. Correct Syntax: §f/§afconfirm §f<§asecretkey§f>§3").toString());
return true;
}
if(confirmed.contains(player.getName())){
sender.sendMessage(new StringBuilder().append(prefix).append("You have already been confirmed! If you are having a problem please take it up with an admin.").toString());
return true;
}
sender.sendMessage(new StringBuilder().append(prefix).append("Attempting to confirm you with the forums...").toString());
try {
boolean apiBool = apiCheck(player.getName(), args[0]);
} catch (Exception e) {
this.getLogger().info("Forum Confirm encountered an error sending a request to the server");
e.printStackTrace();
return true;
}
if(apiBool = false){
sender.sendMessage(new StringBuilder().append(prefix).append("Error! Bad Secret Key or Username match. Please try again or check with an admin.").toString());
return true;
}
getLogger().info(commands.toString());
for(String command : commands){
commandfix = command.replace("$p", sender.getName());
if(commandfix.startsWith("/")){
commandfix = commandfix.substring(1);
}
getServer().dispatchCommand(getServer().getConsoleSender(), commandfix);
}
sender.sendMessage(new StringBuilder().append(prefix).append("Sucessfully Confirmed!").toString());
player.getServer().broadcastMessage(new StringBuilder().append(prefix).append(welcomeMessage.replace("$p", sender.getName())).toString());
String name = sender.getName();
confirmed.add(name);
this.getConfig().set("commandRequest.confirmed", confirmed);
this.saveConfig();
}
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.