Move code in folder
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
// This claas was created by JaTiTV
|
||||
|
||||
package de.jatitv.opsecurity.system;
|
||||
|
||||
import de.jatitv.opsecurity.Util;
|
||||
import de.jatitv.opsecurity.cmdManagement.CmdExecuter;
|
||||
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.Events;
|
||||
import de.jatitv.opsecurity.listener.OPCommand;
|
||||
import de.jatitv.opsecurity.listener.PlugManCommand;
|
||||
import de.jatitv.opsecurity.listener.Timer;
|
||||
import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate;
|
||||
import net.t2code.lib.Spigot.Lib.register.Register;
|
||||
import net.t2code.lib.Spigot.Lib.update.UpdateAPI;
|
||||
import net.t2code.lib.Spigot.system.Metrics;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Load {
|
||||
public static void onLoad(String prefix, List<String> autor, String version, String spigot, int spigotID, String discord, int bstatsID) {
|
||||
Long long_ = T2CodeTemplate.onLoadHeader(prefix, autor, version, spigot, discord);
|
||||
UpdateAPI.onUpdateCheck(Main.plugin, prefix, spigot, spigotID, discord);
|
||||
Metrics.Bstats(Main.plugin, bstatsID);
|
||||
loadReload();
|
||||
Permissions.register();
|
||||
Main.plugin.getCommand("opsecurity").setExecutor(new CmdExecuter());
|
||||
Register.listener(new Events(), Main.plugin);
|
||||
Register.listener(new OPCommand(), Main.plugin);
|
||||
Register.listener(new PlugManCommand(), Main.plugin);
|
||||
T2CodeTemplate.onLoadFooter(prefix, long_);
|
||||
}
|
||||
|
||||
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(Util.getPrefix());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
SelectConfig.sound();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
Timer.RefreshTimer();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
package de.jatitv.opsecurity.system;
|
||||
|
||||
import de.jatitv.opsecurity.Util;
|
||||
import de.jatitv.opsecurity.objects.PlayerObject;
|
||||
import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public final class Main extends JavaPlugin {
|
||||
|
||||
public static List<String> autor;
|
||||
public static String version;
|
||||
public static Main plugin;
|
||||
private static boolean enable;
|
||||
|
||||
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
|
||||
plugin = this;
|
||||
try {
|
||||
enable();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private static void enable() {
|
||||
autor = plugin.getDescription().getAuthors();
|
||||
version = plugin.getDescription().getVersion();
|
||||
if (pluginNotFound("T2CodeLib", 96388, Util.getRequiredT2CodeLibVersion())) return;
|
||||
Load.onLoad(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getSpigotID(), Util.getDiscord(), Util.getBstatsID());
|
||||
enable = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
if (enable) T2CodeTemplate.onDisable(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
|
||||
}
|
||||
public static Boolean pluginNotFound(String pl, Integer spigotID, double ver) {
|
||||
if (Bukkit.getPluginManager().getPlugin(pl) == null) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
|
||||
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §e" + pl + " §4could not be found. Please download it here: " +
|
||||
"§6https://spigotmc.org/resources/" + pl + "." + spigotID + " §4to be able to use this plugin.");
|
||||
Main.plugin.getPluginLoader().disablePlugin(Main.plugin);
|
||||
return true;
|
||||
} else {
|
||||
if (Double.parseDouble(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin(pl)).getDescription().getVersion()) < ver) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
|
||||
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §e" + pl + " §4is out of date! This plugin requires at least version §2" + ver + " §4of §6" + pl + " §4Please update it here: §6https://spigotmc.org/resources/" + pl + "." + spigotID + " §4to use this version of " + plugin.getDescription().getName() + ".");
|
||||
Main.plugin.getPluginLoader().disablePlugin(Main.plugin);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,148 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package de.jatitv.opsecurity.system;
|
||||
|
||||
import net.t2code.lib.Spigot.Lib.register.Register;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
public class Permissions {
|
||||
public static final String key = "opsecurity.";
|
||||
public static final String notify = key + "notify";
|
||||
public static final String updatemsg = key + "updatemsg";
|
||||
public static final String reload = key + "command.reload";
|
||||
public static final String info = key + "command.info";
|
||||
public static final String help = key + "command.help";
|
||||
|
||||
public static final String admin = key + "admin";
|
||||
public static final PermissionDefault op = PermissionDefault.OP;
|
||||
public static final PermissionDefault notOp = PermissionDefault.NOT_OP;
|
||||
|
||||
protected static void register() {
|
||||
Register.permission(notify, op, Main.plugin);
|
||||
Register.permissionDescription(notify,"Players with this permission get the update message when joining if an update is available",Main.plugin);
|
||||
Register.permission(updatemsg, op, Main.plugin);
|
||||
Register.permission(reload, op, Main.plugin);
|
||||
Register.permission(info, op, Main.plugin);
|
||||
Register.permission(help, op, Main.plugin);
|
||||
|
||||
Register.permission(admin, op, notify, true, Main.plugin);
|
||||
Register.permission(admin, op, updatemsg, true, Main.plugin);
|
||||
Register.permission(admin, op, reload, true, Main.plugin);
|
||||
Register.permission(admin, op, info, true, Main.plugin);
|
||||
Register.permission(admin, op, help, true, Main.plugin);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user