use of org.bukkit.inventory.InventoryHolder in project Minigames by AddstarMC.
the class RecorderData method restoreBlocks.
public void restoreBlocks(final MinigamePlayer modifier) {
// When rolling back a single player's changes dont change the overall games state
if (modifier == null) {
minigame.setState(MinigameState.REGENERATING);
}
Iterator<BlockData> it = blockdata.values().iterator();
final List<BlockData> resBlocks = Lists.newArrayList();
final List<BlockData> addBlocks = Lists.newArrayList();
while (it.hasNext()) {
BlockData data = it.next();
if (modifier == null || modifier.equals(data.getModifier())) {
it.remove();
// Clear inventories
if (data.getLocation().getBlock().getState() instanceof InventoryHolder) {
InventoryHolder block = (InventoryHolder) data.getLocation().getBlock().getState();
block.getInventory().clear();
}
if (physBlocks.contains(data.getBlockState().getType()) || data.getItems() != null) {
addBlocks.add(data);
} else {
resBlocks.add(data);
}
}
}
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
Collections.sort(resBlocks, new Comparator<BlockData>() {
@Override
public int compare(BlockData o1, BlockData o2) {
int comp = Integer.valueOf(o1.getBlockState().getChunk().getX()).compareTo(o2.getBlockState().getChunk().getX());
if (comp != 0)
return comp;
comp = Integer.valueOf(o1.getBlockState().getChunk().getZ()).compareTo(o2.getBlockState().getChunk().getZ());
if (comp != 0)
return comp;
return Integer.valueOf(o1.getBlockState().getY()).compareTo(o2.getBlockState().getY());
}
});
Collections.sort(addBlocks, new Comparator<BlockData>() {
@Override
public int compare(BlockData o1, BlockData o2) {
int comp = Integer.valueOf(o1.getBlockState().getChunk().getX()).compareTo(o2.getBlockState().getChunk().getX());
if (comp != 0)
return comp;
comp = Integer.valueOf(o1.getBlockState().getChunk().getZ()).compareTo(o2.getBlockState().getChunk().getZ());
if (comp != 0)
return comp;
return Integer.valueOf(o1.getBlockState().getY()).compareTo(o2.getBlockState().getY());
}
});
new RollbackScheduler(resBlocks, addBlocks, minigame, modifier);
}
});
}
use of org.bukkit.inventory.InventoryHolder in project Glowstone by GlowstoneMC.
the class GlowMinecart method entityInteract.
@Override
public boolean entityInteract(GlowPlayer player, InteractEntityMessage message) {
if (message.getAction() == InteractEntityMessage.Action.ATTACK.ordinal()) {
// todo: damage points
if (this instanceof InventoryHolder) {
InventoryHolder inv = (InventoryHolder) this;
if (inv.getInventory() != null) {
for (ItemStack drop : inv.getInventory().getContents()) {
if (drop == null || drop.getType() == Material.AIR || drop.getAmount() < 1) {
continue;
}
GlowItem item = world.dropItemNaturally(getLocation(), drop);
item.setPickupDelay(30);
item.setBias(player);
}
}
}
remove();
}
return true;
}
use of org.bukkit.inventory.InventoryHolder in project Essentials by drtshock.
the class EssentialsPlayerListener method onInventoryCloseEvent.
@EventHandler(priority = EventPriority.MONITOR)
public void onInventoryCloseEvent(final InventoryCloseEvent event) {
Player refreshPlayer = null;
final Inventory top = event.getView().getTopInventory();
final InventoryType type = top.getType();
if (type == InventoryType.PLAYER) {
final User user = ess.getUser((Player) event.getPlayer());
user.setInvSee(false);
refreshPlayer = user.getBase();
} else if (type == InventoryType.ENDER_CHEST) {
final User user = ess.getUser((Player) event.getPlayer());
user.setEnderSee(false);
refreshPlayer = user.getBase();
} else if (type == InventoryType.WORKBENCH) {
final User user = ess.getUser((Player) event.getPlayer());
if (user.isRecipeSee()) {
user.setRecipeSee(false);
event.getView().getTopInventory().clear();
refreshPlayer = user.getBase();
}
} else if (type == InventoryType.CHEST && top.getSize() == 9) {
final InventoryHolder invHolder = top.getHolder();
if (invHolder != null && invHolder instanceof HumanEntity) {
final User user = ess.getUser((Player) event.getPlayer());
user.setInvSee(false);
refreshPlayer = user.getBase();
}
}
if (refreshPlayer != null) {
final Player player = refreshPlayer;
ess.scheduleSyncDelayedTask(new Runnable() {
@Override
public void run() {
player.updateInventory();
}
}, 1);
}
}
Aggregations