You can now teleport through hoppers by pressing shift.

This commit is contained in:
Brianna O'Keefe 2018-08-27 17:18:44 -04:00
parent 19f7fcb373
commit 8489ec6a51
11 changed files with 71 additions and 41 deletions

View File

@ -77,22 +77,18 @@ public interface Hopper {
void setLastPlayer(UUID uuid);
/**
* Whether or not walk on teleporting has been
* enabled for this hopper.
* Get the teleport trigger is currently enabled.
*
* @return true if walk on teleporting enabled,
* false otherwise
* @return TeleportTrigger
*/
boolean isWalkOnTeleport();
TeleportTrigger getTeleportTrigger();
/**
* Set the ability to teleport players from this
* hopper to a remote hopper.
* Set which teleport trigger is currently enabled.
*
* @param walkOnTeleport whether or not to enabled
* walk on teleporting
* @param teleportTrigger TeleportTrigger
*/
void setWalkOnTeleport(boolean walkOnTeleport);
void setTeleportTrigger(TeleportTrigger teleportTrigger);
/**
* Get the Block containing the hopper that is

View File

@ -0,0 +1,7 @@
package com.songoda.epichoppers.api.hopper;
public enum TeleportTrigger {
DISABLED,
WALK_ON,
SNEAK;
}

View File

@ -6,10 +6,7 @@ import com.songoda.arconix.api.utils.ConfigWrapper;
import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.api.EpicHoppers;
import com.songoda.epichoppers.api.EpicHoppersAPI;
import com.songoda.epichoppers.api.hopper.Hopper;
import com.songoda.epichoppers.api.hopper.HopperManager;
import com.songoda.epichoppers.api.hopper.Level;
import com.songoda.epichoppers.api.hopper.LevelManager;
import com.songoda.epichoppers.api.hopper.*;
import com.songoda.epichoppers.api.utils.ClaimableProtectionPluginHook;
import com.songoda.epichoppers.api.utils.ProtectionPluginHook;
import com.songoda.epichoppers.boost.BoostData;
@ -112,7 +109,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
String blockLoc = dataFile.getConfig().getString("data.sync." + locationStr + ".block");
Block block = blockLoc == null ? null : Arconix.pl().getApi().serialize().unserializeLocation(dataFile.getConfig().getString("data.sync." + locationStr + ".block")).getBlock();
boolean walkOnTeleport = dataFile.getConfig().getBoolean("data.sync." + locationStr + ".walkOnTeleport");
TeleportTrigger teleportTrigger = TeleportTrigger.valueOf(dataFile.getConfig().getString("data.sync." + locationStr + ".teleportTrigger"));
String playerStr = dataFile.getConfig().getString("data.sync." + locationStr + ".player");
String placedByStr = dataFile.getConfig().getString("data.sync." + locationStr + ".placedBy");
@ -133,7 +130,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
filter.setVoidList(voidList);
filter.setEndPoint(black);
EHopper hopper = new EHopper(location, levelManager.getLevel(level), lastPlayer, placedBy, block, filter, walkOnTeleport);
EHopper hopper = new EHopper(location, levelManager.getLevel(level), lastPlayer, placedBy, block, filter, teleportTrigger);
hopperManager.addHopper(location, hopper);
}
@ -218,7 +215,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
dataFile.getConfig().set("data.sync." + locationStr + ".block", hopper.getSyncedBlock() == null ? null : Arconix.pl().getApi().serialize().serializeLocation(hopper.getSyncedBlock().getLocation()));
dataFile.getConfig().set("data.sync." + locationStr + ".player", hopper.getLastPlayer() == null ? null : hopper.getLastPlayer().toString());
dataFile.getConfig().set("data.sync." + locationStr + ".placedBy", hopper.getPlacedBy() == null ? null : hopper.getPlacedBy().toString());
dataFile.getConfig().set("data.sync." + locationStr + ".walkOnTeleport", hopper.isWalkOnTeleport());
dataFile.getConfig().set("data.sync." + locationStr + ".teleportTrigger", hopper.getTeleportTrigger().toString());
dataFile.getConfig().set("data.sync." + locationStr + ".whitelist", hopper.getFilter().getWhiteList());
dataFile.getConfig().set("data.sync." + locationStr + ".blacklist", hopper.getFilter().getBlackList());
dataFile.getConfig().set("data.sync." + locationStr + ".void", hopper.getFilter().getVoidList());

View File

@ -19,6 +19,7 @@ public class CommandEpicHoppers extends AbstractCommand {
sender.sendMessage(TextComponent.formatText("&6/EpicHoppers&7 - Displays this page."));
if (sender.hasPermission("epichoppers.admin")) {
sender.sendMessage(TextComponent.formatText("&6/eh reload &7Reload the Configuration and Language files."));
sender.sendMessage(TextComponent.formatText("&6/eh book [player]&7- Gives Sync Touch book to you or a player."));
sender.sendMessage(TextComponent.formatText("&6/eh give [player] [level]&7 - Give a leveled hopper to a player."));
sender.sendMessage(TextComponent.formatText("&6/eh settings&7 - Edit the EpicHoppers Settings."));

View File

@ -2,12 +2,14 @@ package com.songoda.epichoppers.handlers;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.api.hopper.Hopper;
import com.songoda.epichoppers.api.hopper.TeleportTrigger;
import com.songoda.epichoppers.player.PlayerData;
import com.songoda.epichoppers.utils.Debugger;
import com.songoda.epichoppers.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
@ -46,7 +48,7 @@ public class TeleportHandler {
Hopper hopper = instance.getHopperManager().getHopper(location);
if (!hopper.isWalkOnTeleport()) continue;
if (hopper.getTeleportTrigger() != TeleportTrigger.WALK_ON) continue;
PlayerData playerData = instance.getPlayerDataManager().getPlayerData(player);
@ -86,6 +88,8 @@ public class TeleportHandler {
player.teleport(location);
next = player.getLocation().subtract(0, 0.5, 0).getBlock();
if (instance.getConfig().getBoolean("Main.Sounds Enabled"))
player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 10,10);
num++;
}
if (num == 1 && teleportFrom.containsKey(hopper.getLocation())) {
@ -97,6 +101,9 @@ public class TeleportHandler {
location.setDirection(player.getLocation().getDirection());
player.teleport(location);
next = player.getLocation().subtract(0, 0.5, 0).getBlock();
if (instance.getConfig().getBoolean("Main.Sounds Enabled"))
player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 10,10);
num ++;
}

View File

@ -7,6 +7,7 @@ import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.api.hopper.Filter;
import com.songoda.epichoppers.api.hopper.Hopper;
import com.songoda.epichoppers.api.hopper.Level;
import com.songoda.epichoppers.api.hopper.TeleportTrigger;
import com.songoda.epichoppers.boost.BoostData;
import com.songoda.epichoppers.player.MenuType;
import com.songoda.epichoppers.player.PlayerData;
@ -36,21 +37,21 @@ public class EHopper implements Hopper {
private UUID placedBy;
private Block syncedBlock;
private Filter filter;
private boolean walkOnTeleport;
private TeleportTrigger teleportTrigger;
public EHopper(Location location, com.songoda.epichoppers.api.hopper.Level level, UUID lastPlayer, UUID placedBy, Block syncedBlock, Filter filter, boolean walkOnTeleport) {
public EHopper(Location location, com.songoda.epichoppers.api.hopper.Level level, UUID lastPlayer, UUID placedBy, Block syncedBlock, Filter filter, TeleportTrigger teleportTrigger) {
this.location = location;
this.level = level;
this.syncedBlock = syncedBlock;
this.filter = filter;
this.lastPlayer = lastPlayer;
this.placedBy = placedBy;
this.walkOnTeleport = walkOnTeleport;
this.teleportTrigger = teleportTrigger;
}
public EHopper(Block block, com.songoda.epichoppers.api.hopper.Level level, UUID lastPlayer, UUID placedBy, Block syncedBlock, Filter filter, boolean walkOnTeleport) {
this(block.getLocation(), level, lastPlayer, placedBy, syncedBlock, filter, walkOnTeleport);
public EHopper(Block block, com.songoda.epichoppers.api.hopper.Level level, UUID lastPlayer, UUID placedBy, Block syncedBlock, Filter filter, TeleportTrigger teleportTrigger) {
this(block.getLocation(), level, lastPlayer, placedBy, syncedBlock, filter, teleportTrigger);
}
public void overview(Player player) {
@ -58,7 +59,7 @@ public class EHopper implements Hopper {
EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance();
if (!player.hasPermission("epichoppers.overview")) return;
if (lastPlayer != null) {
if (lastPlayer != null && lastPlayer != player.getUniqueId()) {
Bukkit.getPlayer(lastPlayer).closeInventory();
}
@ -72,7 +73,7 @@ public class EHopper implements Hopper {
ItemMeta perlmeta = perl.getItemMeta();
perlmeta.setDisplayName(instance.getLocale().getMessage("interface.hopper.perltitle"));
ArrayList<String> loreperl = new ArrayList<>();
String[] parts = instance.getLocale().getMessage("interface.hopper.perllore").split("\\|");
String[] parts = instance.getLocale().getMessage("interface.hopper.perllore2", teleportTrigger.name()).split("\\|");
for (String line : parts) {
loreperl.add(Arconix.pl().getApi().format().formatText(line));
}
@ -520,13 +521,13 @@ public class EHopper implements Hopper {
}
@Override
public boolean isWalkOnTeleport() {
return walkOnTeleport;
public TeleportTrigger getTeleportTrigger() {
return teleportTrigger;
}
@Override
public void setWalkOnTeleport(boolean walkOnTeleport) {
this.walkOnTeleport = walkOnTeleport;
public void setTeleportTrigger(TeleportTrigger teleportTrigger) {
this.teleportTrigger = teleportTrigger;
}
@Override

View File

@ -3,6 +3,7 @@ package com.songoda.epichoppers.hopper;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.api.hopper.Hopper;
import com.songoda.epichoppers.api.hopper.HopperManager;
import com.songoda.epichoppers.api.hopper.TeleportTrigger;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@ -28,7 +29,7 @@ public class EHopperManager implements HopperManager {
@Override
public Hopper getHopper(Location location) {
if (!registeredHoppers.containsKey(roundLocation(location))) {
addHopper(location, new EHopper(location, EpicHoppersPlugin.getInstance().getLevelManager().getLowestLevel(), null, null, null, new EFilter(), false));
addHopper(location, new EHopper(location, EpicHoppersPlugin.getInstance().getLevelManager().getLowestLevel(), null, null, null, new EFilter(), TeleportTrigger.DISABLED));
}
return registeredHoppers.get(roundLocation(location));
}

View File

@ -4,6 +4,7 @@ import com.songoda.arconix.plugin.Arconix;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.api.hopper.Hopper;
import com.songoda.epichoppers.api.hopper.Level;
import com.songoda.epichoppers.api.hopper.TeleportTrigger;
import com.songoda.epichoppers.hopper.EFilter;
import com.songoda.epichoppers.hopper.EHopper;
import com.songoda.epichoppers.utils.Debugger;
@ -55,7 +56,7 @@ public class BlockListeners implements Listener {
ItemStack item = e.getItemInHand().clone();
instance.getHopperManager().addHopper(e.getBlock().getLocation(), new EHopper(e.getBlock(), instance.getLevelFromItem(item), e.getPlayer().getUniqueId(), e.getPlayer().getUniqueId(),null, new EFilter(), false));
instance.getHopperManager().addHopper(e.getBlock().getLocation(), new EHopper(e.getBlock(), instance.getLevelFromItem(item), e.getPlayer().getUniqueId(), e.getPlayer().getUniqueId(),null, new EFilter(), TeleportTrigger.DISABLED));
} catch (Exception ee) {
Debugger.runReport(ee);

View File

@ -2,17 +2,21 @@ package com.songoda.epichoppers.listeners;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.api.hopper.Hopper;
import com.songoda.epichoppers.api.hopper.TeleportTrigger;
import com.songoda.epichoppers.hopper.EHopper;
import com.songoda.epichoppers.player.PlayerData;
import com.songoda.epichoppers.player.SyncType;
import com.songoda.epichoppers.utils.Debugger;
import com.songoda.epichoppers.utils.Methods;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
@ -27,6 +31,19 @@ public class InteractListeners implements Listener {
this.instance = instance;
}
@EventHandler
public void onPlayerToggleSneakEvent(PlayerToggleSneakEvent event) {
Player player = event.getPlayer();
if (player.isSneaking()) {
Location location = player.getLocation().getBlock().getRelative(BlockFace.DOWN).getLocation();
if (instance.getHopperManager().isHopper(location)) {
Hopper hopper = instance.getHopperManager().getHopper(location);
if (hopper.getTeleportTrigger() == TeleportTrigger.SNEAK)
instance.getTeleportHandler().tpPlayer(player, hopper);
}
}
}
@EventHandler
public void onBlockInteract(PlayerInteractEvent e) {
try {

View File

@ -2,6 +2,7 @@ package com.songoda.epichoppers.listeners;
import com.songoda.epichoppers.EpicHoppersPlugin;
import com.songoda.epichoppers.api.hopper.Hopper;
import com.songoda.epichoppers.api.hopper.TeleportTrigger;
import com.songoda.epichoppers.hopper.EHopper;
import com.songoda.epichoppers.player.MenuType;
import com.songoda.epichoppers.player.PlayerData;
@ -36,7 +37,6 @@ public class InventoryListeners implements Listener {
Player player = (Player) event.getWhoClicked();
if (inv == null || event.getCurrentItem() == null) return;
if (event.getRawSlot() > event.getView().getTopInventory().getSize() - 1) return;
if (event.getCursor() != null && event.getCurrentItem() != null) {
@ -45,7 +45,7 @@ public class InventoryListeners implements Listener {
if (c.hasItemMeta()
&& c.getItemMeta().hasLore()
&& c.getType() == Material.ENCHANTED_BOOK
&& (item.getType().name().toUpperCase().contains("AXE") || item.getType().name().toUpperCase().contains("SPADE") || item.getType().name().toUpperCase().contains("SWORD"))
&& (item.getType().name().toUpperCase().contains("AXE") || item.getType().name().toUpperCase().contains("SHOVEL") || item.getType().name().toUpperCase().contains("SWORD"))
&& c.getItemMeta().getLore().equals(instance.enchantmentHandler.getbook().getItemMeta().getLore())) {
instance.enchantmentHandler.createSyncTouch(item, null);
event.setCancelled(true);
@ -83,13 +83,15 @@ public class InventoryListeners implements Listener {
instance.getTeleportHandler().tpPlayer(player, hopper);
}
} else {
if (!hopper.isWalkOnTeleport()) {
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.walkteleenabled"));
hopper.setWalkOnTeleport(true);
} else {
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.walkteledisabled"));
hopper.setWalkOnTeleport(false);
if (hopper.getTeleportTrigger() == TeleportTrigger.DISABLED) {
hopper.setTeleportTrigger(TeleportTrigger.SNEAK);
} else if (hopper.getTeleportTrigger() == TeleportTrigger.SNEAK) {
hopper.setTeleportTrigger(TeleportTrigger.WALK_ON);
} else if (hopper.getTeleportTrigger() == TeleportTrigger.WALK_ON) {
hopper.setTeleportTrigger(TeleportTrigger.DISABLED);
}
((EHopper)hopper).overview(player);
return;
}
player.closeInventory();

View File

@ -21,7 +21,7 @@ interface.hopper.blockbreak = "&7Block Break: &6Every %ticks% ticks"
interface.hopper.alreadymaxed = "&7This hopper is already maxed out!"
interface.hopper.synclore = "|&7Left-Click then click a another|&7hopper or chest to sync!||&7Right-Click to desync."
interface.hopper.perltitle = "&6Click to Teleport"
interface.hopper.perllore = "|&7Left-Click to teleport to|&7the end of the chain.||&7Right-Click to toggle walk|&7on teleport."
interface.hopper.perllore2 = "|&7Left-Click to teleport to|&7the end of the chain.||&7Right-Click to switch the|&7teleport trigger mode.|&7Currently set to: &a%type%&7."
interface.hopper.filtertitle = "&cClick to Filter"
interface.hopper.filterlore = "|&7This allows you to choose|&7which items go where."
interface.hopper.synchopper = "&6Click to Sync This hopper"
@ -51,7 +51,7 @@ event.hopper.synctimeout = "&cSyncing timed out."
event.hopper.syncoutofrange = "&cThis block is out of your hoppers range."
event.hopper.syncdidnotplace = "&cSorry! You need to have placed this hopper to sync things to it."
event.hopper.toomany = "&cYou can only place %amount% hoppers per chunk..."
event.hopper.walkteleenabled = "Walk on teleporting has been enabled for this hopper."
event.hopper.walkteleenabled = "The teleport has been enabled for this hopper."
event.hopper.walkteledisabled = "Walk on teleporting has been disabled for this hopper."
event.hopper.onlyone = "&cYou may only place a single item at a time."
event.hopper.syncchest = "&7You have synchronized your &9%name% &7with this chest."