diff --git a/resources/config.yml b/resources/config.yml index 7a4d2cf..2842a9a 100644 --- a/resources/config.yml +++ b/resources/config.yml @@ -17,7 +17,9 @@ BackpackTitle: "&bBackpack" # Defines if the content of the backpack get dropped on the death of a player. # If enabled, it can be disabled for individual players with the "backpack.KeepOnDeath" permission. DropOnDeath: true -# Defines the max amount of columns for a backpack +# Defines the max amount of columns for a backpack. +# The size of the user's backpack will be defined by the permission, permissions for bigger backpacks than this value will be ignored. +# Can be set to anything > 0. Backpacks with more than 6 columns will have a broken UI! Sizes bigger than 9 may not work with all permission plugins. MaxSize: 6 # Defines in which game-modes a player can access his backpack (name or id) # Options: ADVENTURE, CREATIVE, SPECTATOR, SURVIVAL @@ -127,6 +129,19 @@ ItemFilter: # List off items not allowed in the backpack. Can be name or id. Blacklist: [] +# This settings allow control over how the plugin behave in different worlds +WorldSettings: + # All worlds listed here will not have the plugin usable + # Blacklist: ["creative_world"] + # Blacklist: ["creative_world1", "creative_world2"] + Blacklist: [] + # Defines how the Blacklist will be enforced + # Options: + # Message = The player will see an message that the usage of the backpack is denied in this world. + # MissingPermission = The player will receive the plugins no permission message. + # NoPlugin = The plugin will not be available at all and act as if it was not installed. This also exclude players with permission to bypass the world restriction from using it! + BlacklistMode: "Message" + Misc: # Enables/Disables the auto-update function of the plugin. AutoUpdate: true diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java index 72a7726..c9b6ab8 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016-2017 GeorgH93 + * Copyright (C) 2016-2018 GeorgH93 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,7 +19,9 @@ import at.pcgamingfreaks.Bukkit.Configuration; import at.pcgamingfreaks.Bukkit.MinecraftMaterial; +import at.pcgamingfreaks.ConsoleColor; import at.pcgamingfreaks.Minepacks.Bukkit.Database.Helper.OldFileUpdater; +import at.pcgamingfreaks.Minepacks.Bukkit.Database.Helper.WorldBlacklistMode; import org.bukkit.ChatColor; import org.bukkit.GameMode; @@ -280,7 +282,7 @@ public boolean isItemFilterEnabled() public Collection getItemFilterBlacklist() { - List stringBlacklist = config.getStringList("ItemFilter.Blacklist", new LinkedList()); + List stringBlacklist = config.getStringList("ItemFilter.Blacklist", new LinkedList<>()); Collection blacklist = new LinkedList<>(); for(String item : stringBlacklist) { @@ -290,5 +292,27 @@ public Collection getItemFilterBlacklist() return blacklist; } //endregion + + //region World settings + public Collection getWorldBlacklist() + { + return new HashSet<>(config.getStringList("WorldSettings.Blacklist", new LinkedList<>())); + } + + public WorldBlacklistMode getWorldBlacklistMode() + { + String mode = config.getString("WorldSettings.BlacklistMode", "Message"); + WorldBlacklistMode blacklistMode = WorldBlacklistMode.Message; + try + { + blacklistMode = WorldBlacklistMode.valueOf(mode); + } + catch(IllegalArgumentException ignored) + { + logger.warning(ConsoleColor.YELLOW + "Unsupported mode \"" + mode + "\" for option \"WorldSettings.BlacklistMode\"" + ConsoleColor.RESET); + } + return blacklistMode; + } + //endregion //endregion } \ No newline at end of file diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Helper/WorldBlacklistMode.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Helper/WorldBlacklistMode.java new file mode 100644 index 0000000..d74c50a --- /dev/null +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Helper/WorldBlacklistMode.java @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2018 GeorgH93 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package at.pcgamingfreaks.Minepacks.Bukkit.Database.Helper; + +public enum WorldBlacklistMode +{ + Message, MissingPermission, NoPlugin +} \ No newline at end of file diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/InventorySerializer.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/InventorySerializer.java index e676fff..44e6a18 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/InventorySerializer.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/InventorySerializer.java @@ -37,7 +37,7 @@ public InventorySerializer() String[] version = name.substring(name.lastIndexOf('.') + 2).split("_"); try { - if(version[0].equals("1") && Integer.parseInt(version[1]) > 7) + if(NBTItemStackSerializer.isMCVersionCompatible()) { serializer = new NBTItemStackSerializer(); } diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQL.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQL.java index de49d08..93a7f98 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQL.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQL.java @@ -213,7 +213,7 @@ protected final void buildQuerys() queryGetBP += "{FieldName}=?;"; querySyncCooldown = "INSERT INTO {TableCooldowns} ({FieldCDPlayer},{FieldCDTime}) SELECT {FieldPlayerID},? FROM {TablePlayers} WHERE {FieldName}=?;"; } - queryInsertBp = "INSERT INTO {TableBackpacks} ({FieldBPOwner},{FieldBPITS},{FieldBPVersion}) VALUES (?,?,?);"; + queryInsertBp = "REPLACE INTO {TableBackpacks} ({FieldBPOwner},{FieldBPITS},{FieldBPVersion}) VALUES (?,?,?);"; queryUpdateBp = "UPDATE {TableBackpacks} SET {FieldBPITS}=?,{FieldBPVersion}=?,{FieldBPLastUpdate}={NOW} WHERE {FieldBPOwner}=?;"; queryDeleteOldBackpacks = "DELETE FROM {TableBackpacks} WHERE {FieldBPLastUpdate} < DATE('now', '-{VarMaxAge} days')"; if(useUUIDSeparators) diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQLite.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQLite.java index 22a684f..4319d87 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQLite.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQLite.java @@ -89,7 +89,7 @@ protected void updateQuerysForDialect() queryInsertBp = queryInsertBp.replaceAll("\\) VALUES \\(\\?,\\?,\\?", "{FieldBPLastUpdate}) VALUES (?,?,?,DATE('now')"); } queryDeleteOldBackpacks = "DELETE FROM {TableBackpacks} WHERE {FieldBPLastUpdate} < DATE('now', '-{VarMaxAge} days')"; - queryUpdateBp = queryUpdateBp.replaceAll("\\{NOW\\}", "DATE('now')"); + queryUpdateBp = queryUpdateBp.replaceAll("\\{NOW}", "DATE('now')"); if(useUUIDs) { queryUpdatePlayerAdd = "INSERT OR IGNORE INTO {TablePlayers} ({FieldName},{FieldUUID}) VALUES (?,?);";