Implemented all requested Item Cube API methods.
This commit is contained in:
parent
94037dbea6
commit
341a330d6b
Binary file not shown.
@ -158,6 +158,14 @@ public class EliteMonster {
|
||||
if (!m.getLocation().getWorld().equals(myspawn.getWorld())) {
|
||||
myspawn = m.getLocation(); //Then this is my new spawn...
|
||||
}
|
||||
for (Player p : targetlist) {
|
||||
if (p.isDead()) {
|
||||
targetlist.remove(p);
|
||||
}
|
||||
}
|
||||
if (targetlist.size()==0) {
|
||||
participantlist.clear();
|
||||
}
|
||||
}
|
||||
|
||||
protected void dontDrown() {
|
||||
@ -274,7 +282,7 @@ public class EliteMonster {
|
||||
|
||||
//Triggers when this mob hits something.
|
||||
public void hitEvent(LivingEntity ent) {
|
||||
if (!targetlist.contains(ent) && (ent instanceof Player)) {
|
||||
if (!targetlist.contains(ent) && (ent instanceof Player) && !ent.isDead()) {
|
||||
targetlist.add((Player)ent);
|
||||
if (targetlist.size()>4) {
|
||||
double hpgain = m.getMaxHealth()*(0.25*(targetlist.size()-4));
|
||||
|
||||
@ -52,4 +52,22 @@ public class ItemCube {
|
||||
inv.addItem(cursor);
|
||||
}
|
||||
}
|
||||
public static void removeFromViewersofItemCube(int idnumb, ItemStack cursor, Player check) {
|
||||
Inventory inv = getViewingItemCubeInventory(idnumb, check);
|
||||
if (inv!=null) {
|
||||
inv.removeItem(cursor);
|
||||
}
|
||||
}
|
||||
public static void removeFromViewersofItemCube(int idnumb, ItemStack[] cursor, Player check) {
|
||||
Inventory inv = getViewingItemCubeInventory(idnumb, check);
|
||||
if (inv!=null) {
|
||||
inv.removeItem(cursor);
|
||||
}
|
||||
}
|
||||
public static void clearFromViewersofItemCube(int id, Player check) {
|
||||
Inventory inv = getViewingItemCubeInventory(id, check);
|
||||
if (inv!=null) {
|
||||
inv.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,7 +170,7 @@ public class ItemCubeUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static Collection<ItemStack> addItems(int id, ItemStack...items) {
|
||||
public static List<ItemStack> addItems(int id, ItemStack...items) {
|
||||
List<ItemStack> currentcontents = getItemCubeContents(id);
|
||||
List<ItemStack> leftovers = new ArrayList<ItemStack>();
|
||||
//Attempt to add them to an inventory.
|
||||
@ -198,4 +198,59 @@ public class ItemCubeUtils {
|
||||
saveConfig(id,InventoryUtils.ConvertInventoryToList(inv,slots),size);
|
||||
return leftovers;
|
||||
}
|
||||
|
||||
public static List<ItemStack> removeItems(int id, ItemStack...items) {
|
||||
List<ItemStack> currentcontents = getItemCubeContents(id);
|
||||
List<ItemStack> leftovers = new ArrayList<ItemStack>();
|
||||
//Attempt to add them to an inventory.
|
||||
CubeType size = getCubeType(id);
|
||||
int slots = size.getSize();
|
||||
Inventory inv = Bukkit.createInventory(null, slots);
|
||||
for (int i=0;i<slots;i++) {
|
||||
inv.setItem(i, currentcontents.get(i));
|
||||
}
|
||||
for (ItemStack item : items) {
|
||||
if (item!=null) {
|
||||
ItemStack tempitem = item.clone();
|
||||
HashMap<Integer,ItemStack> remaining = inv.removeItem(tempitem.clone());
|
||||
if (remaining.size()>0) {
|
||||
leftovers.add(remaining.get(0).clone());
|
||||
}
|
||||
ItemCube.removeFromViewersofItemCube(id,tempitem.clone(),null);
|
||||
}
|
||||
}
|
||||
saveConfig(id,InventoryUtils.ConvertInventoryToList(inv,slots),size);
|
||||
return leftovers;
|
||||
}
|
||||
|
||||
public static ItemStack removeItemFromSlot(int id, int slot) {
|
||||
List<ItemStack> currentcontents = getItemCubeContents(id);
|
||||
//Attempt to add them to an inventory.
|
||||
CubeType size = getCubeType(id);
|
||||
int slots = size.getSize();
|
||||
Inventory inv = Bukkit.createInventory(null, slots);
|
||||
for (int i=0;i<slots;i++) {
|
||||
inv.setItem(i, currentcontents.get(i));
|
||||
}
|
||||
ItemStack slotitem = inv.getItem(slot).clone();
|
||||
inv.setItem(slot, new ItemStack(Material.AIR));
|
||||
ItemCube.removeFromViewersofItemCube(id,slotitem.clone(),null);
|
||||
saveConfig(id,InventoryUtils.ConvertInventoryToList(inv,slots),size);
|
||||
if (slotitem==null) {
|
||||
return new ItemStack(Material.AIR);
|
||||
} else {
|
||||
return slotitem.clone();
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearItems(int id) {
|
||||
CubeType size = getCubeType(id);
|
||||
int slots = size.getSize();
|
||||
Inventory inv = Bukkit.createInventory(null, slots);
|
||||
for (int i=0;i<slots;i++) {
|
||||
inv.setItem(i, new ItemStack(Material.AIR));
|
||||
}
|
||||
ItemCube.clearFromViewersofItemCube(id,null);
|
||||
saveConfig(id,InventoryUtils.ConvertInventoryToList(inv,slots),size);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1349,6 +1349,21 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case "REMOVECUBE":{
|
||||
Collection<ItemStack> remaining = ItemCubeUtils.removeItems(Integer.parseInt(args[1]), p.getEquipment().getItemInMainHand());
|
||||
if (remaining.size()>0) {
|
||||
for (ItemStack item : remaining) {
|
||||
p.sendMessage("Could not remove "+GenericFunctions.UserFriendlyMaterialName(item)+" "+((item.getAmount()>1)?"x"+item.getAmount():""));
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case "CLEARCUBE":{
|
||||
ItemCubeUtils.clearItems(Integer.parseInt(args[1]));
|
||||
}break;
|
||||
case "REMOVESLOTCUBE":{
|
||||
ItemStack remaining = ItemCubeUtils.removeItemFromSlot(Integer.parseInt(args[1]), Integer.parseInt(args[2]));
|
||||
p.sendMessage("Removed "+GenericFunctions.UserFriendlyMaterialName(remaining));
|
||||
}break;
|
||||
}
|
||||
}
|
||||
//LivingEntity m = MonsterController.convertMonster((Monster)p.getWorld().spawnEntity(p.getLocation(),EntityType.ZOMBIE), MonsterDifficulty.ELITE);
|
||||
@ -5697,7 +5712,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
||||
@EventHandler(priority=EventPriority.LOW,ignoreCancelled = true)
|
||||
public void entityTargetEvent(EntityTargetLivingEntityEvent ev) {
|
||||
if ((ev.getEntity() instanceof Monster)) {
|
||||
log("In here",5);
|
||||
log("In here 1",5);
|
||||
Monster m = (Monster)ev.getEntity();
|
||||
if (m.hasPotionEffect(PotionEffectType.GLOWING)) {
|
||||
ev.setCancelled(true);
|
||||
@ -5705,7 +5720,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
||||
}
|
||||
LivingEntityStructure ms = LivingEntityStructure.getLivingEntityStructure(m);
|
||||
if (ms.getElite()) {
|
||||
log("In here",5);
|
||||
log("In here 2",5);
|
||||
EliteMonster em = null;
|
||||
for (int i=0;i<elitemonsters.size();i++) {
|
||||
if (elitemonsters.get(i).m.equals(ev.getEntity())) {
|
||||
@ -5715,7 +5730,9 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
||||
}
|
||||
if (em!=null && em.targetlist.size()==0) {
|
||||
if (em.targetlist.size()==0 && em.participantlist.size()==0) {
|
||||
TwosideKeeper.log("Cancel", 5);
|
||||
ev.setCancelled(true);
|
||||
ev.setTarget(null);
|
||||
return;
|
||||
}
|
||||
if ((ev.getTarget() instanceof Player) && !em.targetlist.contains((Player)ev.getTarget())) {
|
||||
@ -5748,6 +5765,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
||||
EliteMonster em = GenericFunctions.getProperEliteMonster(m);
|
||||
ms.SetElite(true);
|
||||
elitemonsters.add(em);
|
||||
ev.setCancelled(true);
|
||||
ev.setTarget(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,7 +192,13 @@ public final class TwosideKeeperAPI {
|
||||
public static CubeType getCubeType(int id) {
|
||||
return ItemCubeUtils.getCubeType(id);
|
||||
}
|
||||
public static Collection<ItemStack> getItemCubeContents(int id) {
|
||||
public static ItemStack removeItemFromSlot(int id,int slot) {
|
||||
return ItemCubeUtils.removeItemFromSlot(id,slot);
|
||||
}
|
||||
public static void clearItems(int id) {
|
||||
ItemCubeUtils.clearItems(id);
|
||||
}
|
||||
public static List<ItemStack> getItemCubeContents(int id) {
|
||||
return ItemCubeUtils.getItemCubeContents(id);
|
||||
}
|
||||
/**
|
||||
@ -204,6 +210,9 @@ public final class TwosideKeeperAPI {
|
||||
public static Collection<ItemStack> insertItemsIntoItemCube(int id, ItemStack...items) {
|
||||
return ItemCubeUtils.addItems(id, items);
|
||||
}
|
||||
public static List<ItemStack> removeItems(int id,ItemStack...items) {
|
||||
return ItemCubeUtils.removeItems(id, items);
|
||||
}
|
||||
|
||||
//Hardened Item Commands.
|
||||
public static boolean isHardenedItem(ItemStack i) {
|
||||
|
||||
@ -468,6 +468,9 @@ final class runServerHeartbeat implements Runnable {
|
||||
it.remove();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
it.remove();
|
||||
return;
|
||||
}
|
||||
}
|
||||
count++;
|
||||
@ -521,6 +524,7 @@ final class runServerHeartbeat implements Runnable {
|
||||
//Collect this item.
|
||||
if (((Item)ent).getItemStack().getType().isBlock()) {
|
||||
events.PlayerManualPickupItemEvent ev = new events.PlayerManualPickupItemEvent(p, ((Item) ent).getItemStack());
|
||||
Bukkit.getPluginManager().callEvent(ev);
|
||||
if (!ev.isCancelled()) {
|
||||
ItemStack[] remaining = InventoryUtils.insertItemsInVacuumCube(p, ((Item) ent).getItemStack());
|
||||
if (remaining.length==0) {
|
||||
@ -528,6 +532,9 @@ final class runServerHeartbeat implements Runnable {
|
||||
ent.remove();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
ent.remove();
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user