mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-19 15:17:56 +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;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import fr.xephi.authme.api.API;
|
||||
@ -687,14 +688,20 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
// Check the presence of the ProtocolLib plugin
|
||||
public void checkProtocolLib() {
|
||||
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||
if (server.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||
inventoryProtector = new AuthMeInventoryPacketAdapter(this);
|
||||
inventoryProtector.register();
|
||||
} else {
|
||||
if (!server.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||
ConsoleLogger.showError("WARNING!!! The protectInventory feature requires ProtocolLib! Disabling it...");
|
||||
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 {
|
||||
|
||||
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)
|
||||
//+1 because an index starts with 0
|
||||
private static final int PLAYER_CRAFTING_SIZE = 5;
|
||||
// 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
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -88,7 +90,7 @@ public class AuthMeInventoryPacketAdapter extends PacketAdapter {
|
||||
//we are sending our own 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));
|
||||
ItemStack[] armorContents = player.getInventory().getArmorContents();
|
||||
ItemStack[] mainInventory = player.getInventory().getContents();
|
||||
@ -120,4 +122,19 @@ public class AuthMeInventoryPacketAdapter extends PacketAdapter {
|
||||
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() {
|
||||
RestoreInventoryEvent event = new RestoreInventoryEvent(player);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
pm.callEvent(event);
|
||||
if (!event.isCancelled() && plugin.inventoryProtector != null) {
|
||||
plugin.inventoryProtector.sendInventoryPacket(player);
|
||||
}
|
||||
}
|
||||
|
||||
protected void forceCommands() {
|
||||
for (String command : Settings.forceCommands) {
|
||||
try {
|
||||
player.performCommand(command.replace("%p", player.getName()));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
player.performCommand(command.replace("%p", player.getName()));
|
||||
}
|
||||
for (String command : Settings.forceCommandsAsConsole) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replace("%p", player.getName()));
|
||||
@ -154,7 +151,7 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
|
||||
|
||||
restoreFlyghtState();
|
||||
|
||||
if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) {
|
||||
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||
restoreInventory();
|
||||
}
|
||||
|
||||
|
@ -46,8 +46,9 @@ public class AsynchronousLogout {
|
||||
|
||||
public void process() {
|
||||
preLogout();
|
||||
if (!canLogout)
|
||||
if (!canLogout) {
|
||||
return;
|
||||
}
|
||||
final Player p = player;
|
||||
BukkitScheduler scheduler = p.getServer().getScheduler();
|
||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
||||
@ -66,11 +67,11 @@ public class AsynchronousLogout {
|
||||
Utils.teleportToSpawn(p);
|
||||
}
|
||||
});
|
||||
if (LimboCache.getInstance().hasLimboPlayer(name))
|
||||
if (LimboCache.getInstance().hasLimboPlayer(name)) {
|
||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||
}
|
||||
LimboCache.getInstance().addLimboPlayer(player);
|
||||
Utils.setGroup(player, GroupType.NOTLOGGEDIN);
|
||||
|
||||
scheduler.scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerLogout(p, plugin));
|
||||
}
|
||||
}
|
||||
|
@ -43,14 +43,18 @@ public class ProcessSyncronousPlayerLogout implements Runnable {
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
if (plugin.sessions.containsKey(name))
|
||||
if (plugin.sessions.containsKey(name)) {
|
||||
plugin.sessions.get(name).cancel();
|
||||
plugin.sessions.remove(name);
|
||||
int delay = Settings.getRegistrationTimeout * 20;
|
||||
plugin.sessions.remove(name);
|
||||
}
|
||||
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||
plugin.inventoryProtector.sendBlankInventoryPacket(player);
|
||||
}
|
||||
int timeOut = Settings.getRegistrationTimeout * 20;
|
||||
int interval = Settings.getWarnMessageInterval;
|
||||
BukkitScheduler sched = player.getServer().getScheduler();
|
||||
if (delay != 0) {
|
||||
BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay);
|
||||
if (timeOut != 0) {
|
||||
BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), timeOut);
|
||||
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
|
||||
}
|
||||
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.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSource.DataSourceType;
|
||||
import fr.xephi.authme.listener.AuthMeInventoryPacketAdapter;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
@ -187,7 +188,10 @@ public final class Settings extends YamlConfiguration {
|
||||
getUnrestrictedName = configFile.getStringList("settings.unrestrictions.UnrestrictedName");
|
||||
getRegisteredGroup = configFile.getString("GroupOptions.RegisteredPlayerGroup", "");
|
||||
getEnablePasswordVerifier = configFile.getBoolean("settings.restrictions.enablePasswordVerifier", true);
|
||||
|
||||
protectInventoryBeforeLogInEnabled = configFile.getBoolean("settings.restrictions.ProtectInventoryBeforeLogIn", true);
|
||||
plugin.checkProtocolLib();
|
||||
|
||||
passwordMaxLength = configFile.getInt("settings.security.passwordMaxLength", 20);
|
||||
isBackupActivated = configFile.getBoolean("BackupSystem.ActivateBackup", 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\\");
|
||||
isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true);
|
||||
reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true);
|
||||
|
||||
allowCommands = new ArrayList<>();
|
||||
allowCommands.addAll(Arrays.asList("/login", "/l", "/register", "/reg", "/email", "/captcha"));
|
||||
for (String cmd : configFile.getStringList("settings.restrictions.allowCommands")) {
|
||||
@ -203,6 +208,7 @@ public final class Settings extends YamlConfiguration {
|
||||
allowCommands.add(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
rakamakUsers = configFile.getString("Converter.Rakamak.fileName", "users.rak");
|
||||
rakamakUsersIp = configFile.getString("Converter.Rakamak.ipFileName", "UsersIp.rak");
|
||||
rakamakUseIp = configFile.getBoolean("Converter.Rakamak.useIp", false);
|
||||
|
Loading…
Reference in New Issue
Block a user