Add config option to define the max backpack size

This commit is contained in:
GeorgH93 2016-04-06 18:38:39 +02:00
parent be9b55d56c
commit d81dc5a9e5
4 changed files with 18 additions and 9 deletions

View File

@ -20,6 +20,8 @@ command_cooldown: -1
drop_on_death: true drop_on_death: true
# Defines if the message that the backpack has been closed should be shown # Defines if the message that the backpack has been closed should be shown
show_close_message: flase show_close_message: flase
# Defines the max amount of colums for a backpack
max_size: 6
# Controlls for the auto pickup on full inventory function # Controlls for the auto pickup on full inventory function
full_inventory: full_inventory:
@ -86,4 +88,4 @@ Database:
auto-update: true auto-update: true
# Config file version. Don't touch it! # Config file version. Don't touch it!
Version: 11 Version: 12

View File

@ -27,7 +27,7 @@
public class Config extends Configuration public class Config extends Configuration
{ {
private static final int CONFIG_VERSION = 11; private static final int CONFIG_VERSION = 12;
public Config(JavaPlugin plugin) public Config(JavaPlugin plugin)
{ {
@ -161,6 +161,11 @@ public boolean getDropOnDeath()
return config.getBoolean("drop_on_death", true); return config.getBoolean("drop_on_death", true);
} }
public int getBackpackMaxSize()
{
return config.getInt("max_size", 6);
}
public boolean getAutoUpdate() public boolean getAutoUpdate()
{ {
return config.getBoolean("auto-update", true); return config.getBoolean("auto-update", true);

View File

@ -45,7 +45,9 @@ public class MinePacks extends JavaPlugin
public HashMap<Player, Long> cooldowns = new HashMap<>(); public HashMap<Player, Long> cooldowns = new HashMap<>();
public static String backpackTitleOther, backpackTitle; public static String backpackTitleOther, backpackTitle;
public String Message_InvalidBackpack; public String messageInvalidBackpack;
private static int maxSize;
public static MinePacks getInstance() public static MinePacks getInstance()
{ {
@ -69,7 +71,6 @@ public void onEnable()
//endregion //endregion
config = new Config(this); config = new Config(this);
lang = new Language(this); lang = new Language(this);
lang.load(config.getLanguage(), config.getLanguageUpdateMode()); lang.load(config.getLanguage(), config.getLanguageUpdateMode());
DB = Database.getDatabase(this); DB = Database.getDatabase(this);
getCommand("backpack").setExecutor(new OnCommand(this)); getCommand("backpack").setExecutor(new OnCommand(this));
@ -80,9 +81,10 @@ public void onEnable()
(new ItemsCollector(this)).runTaskTimer(this, config.getFullInvCheckInterval(), config.getFullInvCheckInterval()); (new ItemsCollector(this)).runTaskTimer(this, config.getFullInvCheckInterval(), config.getFullInvCheckInterval());
} }
maxSize = config.getBackpackMaxSize();
backpackTitleOther = config.getBPTitleOther(); backpackTitleOther = config.getBPTitleOther();
backpackTitle = Utils.limitLength(config.getBPTitle(), 32); backpackTitle = Utils.limitLength(config.getBPTitle(), 32);
Message_InvalidBackpack = lang.getTranslated("Ingame.InvalidBackpack"); messageInvalidBackpack = lang.getTranslated("Ingame.InvalidBackpack");
getServer().getServicesManager().register(MinePacks.class, this, this, ServicePriority.Normal); getServer().getServicesManager().register(MinePacks.class, this, this, ServicePriority.Normal);
log.info(lang.get("Console.Enabled")); log.info(lang.get("Console.Enabled"));
} }
@ -141,7 +143,7 @@ public void openBackpack(Player opener, Backpack backpack, boolean editable)
{ {
if(backpack == null) if(backpack == null)
{ {
opener.sendMessage(Message_InvalidBackpack); opener.sendMessage(messageInvalidBackpack);
return; return;
} }
backpack.open(opener, editable); backpack.open(opener, editable);
@ -149,7 +151,7 @@ public void openBackpack(Player opener, Backpack backpack, boolean editable)
public static int getBackpackPermSize(Player player) public static int getBackpackPermSize(Player player)
{ {
for(int i = 9; i > 1; i--) for(int i = maxSize; i > 1; i--)
{ {
if(player.hasPermission("backpack.size." + i)) if(player.hasPermission("backpack.size." + i))
{ {

View File

@ -133,14 +133,14 @@ public void onResult(Backpack backpack)
} }
else else
{ {
player.sendMessage(plugin.Message_InvalidBackpack); player.sendMessage(plugin.messageInvalidBackpack);
} }
} }
@Override @Override
public void onFail() public void onFail()
{ {
player.sendMessage(plugin.Message_InvalidBackpack); player.sendMessage(plugin.messageInvalidBackpack);
} }
}); });
} }