mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-02 17:00:19 +01:00
Add cached item to reset portal creation main hand; resolves #209
This commit is contained in:
parent
c506405a01
commit
50a1b86f3b
@ -69,12 +69,15 @@ public class PortalCommand extends BRCommand {
|
||||
dPortal = new DPortal(DungeonsXL.getGlobalProtections().generateId(DPortal.class, player.getWorld()), player.getWorld(), material, false);
|
||||
dGlobalPlayer.setCreatingPortal(dPortal);
|
||||
dPortal.setWorld(player.getWorld());
|
||||
dGlobalPlayer.setCachedItem(player.getItemInHand());
|
||||
player.getInventory().setItemInHand(new ItemStack(Material.WOOD_SWORD));
|
||||
MessageUtil.sendMessage(player, DMessages.PLAYER_PORTAL_INTRODUCTION.getMessage());
|
||||
|
||||
} else {
|
||||
dPortal.delete();
|
||||
dGlobalPlayer.setCreatingPortal(null);
|
||||
player.setItemInHand(dGlobalPlayer.getCachedItem());
|
||||
dGlobalPlayer.setCachedItem(null);
|
||||
MessageUtil.sendMessage(player, DMessages.PLAYER_PORTAL_ABORT.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package io.github.dre2n.dungeonsxl.global;
|
||||
|
||||
import io.github.dre2n.commons.util.NumberUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.player.DGlobalPlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DPermissions;
|
||||
import io.github.dre2n.dungeonsxl.world.DEditWorld;
|
||||
@ -37,6 +38,7 @@ import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPortalEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel, Wooyoung Son, Frank Baumann, Milan Albrecht
|
||||
@ -134,6 +136,40 @@ public class GlobalProtectionListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPortalCreation(PlayerInteractEvent event) {
|
||||
DGlobalPlayer dPlayer = DungeonsXL.getDPlayers().getByPlayer(event.getPlayer());
|
||||
if (!dPlayer.isCreatingPortal()) {
|
||||
return;
|
||||
}
|
||||
ItemStack item = event.getItem();
|
||||
Block block = event.getClickedBlock();
|
||||
if (item.getType() != Material.WOOD_SWORD || block == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (GlobalProtection protection : DungeonsXL.getGlobalProtections().getProtections(DPortal.class)) {
|
||||
DPortal dPortal = (DPortal) protection;
|
||||
if (dPortal.isActive() || dPortal != dPlayer.getPortal()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dPortal.getBlock1() == null) {
|
||||
dPortal.setBlock1(event.getClickedBlock());
|
||||
dPlayer.sendMessage(DMessages.PLAYER_PORTAL_PROGRESS.getMessage());
|
||||
|
||||
} else if (dPortal.getBlock2() == null) {
|
||||
dPortal.setBlock2(event.getClickedBlock());
|
||||
dPortal.setActive(true);
|
||||
dPortal.create(dPlayer);
|
||||
dPlayer.sendMessage(DMessages.PLAYER_PORTAL_CREATED.getMessage());
|
||||
dPlayer.getPlayer().getInventory().setItemInHand(dPlayer.getCachedItem());
|
||||
dPlayer.setCachedItem(null);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/* SUBJECT TO CHANGE */
|
||||
@Deprecated
|
||||
@EventHandler
|
||||
@ -208,6 +244,7 @@ public class GlobalProtectionListener implements Listener {
|
||||
} else if (lines[1].equalsIgnoreCase("Leave")) {
|
||||
if (block.getState() instanceof Sign) {
|
||||
Sign sign = (Sign) block.getState();
|
||||
|
||||
new LeaveSign(DungeonsXL.getGlobalProtections().generateId(LeaveSign.class, sign.getWorld()), sign);
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,7 @@ public class DGlobalPlayer {
|
||||
private boolean groupChat = false;
|
||||
private boolean chatSpyMode = false;
|
||||
private DPortal creatingPortal;
|
||||
private ItemStack cachedItem;
|
||||
private boolean announcerEnabled = true;
|
||||
|
||||
private ItemStack[] respawnInventory;
|
||||
@ -186,6 +187,21 @@ public class DGlobalPlayer {
|
||||
creatingPortal = dPortal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the item the player had in his hand before he started to create a portal
|
||||
*/
|
||||
public ItemStack getCachedItem() {
|
||||
return cachedItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param item
|
||||
* the cached item to set
|
||||
*/
|
||||
public void setCachedItem(ItemStack item) {
|
||||
cachedItem = item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the players receives announcer messages
|
||||
*/
|
||||
|
@ -546,7 +546,6 @@ public class DPlayerListener implements Listener {
|
||||
if (isCitizensNPC(player)) {
|
||||
return;
|
||||
}
|
||||
DGlobalPlayer dGlobalPlayer = dPlayers.getByPlayer(player);
|
||||
Block clickedBlock = event.getClickedBlock();
|
||||
DGameWorld dGameWorld = DGameWorld.getByWorld(player.getWorld());
|
||||
if (clickedBlock != null) {
|
||||
@ -592,32 +591,6 @@ public class DPlayerListener implements Listener {
|
||||
if (event.getItem() != null) {
|
||||
ItemStack item = event.getItem();
|
||||
|
||||
if (dGlobalPlayer.isCreatingPortal()) {
|
||||
if (item.getType() == Material.WOOD_SWORD) {
|
||||
if (clickedBlock != null) {
|
||||
for (GlobalProtection protection : DungeonsXL.getGlobalProtections().getProtections(DPortal.class
|
||||
)) {
|
||||
DPortal dPortal = (DPortal) protection;
|
||||
if (!dPortal.isActive()) {
|
||||
if (dPortal == dGlobalPlayer.getPortal()) {
|
||||
if (dPortal.getBlock1() == null) {
|
||||
dPortal.setBlock1(event.getClickedBlock());
|
||||
MessageUtil.sendMessage(player, DMessages.PLAYER_PORTAL_PROGRESS.getMessage());
|
||||
|
||||
} else if (dPortal.getBlock2() == null) {
|
||||
dPortal.setBlock2(event.getClickedBlock());
|
||||
dPortal.setActive(true);
|
||||
dPortal.create(dGlobalPlayer);
|
||||
MessageUtil.sendMessage(player, DMessages.PLAYER_PORTAL_CREATED.getMessage());
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy/Paste a Sign and Block-info
|
||||
if (DEditWorld.getByWorld(player.getWorld()) != null) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
|
Loading…
Reference in New Issue
Block a user