Auto pickup on full inventory

Allow bigger backpacks (7, 8 and 9 rows, have broken gui thanks to Minecraft)
This commit is contained in:
GeorgH93 2015-09-12 18:17:41 +02:00
parent 573c2531b4
commit fea451a01c
8 changed files with 264 additions and 95 deletions

186
pom.xml
View File

@ -1,74 +1,114 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>MinePacks</artifactId>
<version>1.12.2</version>
<repositories>
<repository>
<id>in-project</id>
<name>In Project Repo</name>
<url>file://${project.basedir}/jar_libs</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
</repositories>
<build>
<defaultGoal>clean install</defaultGoal>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>add-wsdl-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/libs</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.minecraft</groupId>
<artifactId>Minecraft</artifactId>
<version>1</version>
<scope>system</scope>
<systemPath>${project.basedir}/jar_libs/bukkit.jar</systemPath>
</dependency>
</dependencies>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>MinePacks</artifactId>
<version>1.13</version>
<scm>
<connection>scm:git:git@github.com:GeorgH93/Bukkit_Minepacks.git</connection>
<developerConnection>scm:git:git@github.com:GeorgH93/Bukkit_Minepacks.git</developerConnection>
<url>git@github.com:GeorgH93/Bukkit_Minepacks.git</url>
</scm>
<issueManagement>
<system>GitHub</system>
<url>https://github.com/GeorgH93/Bukkit_Minepacks/issues</url>
</issueManagement>
<ciManagement>
<system>jenkins</system>
<url>http://ci.pcgamingfreaks.at/job/Bukkit_Minepacks/</url>
</ciManagement>
<name>Bukkit Minepacks</name>
<description>A backpack plugin for Bukkit.</description>
<inceptionYear>2014</inceptionYear>
<licenses>
<license>
<name>GNU General Public License (GPL) v3</name>
<url>http://www.gnu.org/licenses/gpl-3.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<repositories>
<repository>
<id>in-project</id>
<name>In Project Repo</name>
<url>file://${project.basedir}/jar_libs</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.minecraft</groupId>
<artifactId>Minecraft</artifactId>
<version>1</version>
<scope>system</scope>
<systemPath>${project.basedir}/jar_libs/bukkit.jar</systemPath>
</dependency>
</dependencies>
<build>
<defaultGoal>clean install</defaultGoal>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>add-wsdl-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/libs</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>releases</id>
<url>http://repo.pcgamingfreaks.at/repository/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://repo.pcgamingfreaks.at/repository/snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>

View File

@ -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:

View File

@ -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:

View File

@ -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

View File

@ -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 @@ public class Config
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 @@ public class Config
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 class Config
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 class Config
{
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
}
}

View File

@ -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 @@ public class Language
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;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<Entity> 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<Integer, ItemStack> full = backpack.getBackpack().addItem(item.getItemStack());
if(!full.isEmpty())
{
item.setItemStack(full.get(0));
}
else
{
item.remove();
}
}
}
}
}
}
}
}

View File

@ -33,50 +33,57 @@ import at.pcgamingfreaks.georgh.MinePacks.Database.*;
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<Player, Long> cooldowns = new HashMap<Player, Long>();
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 class MinePacks extends JavaPlugin
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;
}