Permalink
Browse files

v1.7.2_1 -> v1.7.2_4

Fix some bugs
  • Loading branch information...
hide92795
hide92795 committed Jun 28, 2014
1 parent ac50bc1 commit e8c38a23697aa1f769bebd1c901f9480d906b8b5
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -7,3 +7,4 @@ LocalCountry:
Language: jp
ProtectModeOnLaunch: true
EnableSideBar: true
AdminPlayerName:
@@ -2,68 +2,109 @@
import hide92795.bukkit.plugin.mcbansdetector.data.MCBansData;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.json.JSONObject;
public class CheckMCBansThread extends Thread {
private static final String REQUEST_URL = "http://api.mcbans.com/v2/";
private static final String REQUEST_URL = "http://api.mcbans.com/v3/";
private MCBansDetector plugin;
private String playerName;
private String player_uuid;
private String apikey;
public CheckMCBansThread(MCBansDetector mcBansDetector, String playerName) {
public CheckMCBansThread(MCBansDetector mcBansDetector, String playerName, String player_uuid) {
this.plugin = mcBansDetector;
this.playerName = playerName;
this.apikey = plugin.getConfig().getString("APIKey");
this.player_uuid = player_uuid;
this.apikey = plugin.getConfig().getString("APIKey").trim();
}
@Override
public void run() {
OutputStreamWriter wr = null;
BufferedReader reader = null;
try {
URL url = new URL(REQUEST_URL + apikey);
URLConnection uc = url.openConnection();
uc.setConnectTimeout(5000);
uc.setReadTimeout(5000);
uc.setDoOutput(true);
OutputStream os = uc.getOutputStream();// POST用のOutputStreamを取得
wr = new OutputStreamWriter(uc.getOutputStream());// POST用のOutputStreamWriterを取得
String postStr = "exec=playerLookup&player=" + playerName;// POSTするデータ
PrintStream ps = new PrintStream(os);
ps.print(postStr);// データをPOSTする
ps.close();
String postStr = createPostData();
InputStream is = uc.getInputStream();// POSTした結果を取得
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
wr.write(postStr);
wr.flush();
reader = new BufferedReader(new InputStreamReader(uc.getInputStream()));
StringBuilder sb = new StringBuilder();
String s;
while ((s = reader.readLine()) != null) {
JSONObject json = new JSONObject(s);
int totalBan = (Integer) json.get("total");
int reputation = (Integer) json.get("reputation");
String date = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date());
final MCBansData data = new MCBansData(date, playerName, totalBan, reputation);
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
plugin.resultMCBans(playerName, data);
}
});
break;
sb.append(s);
}
reader.close();
JSONObject json = new JSONObject(sb.toString());
int totalBan = (Integer) json.get("total");
double reputation = Double.parseDouble(json.get("reputation").toString());
String date = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date());
final MCBansData data = new MCBansData(date, playerName, totalBan, reputation);
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
plugin.resultMCBans(playerName, data);
}
});
} catch (Exception e) {
e.printStackTrace();
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
plugin.errorOnMCBans(playerName);
}
});
} finally {
if (wr != null) {
try {
wr.close();
} catch (Exception e) {
}
}
if (reader != null) {
try {
reader.close();
} catch (Exception e) {
}
}
}
}
private String createPostData() throws UnsupportedEncodingException {
StringBuilder sb = new StringBuilder();
sb.append(URLEncoder.encode("exec", "UTF-8"));
sb.append("=");
sb.append(URLEncoder.encode("playerLookup", "UTF-8"));
sb.append("&");
sb.append(URLEncoder.encode("player", "UTF-8"));
sb.append("=");
sb.append(URLEncoder.encode(playerName, "UTF-8"));
sb.append("&");
sb.append(URLEncoder.encode("player_uuid", "UTF-8"));
sb.append("=");
sb.append(URLEncoder.encode(player_uuid, "UTF-8"));
sb.append("&");
sb.append(URLEncoder.encode("admin", "UTF-8"));
sb.append("=");
sb.append(URLEncoder.encode(plugin.admin.getName(), "UTF-8"));
return sb.toString();
}
}
@@ -22,6 +22,7 @@
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -42,6 +43,8 @@
public boolean enableProtect;
private boolean enableSideBar;
private SideBarManager sidebar;
public OfflinePlayer admin;
public boolean valid_config;
@Override
public void onEnable() {
@@ -204,6 +207,7 @@ private void reload() throws Exception {
enableProtect = getConfig().getBoolean("ProtectModeOnLaunch");
enableSideBar = getConfig().getBoolean("EnableSideBar");
countryList = getConfig().getStringList("Country");
admin = getServer().getOfflinePlayer(getConfig().getString("AdminPlayerName"));
if (countryList == null) {
countryList = new ArrayList<>();
getConfig().set("Country", countryList);
@@ -218,6 +222,20 @@ private void reload() throws Exception {
sb1.delete(sb1.length() - 2, sb1.length() - 1);
logger.info(sb1.toString());
createUsage();
checkValidConfig();
}
private void checkValidConfig() {
valid_config = false;
if (getConfig().getString("APIKey").trim().length() == 40) {
if (admin != null) {
valid_config = true;
} else {
logger.warning(localize.getString(Type.INVALID_ADMIN_NAME));
}
} else {
logger.warning(localize.getString(Type.INVALID_API_KEY));
}
}
private void sendData(CommandSender sender, Data data) {
@@ -291,9 +309,9 @@ private void sendListPage(CommandSender sender, int page) {
}
public void checkMCBans(String playerName) {
logger.info("Starting to check \"" + playerName + "\" from MCBans");
getServer().getScheduler().runTask(this, new CheckMCBansThread(this, playerName));
public void checkMCBans(Player player) {
logger.info("Starting to check \"" + player.getName() + "\" from MCBans");
getServer().getScheduler().runTask(this, new CheckMCBansThread(this, player.getName(), player.getUniqueId().toString()));
}
public synchronized void resultMCBans(String playerName, MCBansData data) {
@@ -3,14 +3,12 @@
import hide92795.bukkit.plugin.corelib.Localizable;
public enum Type implements Localizable {
BLOCK_BREAK_MESSAGE("BlockBreakMessage"), PAGE("Page"), SHOW_LIST("ShowList"), SHOW_DETAIL("ShowDetail"), TOGGLE_PROTECT("ToggleProtect"), RELOAD_SETTING(
"ReloadSetting"), NOT_FOUND_ID("NotFoundID"), NOT_FOUND_PAGE("NotFoundPage"), ENABLE_PROTECT("EnableProtect"), DISABLE_PROTECT(
"DisableProtect"), RELOADED_SETTING("ReloadedSetting"), ERROR_RELOAD_SETTING("ErrorReloadSetting"), GET_NEXT_PAGE("GetNextPage"), NO_WARN_PLAYER_LOGIN(
"NoWarnPlayerLogin"), WARN_PLAYER_LOGIN("WarnPlayerLogin"), PLEASE_CHECK_DETAIL("PleaseCheckDetail"), CURRENT_LOGIN_WARN_PLAYER(
"CurrentLoginWarnPlayer"), LOGIN_BANED_PLAYER("LoginBanedPlayer"), PLAYERNAME("PlayerName"), BAN_COUNT("BanCount"), CANT_GET_BANDATA(
"CantGetBanData"), PLEASE_CHECK_MANUALLY("PleaseCheckManually"), CONNTCT_FROM_WARN_COUNTRY("ConntctFromWarnCountry"), IP_ADDRESS(
"IPAddress"), CONNECT_FROM("ConnectFrom"), LAST_CONNECTION("LastConnection"), WARN_PLAYER("WarnPlayer"), SIDEBAR_PLAYER_NAME(
"SideBarPlayerName");
BLOCK_BREAK_MESSAGE("BlockBreakMessage"), PAGE("Page"), SHOW_LIST("ShowList"), SHOW_DETAIL("ShowDetail"), TOGGLE_PROTECT("ToggleProtect"), RELOAD_SETTING("ReloadSetting"), NOT_FOUND_ID(
"NotFoundID"), NOT_FOUND_PAGE("NotFoundPage"), ENABLE_PROTECT("EnableProtect"), DISABLE_PROTECT("DisableProtect"), RELOADED_SETTING("ReloadedSetting"), ERROR_RELOAD_SETTING(
"ErrorReloadSetting"), GET_NEXT_PAGE("GetNextPage"), NO_WARN_PLAYER_LOGIN("NoWarnPlayerLogin"), WARN_PLAYER_LOGIN("WarnPlayerLogin"), PLEASE_CHECK_DETAIL("PleaseCheckDetail"), CURRENT_LOGIN_WARN_PLAYER(
"CurrentLoginWarnPlayer"), LOGIN_BANED_PLAYER("LoginBanedPlayer"), PLAYERNAME("PlayerName"), BAN_COUNT("BanCount"), CANT_GET_BANDATA("CantGetBanData"), PLEASE_CHECK_MANUALLY(
"PleaseCheckManually"), CONNTCT_FROM_WARN_COUNTRY("ConntctFromWarnCountry"), IP_ADDRESS("IPAddress"), CONNECT_FROM("ConnectFrom"), LAST_CONNECTION("LastConnection"), WARN_PLAYER(
"WarnPlayer"), SIDEBAR_PLAYER_NAME("SideBarPlayerName"), INVALID_API_KEY("InvalidAPIKey"), INVALID_ADMIN_NAME("InvalidAdminName"), INVALID_CONFIG("InvalidAPIKey");
private final String type;
private Type(String type) {
@@ -6,9 +6,9 @@
public class MCBansData extends Data {
private final int totalBan;
private final int reputation;
private final double reputation;
public MCBansData(String date, String name, int totalBan, int reputation) {
public MCBansData(String date, String name, int totalBan, double reputation) {
super(date, name);
this.totalBan = totalBan;
this.reputation = reputation;
@@ -33,7 +33,7 @@ public int getTotalBan() {
return totalBan;
}
public int getReputation() {
public double getReputation() {
return reputation;
}
@@ -1,6 +1,7 @@
package hide92795.bukkit.plugin.mcbansdetector.listener;
import hide92795.bukkit.plugin.mcbansdetector.MCBansDetector;
import hide92795.bukkit.plugin.mcbansdetector.Type;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -26,8 +27,13 @@ public void onPlayerJoin(PlayerJoinEvent event) {
return;
}
if (!plugin.valid_config) {
plugin.getLogger().warning(String.format(plugin.localize.getString(Type.INVALID_CONFIG), playerName));
return;
}
// IPcheck
plugin.checkCountry(player);
plugin.checkMCBans(playerName);
plugin.checkMCBans(player);
}
}
@@ -25,7 +25,10 @@ public void update() {
Player[] players = plugin.getServer().getOnlinePlayers();
for (Player player : players) {
if (player.hasPermission("mcbansdetector.sidebar") || player.isOp()) {
player.setScoreboard(scoreboard);
try {
player.setScoreboard(scoreboard);
} catch (Exception e) {
}
}
}
}
@@ -25,4 +25,7 @@ IPAddress: "&cIPアドレス:&e%1$s"
ConnectFrom: "&c接続元:&e%1$s"
LastConnection: "&c最終接続日時:&e%1$s"
WarnPlayer: "&c警戒プレイヤー"
SideBarPlayerName: "&e%1$s:"
SideBarPlayerName: "&e%1$s:"
InvalidAPIKey: "APIキーが正しく設定されていません!"
InvalidAdminName: "AdminPlayerNameが正しく設定されていません!"
InvalidConfig: "設定に不備があるため &1$s の検査をパスしました。"
@@ -1,6 +1,6 @@
name: MCBansDetector
main: hide92795.bukkit.plugin.mcbansdetector.MCBansDetector
version: 1.7.2_1
version: 1.7.2_4
description: Check baned player
author: hide92795
depend: [hide92795CoreLib]

0 comments on commit e8c38a2

Please sign in to comment.