diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java index c6db06459..6593bd931 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java @@ -1439,4 +1439,22 @@ public class UtilBlock return gr.getBlock().getLocation(); } + + public static boolean setSilent(Block block, Material type) + { + return setSilent(block, type, (byte) 0); + } + + /** + * Sets block data without causing a block update. + */ + public static boolean setSilent(Block block, Material type, byte data) + { + BlockState state = block.getState(); + + state.setType(type); + state.setRawData(data); + + return state.update(false, false); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/NetherManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/NetherManager.java index f3bffa07a..38470f58a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/NetherManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/NetherManager.java @@ -12,15 +12,19 @@ import org.bukkit.WorldBorder; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.inventory.ItemStack; import com.google.common.collect.Lists; import mineplex.core.MiniPlugin; +import mineplex.core.common.Rank; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilCollections; import mineplex.core.common.util.UtilFile; import mineplex.core.common.util.UtilPlayer; @@ -91,6 +95,22 @@ public class NetherManager extends MiniPlugin } }); } + + + @EventHandler + public void cmd(PlayerCommandPreprocessEvent event) + { + if (!_clansManager.getClientManager().hasRank(event.getPlayer(), Rank.JNR_DEV)) + { + return; + } + + if (event.getMessage().startsWith("/nether")) + { + event.getPlayer().teleport(new Location(_netherWorld, 0, 90, 0)); + event.setCancelled(true); + } + } @EventHandler public void breakBlock(BlockBreakEvent event) @@ -127,19 +147,19 @@ public class NetherManager extends MiniPlugin @EventHandler public void update(UpdateEvent event) { - if (event.getType() == UpdateType.SEC_08) + if (event.getType() == UpdateType.SLOW) { _portals.forEach(portal -> { - portal.getFromObsidianBlocks().forEach(block -> block.setType(Material.OBSIDIAN)); - portal.getFromPortalBlocks().forEach(block -> block.setType(Material.PORTAL)); + portal.getFromObsidianBlocks().forEach(block -> UtilBlock.setSilent(block, Material.OBSIDIAN)); + portal.getFromPortalBlocks().forEach(block -> UtilBlock.setSilent(block, Material.PORTAL)); - portal.getToObsidianBlocks().forEach(block -> block.setType(Material.OBSIDIAN)); - portal.getToPortalBlocks().forEach(block -> block.setType(Material.PORTAL)); + portal.getToObsidianBlocks().forEach(block -> UtilBlock.setSilent(block, Material.OBSIDIAN)); + portal.getToPortalBlocks().forEach(block -> UtilBlock.setSilent(block, Material.PORTAL)); }); } } - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void onPortal(PlayerPortalEvent event) { Player player = event.getPlayer(); @@ -147,26 +167,9 @@ public class NetherManager extends MiniPlugin ClanTerritory territory = _clansManager.getClanUtility().getClaim(location); - event.setCancelled(true); - - if (territory != null && territory.Owner.equals("Borderlands")) + if (event.getTo().getWorld().equals(_netherWorld)) { - if (event.getTo().getWorld().equals(_netherWorld)) - { - _portals - .stream() - .filter(portal -> - portal.getToPortalBlocks() - .stream() - .filter(block -> player.getLocation().distance(block.getLocation()) <= 2) - .iterator().hasNext() - ).limit(1) - .forEach(portal -> { - player.teleport(portal.getToOut()); - _clansManager.ClanTips.displayTip(TipType.ENTER_NETHER, player); - }); - } - else + if (territory != null && territory.Owner.equals("Borderlands")) { _portals .stream() @@ -177,10 +180,25 @@ public class NetherManager extends MiniPlugin .iterator().hasNext() ).limit(1) .forEach(portal -> { - player.teleport(UtilAlg.getAverageBlockLocation(portal.getToPortalBlocks())); + event.setTo(portal.getToOut()); + _clansManager.ClanTips.displayTip(TipType.ENTER_NETHER, player); }); } } + else + { + _portals + .stream() + .filter(portal -> + portal.getToPortalBlocks() + .stream() + .filter(block -> player.getLocation().distance(block.getLocation()) <= 2) + .iterator().hasNext() + ).limit(1) + .forEach(portal -> { + event.setTo(UtilAlg.getAverageBlockLocation(portal.getFromPortalBlocks())); + }); + } } public World getNetherWorld() diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java index ba3396aee..9c14b384c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java @@ -34,11 +34,20 @@ public class Portal if (!isValidPortalBlock(from.getBlock()) || !isValidPortalBlock(to.getBlock())) { - System.out.println("[PORTAL] INVALID PORTAL PROVIDED (" + from + " --> " + to + ")"); + if (!isValidPortalBlock(from.getBlock())) + from = UtilBlock.getInRadius(from.getBlock(), 4).keySet().stream().filter(this::isValidPortalBlock).limit(1).iterator().next().getLocation(); - Success = false; + if (!isValidPortalBlock(to.getBlock())) + to = UtilBlock.getInRadius(to.getBlock(), 4).keySet().stream().filter(this::isValidPortalBlock).limit(1).iterator().next().getLocation(); - return; + if (to == null || from == null) + { + System.out.println("[PORTAL] INVALID PORTAL PROVIDED (" + from + " --> " + to + ")"); + + Success = false; + + return; + } } for (Block other : UtilBlock.getInRadius(from, 7.5d).keySet()) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java new file mode 100644 index 000000000..e81701ff9 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java @@ -0,0 +1,54 @@ +package mineplex.game.clans.items.legendaries; + +import org.bukkit.Material; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Player; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.LineFormat; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilText; + +public class EnergyCrossbow extends LegendaryItem +{ + private static final long COOLDOWN = 30000; + + private long _lastFire = System.currentTimeMillis(); + private long _interactWait; + + public EnergyCrossbow() + { + super("Energy Crossbow", UtilText.splitLinesToArray(new String[] { + C.cWhite + "This deadly tooth was stolen from a nest of reptillian beasts long ago. " + + "Legends say that the holder is granted the underwater agility of an Alligator", + " ", + "#" + C.cYellow + "Right-Click" + C.cWhite + " to use" + C.cGreen + " Swim" + }, LineFormat.LORE), Material.RECORD_4); + } + + @Override + public void update(Player wielder) + { + if ((System.currentTimeMillis() - _lastBlock) < 98 && (System.currentTimeMillis() - _interactWait) >= 98) + { + if ((System.currentTimeMillis() - _lastFire) >= COOLDOWN) + { + fire(wielder); + + _interactWait = System.currentTimeMillis(); + } + else + { + UtilPlayer.message(wielder, F.main("Clans", "Energy Crossbow is cooling down!")); + } + } + } + + private void fire(Player wielder) + { + final Arrow arrow = wielder.shootArrow(); + + _lastFire = System.currentTimeMillis(); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/LegendaryItem.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/LegendaryItem.java index 45c32ed17..0d21efc43 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/LegendaryItem.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/LegendaryItem.java @@ -15,7 +15,7 @@ public class LegendaryItem extends CustomItem { public final long BLOCK_COOLDOWN = 200l; // Right clicking activates right click for 200ms - private long _lastBlock; // Timestamp of last block from wielder + protected long _lastBlock; // Timestamp of last block from wielder public long timeSinceLastBlock() { return System.currentTimeMillis() - _lastBlock; } public LegendaryItem(String name, String[] description, Material material)