Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.drbooker.bookchecker;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- import java.util.Map.Entry;
- import org.bukkit.Bukkit;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.event.player.PlayerQuitEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin implements Listener {
- @Override
- public void onEnable() {
- getConfig().options().copyDefaults(true);
- saveDefaultConfig();
- Bukkit.getServer().getPluginManager().registerEvents(this, this);
- }
- @EventHandler
- public void onJoin(PlayerJoinEvent e) {
- final Player p = e.getPlayer();
- Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(this, new Runnable() {
- @Override
- public void run() {
- List<String> ips = Main.this.getConfig().getStringList("players. " + p.getUniqueId().toString() + ".ips");
- if(Main.this.contains(p, p.getAddress().getHostName())) {
- Main.this.update(p, p.getAddress().getHostName(), ips);
- } else {
- ips.add(p.getAddress().getHostName());
- }
- if((p.isOp()) || (p.hasPermission("bookchecker.check"))) {
- Main.this.getConfig().set("players." + p.getUniqueId().toString() + ".allowChecks", Boolean.valueOf(true));
- } else {
- Main.this.getConfig().set("players." + p.getUniqueId().toString(), Boolean.valueOf(false));
- }
- Main.this.getConfig().set("players." + p.getUniqueId().toString() + ".ips", ips);
- Main.this.getConfig().set("players." + p.getUniqueId().toString() + ".name", p.getName());
- Main.this.saveConfig();
- }
- }, 1L);
- for(Player po : Bukkit.getOnlinePlayers()) {
- if(po.hasPermission("bookchecker.check")) {
- Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
- @Override
- public void run() {
- String targetName = null;
- UUID targetUUID = null;
- if(e.getPlayer().getName().matches("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}")) {
- targetUUID = UUID.fromString(e.getPlayer().getName());
- } else {
- targetName = e.getPlayer().getName();
- }
- HashMap<String, List<String>> alts = new HashMap();
- if(targetUUID == null) {
- alts = Main.this.getAlts1(e.getPlayer(), targetName);
- } else if (targetName == null) {
- alts = Main.this.getAlts1(e.getPlayer(), targetUUID);
- }
- for (Map.Entry<String, List<String>> entry : alts.entrySet()) {
- po.sendMessage("§cNick'i, z ktorych sie logowal gracz §4[" + e.getPlayer().getName() + "]§c: §4" + ((List)entry.getValue()).toString());
- }
- }
- }, 1L);
- }
- }
- }
- @Override
- public boolean onCommand(final CommandSender sender, Command cmd, String label, final String[] args) {
- if(cmd.getName().equalsIgnoreCase("ipcheck")) {
- if(!sender.hasPermission("bookchecker.check")) {
- return true;
- }
- if(args.length == 0) {
- sender.sendMessage("§c/ipcheck <nick> albo /ipcheck <uuid>");
- return true;
- }
- sender.sendMessage("§cInformacje o §4" + args[0] + "§c:");
- Bukkit.getScheduler().runTaskLaterAsynchronously(this, new Runnable() {
- @Override
- public void run() {
- String targetName = null;
- UUID targetUUID = null;
- if(args[0].matches("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}")) {
- targetUUID = UUID.fromString(args[0]);
- } else {
- targetName = args[0];
- }
- HashMap<String, List<String>> alts = new HashMap();
- if(targetUUID == null) {
- alts = Main.this.getAlts(sender, targetName);
- } else if (targetName == null) {
- alts = Main.this.getAlts(sender, targetUUID);
- }
- for (Map.Entry<String, List<String>> entry : alts.entrySet()) {
- sender.sendMessage("§cIP: §4" + (String)entry.getKey());
- sender.sendMessage("§cNick'i, z ktorych sie logowal: §4" + ((List)entry.getValue()).toString());
- }
- String pName = args[0];
- if(Bukkit.getPlayer(pName) !=null){
- Player p = Bukkit.getPlayer(pName);
- if(p.isOp()) {
- return;
- }
- if(p.hasPermission("bookchecker.bypass")) {
- sender.sendMessage("§cIP: §4" + p.getAddress().getHostName());
- sender.sendMessage("§cNick'i, z ktorych sie logowal: §4[" + args[0] + "]");
- }
- }
- }
- }, 1L);
- }
- if(cmd.getName().equalsIgnoreCase("multikonto")) {
- if(sender.hasPermission("bookchecker.multikonto")) {
- if(args.length == 2) {
- if(args[0].equalsIgnoreCase("dodaj")) {
- String pName = args[1];
- if(Bukkit.getPlayer(pName) !=null){
- Player p = Bukkit.getPlayer(pName);
- Bukkit.getServer().dispatchCommand(getServer().getConsoleSender(), "pex user " + p.getName().toString() + " add bookchecker.bypass");
- sender.sendMessage("§cDodano do listy multikont gracza §4" + p.getName().toString() + "§c.");
- }
- }
- if(args[0].equalsIgnoreCase("usun")) {
- String pName = args[1];
- if(Bukkit.getPlayer(pName) !=null){
- Player p = Bukkit.getPlayer(pName);
- Bukkit.getServer().dispatchCommand(getServer().getConsoleSender(), "pex user " + p.getName().toString() + " remove bookchecker.bypass");
- sender.sendMessage("§cUsunieto z listy multikont gracza §4" + p.getName().toString() + "§c.");
- }
- }
- } else {
- sender.sendMessage("§c/multikonto <dodaj/usun> <nick>");
- }
- }
- }
- return false;
- }
- public HashMap<String, List<String>> getAlts(CommandSender sender, String name) {
- UUID uuid = null;
- HashMap<String, List<String>> toReturn = new HashMap();
- String foundName;
- for(String s : Main.this.getConfig().getConfigurationSection("players.").getKeys(false)) {
- foundName = Main.this.getConfig().getString("players." + s + ".name");
- if(foundName.equalsIgnoreCase(name)) {
- uuid = UUID.fromString(s);
- break;
- }
- }
- if (uuid == null) {
- return toReturn;
- }
- List<String> ips = getConfig().getStringList("players." + uuid.toString() + ".ips");
- if ((getConfig().getBoolean("players." + uuid.toString() + ".allowChecks")) && (!sender.hasPermission("bookchecker.bypass"))) {
- return toReturn;
- }
- for(String ip : ips) {
- toReturn.put(ip, findNames(ip));
- }
- return toReturn;
- }
- public HashMap<String, List<String>> getAlts(CommandSender sender, UUID uuid) {
- HashMap<String, List<String>> toReturn = new HashMap();
- List<String> ips = getConfig().getStringList("players." + uuid.toString() + ".ips");
- if ((getConfig().getBoolean("players." + uuid.toString() + ".allowChecks")) && (!sender.hasPermission("bookchecker.bypass"))) {
- return toReturn;
- }
- for(String ip : ips) {
- toReturn.put(ip, findNames(ip));
- }
- return toReturn;
- }
- public HashMap<String, List<String>> getAlts1(Player p, String name) {
- UUID uuid = null;
- HashMap<String, List<String>> toReturn = new HashMap();
- String foundName;
- for(String s : Main.this.getConfig().getConfigurationSection("players.").getKeys(false)) {
- foundName = Main.this.getConfig().getString("players." + s + ".name");
- if(foundName.equalsIgnoreCase(name)) {
- uuid = UUID.fromString(s);
- break;
- }
- }
- if (uuid == null) {
- return toReturn;
- }
- List<String> ips = getConfig().getStringList("players." + uuid.toString() + ".ips");
- if ((getConfig().getBoolean("players." + uuid.toString() + ".allowChecks")) && (!p.hasPermission("bookchecker.bypass"))) {
- return toReturn;
- }
- for(String ip : ips) {
- toReturn.put(ip, findNames(ip));
- }
- return toReturn;
- }
- public HashMap<String, List<String>> getAlts1(Player p, UUID uuid) {
- HashMap<String, List<String>> toReturn = new HashMap();
- List<String> ips = getConfig().getStringList("players." + uuid.toString() + ".ips");
- if ((getConfig().getBoolean("players." + uuid.toString() + ".allowChecks")) && (!p.hasPermission("bookchecker.bypass"))) {
- return toReturn;
- }
- for(String ip : ips) {
- toReturn.put(ip, findNames(ip));
- }
- return toReturn;
- }
- public boolean contains(Player p, String ip) {
- List<String> ips = Main.this.getConfig().getStringList("players." + p.getUniqueId().toString() + ".ips");
- for(String s : ips) {
- if(s.equalsIgnoreCase(ip)) {
- return true;
- }
- }
- return false;
- }
- public void update(Player p, String ip, List<String> ips) {
- String updatedString = "";
- for(int i = 0; i < ips.size(); i++) {
- String s = (String)ips.get(i);
- if(s.equalsIgnoreCase(ip)) {
- ips.set(i, updatedString);
- return;
- }
- }
- }
- public List<String> findNames(String ip) {
- List<String> toReturn = new ArrayList();
- for(String s : Main.this.getConfig().getConfigurationSection("players").getKeys(false)) {
- List<String> ips = Main.this.getConfig().getStringList("players." + s + ".ips");
- for (String st : ips) {
- if(st.equalsIgnoreCase(ip)) {
- toReturn.add(Main.this.getConfig().getString(new StringBuilder("players.").append(s).append(".name").toString()));
- break;
- }
- }
- }
- return toReturn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement