Add world filter

This commit is contained in:
GeorgH93 2018-04-26 15:47:30 +02:00
parent 270e22f7d0
commit ae74f241ee
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
12 changed files with 96 additions and 24 deletions

View File

@ -1,10 +1,19 @@
<div style="text-align:center"><img src ="https://pcgamingfreaks.at/images/minepacks.png" alt="Logo" /></div>
<div style="text-align:center">Minepacks is a backpack plugin with different backpack sizes, multi-language and MySQL storage support.</div>
<img align="center" src ="https://pcgamingfreaks.at/images/minepacks.png" alt="Logo" />
<p align="center">Minepacks is a backpack plugin with different backpack sizes, multi-language and MySQL storage support.</p>
## Features:
* Configuration
* Permissions
* Backpack size controlled by permissions
* Auto item-collect on full inventory (can be enabled in the config)
* SQLite/MySQL database
* Multi Language (English and German Language File included)
* Preserves the NBT data of items (everything that can be stored in a chest can be stored in the backpack)
* Support for MC 1.7.6 and newer (name changing / UUID)
* Auto-updater
# Links
[Spigot](https://www.spigotmc.org/resources/minepacks.19286/)</br>
[Dev Bukkit](http://dev.bukkit.org/bukkit-plugins/minepacks/)</br>
[Issue tracker](https://github.com/GeorgH93/Bukkit_Minepacks/issues)</br>
[Build Server ![Build Status](http://ci.pcgamingfreaks.at/job/Minepacks%20V2/badge/icon)](http://ci.pcgamingfreaks.at/job/Minepacks%20V2/)
## Links
* [Spigot](https://www.spigotmc.org/resources/minepacks.19286/)
* [Dev Bukkit](http://dev.bukkit.org/bukkit-plugins/minepacks/)
* [Issue tracker](https://github.com/GeorgH93/Minepacks/issues)
* [Build Server ![Build Status](http://ci.pcgamingfreaks.at/job/Minepacks%20V2/badge/icon)](http://ci.pcgamingfreaks.at/job/Minepacks%20V2/)

View File

@ -139,7 +139,9 @@ WorldSettings:
# 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!
# 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"
Misc:
@ -149,4 +151,4 @@ Misc:
UseBungeeCord: false
# Config file version. Don't touch it!
Version: 20
Version: 21

View File

@ -2,6 +2,7 @@ Language:
NotFromConsole: "&cDieser Befehl kann nicht in der Console ausgeführt werden."
Ingame:
NoPermission: "&cDir fehlen die Rechte dafür."
WorldDisabled: "&cDie Verwendung des Rucksacks ist in dieser Welt deaktiviert!"
OwnBackpackClose: "Rucksack geschlossen."
OwnBackpackClose_SendMethod: "action_bar"
#Parameter: {OwnerName}, {OwnerDisplayName}
@ -22,4 +23,4 @@ Language:
View: "Öffnet den Rucksack eines anderen Spielers."
# Language file version. Don't touch it!
Version: 10
Version: 11

View File

@ -2,6 +2,7 @@ Language:
NotFromConsole: "&cCommand not usable from console."
Ingame:
NoPermission: "&cYou don't have the Permission to do that."
WorldDisabled: "&cThe use of the backpack is not allowed in this world."
OwnBackpackClose: "Backpack closed!"
OwnBackpackClose_SendMethod: "action_bar"
#Parameter: {OwnerName}, {OwnerDisplayName}
@ -22,4 +23,4 @@ Language:
View: "Shows the backpack of other player."
# Language file version. Don't touch it!
Version: 10
Version: 11

View File

@ -100,4 +100,7 @@ permissions:
default: op
backpack.ignoreGameMode:
description: Allows to bypass the game-mode restriction.
default: op
backpack.ignoreWorldBlacklist:
description: Allows to bypass the world blacklist.
default: op

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 GeorgH93
* Copyright (C) 2017, 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
@ -20,6 +20,7 @@
import at.pcgamingfreaks.Bukkit.Message.Message;
import at.pcgamingfreaks.Minepacks.Bukkit.API.Callback;
import at.pcgamingfreaks.Minepacks.Bukkit.Backpack;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Helper.WorldBlacklistMode;
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
import org.bukkit.Bukkit;
@ -52,7 +53,7 @@ public OnCommand(Minepacks mp)
cooldown = plugin.config.getCommandCooldown();
syncCooldown = plugin.config.isCommandCooldownSyncEnabled();
gameModes = plugin.config.getAllowedGameModes();
StringBuilder allowedGameModesBuilder = new StringBuilder("");
StringBuilder allowedGameModesBuilder = new StringBuilder();
for(GameMode gameMode : gameModes)
{
if(allowedGameModesBuilder.length() > 1)
@ -74,6 +75,17 @@ public boolean onCommand(CommandSender sender, Command cmd, String arg, String[]
return true;
}
final Player player = (Player) sender;
WorldBlacklistMode disabled = plugin.isDisabled(player);
if(disabled != WorldBlacklistMode.None)
{
switch(disabled)
{
case Message: plugin.messageWorldDisabled.send(sender); break;
case MissingPermission: plugin.messageNoPermission.send(sender); break;
case NoPlugin: return false;
}
return true;
}
if(args.length == 0)
{
// Open player backpack

View File

@ -31,7 +31,7 @@
public class Config extends Configuration
{
private static final int CONFIG_VERSION = 20, UPGRADE_THRESHOLD = 20;
private static final int CONFIG_VERSION = 21, UPGRADE_THRESHOLD = 21;
public Config(JavaPlugin plugin)
{
@ -296,7 +296,12 @@ public Collection<MinecraftMaterial> getItemFilterBlacklist()
//region World settings
public Collection<String> getWorldBlacklist()
{
return new HashSet<>(getConfig().getStringList("WorldSettings.Blacklist", new LinkedList<>()));
HashSet<String> blacklist = new HashSet<>();
for(String world : getConfig().getStringList("WorldSettings.Blacklist", new LinkedList<>()))
{
blacklist.add(world.toLowerCase());
}
return blacklist;
}
public WorldBlacklistMode getWorldBlacklistMode()

View File

@ -19,5 +19,5 @@
public enum WorldBlacklistMode
{
Message, MissingPermission, NoPlugin
Message, MissingPermission, NoPlugin, None
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 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
@ -27,7 +27,7 @@
public class Language extends at.pcgamingfreaks.Bukkit.Language
{
private static final int LANG_VERSION = 10, UPGRADE_THRESHOLD = 10;
private static final int LANG_VERSION = 11, UPGRADE_THRESHOLD = 11;
public Language(JavaPlugin plugin)
{
@ -40,7 +40,7 @@ protected void doUpdate() {}
@Override
protected void doUpgrade(at.pcgamingfreaks.Language oldLang)
{
if(oldLang.getVersion() < UPGRADE_THRESHOLD)
if(oldLang.getVersion() < 10) // Pre v2.0 versions
{
YAML oldYAML = oldLang.getLang(), newYAML = getLang();
Map<String, String> simpleConverter = new LinkedHashMap<>(), advancedConverter = new LinkedHashMap<>();

View File

@ -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
@ -17,6 +17,8 @@
package at.pcgamingfreaks.Minepacks.Bukkit;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Helper.WorldBlacklistMode;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
@ -43,6 +45,7 @@ public void run()
{
for(Player player : Bukkit.getServer().getOnlinePlayers())
{
if(plugin.isDisabled(player) != WorldBlacklistMode.None) return;
if(player.getInventory().firstEmpty() == -1 && player.hasPermission("backpack.use") && player.hasPermission("backpack.fullpickup"))
{
// Only check loaded backpacks (loading them would take to much time for a repeating task, the backpack will be loaded async soon enough)

View File

@ -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,6 +19,7 @@
import at.pcgamingfreaks.Minepacks.Bukkit.API.Callback;
import at.pcgamingfreaks.Minepacks.Bukkit.Backpack;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Helper.WorldBlacklistMode;
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
import org.bukkit.Location;
@ -37,6 +38,7 @@ public DropOnDeath(Minepacks plugin)
public void onDeath(PlayerDeathEvent event)
{
final Player player = event.getEntity();
if(plugin.isDisabled(player) != WorldBlacklistMode.None) return;
if (!player.hasPermission("backpack.keepOnDeath"))
{
final Location location = player.getLocation();

View File

@ -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
@ -27,6 +27,7 @@
import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksPlugin;
import at.pcgamingfreaks.Minepacks.Bukkit.Commands.OnCommand;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Config;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Helper.WorldBlacklistMode;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Language;
import at.pcgamingfreaks.Minepacks.Bukkit.Listener.DisableShulkerboxes;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Database;
@ -45,6 +46,7 @@
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@ -60,9 +62,11 @@ public class Minepacks extends JavaPlugin implements MinepacksPlugin
public final Map<UUID, Long> cooldowns = new HashMap<>();
public String backpackTitleOther = "%s Backpack", backpackTitle = "Backpack";
public Message messageNoPermission, messageInvalidBackpack;
public Message messageNoPermission, messageInvalidBackpack, messageWorldDisabled;
private int maxSize;
private Collection<String> worldBlacklist;
private WorldBlacklistMode worldBlacklistMode;
public static Minepacks getInstance()
{
@ -133,6 +137,7 @@ private void load()
backpackTitle = StringUtils.limitLength(config.getBPTitle(), 32);
messageNoPermission = lang.getMessage("Ingame.NoPermission");
messageInvalidBackpack = lang.getMessage("Ingame.InvalidBackpack");
messageWorldDisabled = lang.getMessage("Ingame.WorldDisabled");
getCommand("backpack").setExecutor(new OnCommand(this));
//region register events
@ -146,6 +151,15 @@ private void load()
{
(new ItemsCollector(this)).runTaskTimer(this, config.getFullInvCheckInterval(), config.getFullInvCheckInterval());
}
worldBlacklist = config.getWorldBlacklist();
if(worldBlacklist.size() == 0)
{
worldBlacklistMode = WorldBlacklistMode.None;
}
else
{
worldBlacklistMode = config.getWorldBlacklistMode();
}
}
private void unload()
@ -202,6 +216,16 @@ public void onFail() {}
public void openBackpack(@NotNull final Player opener, @Nullable final Backpack backpack, boolean editable)
{
Validate.notNull(opener);
WorldBlacklistMode disabled = isDisabled(opener);
if(disabled != WorldBlacklistMode.None)
{
switch(disabled)
{
case Message: messageWorldDisabled.send(opener); break;
case MissingPermission: messageNoPermission.send(opener); break;
}
return;
}
if(backpack == null)
{
messageInvalidBackpack.send(opener);
@ -233,4 +257,14 @@ public int getBackpackPermSize(Player player)
}
return 9;
}
public WorldBlacklistMode isDisabled(Player player)
{
if(worldBlacklistMode == WorldBlacklistMode.None || (worldBlacklistMode != WorldBlacklistMode.NoPlugin && player.hasPermission("backpack.ignoreWorldBlacklist"))) return WorldBlacklistMode.None;
if(worldBlacklist.contains(player.getWorld().getName().toLowerCase()))
{
return worldBlacklistMode;
}
return WorldBlacklistMode.None;
}
}