ausgebildet
Redstoneengineer
Hey , ich brauche Hilfe bei meinem SkyBlock Plugin. Sobald ich meine Insel erstellen will folgt einer NullPointerException in der Island.class (Zeile 51).
Fehler :
Island.class
Um eine Insel zu erstellen rufe ich folgende Methode auf
"plugin.getIslandManagerClass().createIsland(sender);"
Die InselManagerClass sehr ihr hier.
Fehler :
Code:
[03:44:45 WARN]: [SkyBlock] Task #143 for SkyBlock v2.9 generated an exception
java.lang.NullPointerException
at de.denN1s.skyblock.manager.Island.gen(Island.java:51) ~[?:?]
at de.denN1s.skyblock.manager.Island.<init>(Island.java:41) ~[?:?]
at de.denN1s.skyblock.manager.IslandManager.createIsland(IslandManager.java:60) ~[?:?]
at de.denN1s.skyblock.commands.DefaultSkyBlockCommand$1.run(DefaultSkyBlockCommand.java:63) ~[?:?]
at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:723) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
at java.base/java.lang.Thread.run(Unknown Source) [?:?]
Island.class
Code:
package de.denN1s.skyblock.manager;
import java.io.File;
import java.io.IOException;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Chest;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.sk89q.worldedit.CuboidClipboard;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlock***ception;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.data.DataException;
import com.sk89q.worldedit.schematic.SchematicFormat;
import de.denN1s.skyblock.SkyBlock;
@SuppressWarnings("deprecation")
public class Island {
public static SkyBlock plugin;
private String ownerName;
public Location loc;
private Location spawn;
int r = 420;
LocalSession ls;
LocalPlayer lp;
public Island(Player owner, Location loc, boolean gen) {
this.ownerName = owner.getName();
this.loc = loc;
this.spawn = loc.clone().add(1.5D, 3.0D, 5.5D);
this.spawn.setYaw(-180.0F);
if (gen) {
gen();
}
}
ItemStack[] items = { new ItemStack(Material.ICE, 2), new ItemStack(Material.LAVA_BUCKET),
new ItemStack(Material.CACTUS), new ItemStack(Material.PUMPKIN, 1), new ItemStack(Material.MELON, 2),
new ItemStack(Material.RED_MUSHROOM), new ItemStack(Material.BROWN_MUSHROOM),
new ItemStack(Material.BONE, 3), new ItemStack(Material.SUGAR_CANE, 3), new ItemStack(Material.APPLE, 3) };
private void gen() {
ls = plugin.getWorldEditPlugin().getSession(Bukkit.getPlayer(this.ownerName));
lp = plugin.getWorldEditPlugin().wrapPlayer(Bukkit.getPlayer(this.ownerName));
try {
SchematicFormat sf = SchematicFormat.getFormat(new File("plugins/SkyBlock", "island.schematic"));
CuboidClipboard cc = sf.load(new File("plugins/SkyBlock", "island.schematic"));
cc.paste(ls.createEditSession(lp), BukkitUtil.toVector(this.loc), true);
} catch (DataException | IOException e) {
e.printStackTrace();
} catch (MaxChangedBlock***ception e) {
e.printStackTrace();
}
Location chestLoc = this.loc.clone().add(1.0D, 3.0D, 0.0D);
if (chestLoc.getBlock().getType() != Material.CHEST) {
chestLoc.getBlock().setType(Material.CHEST);
}
Chest chest = (Chest) chestLoc.getBlock().getState();
ItemStack[] arrayOfItemStack;
int j = (arrayOfItemStack = this.items).length;
for (int i = 0; i < j; i++) {
ItemStack item = arrayOfItemStack[i];
chest.getInventory().addItem(new ItemStack[] { item });
}
}
public boolean isAt(Location location) {
if (location == null) {
return false;
}
int x = Math.abs(location.getBlockX() - this.loc.getBlockX());
int z = Math.abs(location.getBlockZ() - this.loc.getBlockZ());
return (x < this.r) && (z < this.r);
}
public Player getPlayer() {
return Bukkit.getPlayerExact(this.ownerName);
}
public Location getLocation() {
return this.loc;
}
public Location getSpawnLocation() {
return this.spawn;
}
}
Um eine Insel zu erstellen rufe ich folgende Methode auf
"plugin.getIslandManagerClass().createIsland(sender);"
Die InselManagerClass sehr ihr hier.
Code:
package de.denN1s.skyblock.manager;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import de.denN1s.skyblock.SkyBlock;
public class IslandManager {
SkyBlock plugin;
public IslandManager(SkyBlock plugin) {
this.plugin = plugin;
}
public double x = -36000.0D;
public double z = -36000.0D;
public double offset = 1000.0D;
public File islandFile = new File("plugins/SkyBlock/data", "islands.yml");
public FileConfiguration islandConfiguration = YamlConfiguration.loadConfiguration(islandFile);
public File file;
public FileConfiguration config;
public Map<UUID, Island> islands = new HashMap<UUID, Island>();
Location nextLocation = new Location(Bukkit.getWorld("WorldOfSkyBlock"), x, 72.0D, z);
public void saveIslands() {
try {
islandConfiguration.save(islandFile);
} catch (Exception e) {
e.printStackTrace();
}
}
public void createIsland(Player p) {
double x = nextLocation.getX() + offset;
double z = nextLocation.getZ();
if (x > Math.abs(x)) {
z += offset;
nextLocation.setX(x);
x = nextLocation.getX() + offset;
nextLocation.setZ(z);
}
Math.abs(z);
Location loc = new Location(plugin.world, x, 72.0D, z);
Location playerLoc = loc.clone().add(1.5D, 3.0D, 5.5D);
playerLoc.setYaw(-180.0F);
p.teleport(playerLoc);
Island il = new Island(p, loc, true);
islands.put(p.getUniqueId(), il);
nextLocation = il.getLocation();
ConfigurationSection s = islandConfiguration.createSection(p.getUniqueId().toString());
s.set("name", p.getName());
s.set("x", Double.valueOf(il.getLocation().getX()));
s.set("z", Double.valueOf(il.getLocation().getZ()));
saveIslands();
}
public void registerFile() {
this.file = new File("plugins/SkyBlock/data", "IslandManager.yml");
this.config = YamlConfiguration.loadConfiguration(this.file);
saveFile();
}
public void saveFile() {
try {
this.config.save(this.file);
} catch (IOException localIOException) {
}
}
public void loadNextLocation() {
if (this.config.contains("nextLocation")) {
ConfigurationSection s = this.config.getConfigurationSection("nextLocation");
double x = s.getDouble("x");
double z = s.getDouble("z");
nextLocation = new Location(plugin.world, x, 72.0D, z);
} else {
ConfigurationSection s = this.config.createSection("nextLocation");
s.set("x", Double.valueOf(nextLocation.getX()));
s.set("z", Double.valueOf(nextLocation.getZ()));
saveFile();
}
}
public void loadPlayer(Player p) {
if (islandConfiguration.contains(p.getUniqueId().toString())) {
ConfigurationSection s = islandConfiguration.getConfigurationSection(p.getUniqueId().toString());
double x = s.getDouble("x");
double z = s.getDouble("z");
Island i = new Island(p, new Location(plugin.world, x, 72.0D, z), false);
islands.put(p.getUniqueId(), i);
}
}
public void unloadPlayer(Player p) {
if (hasIsland(p)) {
islands.remove(p.getUniqueId());
}
}
public Island getIsland(Player p) {
if (hasIsland(p)) {
return (Island) islands.get(p.getUniqueId());
}
return null;
}
public void sendHome(Player p) {
p.teleport(getIsland(p).getSpawnLocation());
}
public boolean hasIsland(Player p) {
return islands.containsKey(p.getUniqueId());
}
}