#9: Allow any kind of portal material

This commit is contained in:
Daniel Saukel 2016-08-01 19:08:23 +02:00
parent 9c9bf05b95
commit b112b81e51
7 changed files with 57 additions and 35 deletions

View File

@ -21,7 +21,6 @@ import io.github.dre2n.commons.util.messageutil.MessageUtil;
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;

View File

@ -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);
@ -55,10 +55,20 @@ public class PortalCommand extends BRCommand {
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));

View File

@ -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"),

View File

@ -21,8 +21,10 @@ import io.github.dre2n.commons.util.messageutil.MessageUtil;
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;
@ -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;
}
@ -103,12 +113,13 @@ public class DPortal extends GlobalProtection {
/**
* 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;
@ -138,11 +149,8 @@ public class DPortal extends GlobalProtection {
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;
@ -153,6 +161,10 @@ public class DPortal extends GlobalProtection {
xx = xx + xcount;
} while (xx != x2 + xcount);
if (player != null) {
player.setCreatingPortal(null);
}
}
/**
@ -186,9 +198,12 @@ public class DPortal extends GlobalProtection {
}
if (target == null && dGroup.getMapName() != null) {
target = plugin.getDWorlds().getResourceByName(dGroup.getMapName()).instantiateAsGameWorld();//TO DO
DResourceWorld resource = plugin.getDWorlds().getResourceByName(dGroup.getMapName());
if (resource != null) {
target = resource.instantiateAsGameWorld();
dGroup.setGameWorld(target);
}
}
if (target == null) {
MessageUtil.sendMessage(player, DMessages.ERROR_DUNGEON_NOT_EXIST.getMessage());
@ -197,6 +212,7 @@ public class DPortal extends GlobalProtection {
if (game == null) {
game = new Game(dGroup, target);
} else {
game.setWorld(target);
dGroup.setGameWorld(target);
@ -225,20 +241,26 @@ public class DPortal extends GlobalProtection {
}
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;
@ -269,7 +291,7 @@ public class DPortal extends GlobalProtection {
do {
Material type = getWorld().getBlockAt(xx, yy, zz).getType();
if (type == Material.PORTAL) {
if (type == material) {
getWorld().getBlockAt(xx, yy, zz).setType(Material.AIR);
}

View File

@ -10,6 +10,7 @@ import java.io.File;
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;
@ -225,8 +226,9 @@ public class GlobalProtections {
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));

View File

@ -32,6 +32,7 @@ import io.github.dre2n.dungeonsxl.sign.DSign;
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;
@ -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);
}
@ -199,21 +196,13 @@ public class BlockListener implements Listener {
@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);
}
}

View File

@ -204,7 +204,7 @@ public class PlayerListener implements Listener {
} 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);