From fea451a01c5f68b3c551a4a0d4f8c69fabdade91 Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Sat, 12 Sep 2015 18:17:41 +0200 Subject: [PATCH] Auto pickup on full inventory Allow bigger backpacks (7, 8 and 9 rows, have broken gui thanks to Minecraft) --- pom.xml | 186 +++++++++++------- resources/Lang/de.yml | 4 +- resources/Lang/en.yml | 4 +- resources/plugin.yml | 12 ++ .../georgh/MinePacks/Database/Config.java | 29 ++- .../georgh/MinePacks/Database/Language.java | 3 +- .../georgh/MinePacks/ItemsCollector.java | 76 +++++++ .../georgh/MinePacks/MinePacks.java | 45 +++-- 8 files changed, 264 insertions(+), 95 deletions(-) create mode 100644 src/at/pcgamingfreaks/georgh/MinePacks/ItemsCollector.java diff --git a/pom.xml b/pom.xml index 07ded49..c5211fc 100644 --- a/pom.xml +++ b/pom.xml @@ -1,74 +1,114 @@ - - 4.0.0 - at.pcgamingfreaks - MinePacks - 1.12.2 - - - in-project - In Project Repo - file://${project.basedir}/jar_libs - - - spigot-repo - https://hub.spigotmc.org/nexus/content/groups/public/ - - - - clean install - src - - - resources - true - - **/*.java - - - - - - maven-compiler-plugin - 3.1 - - 1.7 - 1.7 - - - - org.codehaus.mojo - build-helper-maven-plugin - 1.4 - - - add-wsdl-source - generate-sources - - add-source - - - - ${basedir}/libs - - - - - - - - - - org.bukkit - bukkit - LATEST - provided - - - net.minecraft - Minecraft - 1 - system - ${project.basedir}/jar_libs/bukkit.jar - - + + 4.0.0 + at.pcgamingfreaks + MinePacks + 1.13 + + + scm:git:git@github.com:GeorgH93/Bukkit_Minepacks.git + scm:git:git@github.com:GeorgH93/Bukkit_Minepacks.git + git@github.com:GeorgH93/Bukkit_Minepacks.git + + + GitHub + https://github.com/GeorgH93/Bukkit_Minepacks/issues + + + jenkins + http://ci.pcgamingfreaks.at/job/Bukkit_Minepacks/ + + + Bukkit Minepacks + A backpack plugin for Bukkit. + 2014 + + + GNU General Public License (GPL) v3 + http://www.gnu.org/licenses/gpl-3.0.txt + repo + + + + + + in-project + In Project Repo + file://${project.basedir}/jar_libs + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + + + + org.bukkit + bukkit + LATEST + provided + + + net.minecraft + Minecraft + 1 + system + ${project.basedir}/jar_libs/bukkit.jar + + + + + clean install + src + + + resources + true + + **/*.java + + + + + + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.4 + + + add-wsdl-source + generate-sources + + add-source + + + + ${basedir}/libs + + + + + + + + + + + releases + http://repo.pcgamingfreaks.at/repository/releases/ + + + snapshots + http://repo.pcgamingfreaks.at/repository/snapshots/ + + \ No newline at end of file diff --git a/resources/Lang/de.yml b/resources/Lang/de.yml index 48a128b..2b0d1d0 100644 --- a/resources/Lang/de.yml +++ b/resources/Lang/de.yml @@ -1,4 +1,4 @@ -Version: 2 +Version: 3 Language: Console: Enabled: MinePacks wurde aktiviert! @@ -11,7 +11,7 @@ Language: NoPermission: 'Dir fehlen die Rechte dafür.' OwnBackPackClose: 'Rucksack geschlossen!' PlayerBackPackClose: "%s's Rucksack geschlossen!" - IvalidBackpack: Rucksack fehlerhaft. + InvalidBackpack: Rucksack fehlerhaft. BackpackCleaned: Rucksack gelehrt. Cooldown: 'Bitte warte etwas bis du deinen Rucksack erneut öffnest.' Description: diff --git a/resources/Lang/en.yml b/resources/Lang/en.yml index 17f32a5..2732902 100644 --- a/resources/Lang/en.yml +++ b/resources/Lang/en.yml @@ -1,4 +1,4 @@ -Version: 2 +Version: 3 Language: Console: Enabled: MinePacks has been enabled! @@ -11,7 +11,7 @@ Language: NoPermission: You don't have the Permission to do that. OwnBackPackClose: 'Backpack closed!' PlayerBackPackClose: "%s's backpack closed!" - IvalidBackpack: Invalid backpack. + InvalidBackpack: Invalid backpack. BackpackCleaned: Backpack cleaned. Cooldown: "Please wait till you reopen your backpack." Description: diff --git a/resources/plugin.yml b/resources/plugin.yml index fee383f..f766401 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -46,9 +46,21 @@ permissions: backpack.size.6: description: 6*9 backpack default: false + backpack.size.7: + description: 7*9 backpack (broken gui) + default: false + backpack.size.8: + description: 8*9 backpack (broken gui) + default: false + backpack.size.9: + description: 9*9 backpack (broken gui) + default: false backpack.clean: description: Allows the player to clean their own backpack. default: false + backpack.fullpickup: + desctiption: Allows the player to automatically pick up items when their inventory is full (function needs to be enabled in the config) + defaut: true backpack.clean.other: description: Allows the player to clean other players backpacks. default: op diff --git a/src/at/pcgamingfreaks/georgh/MinePacks/Database/Config.java b/src/at/pcgamingfreaks/georgh/MinePacks/Database/Config.java index b16acb5..a6adbba 100644 --- a/src/at/pcgamingfreaks/georgh/MinePacks/Database/Config.java +++ b/src/at/pcgamingfreaks/georgh/MinePacks/Database/Config.java @@ -31,7 +31,7 @@ public class Config { private MinePacks MP; private FileConfiguration config; - private static final int CONFIG_VERSION = 7; + private static final int CONFIG_VERSION = 8; public Config(MinePacks mp) { @@ -85,9 +85,12 @@ private void NewConfig(File file) config.set("BackpackTitle", ChatColor.AQUA + "%s Backpack"); config.set("command_cooldown", -1); config.set("drop_on_death", true); + config.set("full_inventory.collect_items", false); + config.set("full_inventory.check_interval", 1); // in seconds + config.set("full_inventory.collect_radius", 1); // in blocks config.set("Language", "en"); config.set("LanguageUpdateMode","Overwrite"); - config.set("Database.Type","sqlite"); + config.set("Database.Type","SQLite"); config.set("Database.UpdatePlayer", true); config.set("Database.AutoCleanup.MaxInactiveDays", -1); config.set("Database.UseUUIDs", Bukkit.getServer().getOnlineMode() && UUIDComp()); @@ -141,6 +144,10 @@ private boolean UpdateConfig(File file) config.set("Database.Tables.Fields.Backpack.LastUpdate", "lastupdate"); case 6: config.set("show_close_message", true); + case 7: + config.set("full_inventory.collect_items", false); + config.set("full_inventory.check_interval", 1); // in seconds + config.set("full_inventory.collect_radius", 1.5); // in blocks break; case CONFIG_VERSION: return false; default: MP.log.info("Config File Version newer than expected!"); return false; @@ -235,8 +242,7 @@ public boolean getUseUUIDSeparators() public String getBPTitle() { - String BPTitle = config.getString("BackpackTitle", "%s Backpack"); - return BPTitle; + return config.getString("BackpackTitle", "%s Backpack"); } public boolean getDropOnDeath() @@ -258,4 +264,19 @@ public boolean getShowCloseMessage() { return config.getBoolean("show_close_message", true); } + + public boolean getFullInvCollect() + { + return config.getBoolean("full_inventory.collect_items", false); + } + + public long getFullInvCheckInterval() + { + return config.getInt("full_inventory.check_interval", 1) * 20L; // in seconds + } + + public double getFullInvRadius() + { + return config.getDouble("full_inventory.collect_radius", 1.5); // in blocks + } } \ No newline at end of file diff --git a/src/at/pcgamingfreaks/georgh/MinePacks/Database/Language.java b/src/at/pcgamingfreaks/georgh/MinePacks/Database/Language.java index 562880b..1fe68ce 100644 --- a/src/at/pcgamingfreaks/georgh/MinePacks/Database/Language.java +++ b/src/at/pcgamingfreaks/georgh/MinePacks/Database/Language.java @@ -31,7 +31,7 @@ public class Language { private MinePacks MP; private FileConfiguration lang; - private static final int LANG_VERSION = 2; + private static final int LANG_VERSION = 3; public Language(MinePacks mp) { @@ -100,6 +100,7 @@ private boolean UpdateLangFile(File file) switch(lang.getInt("Version")) { case 1: lang.set("Language.Ingame.Cooldown", "Please wait till you reopen your backpack."); + case 2: lang.set("Language.Ingame.InvalidBackpack", lang.getString("Language.Ingame.IvalidBackpack", "Invalid backpack.")); break; default: MP.log.warning("Language File Version newer than expected!"); return false; } diff --git a/src/at/pcgamingfreaks/georgh/MinePacks/ItemsCollector.java b/src/at/pcgamingfreaks/georgh/MinePacks/ItemsCollector.java new file mode 100644 index 0000000..fbe53e4 --- /dev/null +++ b/src/at/pcgamingfreaks/georgh/MinePacks/ItemsCollector.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2014-2015 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.georgh.MinePacks; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.HashMap; +import java.util.List; + +public class ItemsCollector extends BukkitRunnable +{ + private double radius = 1.5; + private MinePacks plugin; + + public ItemsCollector(MinePacks mp) + { + plugin = mp; + radius = plugin.config.getFullInvRadius(); + } + + @Override + public void run() + { + for(Player player : Bukkit.getServer().getOnlinePlayers()) + { + if(player.getInventory().firstEmpty() == -1 && player.hasPermission("backpack.fullpickup")) + { + Backpack backpack = plugin.DB.getBackpack(player, false); + if(backpack == null) + { + continue; + } + List entities = player.getNearbyEntities(radius, radius, radius); + for(Entity entity : entities) + { + if(entity instanceof Item) + { + Item item = (Item) entity; + if(!item.isDead() && item.getPickupDelay() <= 0) + { + HashMap full = backpack.getBackpack().addItem(item.getItemStack()); + if(!full.isEmpty()) + { + item.setItemStack(full.get(0)); + } + else + { + item.remove(); + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/src/at/pcgamingfreaks/georgh/MinePacks/MinePacks.java b/src/at/pcgamingfreaks/georgh/MinePacks/MinePacks.java index 4f6dac7..6e5c6a1 100644 --- a/src/at/pcgamingfreaks/georgh/MinePacks/MinePacks.java +++ b/src/at/pcgamingfreaks/georgh/MinePacks/MinePacks.java @@ -33,50 +33,57 @@ public class MinePacks extends JavaPlugin { - public Logger log = getLogger(); - public Config config; + public final Logger log = getLogger(); + public final Config config = new Config(this); public Language lang; public Database DB; public HashMap cooldowns = new HashMap(); - static public String BackpackTitle; - public String Message_IvalidBackpack; - + public static String BackpackTitle; + public String Message_InvalidBackpack; + + @Override public void onEnable() { - config = new Config(this); lang = new Language(this); DB = Database.getDatabase(this); getCommand("backpack").setExecutor(new OnCommand(this)); getServer().getPluginManager().registerEvents(new EventListener(this), this); + + if(config.getFullInvCollect()) + { + (new ItemsCollector(this)).runTaskTimerAsynchronously(this, config.getFullInvCheckInterval(), config.getFullInvCheckInterval()); + } BackpackTitle = config.getBPTitle(); - Message_IvalidBackpack = ChatColor.translateAlternateColorCodes('&', ChatColor.RED + lang.Get("Ingame.IvalidBackpack")); + Message_InvalidBackpack = ChatColor.translateAlternateColorCodes('&', ChatColor.RED + lang.Get("Ingame.InvalidBackpack")); getServer().getServicesManager().register(MinePacks.class, this, this, ServicePriority.Normal); log.info(lang.Get("Console.Enabled")); } - + + @Override public void onDisable() { + getServer().getScheduler().cancelTasks(this); + DB.Close(); if(config.getAutoUpdate()) { new Bukkit_Updater(this, 83445, this.getFile(), UpdateType.DEFAULT, true); } - DB.Close(); log.info(lang.Get("Console.Disabled")); } - public void OpenBackpack(Player opener, OfflinePlayer owener, boolean editable) + public void OpenBackpack(Player opener, OfflinePlayer owner, boolean editable) { - OpenBackpack(opener, DB.getBackpack(owener, false), editable); + OpenBackpack(opener, DB.getBackpack(owner, false), editable); } public void OpenBackpack(Player opener, Backpack backpack, boolean editable) { if(backpack == null) { - opener.sendMessage(Message_IvalidBackpack); + opener.sendMessage(Message_InvalidBackpack); return; } backpack.Open(opener, editable); @@ -84,7 +91,19 @@ public void OpenBackpack(Player opener, Backpack backpack, boolean editable) public int getBackpackPermSize(Player player) { - if(player.hasPermission("backpack.size.6")) + if(player.hasPermission("backpack.size.9")) + { + return 81; + } + else if(player.hasPermission("backpack.size.8")) + { + return 72; + } + else if(player.hasPermission("backpack.size.7")) + { + return 63; + } + else if(player.hasPermission("backpack.size.6")) { return 54; }