mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-01-26 09:31:29 +01:00
Merge pull request #227 from AuthMe-Team/master
Stuff from the team [MERGE NOW PLEASE]
This commit is contained in:
commit
f149c21eb7
16
pom.xml
16
pom.xml
@ -95,6 +95,7 @@
|
||||
<include>com.sun.mail:javax.mail</include>
|
||||
<include>com.comphenix.attribute:AttributeStorage</include>
|
||||
<include>org.mcstats.bukkit:metrics</include>
|
||||
<include>com.google.code.gson:gson</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
@ -214,7 +215,7 @@
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.8.11.1</version>
|
||||
<version>3.8.11.2</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
@ -241,6 +242,15 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- GSON required for 1.7.X compatibility -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.4</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Maxmind GeoIp API -->
|
||||
<dependency>
|
||||
@ -266,8 +276,7 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Spigot-Api, http://www.spigotmc.org/ Based on the Bukkit project,
|
||||
http://bukkit.org/ -->
|
||||
<!-- Bukkit API, http://www.spigotmc.org/ or http://bukkit.org/ -->
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
@ -314,6 +323,7 @@
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>3.4.0</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
@ -10,8 +10,8 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
@ -22,11 +22,12 @@ import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.mcstats.Metrics;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import org.mcstats.Metrics;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import net.minelink.ctplus.CombatTagPlus;
|
||||
|
||||
import fr.xephi.authme.api.API;
|
||||
import fr.xephi.authme.api.NewAPI;
|
||||
@ -55,8 +56,10 @@ import fr.xephi.authme.datasource.SQLite;
|
||||
import fr.xephi.authme.datasource.SQLite_HIKARI;
|
||||
import fr.xephi.authme.listener.AuthMeBlockListener;
|
||||
import fr.xephi.authme.listener.AuthMeEntityListener;
|
||||
import fr.xephi.authme.listener.AuthMeInventoryListener;
|
||||
import fr.xephi.authme.listener.AuthMeInventoryPacketAdapter;
|
||||
import fr.xephi.authme.listener.AuthMePlayerListener;
|
||||
import fr.xephi.authme.listener.AuthMePlayerListener16;
|
||||
import fr.xephi.authme.listener.AuthMePlayerListener18;
|
||||
import fr.xephi.authme.listener.AuthMeServerListener;
|
||||
import fr.xephi.authme.modules.ModuleManager;
|
||||
import fr.xephi.authme.plugin.manager.BungeeCordMessage;
|
||||
@ -66,15 +69,13 @@ import fr.xephi.authme.settings.Messages;
|
||||
import fr.xephi.authme.settings.OtherAccounts;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.Spawn;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import net.minelink.ctplus.CombatTagPlus;
|
||||
|
||||
public class AuthMe extends JavaPlugin {
|
||||
|
||||
private static AuthMe authme;
|
||||
private static Server server;
|
||||
private Logger authmeLogger;
|
||||
|
||||
private final Server server = getServer();
|
||||
private Logger authmeLogger = Logger.getLogger("AuthMe");
|
||||
public Management management;
|
||||
public NewAPI api;
|
||||
public SendMailSSL mail;
|
||||
@ -93,9 +94,9 @@ public class AuthMe extends JavaPlugin {
|
||||
public Essentials ess;
|
||||
public MultiverseCore multiverse;
|
||||
public CombatTagPlus combatTagPlus;
|
||||
public AuthMeInventoryListener inventoryProtector;
|
||||
public AuthMeInventoryPacketAdapter inventoryProtector;
|
||||
|
||||
// Manager
|
||||
// Module manager
|
||||
private ModuleManager moduleManager;
|
||||
|
||||
// TODO: Create Manager for fields below
|
||||
@ -123,6 +124,8 @@ public class AuthMe extends JavaPlugin {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Set the Instance
|
||||
server = getServer();
|
||||
authmeLogger = Logger.getLogger("AuthMe");
|
||||
authme = this;
|
||||
|
||||
// TODO: split the plugin in more modules
|
||||
@ -157,7 +160,6 @@ public class AuthMe extends JavaPlugin {
|
||||
m = Messages.getInstance();
|
||||
|
||||
// Start the metrics service
|
||||
// TODO: add a setting to disable metrics
|
||||
try {
|
||||
Metrics metrics = new Metrics(this);
|
||||
metrics.start();
|
||||
@ -280,6 +282,18 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
// Register events
|
||||
pm.registerEvents(new AuthMePlayerListener(this), this);
|
||||
// Try to register 1.6 player listeners
|
||||
try {
|
||||
Class.forName("org.bukkit.event.player.PlayerEditBookEvent");
|
||||
pm.registerEvents(new AuthMePlayerListener16(this), this);
|
||||
} catch (ClassNotFoundException ignore) {
|
||||
}
|
||||
// Try to register 1.8 player listeners
|
||||
try {
|
||||
Class.forName("org.bukkit.event.player.PlayerInteractAtEntityEvent");
|
||||
pm.registerEvents(new AuthMePlayerListener18(this), this);
|
||||
} catch (ClassNotFoundException ignore) {
|
||||
}
|
||||
pm.registerEvents(new AuthMeBlockListener(this), this);
|
||||
pm.registerEvents(new AuthMeEntityListener(this), this);
|
||||
pm.registerEvents(new AuthMeServerListener(this), this);
|
||||
@ -367,6 +381,7 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
// Initialize and setup the database
|
||||
public void setupDatabase() throws Exception {
|
||||
if (database != null) database.close();
|
||||
// Backend MYSQL - FILE - SQLITE - SQLITEHIKARI
|
||||
boolean isSQLite = false;
|
||||
switch (Settings.getDataSource) {
|
||||
@ -496,8 +511,8 @@ public class AuthMe extends JavaPlugin {
|
||||
public void checkProtocolLib() {
|
||||
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||
if (server.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||
inventoryProtector = new AuthMeInventoryListener(this);
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(inventoryProtector);
|
||||
inventoryProtector = new AuthMeInventoryPacketAdapter(this);
|
||||
inventoryProtector.register();
|
||||
} else {
|
||||
ConsoleLogger.showError("WARNING!!! The protectInventory feature requires ProtocolLib! Disabling it...");
|
||||
Settings.protectInventoryBeforeLogInEnabled = false;
|
||||
@ -728,6 +743,10 @@ public class AuthMe extends JavaPlugin {
|
||||
return count >= Settings.getMaxJoinPerIp;
|
||||
}
|
||||
|
||||
public ModuleManager getModuleManager() {
|
||||
return moduleManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Player real IP through VeryGames method
|
||||
*
|
||||
@ -761,5 +780,4 @@ public class AuthMe extends JavaPlugin {
|
||||
public String getCountryName(String ip) {
|
||||
return Utils.getCountryName(ip);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -103,21 +103,26 @@ public class DataManager {
|
||||
for (String name : cleared) {
|
||||
try {
|
||||
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
|
||||
if (player == null)
|
||||
File playerFile = null;
|
||||
if (player == null) {
|
||||
continue;
|
||||
String playerName = player.getName();
|
||||
File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + playerName + ".dat");
|
||||
}
|
||||
|
||||
try {
|
||||
playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getUniqueId() + ".dat");
|
||||
} catch(Exception ignore) {
|
||||
}
|
||||
if (playerFile.exists()) {
|
||||
playerFile.delete();
|
||||
i++;
|
||||
} else {
|
||||
playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getUniqueId() + ".dat");
|
||||
playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getName() + ".dat");
|
||||
if (playerFile.exists()) {
|
||||
playerFile.delete();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " .dat Files");
|
||||
@ -128,18 +133,19 @@ public class DataManager {
|
||||
int i = 0;
|
||||
for (String name : cleared) {
|
||||
try {
|
||||
File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml");
|
||||
File playerFile = null;
|
||||
try {
|
||||
playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + plugin.getServer().getOfflinePlayer(name).getUniqueId() + ".yml");
|
||||
} catch(Exception ignore) {
|
||||
}
|
||||
if (playerFile.exists()) {
|
||||
playerFile.delete();
|
||||
i++;
|
||||
} else {
|
||||
try {
|
||||
playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + Bukkit.getOfflinePlayer(name).getUniqueId() + ".yml");
|
||||
if (playerFile.exists()) {
|
||||
playerFile.delete();
|
||||
i++;
|
||||
}
|
||||
} catch (Exception e) { // Don't do nothing if the method getUniqueId() isn't avariable ( MC version < 1.7.5 )
|
||||
playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml");
|
||||
if (playerFile.exists()) {
|
||||
playerFile.delete();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -110,11 +110,12 @@ public class AdminCommand implements CommandExecutor {
|
||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||
try {
|
||||
Settings.reload();
|
||||
plugin.getModuleManager().reloadModules();
|
||||
m.reloadMessages();
|
||||
plugin.database.close();
|
||||
plugin.setupDatabase();
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.showError("Fatal error occurred! Authme instance ABORTED!");
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
plugin.stopOrUnload();
|
||||
return false;
|
||||
}
|
||||
|
@ -2,7 +2,11 @@ package fr.xephi.authme.listener;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.Utils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -14,9 +18,16 @@ import org.bukkit.projectiles.ProjectileSource;
|
||||
public class AuthMeEntityListener implements Listener {
|
||||
|
||||
public AuthMe instance;
|
||||
private static Method getShooter;
|
||||
private static boolean shooterIsProjectileSource;
|
||||
|
||||
public AuthMeEntityListener(AuthMe instance) {
|
||||
this.instance = instance;
|
||||
try {
|
||||
Method m = Projectile.class.getDeclaredMethod("getShooter");
|
||||
shooterIsProjectileSource = m.getReturnType() != LivingEntity.class;
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
@ -31,7 +42,7 @@ public class AuthMeEntityListener implements Listener {
|
||||
return;
|
||||
}
|
||||
player.setFireTicks(0);
|
||||
event.setDamage(0.0);
|
||||
event.setDamage(0);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@ -90,7 +101,7 @@ public class AuthMeEntityListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setAmount(0.0);
|
||||
event.setAmount(0);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@ -126,15 +137,29 @@ public class AuthMeEntityListener implements Listener {
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onProjectileLaunch(ProjectileLaunchEvent event) {
|
||||
Projectile projectile = event.getEntity();
|
||||
if (projectile == null)
|
||||
return;
|
||||
|
||||
ProjectileSource shooter = projectile.getShooter();
|
||||
if (shooter == null || !(shooter instanceof Player)) {
|
||||
Player player = null;
|
||||
if (projectile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Utils.checkAuth((Player) shooter)) {
|
||||
if (shooterIsProjectileSource) {
|
||||
ProjectileSource shooter = projectile.getShooter();
|
||||
if (shooter == null || !(shooter instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
player = (Player) shooter;
|
||||
} else {
|
||||
try {
|
||||
if (getShooter == null) {
|
||||
getShooter = Projectile.class.getMethod("getShooter");
|
||||
}
|
||||
Object obj = getShooter.invoke(null);
|
||||
player = (Player) obj;
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
if (Utils.checkAuth(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -22,21 +22,19 @@ import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class AuthMeInventoryListener extends PacketAdapter {
|
||||
public class AuthMeInventoryPacketAdapter extends PacketAdapter {
|
||||
|
||||
private static final int PLAYER_INVENTORY = 0;
|
||||
//http://wiki.vg/Inventory#Inventory (0-4 crafting, 5-8 armor, 9-35 main inventory, 36-44 inventory)
|
||||
@ -44,7 +42,7 @@ public class AuthMeInventoryListener extends PacketAdapter {
|
||||
private static final int PLAYER_CRAFTING_SIZE = 5;
|
||||
private static final int HOTBAR_SIZE = 9;
|
||||
|
||||
public AuthMeInventoryListener(AuthMe plugin) {
|
||||
public AuthMeInventoryPacketAdapter(AuthMe plugin) {
|
||||
super(plugin, PacketType.Play.Server.SET_SLOT, PacketType.Play.Server.WINDOW_ITEMS);
|
||||
}
|
||||
|
||||
@ -60,6 +58,10 @@ public class AuthMeInventoryListener extends PacketAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
public void register() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(this);
|
||||
}
|
||||
|
||||
public void sendInventoryPacket(Player player) {
|
||||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
PacketContainer inventoryPacket = protocolManager.createPacket(PacketType.Play.Server.WINDOW_ITEMS);
|
||||
@ -68,6 +70,7 @@ public class AuthMeInventoryListener extends PacketAdapter {
|
||||
inventoryPacket.getIntegers().write(0, PLAYER_INVENTORY);
|
||||
|
||||
ItemStack[] playerCrafting = new ItemStack[PLAYER_CRAFTING_SIZE];
|
||||
Arrays.fill(playerCrafting, new ItemStack(Material.AIR));
|
||||
ItemStack[] armorContents = player.getInventory().getArmorContents();
|
||||
ItemStack[] mainInventory = player.getInventory().getContents();
|
||||
|
@ -448,14 +448,6 @@ public class AuthMePlayerListener implements Listener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player == null || Utils.checkAuth(player))
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
if (Utils.checkAuth(event.getPlayer()))
|
||||
@ -527,11 +519,4 @@ public class AuthMePlayerListener implements Listener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
|
||||
public void onPlayerEditBook(PlayerEditBookEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player == null || Utils.checkAuth(player))
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
package fr.xephi.authme.listener;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.Utils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.*;
|
||||
|
||||
public class AuthMePlayerListener16 implements Listener {
|
||||
|
||||
public AuthMe plugin;
|
||||
|
||||
public AuthMePlayerListener16(AuthMe plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
|
||||
public void onPlayerEditBook(PlayerEditBookEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player == null || Utils.checkAuth(player))
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package fr.xephi.authme.listener;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.Utils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.*;
|
||||
|
||||
public class AuthMePlayerListener18 implements Listener {
|
||||
|
||||
public AuthMe plugin;
|
||||
|
||||
public AuthMePlayerListener18(AuthMe plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player == null || Utils.checkAuth(player))
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
@ -112,6 +112,11 @@ public class ModuleManager {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void reloadModules(){
|
||||
unloadModules();
|
||||
loadModules();
|
||||
}
|
||||
|
||||
public void unloadModule(String name) {
|
||||
Iterator<Module> it = modules.iterator();
|
||||
while (it.hasNext()) {
|
||||
|
@ -45,7 +45,7 @@ public class OtherAccounts extends CustomConfiguration {
|
||||
save();
|
||||
}
|
||||
} catch (NoSuchMethodError | Exception e) {
|
||||
//ingore
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user