Skip to content

Commit

Permalink
Test code for portal gen
Browse files Browse the repository at this point in the history
  • Loading branch information
mbax committed Sep 4, 2012
1 parent b5efd0c commit 2c14e29
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 30 deletions.
18 changes: 9 additions & 9 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
portals: [example]
example:
shape: [XXOXX,XOOOX,XOOOX,XXXXX]
# XXOXX
# XOOOX
# XOOOX
# XXXXX
x: 100
y: 70
z: 100
shape: |
OO
OO
OO
world: 'world'
x: 100 # Lowest X
y: 70 # Lowest Y
z: 100 # Lowest Z
horizontalByX: true
permission: portal.example
50 changes: 30 additions & 20 deletions src/to/joe/j2mc/portals/J2MC_Portals.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -51,42 +52,51 @@ public void onEnable() {

public void loadPortalAreas() {
this.reloadConfig();
for (String area : this.getConfig().getStringList("portals")) {
for (String area : this.getConfig().getKeys(false)) {
String path = /*"portals." + */area;
int x = this.getConfig().getInt(path + ".x");
int y = this.getConfig().getInt(path + ".y");
int z = this.getConfig().getInt(path + ".z");
Location upperLeft = new Location(this.getServer().getWorlds().get(0), x, y, z);

int baseX = this.getConfig().getInt(path + ".x", 0);
int baseY = this.getConfig().getInt(path + ".y", 0);
int baseZ = this.getConfig().getInt(path + ".z", 0);
boolean xdim = this.getConfig().getBoolean(path + ".horizontalByX", false);
String worldName = this.getConfig().getString("world","world");
World world = this.getServer().getWorld(worldName);
if(world == null) {
world = this.getServer().getWorlds().get(0);
}
HashSet<Location> locations = new HashSet<Location>();
List<String> shape = this.getConfig().getStringList(path + ".shape");
//int height = shape.size();
int width = shape.get(0).length();
int curZ = z;
int curX = baseX;
int curY = baseY + shape.size();
int curZ = baseZ;
for (String line : shape) {
if (line.length() != width) {
this.getLogger().info("YOUR CONFIG IS BAD AND YOU SHOULD FEEL BAD. Shutting down plugin.");
this.getPluginLoader().disablePlugin(this);
return;
curY--;
if(xdim) {
curX = baseX;
} else {
curZ = baseZ;
}
for (int i = 0; i < width; i++) {
if (line.charAt(i) == 'X') {
Location loc = new Location(this.getServer().getWorlds().get(0), x + i, y, curZ);
for(char c:line.toCharArray()){
if(xdim) {
curX++;
} else {
curZ++;
}
if(c == 'O'){
Location loc = new Location(world, curX, curY, curZ);
locations.add(loc);
loc.getBlock().setType(Material.BEDROCK); //debug
this.getLogger().info("Placed bedrock at " + loc.getX() + " " + loc.getBlockY() + " " + loc.getZ());
loc.getBlock().setTypeId(17);
}
}
curZ++;
}

String destination = area;
String perm = this.getConfig().getString(path + ".permission");
if (perm.equals("j2mc.portals.everyone")) {
if (!perm.equals("j2mc.portals.everyone")) {
this.getServer().getPluginManager().addPermission(new Permission("perm", PermissionDefault.OP));
}

this.portalAreas.add(new PortalArea(locations, destination, perm, upperLeft));
this.portalAreas.add(new PortalArea(locations, area, perm));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/to/joe/j2mc/portals/PortalArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class PortalArea {
private String destination;
private String permission;

public PortalArea(HashSet<Location> locations, String destination, String permission, Location upperLeft) {
public PortalArea(HashSet<Location> locations, String destination, String permission) {
this.locations = locations;
this.destination = destination;
this.permission = permission;
Expand Down

0 comments on commit 2c14e29

Please sign in to comment.