Skip to content

Instantly share code, notes, and snippets.


AskAlice/ Secret

Created Jan 23, 2013
What would you like to do?
package org.terrorsquad.commandRequest;
import java.util.*;
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;
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...");
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.");
public void onDisable() {
// TODO Insert logic to be performed when the plugin is disabled
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)
return true;
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;
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");
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;
for(String command : commands){
commandfix = command.replace("$p", sender.getName());
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();
this.getConfig().set("commandRequest.confirmed", confirmed);
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.