mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2025-01-07 19:28:11 +01:00
Add world filter whitelist option
This commit is contained in:
parent
2eee3b5fb4
commit
e685f28680
@ -148,10 +148,12 @@ ItemFilter:
|
||||
|
||||
# These settings allow control over how the plugin behave in different worlds
|
||||
WorldSettings:
|
||||
# Options: blacklist (all worlds listed in FilteredWorlds will be blocked), whitelist (all worlds listed in FilteredWorlds will be allowed)
|
||||
FilterType: "blacklist"
|
||||
# All worlds listed here will not have the plugin usable
|
||||
# Blacklist: ["creative_world"]
|
||||
# Blacklist: ["creative_world1", "creative_world2"]
|
||||
Blacklist: []
|
||||
# FilteredWorlds: ["creative_world"]
|
||||
# FilteredWorlds: ["creative_world1", "creative_world2"]
|
||||
FilteredWorlds: []
|
||||
# Defines how the Blacklist will be enforced
|
||||
# Options:
|
||||
# Message = The player will see a message that the usage of the backpack is not allowed in this world.
|
||||
@ -159,7 +161,7 @@ WorldSettings:
|
||||
# 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!
|
||||
# It will not disable the Shulkerboxes filter!
|
||||
BlacklistMode: "Message"
|
||||
BlockMode: "Message"
|
||||
|
||||
# Gives the players an item they can interact with to open their backpack. Only works on MC 1.8 or newer.
|
||||
ItemShortcut:
|
||||
@ -210,4 +212,4 @@ Misc:
|
||||
UseBungeeCord: false
|
||||
|
||||
# Config file version. Don't touch it!
|
||||
Version: 30
|
||||
Version: 31
|
@ -27,9 +27,7 @@
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.ShrinkApproach;
|
||||
import at.pcgamingfreaks.YamlFileManager;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -38,7 +36,7 @@
|
||||
|
||||
public class Config extends Configuration implements DatabaseConnectionConfiguration
|
||||
{
|
||||
private static final int CONFIG_VERSION = 30, UPGRADE_THRESHOLD = CONFIG_VERSION, PRE_V2_VERSION = 20;
|
||||
private static final int CONFIG_VERSION = 31, UPGRADE_THRESHOLD = CONFIG_VERSION, PRE_V2_VERSION = 20;
|
||||
|
||||
public Config(JavaPlugin plugin)
|
||||
{
|
||||
@ -65,6 +63,11 @@ protected void doUpgrade(@NotNull YamlFileManager oldConfig)
|
||||
Map<String, String> remappedKeys = new HashMap<>();
|
||||
if(oldConfig.getVersion() <= 23) remappedKeys.put("ItemFilter.Materials", "ItemFilter.Blacklist");
|
||||
if(oldConfig.getVersion() <= 28) remappedKeys.put("Misc.AutoUpdate.Enabled", "Misc.AutoUpdate");
|
||||
if(oldConfig.getVersion() <= 30)
|
||||
{
|
||||
remappedKeys.put("WorldSettings.FilteredWorlds", "WorldSettings.Blacklist");
|
||||
remappedKeys.put("WorldSettings.BockMode", "WorldSettings.BlacklistMode");
|
||||
}
|
||||
Collection<String> keysToKeep = oldConfig.getYamlE().getKeysFiltered("Database\\.SQL\\.(MaxLifetime|IdleTimeout)");
|
||||
keysToKeep.addAll(oldConfig.getYamlE().getKeysFiltered("Database\\.Tables\\.Fields\\..+"));
|
||||
doUpgrade(oldConfig, remappedKeys, keysToKeep);
|
||||
@ -359,19 +362,39 @@ public boolean isItemFilterModeWhitelist()
|
||||
//endregion
|
||||
|
||||
//region World settings
|
||||
public Collection<String> getWorldBlacklist()
|
||||
public boolean isWorldWhitelistMode()
|
||||
{
|
||||
HashSet<String> blacklist = new HashSet<>();
|
||||
for(String world : getConfigE().getStringList("WorldSettings.Blacklist", new LinkedList<>()))
|
||||
{
|
||||
blacklist.add(world.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
return blacklist;
|
||||
return getConfigE().getString("WorldSettings.FilterType", "blacklist").equalsIgnoreCase("whitelist");
|
||||
}
|
||||
|
||||
public WorldBlacklistMode getWorldBlacklistMode()
|
||||
public Set<String> getWorldFilteredList()
|
||||
{
|
||||
String mode = getConfigE().getString("WorldSettings.BlacklistMode", "Message");
|
||||
Set<String> worldList = new HashSet<>();
|
||||
for(String world : getConfigE().getStringList("WorldSettings.FilteredWorlds", new ArrayList<>(0)))
|
||||
{
|
||||
worldList.add(world.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
return worldList;
|
||||
}
|
||||
|
||||
public Set<String> getWorldBlacklist()
|
||||
{
|
||||
if(isWorldWhitelistMode())
|
||||
{
|
||||
Set<String> whitelist = getWorldFilteredList(), blacklist = new HashSet<>();
|
||||
for(World world : Bukkit.getServer().getWorlds())
|
||||
{
|
||||
String worldName = world.getName().toLowerCase(Locale.ROOT);
|
||||
if(!whitelist.contains(worldName)) blacklist.add(worldName);
|
||||
}
|
||||
return blacklist;
|
||||
}
|
||||
else return getWorldFilteredList();
|
||||
}
|
||||
|
||||
public WorldBlacklistMode getWorldBlockMode()
|
||||
{
|
||||
String mode = getConfigE().getString("WorldSettings.BlockMode", "Message");
|
||||
WorldBlacklistMode blacklistMode = WorldBlacklistMode.Message;
|
||||
try
|
||||
{
|
||||
@ -379,7 +402,7 @@ public WorldBlacklistMode getWorldBlacklistMode()
|
||||
}
|
||||
catch(IllegalArgumentException ignored)
|
||||
{
|
||||
logger.warning(ConsoleColor.YELLOW + "Unsupported mode \"" + mode + "\" for option \"WorldSettings.BlacklistMode\"" + ConsoleColor.RESET);
|
||||
logger.warning(ConsoleColor.YELLOW + "Unsupported mode \"" + mode + "\" for option \"WorldSettings.BlockMode\"" + ConsoleColor.RESET);
|
||||
}
|
||||
return blacklistMode;
|
||||
}
|
||||
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package at.pcgamingfreaks.Minepacks.Bukkit.Listener;
|
||||
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldInitEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class WorldBlacklistUpdater implements Listener
|
||||
{
|
||||
private final @NotNull Minepacks plugin;
|
||||
|
||||
@EventHandler
|
||||
public void onWorldInit(final WorldInitEvent event)
|
||||
{
|
||||
String worldName = event.getWorld().getName().toLowerCase(Locale.ROOT);
|
||||
if(!plugin.getConfiguration().getWorldFilteredList().contains(worldName))
|
||||
{
|
||||
plugin.getWorldBlacklist().add(worldName);
|
||||
}
|
||||
}
|
||||
}
|
@ -49,9 +49,12 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
public class Minepacks extends JavaPlugin implements MinepacksPlugin
|
||||
{
|
||||
@ -65,7 +68,7 @@ public class Minepacks extends JavaPlugin implements MinepacksPlugin
|
||||
public Message messageNoPermission, messageInvalidBackpack, messageWorldDisabled, messageNotFromConsole, messageNotANumber;
|
||||
|
||||
private int maxSize;
|
||||
private Collection<String> worldBlacklist;
|
||||
@Getter private Set<String> worldBlacklist;
|
||||
private WorldBlacklistMode worldBlacklistMode;
|
||||
private ItemsCollector collector;
|
||||
private CommandManager commandManager;
|
||||
@ -190,10 +193,11 @@ private void load()
|
||||
}
|
||||
if(config.isShulkerboxesDisable()) pluginManager.registerEvents(new DisableShulkerboxes(this), this);
|
||||
if(config.isItemShortcutEnabled()) pluginManager.registerEvents(new ItemShortcut(this), this);
|
||||
if(config.isWorldWhitelistMode()) pluginManager.registerEvents(new WorldBlacklistUpdater(this), this);
|
||||
//endregion
|
||||
if(config.getFullInvCollect()) collector = new ItemsCollector(this);
|
||||
worldBlacklist = config.getWorldBlacklist();
|
||||
worldBlacklistMode = (worldBlacklist.size() == 0) ? WorldBlacklistMode.None : config.getWorldBlacklistMode();
|
||||
worldBlacklistMode = (worldBlacklist.size() == 0) ? WorldBlacklistMode.None : config.getWorldBlockMode();
|
||||
|
||||
gameModes = config.getAllowedGameModes();
|
||||
if(config.getCommandCooldown() > 0) cooldownManager = new CooldownManager(this);
|
||||
|
Loading…
Reference in New Issue
Block a user