Skip to content

Commit

Permalink
#9: Allow any kind of portal material
Browse files Browse the repository at this point in the history
  • Loading branch information
Sataniel98 committed Aug 1, 2016
1 parent 9c9bf05 commit b112b81
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerLeaveDGroupEvent;
import io.github.dre2n.dungeonsxl.event.dplayer.instance.edit.DEditPlayerEscapeEvent;
import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerEscapeEvent;
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class PortalCommand extends BRCommand {
public PortalCommand() {
setCommand("portal");
setMinArgs(0);
setMaxArgs(0);
setMaxArgs(1);
setHelp(DMessages.HELP_CMD_PORTAL.getMessage());
setPermission(DPermissions.PORTAL.getNode());
setPlayerCommand(true);
Expand All @@ -55,10 +55,20 @@ public void onExecute(String[] args, CommandSender sender) {
return;
}

Material material = null;

if (args.length == 2) {
material = Material.matchMaterial(args[1]);
}

if (material == null) {
material = Material.PORTAL;
}

DPortal dPortal = dGlobalPlayer.getPortal();

if (dPortal == null) {
dPortal = new DPortal(plugin.getGlobalProtections().generateId(DPortal.class, player.getWorld()), player.getWorld(), false);
dPortal = new DPortal(plugin.getGlobalProtections().generateId(DPortal.class, player.getWorld()), player.getWorld(), material, false);
dGlobalPlayer.setCreatingPortal(dPortal);
dPortal.setWorld(player.getWorld());
player.getInventory().setItemInHand(new ItemStack(Material.WOOD_SWORD));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public enum DMessages implements Messages {
HELP_CMD_MAIN("Help_Cmd_Main", "/dxl - General status information"),
HELP_CMD_MSG("Help_Cmd_Msg", "/dxl msg [id] '[msg]' - Show or edit a message"),
HELP_CMD_PLAY("Help_Cmd_Play", "/dxl play ([dungeon|map]) [name] - Allows the player to play a dungeon without a portal"),
HELP_CMD_PORTAL("Help_Cmd_Portal", "/dxl portal - Creates a portal that leads into a dungeon"),
HELP_CMD_PORTAL("Help_Cmd_Portal", "/dxl portal ([material=portal])- Creates a portal that leads into a dungeon"),
HELP_CMD_RELOAD("Help_Cmd_Reload", "/dxl reload - Reloads the plugin"),
HELP_CMD_SAVE("Help_Cmd_Save", "/dxl save - Saves the current dungeon"),
HELP_CMD_STATUS("Help_Cmd_Status", "/dxl status - Shows the technical status of DungeonsXL"),
Expand Down
46 changes: 34 additions & 12 deletions core/src/main/java/io/github/dre2n/dungeonsxl/global/DPortal.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DGlobalPlayer;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.world.DGameWorld;
import io.github.dre2n.dungeonsxl.world.DResourceWorld;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Location;
Expand All @@ -39,19 +41,27 @@ public class DPortal extends GlobalProtection {

private Block block1;
private Block block2;
private Material material = Material.PORTAL;
private boolean active;
private Set<Block> blocks;

public DPortal(int id, World world, boolean active) {
this(id, world, Material.PORTAL, active);
}

public DPortal(int id, World world, Material material, boolean active) {
super(world, id);

this.material = material;
this.active = active;
}

public DPortal(int id, Block block1, Block block2, boolean active) {
public DPortal(int id, Block block1, Block block2, Material material, boolean active) {
super(block1.getWorld(), id);

this.block1 = block1;
this.block2 = block2;
this.material = material;
this.active = active;
}

Expand Down Expand Up @@ -103,12 +113,13 @@ public void setActive(boolean active) {
/**
* Create a new DPortal
*/
public void create() {
public void create(DGlobalPlayer player) {
if (block1 == null || block2 == null) {
delete();
return;
}


int x1 = block1.getX(), y1 = block1.getY(), z1 = block1.getZ();
int x2 = block2.getX(), y2 = block2.getY(), z2 = block2.getZ();
int xcount = 0, ycount = 0, zcount = 0;
Expand Down Expand Up @@ -138,11 +149,8 @@ public void create() {

do {
Material type = getWorld().getBlockAt(xx, yy, zz).getType();
if (type == Material.AIR || type == Material.WATER || type == Material.STATIONARY_WATER || type == Material.LAVA || type == Material.STATIONARY_LAVA || type == Material.SAPLING
|| type == Material.WEB || type == Material.LONG_GRASS || type == Material.DEAD_BUSH || type == Material.PISTON_EXTENSION || type == Material.YELLOW_FLOWER
|| type == Material.RED_ROSE || type == Material.BROWN_MUSHROOM || type == Material.RED_MUSHROOM || type == Material.TORCH || type == Material.FIRE
|| type == Material.CROPS || type == Material.REDSTONE_WIRE || type == Material.REDSTONE_TORCH_OFF || type == Material.SNOW || type == Material.REDSTONE_TORCH_ON) {
getWorld().getBlockAt(xx, yy, zz).setType(Material.PORTAL);
if (!type.isSolid()) {
getWorld().getBlockAt(xx, yy, zz).setType(material, false);
}

zz = zz + zcount;
Expand All @@ -153,6 +161,10 @@ public void create() {

xx = xx + xcount;
} while (xx != x2 + xcount);

if (player != null) {
player.setCreatingPortal(null);
}
}

/**
Expand Down Expand Up @@ -186,8 +198,11 @@ public void teleport(Player player) {
}

if (target == null && dGroup.getMapName() != null) {
target = plugin.getDWorlds().getResourceByName(dGroup.getMapName()).instantiateAsGameWorld();//TO DO
dGroup.setGameWorld(target);
DResourceWorld resource = plugin.getDWorlds().getResourceByName(dGroup.getMapName());
if (resource != null) {
target = resource.instantiateAsGameWorld();
dGroup.setGameWorld(target);
}
}

if (target == null) {
Expand All @@ -197,6 +212,7 @@ public void teleport(Player player) {

if (game == null) {
game = new Game(dGroup, target);

} else {
game.setWorld(target);
dGroup.setGameWorld(target);
Expand Down Expand Up @@ -225,20 +241,26 @@ public void save(FileConfiguration configFile) {
}

String preString = "protections.portals." + getWorld().getName() + "." + getId();
// Location1

configFile.set(preString + ".loc1.x", block1.getX());
configFile.set(preString + ".loc1.y", block1.getY());
configFile.set(preString + ".loc1.z", block1.getZ());
// Location1

configFile.set(preString + ".loc2.x", block2.getX());
configFile.set(preString + ".loc2.y", block2.getY());
configFile.set(preString + ".loc2.z", block2.getZ());

configFile.set(preString + ".material", material.toString());
}

@Override
public void delete() {
protections.removeProtection(this);

if (block1 == null || block2 == null) {
return;
}

int x1 = block1.getX(), y1 = block1.getY(), z1 = block1.getZ();
int x2 = block2.getX(), y2 = block2.getY(), z2 = block2.getZ();
int xcount = 0, ycount = 0, zcount = 0;
Expand Down Expand Up @@ -269,7 +291,7 @@ public void delete() {
do {
Material type = getWorld().getBlockAt(xx, yy, zz).getType();

if (type == Material.PORTAL) {
if (type == material) {
getWorld().getBlockAt(xx, yy, zz).setType(Material.AIR);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
Expand Down Expand Up @@ -225,8 +226,9 @@ public void loadAll() {
if (data.contains(preString)) {
Block block1 = world.getBlockAt(data.getInt(preString + "loc1.x"), data.getInt(preString + "loc1.y"), data.getInt(preString + "loc1.z"));
Block block2 = world.getBlockAt(data.getInt(preString + "loc2.x"), data.getInt(preString + "loc2.y"), data.getInt(preString + "loc2.z"));
DPortal dPortal = new DPortal(id, block1, block2, true);
dPortal.create();
Material material = Material.getMaterial(data.getString(preString + "material"));
DPortal dPortal = new DPortal(id, block1, block2, material != null ? material : Material.PORTAL, true);
dPortal.create(null);
}

} while (data.contains(preString));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.github.dre2n.dungeonsxl.task.RedstoneEventTask;
import io.github.dre2n.dungeonsxl.world.DEditWorld;
import io.github.dre2n.dungeonsxl.world.DGameWorld;
import io.github.dre2n.dungeonsxl.world.DInstanceWorld;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
Expand All @@ -58,10 +59,6 @@ public class BlockListener implements Listener {

@EventHandler(priority = EventPriority.HIGH)
public void onPhysics(BlockPhysicsEvent event) {
if (event.getBlock().getType() != Material.PORTAL) {
return;
}

if (DPortal.getByBlock(event.getBlock()) != null) {
event.setCancelled(true);
}
Expand Down Expand Up @@ -199,21 +196,13 @@ public void onSignChange(SignChangeEvent event) {

@EventHandler(priority = EventPriority.NORMAL)
public void onSpread(BlockSpreadEvent event) {
Block block = event.getBlock();
// Block the Spread off Vines
if (block.getType() != Material.VINE) {
return;
}
Block block = event.getSource();

// Check GameWorlds
DGameWorld gameWorld = DGameWorld.getByWorld(event.getBlock().getWorld());
if (gameWorld != null) {
DInstanceWorld instance = plugin.getDWorlds().getInstanceByName(block.getWorld().getName());
if (instance != null && block.getType() == Material.VINE) {
event.setCancelled(true);
}

// Check EditWorlds
DEditWorld editWorld = DEditWorld.getByWorld(event.getBlock().getWorld());
if (editWorld != null) {
} else if (DPortal.getByBlock(block) != null) {
event.setCancelled(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public void onInteract(PlayerInteractEvent event) {
} else if (dPortal.getBlock2() == null) {
dPortal.setBlock2(event.getClickedBlock());
dPortal.setActive(true);
dPortal.create();
dPortal.create(dGlobalPlayer);
MessageUtil.sendMessage(player, DMessages.PLAYER_PORTAL_CREATED.getMessage());
}
event.setCancelled(true);
Expand Down

0 comments on commit b112b81

Please sign in to comment.