Updated to CraftBukkit 1.9

This commit is contained in:
ShadowRanger 2016-03-02 20:11:45 +11:00
parent 7ae87d1dbe
commit c4a9cb0a4a
17 changed files with 119 additions and 101 deletions

2
README
View file

@ -1,4 +1,4 @@
Copyright (C) 2011-2014 lishid. All rights reserved. Copyright (C) 2011-2016 lishid. All rights reserved.
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2016 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -20,6 +20,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2016 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2016 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2016 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -147,10 +147,14 @@ public class OpenInvCommand implements CommandExecutor {
openInvHistory.put(player.getUniqueId(), target.getUniqueId()); openInvHistory.put(player.getUniqueId(), target.getUniqueId());
// Create the inventory // Create the inventory
/*
SpecialPlayerInventory inv = OpenInv.inventories.get(target.getUniqueId()); SpecialPlayerInventory inv = OpenInv.inventories.get(target.getUniqueId());
if (inv == null) { if (inv == null) {
inv = new SpecialPlayerInventory(target, target.isOnline()); inv = new SpecialPlayerInventory(target, target.isOnline());
} }
*/
SpecialPlayerInventory inv = new SpecialPlayerInventory(target, target.isOnline());
// Open the inventory // Open the inventory
player.openInventory(inv.getBukkitInventory()); player.openInventory(inv.getBukkitInventory());

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2016 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2016 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2016 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2016 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2016 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2016 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2016 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2016 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2016 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -30,21 +30,26 @@ import org.bukkit.craftbukkit.v1_9_R1.inventory.*;
/* /*
* ----------------------------------------------- * -----------------------------------------------
* This class still needs to be updated for 1.9. * This class still needs to be updated for 1.9.
*
* It has been partially updated, but is very buggy
* and does not work correctly.
* ----------------------------------------------- * -----------------------------------------------
*/ */
public class SpecialPlayerInventory extends PlayerInventory { public class SpecialPlayerInventory extends PlayerInventory {
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private final ItemStack[] extra = new ItemStack[5]; private final ItemStack[] extra = new ItemStack[5];
private final ItemStack[][] g;
private final CraftPlayer owner; private final CraftPlayer owner;
private boolean playerOnline; private boolean playerOnline;
public SpecialPlayerInventory(Player p, boolean online) { public SpecialPlayerInventory(Player p, boolean online) {
super(((CraftPlayer) p).getHandle()); super(((CraftPlayer) p).getHandle());
this.owner = (CraftPlayer) p; this.owner = (CraftPlayer) p;
this.items = player.inventory.items; System.arraycopy(player.inventory.items, 0, this.items, 0, this.items.length);
this.armor = player.inventory.armor; System.arraycopy(player.inventory.armor, 0, this.armor, 0, this.armor.length);
this.g = new ItemStack[][]{this.items, this.armor, this.extra};
this.playerOnline = online; this.playerOnline = online;
OpenInv.inventories.put(owner.getUniqueId(), this); // OpenInv.inventories.put(owner.getUniqueId(), this);
} }
public Inventory getBukkitInventory() { public Inventory getBukkitInventory() {
@ -52,15 +57,19 @@ public class SpecialPlayerInventory extends PlayerInventory {
} }
private void saveOnExit() { private void saveOnExit() {
if (playerOnline) {
linkInventory(player.inventory);
}
if (transaction.isEmpty() && !playerOnline) { if (transaction.isEmpty() && !playerOnline) {
owner.saveData(); owner.saveData();
OpenInv.inventories.remove(owner.getUniqueId()); // OpenInv.inventories.remove(owner.getUniqueId());
} }
} }
private void linkInventory(PlayerInventory inventory) { private void linkInventory(PlayerInventory inventory) {
inventory.items = this.items; System.arraycopy(this.items, 0, inventory.items, 0, inventory.items.length);
inventory.armor = this.armor; System.arraycopy(this.armor, 0, inventory.armor, 0, inventory.armor.length);
} }
public void playerOnline(Player player) { public void playerOnline(Player player) {
@ -87,99 +96,100 @@ public class SpecialPlayerInventory extends PlayerInventory {
@Override @Override
public ItemStack[] getContents() { public ItemStack[] getContents() {
ItemStack[] C = new ItemStack[getSize()]; ItemStack[] contents = new ItemStack[getSize()];
System.arraycopy(items, 0, C, 0, items.length); System.arraycopy(this.items, 0, contents, 0, this.items.length);
System.arraycopy(armor, 0, C, items.length, armor.length); System.arraycopy(this.armor, 0, contents, this.items.length, this.armor.length);
return C; return contents;
} }
@Override @Override
public int getSize() { public int getSize() {
return super.getSize() + 5; return super.getSize() + 5; // super.getSize() - this.extraSlots.length + 5;
} }
@Override @Override
public ItemStack getItem(int i) { public ItemStack getItem(int i) {
ItemStack[] is = this.items; ItemStack[] is = null;
ItemStack[][] contents = this.g;
int j = contents.length;
if (i >= is.length) { for (int k = 0; k < j; ++k) {
i -= is.length; ItemStack[] is2 = contents[k];
is = this.armor; if (i < is2.length) {
} else { is = is2;
i = getReversedItemSlotNum(i); break;
}
i -= is2.length;
} }
if (i >= is.length) { if (is == this.items) {
i -= is.length; i = getReversedItemSlotNum(i);
is = this.extra;
} else if (is == this.armor) { } else if (is == this.armor) {
i = getReversedArmorSlotNum(i); i = getReversedArmorSlotNum(i);
} else if (is == this.extra) {
// Do nothing
} }
return is[i]; return is == null ? null : is[i];
} }
@Override @Override
public ItemStack splitStack(int i, int j) { public ItemStack splitStack(int i, int j) {
ItemStack[] is = this.items; ItemStack[] is = null;
ItemStack[][] contents = this.g;
int k = contents.length;
if (i >= is.length) { for (int l = 0; l < k; ++l) {
i -= is.length; ItemStack[] is2 = contents[l];
is = this.armor; if (i < is2.length) {
} else { is = is2;
i = getReversedItemSlotNum(i); break;
}
i -= is2.length;
} }
if (i >= is.length) { if (is == this.items) {
i -= is.length; i = getReversedItemSlotNum(i);
is = this.extra;
} else if (is == this.armor) { } else if (is == this.armor) {
i = getReversedArmorSlotNum(i); i = getReversedArmorSlotNum(i);
} else if (is == this.extra) {
// Do nothing
} }
if (is[i] != null) { return is != null && is[i] != null ? ContainerUtil.a(is, i, j) : null;
ItemStack itemstack;
if (is[i].count <= j) {
itemstack = is[i];
is[i] = null;
return itemstack;
} else {
itemstack = is[i].cloneAndSubtract(j);
if (is[i].count == 0) {
is[i] = null;
}
return itemstack;
}
} else {
return null;
}
} }
@Override @Override
public ItemStack splitWithoutUpdate(int i) { public ItemStack splitWithoutUpdate(int i) {
ItemStack[] is = this.items; ItemStack[] is = null;
ItemStack[][] contents = this.g;
int j = contents.length;
if (i >= is.length) { for (int object = 0; object < j; ++object) {
i -= is.length; ItemStack[] is2 = contents[object];
is = this.armor; if (i < is2.length) {
} else { is = is2;
i = getReversedItemSlotNum(i); break;
}
i -= is2.length;
} }
if (i >= is.length) {
i -= is.length;
is = this.extra;
} else if (is == this.armor) {
i = getReversedArmorSlotNum(i);
}
if (is[i] != null) { if (is != null && is[i] != null) {
ItemStack itemstack = is[i]; if (is == this.items) {
i = getReversedItemSlotNum(i);
} else if (is == this.armor) {
i = getReversedArmorSlotNum(i);
} else if (is == this.extra) {
// Do nothing
}
Object object = is[i];
is[i] = null; is[i] = null;
return itemstack; return (ItemStack) object;
} else { } else {
return null; return null;
} }
@ -187,31 +197,34 @@ public class SpecialPlayerInventory extends PlayerInventory {
@Override @Override
public void setItem(int i, ItemStack itemStack) { public void setItem(int i, ItemStack itemStack) {
ItemStack[] is = this.items; ItemStack[] is = null;
ItemStack[][] contents = this.g;
int j = contents.length;
if (i >= is.length) { for (int k = 0; k < j; ++k) {
i -= is.length; ItemStack[] is2 = contents[k];
is = this.armor; if (i < is2.length) {
} else { is = is2;
i = getReversedItemSlotNum(i); break;
}
i -= is2.length;
} }
if (i >= is.length) { if (is != null) {
i -= is.length; if (is == this.items) {
is = this.extra; i = getReversedItemSlotNum(i);
} else if (is == this.armor) { } else if (is == this.armor) {
i = getReversedArmorSlotNum(i); i = getReversedArmorSlotNum(i);
} else if (is == this.extra) {
owner.getHandle().drop(itemStack, true);
itemStack = null;
}
is[i] = itemStack;
// owner.getHandle().defaultContainer.b();
} }
// Effects
if (is == this.extra) {
owner.getHandle().drop(itemStack, true);
itemStack = null;
}
is[i] = itemStack;
owner.getHandle().defaultContainer.b();
} }
private int getReversedItemSlotNum(int i) { private int getReversedItemSlotNum(int i) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2016 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2016 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2016 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by