Skip to content

Instantly share code, notes, and snippets.

@daboross
Last active August 29, 2015 14:05
Show Gist options
  • Save daboross/e3e58c1889e635a804b3 to your computer and use it in GitHub Desktop.
Save daboross/e3e58c1889e635a804b3 to your computer and use it in GitHub Desktop.
java.lang.NullPointerException
at org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory.getSize(CraftInventory.java:41) ~[spigot.jar:git-Spigot-1543]
at org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory.getContents(CraftInventory.java:54) ~[spigot.jar:git-Spigot-1543]
at net.daboross.bukkitdev.skywars.world.WorldCopier.copy(WorldCopier.java:86) ~[SkyWars.jar:git-skywars-2.0.0]
at net.daboross.bukkitdev.skywars.world.WorldCopier.copyArena(WorldCopier.java:37) ~[SkyWars.jar:git-skywars-2.0.0]
at net.daboross.bukkitdev.skywars.world.SkyWorldHandler.onGameStart(SkyWorldHandler.java:100) ~[SkyWars.jar:git-skywars-2.0.0]
at net.daboross.bukkitdev.skywars.events.GameEventDistributor.distribute(GameEventDistributor.java:67) [SkyWars.jar:git-skywars-2.0.0]
at net.daboross.bukkitdev.skywars.game.GameHandler.startNewGame(GameHandler.java:47) [SkyWars.jar:git-skywars-2.0.0]
at net.daboross.bukkitdev.skywars.commands.mainsubcommands.ForceStartCommand.runCommand(ForceStartCommand.java:42) [SkyWars.jar:git-skywars-2.0.0]
at net.daboross.bukkitdev.skywars.libraries.ceb.CommandExecutorBase.onCommand(CommandExecutorBase.java:61) [SkyWars.jar:git-skywars-2.0.0]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) [spigot.jar:git-Spigot-1543]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) [spigot.jar:git-Spigot-1543]
at net.minecraft.server.v1_7_R3.CommandBlockListenerAbstract.a(CommandBlockListenerAbstract.java:172) [spigot.jar:git-Spigot-1543]
at net.minecraft.server.v1_7_R3.BlockCommand.a(BlockCommand.java:47) [spigot.jar:git-Spigot-1543]
at net.minecraft.server.v1_7_R3.WorldServer.a(WorldServer.java:568) [spigot.jar:git-Spigot-1543]
at net.minecraft.server.v1_7_R3.WorldServer.doTick(WorldServer.java:211) [spigot.jar:git-Spigot-1543]
at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:687) [spigot.jar:git-Spigot-1543]
at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:284) [spigot.jar:git-Spigot-1543]
at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:584) [spigot.jar:git-Spigot-1543]
at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:490) [spigot.jar:git-Spigot-1543]
at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-Spigot-1543]
java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R3.block.CraftBlockState cannot be cast to org.bukkit.block.Chest
at net.daboross.bukkitdev.skywars.world.WorldCopier.copy(WorldCopier.java:84) ~[SkyWars.jar:git-skywars-2.0.0]
at net.daboross.bukkitdev.skywars.world.WorldCopier.copyArena(WorldCopier.java:37) ~[SkyWars.jar:git-skywars-2.0.0]
at net.daboross.bukkitdev.skywars.world.SkyWorldHandler.onGameStart(SkyWorldHandler.java:100) ~[SkyWars.jar:git-skywars-2.0.0]
at net.daboross.bukkitdev.skywars.events.GameEventDistributor.distribute(GameEventDistributor.java:67) [SkyWars.jar:git-skywars-2.0.0]
at net.daboross.bukkitdev.skywars.game.GameHandler.startNewGame(GameHandler.java:47) [SkyWars.jar:git-skywars-2.0.0]
at net.daboross.bukkitdev.skywars.commands.mainsubcommands.ForceStartCommand.runCommand(ForceStartCommand.java:42) [SkyWars.jar:git-skywars-2.0.0]
at net.daboross.bukkitdev.skywars.libraries.ceb.CommandExecutorBase.onCommand(CommandExecutorBase.java:61) [SkyWars.jar:git-skywars-2.0.0]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) [spigot.jar:git-Spigot-1543]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) [spigot.jar:git-Spigot-1543]
at net.minecraft.server.v1_7_R3.CommandBlockListenerAbstract.a(CommandBlockListenerAbstract.java:172) [spigot.jar:git-Spigot-1543]
at net.minecraft.server.v1_7_R3.BlockCommand.a(BlockCommand.java:47) [spigot.jar:git-Spigot-1543]
at net.minecraft.server.v1_7_R3.WorldServer.a(WorldServer.java:568) [spigot.jar:git-Spigot-1543]
at net.minecraft.server.v1_7_R3.WorldServer.doTick(WorldServer.java:211) [spigot.jar:git-Spigot-1543]
at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:687) [spigot.jar:git-Spigot-1543]
at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:284) [spigot.jar:git-Spigot-1543]
at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:584) [spigot.jar:git-Spigot-1543]
at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:490) [spigot.jar:git-Spigot-1543]
at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-Spigot-1543]
/*
* Copyright (C) 2013-2014 Dabo Ross <http://www.daboross.net/>
*
* 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 net.daboross.bukkitdev.skywars.world;
import java.util.Arrays;
import net.daboross.bukkitdev.skywars.api.location.SkyBlockLocation;
import net.daboross.bukkitdev.skywars.api.location.SkyBlockLocationRange;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.block.Dispenser;
import org.bukkit.inventory.ItemStack;
public class WorldCopier {
public void copyArena(SkyBlockLocation toMin, SkyBlockLocationRange from) {
Validate.notNull(toMin, "ToMin cannot be null");
Validate.notNull(from, "From cannot be null");
copy(from.min, from.max, toMin);
}
public void destroyArena(SkyBlockLocation arenaMin, SkyBlockLocationRange area) {
Validate.notNull(arenaMin, "ArenaMin cannot be null");
Validate.notNull(area, "Area cannot be null");
World world = Bukkit.getWorld(arenaMin.world);
Validate.isTrue(world != null, "World not found");
SkyBlockLocation clearingMin = new SkyBlockLocation(arenaMin.x + area.min.x, arenaMin.y + area.min.y, arenaMin.z + area.min.z, null);
SkyBlockLocation clearingMax = new SkyBlockLocation(arenaMin.x + area.max.x, arenaMin.y + area.max.y, arenaMin.z + area.max.z, null);
destroyArena(clearingMin, clearingMax, world);
}
public void destroyArena(SkyBlockLocation min, SkyBlockLocation max, World world) {
Validate.notNull(min, "Min cannot be null");
Validate.notNull(max, "Max cannot be null");
Validate.notNull(world, "World cannot be null");
for (int x = min.x; x <= max.x; x++) {
for (int y = min.y; y <= max.y; y++) {
for (int z = min.z; z <= max.z; z++) {
world.getBlockAt(x, y, z).setType(Material.AIR);
}
}
}
}
public void copy(SkyBlockLocation fromMin, SkyBlockLocation fromMax, SkyBlockLocation toMin) {
Validate.notNull(fromMin, "FromMin cannot be null");
Validate.notNull(fromMax, "FromMax cannot be null");
Validate.notNull(toMin, "ToMin cannot be null");
Validate.isTrue(fromMin.world.equals(fromMax.world), "From min and from max must be in the same world");
World fromWorld = Bukkit.getWorld(fromMin.world);
World toWorld = Bukkit.getWorld(toMin.world);
Validate.notNull(fromWorld, "From world doesn't exist");
Validate.notNull(toWorld, "To world doesn't exist");
int xLength = fromMax.x - fromMin.x;
int yLength = fromMax.y - fromMin.y;
int zLength = fromMax.z - fromMin.z;
for (int x = 0; x <= xLength; x++) {
for (int y = 0; y <= yLength; y++) {
for (int z = 0; z <= zLength; z++) {
Block from = fromWorld.getBlockAt(fromMin.x + x, fromMin.y + y, fromMin.z + z);
Block to = toWorld.getBlockAt(toMin.x + x, toMin.y + y, toMin.z + z);
//noinspection deprecation
to.setTypeIdAndData(from.getTypeId(), from.getData(), false);
BlockState fromState = from.getState();
if (fromState instanceof Chest) {
Chest toChest = (Chest) to.getState();
Chest fromChest = (Chest) fromState;
ItemStack[] contents = fromChest.getBlockInventory().getContents();
toChest.getBlockInventory().setContents(Arrays.copyOf(contents, contents.length));
toChest.update(true, false);
} else if (fromState instanceof Dispenser) {
Dispenser toDispenser = (Dispenser) to.getState();
Dispenser fromDispenser = (Dispenser) fromState;
ItemStack[] contents = fromDispenser.getInventory().getContents();
toDispenser.getInventory().setContents(Arrays.copyOf(contents, contents.length));
toDispenser.update(true, false);
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment