mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-19 23:28:59 +01:00
- send blank inventory on logout if protect inventory is enabled.
- added reload support for protect inventory option.
This commit is contained in:
parent
fb6ddb4b59
commit
25c23e144c
@ -1,5 +1,6 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import com.earth2me.essentials.Essentials;
|
import com.earth2me.essentials.Essentials;
|
||||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
import fr.xephi.authme.api.API;
|
import fr.xephi.authme.api.API;
|
||||||
@ -687,14 +688,20 @@ public class AuthMe extends JavaPlugin {
|
|||||||
|
|
||||||
// Check the presence of the ProtocolLib plugin
|
// Check the presence of the ProtocolLib plugin
|
||||||
public void checkProtocolLib() {
|
public void checkProtocolLib() {
|
||||||
|
if (!server.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||||
if (Settings.protectInventoryBeforeLogInEnabled) {
|
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||||
if (server.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
|
||||||
inventoryProtector = new AuthMeInventoryPacketAdapter(this);
|
|
||||||
inventoryProtector.register();
|
|
||||||
} else {
|
|
||||||
ConsoleLogger.showError("WARNING!!! The protectInventory feature requires ProtocolLib! Disabling it...");
|
ConsoleLogger.showError("WARNING!!! The protectInventory feature requires ProtocolLib! Disabling it...");
|
||||||
Settings.protectInventoryBeforeLogInEnabled = false;
|
Settings.protectInventoryBeforeLogInEnabled = false;
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||||
|
inventoryProtector = new AuthMeInventoryPacketAdapter(this);
|
||||||
|
inventoryProtector.register();
|
||||||
|
} else if (inventoryProtector != null) {
|
||||||
|
ProtocolLibrary.getProtocolManager().removePacketListener(inventoryProtector);
|
||||||
|
inventoryProtector = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,9 +39,11 @@ import java.util.logging.Level;
|
|||||||
public class AuthMeInventoryPacketAdapter extends PacketAdapter {
|
public class AuthMeInventoryPacketAdapter extends PacketAdapter {
|
||||||
|
|
||||||
private static final int PLAYER_INVENTORY = 0;
|
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)
|
// http://wiki.vg/Inventory#Inventory (0-4 crafting, 5-8 armor, 9-35 main inventory, 36-44 hotbar)
|
||||||
//+1 because an index starts with 0
|
// +1 because an index starts with 0
|
||||||
private static final int PLAYER_CRAFTING_SIZE = 5;
|
private static final int CRAFTING_SIZE = 5;
|
||||||
|
private static final int ARMOR_SIZE = 4;
|
||||||
|
private static final int MAIN_SIZE = 27;
|
||||||
private static final int HOTBAR_SIZE = 9;
|
private static final int HOTBAR_SIZE = 9;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,7 +90,7 @@ public class AuthMeInventoryPacketAdapter extends PacketAdapter {
|
|||||||
//we are sending our own inventory
|
//we are sending our own inventory
|
||||||
inventoryPacket.getIntegers().write(0, PLAYER_INVENTORY);
|
inventoryPacket.getIntegers().write(0, PLAYER_INVENTORY);
|
||||||
|
|
||||||
ItemStack[] playerCrafting = new ItemStack[PLAYER_CRAFTING_SIZE];
|
ItemStack[] playerCrafting = new ItemStack[CRAFTING_SIZE];
|
||||||
Arrays.fill(playerCrafting, new ItemStack(Material.AIR));
|
Arrays.fill(playerCrafting, new ItemStack(Material.AIR));
|
||||||
ItemStack[] armorContents = player.getInventory().getArmorContents();
|
ItemStack[] armorContents = player.getInventory().getArmorContents();
|
||||||
ItemStack[] mainInventory = player.getInventory().getContents();
|
ItemStack[] mainInventory = player.getInventory().getContents();
|
||||||
@ -120,4 +122,19 @@ public class AuthMeInventoryPacketAdapter extends PacketAdapter {
|
|||||||
plugin.getLogger().log(Level.WARNING, "Error during inventory recovery", invocationExc);
|
plugin.getLogger().log(Level.WARNING, "Error during inventory recovery", invocationExc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendBlankInventoryPacket(Player player) {
|
||||||
|
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||||
|
PacketContainer inventoryPacket = protocolManager.createPacket(PacketType.Play.Server.WINDOW_ITEMS);
|
||||||
|
inventoryPacket.getIntegers().write(0, PLAYER_INVENTORY);
|
||||||
|
int inventorySize = CRAFTING_SIZE + ARMOR_SIZE + MAIN_SIZE;
|
||||||
|
ItemStack[] blankInventory = new ItemStack[inventorySize];
|
||||||
|
Arrays.fill(blankInventory, new ItemStack(Material.AIR));
|
||||||
|
inventoryPacket.getItemArrayModifier().write(0, blankInventory);
|
||||||
|
try {
|
||||||
|
protocolManager.sendServerPacket(player, inventoryPacket, false);
|
||||||
|
} catch (InvocationTargetException invocationExc) {
|
||||||
|
plugin.getLogger().log(Level.WARNING, "Error during sending blank inventory", invocationExc);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,18 +98,15 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
|
|||||||
|
|
||||||
protected void restoreInventory() {
|
protected void restoreInventory() {
|
||||||
RestoreInventoryEvent event = new RestoreInventoryEvent(player);
|
RestoreInventoryEvent event = new RestoreInventoryEvent(player);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
pm.callEvent(event);
|
||||||
if (!event.isCancelled()) {
|
if (!event.isCancelled() && plugin.inventoryProtector != null) {
|
||||||
plugin.inventoryProtector.sendInventoryPacket(player);
|
plugin.inventoryProtector.sendInventoryPacket(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void forceCommands() {
|
protected void forceCommands() {
|
||||||
for (String command : Settings.forceCommands) {
|
for (String command : Settings.forceCommands) {
|
||||||
try {
|
|
||||||
player.performCommand(command.replace("%p", player.getName()));
|
player.performCommand(command.replace("%p", player.getName()));
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (String command : Settings.forceCommandsAsConsole) {
|
for (String command : Settings.forceCommandsAsConsole) {
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replace("%p", player.getName()));
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replace("%p", player.getName()));
|
||||||
@ -154,7 +151,7 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
|
|||||||
|
|
||||||
restoreFlyghtState();
|
restoreFlyghtState();
|
||||||
|
|
||||||
if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) {
|
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||||
restoreInventory();
|
restoreInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,8 +46,9 @@ public class AsynchronousLogout {
|
|||||||
|
|
||||||
public void process() {
|
public void process() {
|
||||||
preLogout();
|
preLogout();
|
||||||
if (!canLogout)
|
if (!canLogout) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
final Player p = player;
|
final Player p = player;
|
||||||
BukkitScheduler scheduler = p.getServer().getScheduler();
|
BukkitScheduler scheduler = p.getServer().getScheduler();
|
||||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
||||||
@ -66,11 +67,11 @@ public class AsynchronousLogout {
|
|||||||
Utils.teleportToSpawn(p);
|
Utils.teleportToSpawn(p);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (LimboCache.getInstance().hasLimboPlayer(name))
|
if (LimboCache.getInstance().hasLimboPlayer(name)) {
|
||||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||||
|
}
|
||||||
LimboCache.getInstance().addLimboPlayer(player);
|
LimboCache.getInstance().addLimboPlayer(player);
|
||||||
Utils.setGroup(player, GroupType.NOTLOGGEDIN);
|
Utils.setGroup(player, GroupType.NOTLOGGEDIN);
|
||||||
|
|
||||||
scheduler.scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerLogout(p, plugin));
|
scheduler.scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerLogout(p, plugin));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,14 +43,18 @@ public class ProcessSyncronousPlayerLogout implements Runnable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (plugin.sessions.containsKey(name))
|
if (plugin.sessions.containsKey(name)) {
|
||||||
plugin.sessions.get(name).cancel();
|
plugin.sessions.get(name).cancel();
|
||||||
plugin.sessions.remove(name);
|
plugin.sessions.remove(name);
|
||||||
int delay = Settings.getRegistrationTimeout * 20;
|
}
|
||||||
|
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||||
|
plugin.inventoryProtector.sendBlankInventoryPacket(player);
|
||||||
|
}
|
||||||
|
int timeOut = Settings.getRegistrationTimeout * 20;
|
||||||
int interval = Settings.getWarnMessageInterval;
|
int interval = Settings.getWarnMessageInterval;
|
||||||
BukkitScheduler sched = player.getServer().getScheduler();
|
BukkitScheduler sched = player.getServer().getScheduler();
|
||||||
if (delay != 0) {
|
if (timeOut != 0) {
|
||||||
BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay);
|
BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), timeOut);
|
||||||
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
|
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
|
||||||
}
|
}
|
||||||
BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("login_msg"), interval));
|
BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("login_msg"), interval));
|
||||||
|
@ -4,6 +4,7 @@ import fr.xephi.authme.AuthMe;
|
|||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.datasource.DataSource.DataSourceType;
|
import fr.xephi.authme.datasource.DataSource.DataSourceType;
|
||||||
|
import fr.xephi.authme.listener.AuthMeInventoryPacketAdapter;
|
||||||
import fr.xephi.authme.security.HashAlgorithm;
|
import fr.xephi.authme.security.HashAlgorithm;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
@ -187,7 +188,10 @@ public final class Settings extends YamlConfiguration {
|
|||||||
getUnrestrictedName = configFile.getStringList("settings.unrestrictions.UnrestrictedName");
|
getUnrestrictedName = configFile.getStringList("settings.unrestrictions.UnrestrictedName");
|
||||||
getRegisteredGroup = configFile.getString("GroupOptions.RegisteredPlayerGroup", "");
|
getRegisteredGroup = configFile.getString("GroupOptions.RegisteredPlayerGroup", "");
|
||||||
getEnablePasswordVerifier = configFile.getBoolean("settings.restrictions.enablePasswordVerifier", true);
|
getEnablePasswordVerifier = configFile.getBoolean("settings.restrictions.enablePasswordVerifier", true);
|
||||||
|
|
||||||
protectInventoryBeforeLogInEnabled = configFile.getBoolean("settings.restrictions.ProtectInventoryBeforeLogIn", true);
|
protectInventoryBeforeLogInEnabled = configFile.getBoolean("settings.restrictions.ProtectInventoryBeforeLogIn", true);
|
||||||
|
plugin.checkProtocolLib();
|
||||||
|
|
||||||
passwordMaxLength = configFile.getInt("settings.security.passwordMaxLength", 20);
|
passwordMaxLength = configFile.getInt("settings.security.passwordMaxLength", 20);
|
||||||
isBackupActivated = configFile.getBoolean("BackupSystem.ActivateBackup", false);
|
isBackupActivated = configFile.getBoolean("BackupSystem.ActivateBackup", false);
|
||||||
isBackupOnStart = configFile.getBoolean("BackupSystem.OnServerStart", false);
|
isBackupOnStart = configFile.getBoolean("BackupSystem.OnServerStart", false);
|
||||||
@ -195,6 +199,7 @@ public final class Settings extends YamlConfiguration {
|
|||||||
backupWindowsPath = configFile.getString("BackupSystem.MysqlWindowsPath", "C:\\Program Files\\MySQL\\MySQL Server 5.1\\");
|
backupWindowsPath = configFile.getString("BackupSystem.MysqlWindowsPath", "C:\\Program Files\\MySQL\\MySQL Server 5.1\\");
|
||||||
isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true);
|
isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true);
|
||||||
reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true);
|
reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true);
|
||||||
|
|
||||||
allowCommands = new ArrayList<>();
|
allowCommands = new ArrayList<>();
|
||||||
allowCommands.addAll(Arrays.asList("/login", "/l", "/register", "/reg", "/email", "/captcha"));
|
allowCommands.addAll(Arrays.asList("/login", "/l", "/register", "/reg", "/email", "/captcha"));
|
||||||
for (String cmd : configFile.getStringList("settings.restrictions.allowCommands")) {
|
for (String cmd : configFile.getStringList("settings.restrictions.allowCommands")) {
|
||||||
@ -203,6 +208,7 @@ public final class Settings extends YamlConfiguration {
|
|||||||
allowCommands.add(cmd);
|
allowCommands.add(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rakamakUsers = configFile.getString("Converter.Rakamak.fileName", "users.rak");
|
rakamakUsers = configFile.getString("Converter.Rakamak.fileName", "users.rak");
|
||||||
rakamakUsersIp = configFile.getString("Converter.Rakamak.ipFileName", "UsersIp.rak");
|
rakamakUsersIp = configFile.getString("Converter.Rakamak.ipFileName", "UsersIp.rak");
|
||||||
rakamakUseIp = configFile.getBoolean("Converter.Rakamak.useIp", false);
|
rakamakUseIp = configFile.getBoolean("Converter.Rakamak.useIp", false);
|
||||||
|
Loading…
Reference in New Issue
Block a user