Move to T2Code Git
This commit is contained in:
67
src/main/java/de/jatitv/opsecurity/system/Load.java
Normal file
67
src/main/java/de/jatitv/opsecurity/system/Load.java
Normal file
@@ -0,0 +1,67 @@
|
||||
// This claas was created by JaTiTV
|
||||
|
||||
package de.jatitv.opsecurity.system;
|
||||
|
||||
import de.jatitv.opsecurity.config.config.ConfigConvert;
|
||||
import de.jatitv.opsecurity.config.config.CreateConfig;
|
||||
import de.jatitv.opsecurity.config.languages.LanguagesCreate;
|
||||
import de.jatitv.opsecurity.config.languages.SelectMessages;
|
||||
import de.jatitv.opsecurity.config.config.SelectConfig;
|
||||
import de.jatitv.opsecurity.listener.Timer;
|
||||
import de.jatitv.opsecurity.util.send;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Load {
|
||||
public static void onLoad(String Prefix, List Autor, String Version, String Spigot, String Discord) {
|
||||
send.console(Prefix + " §2-------------- §2OP§4Security §2--------------");
|
||||
send.console(Prefix + " §2Autor: §6JaTiTV");
|
||||
send.console(Prefix + " §2Version: §6" + Version);
|
||||
send.console(Prefix + " §2Spigot: §6" + Spigot);
|
||||
send.console(Prefix + " §2Discord: §6" + Discord);
|
||||
send.console(Prefix + " §2");
|
||||
send.console(Prefix + " §4Plugin load...");
|
||||
send.console(Prefix + " §8-------------------------------");
|
||||
loadReload();
|
||||
send.console(Prefix + " §8-------------------------------");
|
||||
send.console(Prefix + " §2Plugin loaded successfully.");
|
||||
send.console(Prefix + " §2-----------------------------------------");
|
||||
}
|
||||
|
||||
public static void loadReload() {
|
||||
|
||||
ConfigConvert.convert();
|
||||
|
||||
try {
|
||||
CreateConfig.configCreate();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
SelectConfig.onSelect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
LanguagesCreate.messagesCreate();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
SelectMessages.selectCreate(Main.Prefix);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
SelectConfig.sound();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
Timer.RefreshTimer();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
105
src/main/java/de/jatitv/opsecurity/system/Main.java
Normal file
105
src/main/java/de/jatitv/opsecurity/system/Main.java
Normal file
@@ -0,0 +1,105 @@
|
||||
package de.jatitv.opsecurity.system;
|
||||
|
||||
import de.jatitv.opsecurity.cmdManagement.CmdExecuter;
|
||||
import de.jatitv.opsecurity.config.config.SelectConfig;
|
||||
import de.jatitv.opsecurity.listener.Events;
|
||||
import de.jatitv.opsecurity.listener.OPCommand;
|
||||
import de.jatitv.opsecurity.listener.PlugManCommand;
|
||||
import de.jatitv.opsecurity.objects.PlayerObject;
|
||||
import de.jatitv.opsecurity.util.Metrics;
|
||||
import de.jatitv.opsecurity.util.UpdateChecker;
|
||||
import de.jatitv.opsecurity.util.send;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public final class Main extends JavaPlugin {
|
||||
|
||||
|
||||
// Debug Settings
|
||||
|
||||
public static Boolean Bstats = true;
|
||||
|
||||
public static String Prefix = "§8[§2OP§4Security§8]";
|
||||
|
||||
public static List<String> Autor;
|
||||
public static Integer SpigotID = 90739;
|
||||
public static Integer BstatsID = 10858;
|
||||
public static String Spigot = "https://spigotmc.org/resources/" + SpigotID;
|
||||
public static String Discord = "http://dc.t2code.net";
|
||||
|
||||
|
||||
// ---------------------------------------------
|
||||
|
||||
public static String Version;
|
||||
|
||||
public static Main plugin;
|
||||
public static String update_version = null;
|
||||
|
||||
public static boolean minecraft1_8;
|
||||
public static boolean minecraft1_9;
|
||||
public static boolean minecraft1_10;
|
||||
public static boolean minecraft1_11;
|
||||
public static boolean minecraft1_12;
|
||||
|
||||
public static File getPath() {
|
||||
return plugin.getDataFolder();
|
||||
}
|
||||
|
||||
public static HashMap<String, PlayerObject> opHashMap = new HashMap<String, PlayerObject>();
|
||||
public static HashMap<String, PlayerObject> permissionHashMap = new HashMap<String, PlayerObject>();
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
Logger logger = this.getLogger();
|
||||
plugin = this;
|
||||
|
||||
Autor = plugin.getDescription().getAuthors();
|
||||
Version = plugin.getDescription().getVersion();
|
||||
|
||||
minecraft1_8 = Bukkit.getServer().getClass().getPackage().getName().contains("1_8");
|
||||
minecraft1_9 = Bukkit.getServer().getClass().getPackage().getName().contains("1_9");
|
||||
minecraft1_10 = Bukkit.getServer().getClass().getPackage().getName().contains("1_10");
|
||||
minecraft1_11 = Bukkit.getServer().getClass().getPackage().getName().contains("1_11");
|
||||
minecraft1_12 = Bukkit.getServer().getClass().getPackage().getName().contains("1_12");
|
||||
|
||||
Load.onLoad(Prefix, Autor, Version, Spigot, Discord);
|
||||
|
||||
getCommand("opsecurity").setExecutor(new CmdExecuter());
|
||||
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new Events(), this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new OPCommand(), this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new PlugManCommand(), this);
|
||||
// Bukkit.getServer().getPluginManager().registerEvents(new LPCommand(), this);
|
||||
|
||||
|
||||
if (Main.Bstats) {
|
||||
int pluginId = BstatsID; // <-- Replace with the id of your plugin!
|
||||
Metrics metrics = new Metrics(this, pluginId);
|
||||
metrics.addCustomChart(new Metrics.SimplePie("updatecheckonjoin", () -> String.valueOf(SelectConfig.UpdateCheckOnJoin)));
|
||||
} else {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Bukkit.getConsoleSender().sendMessage(Main.Prefix + "§4\n" + Main.Prefix + "§4Bstats is disabled!");
|
||||
}
|
||||
}.runTaskLater(Main.plugin, 200L);
|
||||
}
|
||||
|
||||
|
||||
UpdateChecker.onUpdateCheck();
|
||||
UpdateChecker.onUpdateCheckTimer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
}
|
||||
}
|
149
src/main/java/de/jatitv/opsecurity/system/NameHistory.java
Normal file
149
src/main/java/de/jatitv/opsecurity/system/NameHistory.java
Normal file
@@ -0,0 +1,149 @@
|
||||
package de.jatitv.opsecurity.system;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public class NameHistory {
|
||||
|
||||
|
||||
/**
|
||||
* The URL from Mojang API that provides the JSON String in response.
|
||||
*/
|
||||
private static final String LOOKUP_URL = "https://api.mojang.com/user/profiles/%s/names";
|
||||
|
||||
/**
|
||||
* The URL from Mojang API to resolve the UUID of a player from their name.
|
||||
*/
|
||||
private static final String GET_UUID_URL = "https://api.mojang.com/users/profiles/minecraft/%s?t=0";
|
||||
private static final Gson JSON_PARSER = new Gson();
|
||||
|
||||
/**
|
||||
* <h1>NOTE: Avoid running this method <i>Synchronously</i> with the main thread!It blocks while attempting to get a response from Mojang servers!</h1>
|
||||
*
|
||||
* @param player The UUID of the player to be looked up.
|
||||
* @return Returns an array of {@link PreviousPlayerNameEntry} objects, or null if the response couldn't be interpreted.
|
||||
* @throws IOException {@link #getPlayerPreviousNames(String)}
|
||||
*/
|
||||
public static PreviousPlayerNameEntry[] getPlayerPreviousNames(UUID player) throws IOException {
|
||||
return getPlayerPreviousNames(player.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>NOTE: Avoid running this method <i>Synchronously</i> with the main thread! It blocks while attempting to get a response from Mojang servers!</h1>
|
||||
* Alternative method accepting an 'OfflinePlayer' (and therefore 'Player') objects as parameter.
|
||||
*
|
||||
* @param player The OfflinePlayer object to obtain the UUID from.
|
||||
* @return Returns an array of {@link PreviousPlayerNameEntry} objects, or null if the response couldn't be interpreted.
|
||||
* @throws IOException {@link #getPlayerPreviousNames(UUID)}
|
||||
*/
|
||||
public static PreviousPlayerNameEntry[] getPlayerPreviousNames(OfflinePlayer player) throws IOException {
|
||||
return getPlayerPreviousNames(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>NOTE: Avoid running this method <i>Synchronously</i> with the main thread! It blocks while attempting to get a response from Mojang servers!</h1>
|
||||
* Alternative method accepting an {@link OfflinePlayer} (and therefore {@link Player}) objects as parameter.
|
||||
*
|
||||
* @param uuid The UUID String to lookup
|
||||
* @return Returns an array of {@link PreviousPlayerNameEntry} objects, or null if the response couldn't be interpreted.
|
||||
* @throws IOException
|
||||
*/
|
||||
public static PreviousPlayerNameEntry[] getPlayerPreviousNames(String uuid) throws IOException {
|
||||
if (uuid == null || uuid.isEmpty())
|
||||
return null;
|
||||
String response = getRawJsonResponse(new URL(String.format(LOOKUP_URL, uuid)));
|
||||
PreviousPlayerNameEntry[] names = JSON_PARSER.fromJson(response, PreviousPlayerNameEntry[].class);
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* If you don't have the UUID of a player, this method will resolve it for you.<br>
|
||||
* The output of this method may be used directly with {@link #getPlayerPreviousNames(String)}.<br>
|
||||
* <b>NOTE: as with the rest, this method opens a connection with a remote server, so running it synchronously will block the main thread which will lead to server lag.</b>
|
||||
*
|
||||
* @param name The name of the player to lookup.
|
||||
* @return A String which represents the player's UUID. <b>Note: the uuid cannot be parsed to a UUID object directly, as it doesnt contain dashes. This feature will be implemented later</b>
|
||||
* @throws IOException Inherited by {@link BufferedReader#readLine()}, {@link BufferedReader#close()}, {@link URL}, {@link HttpURLConnection#getInputStream()}
|
||||
*/
|
||||
public static String getPlayerUUID(String name) throws IOException {
|
||||
String response = getRawJsonResponse(new URL(String.format(GET_UUID_URL, name)));
|
||||
JsonObject o = JSON_PARSER.fromJson(response, JsonObject.class);
|
||||
if (o == null)
|
||||
return null;
|
||||
return o.get("id") == null ? null : o.get("id").getAsString();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a helper method used to read the response of Mojang's API webservers.
|
||||
*
|
||||
* @param u the URL to connect to
|
||||
* @return a String with the data read.
|
||||
* @throws IOException Inherited by {@link BufferedReader#readLine()}, {@link BufferedReader#close()}, {@link URL}, {@link HttpURLConnection#getInputStream()}
|
||||
*/
|
||||
private static String getRawJsonResponse(URL u) throws IOException {
|
||||
HttpURLConnection con = (HttpURLConnection) u.openConnection();
|
||||
con.setDoInput(true);
|
||||
con.setConnectTimeout(2000);
|
||||
con.setReadTimeout(2000);
|
||||
con.connect();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||
String response = in.readLine();
|
||||
in.close();
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class represents the typical response expected by Mojang servers when requesting the name history of a player.
|
||||
*/
|
||||
public class PreviousPlayerNameEntry {
|
||||
private String name;
|
||||
@SerializedName("changedToAt")
|
||||
private long changeTime;
|
||||
|
||||
/**
|
||||
* Gets the player name of this entry.
|
||||
*
|
||||
* @return The name of the player.
|
||||
*/
|
||||
public String getPlayerName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time of change of the name.
|
||||
* <br><b>Note: This will return 0 if the name is the original (initial) name of the player! Make sure you check if it is 0 before handling!
|
||||
* <br>Parsing 0 to a Date will result in the date "01/01/1970".</b>
|
||||
*
|
||||
* @return a timestamp in miliseconds that you can turn into a date or handle however you want :)
|
||||
*/
|
||||
public long getChangeTime() {
|
||||
return changeTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this name is the name used to register the account (the initial/original name)
|
||||
*
|
||||
* @return a boolean, true if it is the the very first name of the player, otherwise false.
|
||||
*/
|
||||
public boolean isPlayersInitialName() {
|
||||
return getChangeTime() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Name: " + name + " Date of change: " + new Date(changeTime).toString();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user