Code cleanup

Now less restrictive
This commit is contained in:
GeorgH93 2015-09-21 16:07:34 +02:00
parent 06634817be
commit 2209b02feb
5 changed files with 18 additions and 23 deletions

View File

@ -8,7 +8,7 @@ Language: en
# Update = the old language file will be updated with the new english messages, all your changes to the file will survive the update
LanguageUpdateMode: Overwrite
# Title to be showen for the opened inventory. Musst contain an %s (which will be replaced with the players name)
# Title to be showen for the opened inventory. Can contain %s (which will be replaced with the players name).
BackpackTitle: "&b%s Backpack"
# Defines how long a player have to wait till he can reopen his backpack.
# Time is in seconds. Values < 1 disable the cooldown.

View File

@ -47,10 +47,10 @@ public Backpack(OfflinePlayer owner, int size)
this(owner, size, -1);
}
public Backpack(OfflinePlayer Owner, int Size, int ID)
public Backpack(OfflinePlayer owner, int Size, int ID)
{
owner = Owner;
title = String.format(MinePacks.BackpackTitle, Owner.getName());
this.owner = owner;
title = String.format(MinePacks.BackpackTitle, owner.getName());
bp = Bukkit.createInventory(null, Size, title);
size = Size;
id = ID;
@ -78,13 +78,13 @@ public OfflinePlayer getOwner()
return owner;
}
public void Open(Player p, boolean editable)
public void open(Player p, boolean editable)
{
opened.put(p, editable);
p.openInventory(bp);
}
public void Close(Player p)
public void close(Player p)
{
opened.remove(p);
}
@ -116,7 +116,7 @@ public List<ItemStack> setSize(int newSize)
{
e.getKey().closeInventory();
}
List<ItemStack> RemovedItems = new ArrayList<>();
List<ItemStack> removedItems = new ArrayList<>();
ItemStack[] itemStackArray;
if(bp.getSize() > newSize)
{
@ -133,7 +133,7 @@ public List<ItemStack> setSize(int newSize)
}
else
{
RemovedItems.add(i);
removedItems.add(i);
}
}
}
@ -142,7 +142,7 @@ public List<ItemStack> setSize(int newSize)
{
itemStackArray = bp.getContents();
}
bp = Bukkit.createInventory(null, newSize, title);
bp = Bukkit.createInventory(bp.getHolder(), newSize, title);
for(int i = 0; i < itemStackArray.length; i++)
{
bp.setItem(i, itemStackArray[i]);
@ -153,16 +153,11 @@ public List<ItemStack> setSize(int newSize)
e.getKey().openInventory(bp);
}
inWork = false;
return RemovedItems;
return removedItems;
}
public Inventory getBackpack()
{
return bp;
}
public String getTitle()
{
return title;
}
}

View File

@ -25,6 +25,7 @@
import at.pcgamingfreaks.georgh.MinePacks.Backpack;
import at.pcgamingfreaks.georgh.MinePacks.MinePacks;
import at.pcgamingfreaks.georgh.MinePacks.Database.ItemStackSerializer.ItemStackSerializer;
import org.bukkit.inventory.Inventory;
public class Database
{
@ -90,11 +91,11 @@ private Backpack findBackpack(OfflinePlayer player)
return null;
}
public Backpack getBackpack(String title)
public Backpack getBackpack(Inventory inventory)
{
for(Backpack bp : backpacks)
{
if(bp.getTitle().equals(title))
if(bp.getBackpack().equals(inventory))
{
return bp;
}

View File

@ -70,7 +70,7 @@ public void onClose(InventoryCloseEvent event)
{
if (event.getInventory() != null && event.getInventory().getTitle() != null && event.getPlayer() instanceof Player)
{
Backpack backpack = plugin.DB.getBackpack(event.getInventory().getTitle());
Backpack backpack = plugin.DB.getBackpack(event.getInventory());
if(backpack != null && !backpack.inUse())
{
Player closer = (Player)event.getPlayer();
@ -78,7 +78,7 @@ public void onClose(InventoryCloseEvent event)
{
plugin.DB.saveBackpack(backpack);
}
backpack.Close(closer);
backpack.close(closer);
if(event.getPlayer().getName().equals(backpack.getOwner().getName()))
{
if(showCloseMessageOwn)
@ -102,7 +102,7 @@ public void onClick(InventoryClickEvent event)
{
if (event.getInventory() != null && event.getInventory().getTitle() != null && event.getWhoClicked() instanceof Player)
{
Backpack backpack = plugin.DB.getBackpack(event.getInventory().getTitle());
Backpack backpack = plugin.DB.getBackpack(event.getInventory());
if(backpack != null && !backpack.canEdit((Player)event.getWhoClicked()))
{
event.setCancelled(true);

View File

@ -23,7 +23,6 @@
import net.gravitydevelopment.Updater.Bukkit_Updater;
import net.gravitydevelopment.Updater.UpdateType;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.ServicePriority;
@ -60,7 +59,7 @@ public void onEnable()
(new ItemsCollector(this)).runTaskTimerAsynchronously(this, config.getFullInvCheckInterval(), config.getFullInvCheckInterval());
}
BackpackTitle = (config.getBPTitle().contains("%s") ? config.getBPTitle() : ChatColor.AQUA + "%s Backpack");
BackpackTitle = config.getBPTitle();
Message_InvalidBackpack = lang.getTranslated("Ingame.InvalidBackpack");
getServer().getServicesManager().register(MinePacks.class, this, this, ServicePriority.Normal);
log.info(lang.get("Console.Enabled"));
@ -90,7 +89,7 @@ public void OpenBackpack(Player opener, Backpack backpack, boolean editable)
opener.sendMessage(Message_InvalidBackpack);
return;
}
backpack.Open(opener, editable);
backpack.open(opener, editable);
}
public int getBackpackPermSize(Player player)