Let's try and load the jails from flatfile.
This commit is contained in:
parent
7d18cf9a96
commit
11f9e94f40
@ -2,11 +2,13 @@ package com.graywolf336.jail;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
import com.graywolf336.jail.beans.Jail;
|
import com.graywolf336.jail.beans.Jail;
|
||||||
|
import com.graywolf336.jail.beans.SimpleLocation;
|
||||||
|
|
||||||
public class JailIO {
|
public class JailIO {
|
||||||
private JailMain pl;
|
private JailMain pl;
|
||||||
@ -50,10 +52,22 @@ public class JailIO {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
//load the jails from flatfile
|
//load the jails from flatfile
|
||||||
if(flat.contains("jails"))
|
if(flat.isConfigurationSection("jails")) {
|
||||||
pl.getLogger().info("Jails exists");
|
Set<String> jails = flat.getConfigurationSection("jails").getKeys(false);
|
||||||
|
if(!jails.isEmpty()) {
|
||||||
|
pl.getLogger().info("Jails configuration section exists and there are " + jails.size() + ".");
|
||||||
|
for(String name : jails) {
|
||||||
|
loadJail(name);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
pl.getLogger().warning("Jails configuration section exists but no jails are there.");
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int s = pl.getJailManager().getJails().size();
|
||||||
|
pl.getLogger().info("Loaded " + s + (s == 1 ? " jail." : " jails."));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveJail(Jail j) {
|
public void saveJail(Jail j) {
|
||||||
@ -66,6 +80,7 @@ public class JailIO {
|
|||||||
String node = "jails." + j.getName() + ".";
|
String node = "jails." + j.getName() + ".";
|
||||||
|
|
||||||
//Corners
|
//Corners
|
||||||
|
flat.set(node + "world", j.getWorldName());
|
||||||
flat.set(node + "top.x", j.getMaxPoint().getBlockX());
|
flat.set(node + "top.x", j.getMaxPoint().getBlockX());
|
||||||
flat.set(node + "top.y", j.getMaxPoint().getBlockY());
|
flat.set(node + "top.y", j.getMaxPoint().getBlockY());
|
||||||
flat.set(node + "top.z", j.getMaxPoint().getBlockZ());
|
flat.set(node + "top.z", j.getMaxPoint().getBlockZ());
|
||||||
@ -77,15 +92,16 @@ public class JailIO {
|
|||||||
flat.set(node + "tps.in.x", j.getTeleportIn().getX());
|
flat.set(node + "tps.in.x", j.getTeleportIn().getX());
|
||||||
flat.set(node + "tps.in.y", j.getTeleportIn().getY());
|
flat.set(node + "tps.in.y", j.getTeleportIn().getY());
|
||||||
flat.set(node + "tps.in.z", j.getTeleportIn().getZ());
|
flat.set(node + "tps.in.z", j.getTeleportIn().getZ());
|
||||||
flat.set(node + "tps.in.pitch", j.getTeleportIn().getPitch());
|
|
||||||
flat.set(node + "tps.in.yaw", j.getTeleportIn().getYaw());
|
flat.set(node + "tps.in.yaw", j.getTeleportIn().getYaw());
|
||||||
|
flat.set(node + "tps.in.pitch", j.getTeleportIn().getPitch());
|
||||||
|
|
||||||
//Tele out
|
//Tele out
|
||||||
|
flat.set(node + "tps.free.world", j.getTeleportFree().getWorld().getName());
|
||||||
flat.set(node + "tps.free.x", j.getTeleportFree().getX());
|
flat.set(node + "tps.free.x", j.getTeleportFree().getX());
|
||||||
flat.set(node + "tps.free.y", j.getTeleportFree().getY());
|
flat.set(node + "tps.free.y", j.getTeleportFree().getY());
|
||||||
flat.set(node + "tps.free.z", j.getTeleportFree().getZ());
|
flat.set(node + "tps.free.z", j.getTeleportFree().getZ());
|
||||||
flat.set(node + "tps.free.pitch", j.getTeleportFree().getPitch());
|
|
||||||
flat.set(node + "tps.free.yaw", j.getTeleportFree().getYaw());
|
flat.set(node + "tps.free.yaw", j.getTeleportFree().getYaw());
|
||||||
|
flat.set(node + "tps.free.pitch", j.getTeleportFree().getPitch());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
flat.save(new File(pl.getDataFolder(), "data.yml"));
|
flat.save(new File(pl.getDataFolder(), "data.yml"));
|
||||||
@ -98,4 +114,37 @@ public class JailIO {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadJail(String name) {
|
||||||
|
switch(storage) {
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
String node = "jails." + name + ".";
|
||||||
|
Jail j = new Jail(pl, name);
|
||||||
|
|
||||||
|
j.setWorld(node + "world");
|
||||||
|
j.setMaxPoint(new int[] {flat.getInt(node + "top.x"), flat.getInt(node + "top.y"), flat.getInt(node + "top.z")});
|
||||||
|
j.setMinPoint(new int[] {flat.getInt(node + "bottom.x"), flat.getInt(node + "bottom.y"), flat.getInt(node + "bottom.z")});
|
||||||
|
|
||||||
|
j.setTeleportIn(new SimpleLocation(
|
||||||
|
flat.getString(node + "world"),
|
||||||
|
flat.getDouble(node + "tps.in.x"),
|
||||||
|
flat.getDouble(node + "tps.in.y"),
|
||||||
|
flat.getDouble(node + "tps.in.z"),
|
||||||
|
(float) flat.getDouble(node + "tps.in.yaw"),
|
||||||
|
(float) flat.getDouble(node + "tps.in.pitch")));
|
||||||
|
j.setTeleportFree(new SimpleLocation(
|
||||||
|
flat.getString(node + "tps.free.world"),
|
||||||
|
flat.getDouble(node + "tps.free.x"),
|
||||||
|
flat.getDouble(node + "tps.free.y"),
|
||||||
|
flat.getDouble(node + "tps.free.z"),
|
||||||
|
(float) flat.getDouble(node + "tps.free.yaw"),
|
||||||
|
(float) flat.getDouble(node + "tps.free.pitch")));
|
||||||
|
|
||||||
|
pl.getJailManager().addJail(j, false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,11 @@ public class JailMain extends JavaPlugin {
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
|
jm = new JailManager(this);
|
||||||
io = new JailIO(this);
|
io = new JailIO(this);
|
||||||
io.prepareStorage();
|
io.prepareStorage();
|
||||||
io.loadJails();
|
io.loadJails();
|
||||||
|
|
||||||
jm = new JailManager(this);
|
|
||||||
cmdHand = new CommandHandler(this);
|
cmdHand = new CommandHandler(this);
|
||||||
|
|
||||||
PluginManager pm = this.getServer().getPluginManager();
|
PluginManager pm = this.getServer().getPluginManager();
|
||||||
|
@ -5,6 +5,7 @@ import java.util.HashSet;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.graywolf336.jail.JailMain;
|
import com.graywolf336.jail.JailMain;
|
||||||
@ -13,7 +14,7 @@ import com.graywolf336.jail.JailMain;
|
|||||||
*
|
*
|
||||||
* @author graywolf336
|
* @author graywolf336
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
* @version 1.0.2
|
* @version 1.0.3
|
||||||
*/
|
*/
|
||||||
public class Jail {
|
public class Jail {
|
||||||
private JailMain plugin;
|
private JailMain plugin;
|
||||||
@ -91,6 +92,21 @@ public class Jail {
|
|||||||
this.maxZ = coords[2];
|
this.maxZ = coords[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sets the name of the world this Jail is in. */
|
||||||
|
public void setWorld(String name) {
|
||||||
|
this.world = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the name of the world this Jail is in. */
|
||||||
|
public String getWorldName() {
|
||||||
|
return this.world;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the instance of the {@link World world} this Jail is in. */
|
||||||
|
public World getWorld() {
|
||||||
|
return plugin.getServer().getWorld(world);
|
||||||
|
}
|
||||||
|
|
||||||
/** Sets the {@link SimpleLocation location} of the teleport <strong>in</strong>. */
|
/** Sets the {@link SimpleLocation location} of the teleport <strong>in</strong>. */
|
||||||
public void setTeleportIn(SimpleLocation location) {
|
public void setTeleportIn(SimpleLocation location) {
|
||||||
if(this.world.isEmpty()) this.world = location.getWorldName();
|
if(this.world.isEmpty()) this.world = location.getWorldName();
|
||||||
|
@ -277,6 +277,7 @@ public class MockPlayerInventory implements PlayerInventory {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private static Map<String, Object> makeMap(ItemStack[] items) {
|
private static Map<String, Object> makeMap(ItemStack[] items) {
|
||||||
Map<String, Object> contents = new LinkedHashMap<String, Object>(
|
Map<String, Object> contents = new LinkedHashMap<String, Object>(
|
||||||
items.length);
|
items.length);
|
||||||
|
@ -15,7 +15,6 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.WorldType;
|
import org.bukkit.WorldType;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
@ -97,7 +96,8 @@ public class MockWorldFactory {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
when(mockWorld.getBlockAt(any(Location.class))).thenAnswer(new Answer<Block>() {
|
when(mockWorld.getBlockAt(any(Location.class))).thenAnswer(new Answer<Block>() {
|
||||||
public Block answer(InvocationOnMock invocation) throws Throwable {
|
@SuppressWarnings("deprecation")
|
||||||
|
public Block answer(InvocationOnMock invocation) throws Throwable {
|
||||||
Location loc;
|
Location loc;
|
||||||
try {
|
try {
|
||||||
loc = (Location) invocation.getArguments()[0];
|
loc = (Location) invocation.getArguments()[0];
|
||||||
@ -141,7 +141,8 @@ public class MockWorldFactory {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
when(mockWorld.getBlockAt(any(Location.class))).thenAnswer(new Answer<Block>() {
|
when(mockWorld.getBlockAt(any(Location.class))).thenAnswer(new Answer<Block>() {
|
||||||
public Block answer(InvocationOnMock invocation) throws Throwable {
|
@SuppressWarnings("deprecation")
|
||||||
|
public Block answer(InvocationOnMock invocation) throws Throwable {
|
||||||
Location loc;
|
Location loc;
|
||||||
try {
|
try {
|
||||||
loc = (Location) invocation.getArguments()[0];
|
loc = (Location) invocation.getArguments()[0];
|
||||||
|
Loading…
Reference in New Issue
Block a user