Skip to content

Instantly share code, notes, and snippets.

@PaulBGD
Created October 14, 2013 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulBGD/6969966 to your computer and use it in GitHub Desktop.
Save PaulBGD/6969966 to your computer and use it in GitHub Desktop.
Arena Resource 5
package me.ultimate.Arena;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.block.BlockState;
import org.bukkit.configuration.file.FileConfiguration;
public class Arena {
private String name; // A spot to store our arena's name
private Location l1, l2; // Our two corners
private Location spawn, stop; // Where we start and stop
private PlayerManager playerManager; // This is to manage all of the players
/*
* This will hold all the data from the original arena. We can roll it back
* later
*/
private List<BlockState> originalBlocks = new ArrayList<BlockState>();
// We'll create a new instance of this class with all the data
public Arena(String name, Location l1, Location l2, Location spawn, Location stop) {
// Assign it all to local variables except the two locations
this.name = name;
this.spawn = spawn;
this.stop = stop;
// This will get the larger and smaller corners. l2 is min, l1 max.
double tmp;
if (l1.getBlockX() < l2.getBlockX()) {
tmp = l1.getBlockX();
l1.setX(l2.getBlockX());
l2.setX(tmp);
}
if (l1.getBlockY() < l2.getBlockY()) {
tmp = l1.getBlockY();
l1.setY(l2.getBlockY());
l2.setY(tmp);
}
if (l1.getBlockZ() < l2.getBlockZ()) {
tmp = l1.getBlockZ();
l1.setZ(l2.getBlockZ());
l2.setZ(tmp);
}
this.l1 = l1;
this.l2 = l2;
/*
* Now let's get ALL of the blocks between the two points, and add them
* our originalBlocks list
*/
for (int x = l2.getBlockX(); x < l1.getBlockX(); x++)
for (int z = l2.getBlockZ(); x < l1.getBlockZ(); z++)
for (int y = l2.getBlockY(); x < l1.getBlockY(); y++)
originalBlocks.add(l1.getWorld().getBlockAt(x, y, z).getState());
// Now get a new PlayerManager
playerManager = new PlayerManager(this);
// We'll have the arena register itself
ArenaManager.addArena(this);
}
// Now, we'll put a few methods here to get the variables
public String getName() {
return name;
}
public Location getLocationOne() {
return l1;
}
public Location getLocationTwo() {
return l2;
}
public Location getSpawn() {
return spawn;
}
public Location getStop() {
return stop;
}
// Now for when we need to rollback our blocks
public void rollback() {
/*
* All we need to do here, is create a new RollbackRunnable with our
* blocks.
*/
new RollbackRunnable(originalBlocks);
}
// Add a method to get the playerManager
public PlayerManager getPlayerManager() {
return playerManager;
}
// For loading from/to a config
public void save(FileConfiguration c, String path) {
path += "." + name + ".";
c.set(path + "l1", LocationUtils.fromLocation(l1, true, false));
c.set(path + "l2", LocationUtils.fromLocation(l1, true, false));
c.set(path + "spawn", LocationUtils.fromLocation(l1, false, true));
c.set(path + "stop", LocationUtils.fromLocation(l1, false, true));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment