Fixed an issue with negitave durability with synctouch

This commit is contained in:
Brianna O'Keefe 2018-05-31 23:52:35 -04:00
parent 36f839ef50
commit ee099c4d43
9 changed files with 65 additions and 39 deletions

View File

@ -56,6 +56,8 @@ public final class EpicHoppers extends JavaPlugin implements Listener {
private HopperManager hopperManager;
private LevelManager levelManager;
private TeleportHandler teleportHandler;
private EpicHoppersAPI api;
public void onEnable() {
@ -124,7 +126,7 @@ public final class EpicHoppers extends JavaPlugin implements Listener {
hooks.hook();
new HopHandler(this);
new TeleportHandler(this);
teleportHandler = new TeleportHandler(this);
new MCUpdate(this, true);
//new MassiveStats(this, 9000);
@ -262,6 +264,10 @@ public final class EpicHoppers extends JavaPlugin implements Listener {
return locale;
}
public TeleportHandler getTeleportHandler() {
return teleportHandler;
}
public LevelManager getLevelManager() {
return levelManager;
}

View File

@ -176,6 +176,9 @@ public class BlockListeners implements Listener {
e.isCancelled();
short dur = e.getPlayer().getItemInHand().getDurability();
e.getPlayer().getItemInHand().setDurability((short) (dur + 1));
if (e.getPlayer().getItemInHand().getDurability() >= e.getPlayer().getItemInHand().getType().getMaxDurability()) {
e.getPlayer().getItemInHand().setType(Material.AIR);
}
if (e.getExpToDrop() > 0)
e.getPlayer().getWorld().spawn(e.getBlock().getLocation(), ExperienceOrb.class).setExperience(e.getExpToDrop());
e.getBlock().setType(Material.AIR);

View File

@ -73,7 +73,7 @@ public class InventoryListeners implements Listener {
&& (instance.getConfig().getBoolean("Main.Allow Players To Teleport Through Hoppers") || player.hasPermission("EpicHoppers.Teleport"))) {
if (e.isLeftClick()) {
if (hopper.getSyncedBlock() != null) {
Methods.tpPlayer(player, hopper);
instance.getTeleportHandler().tpPlayer(player, hopper);
}
} else {
if (!hopper.isWalkOnTeleport()) {

View File

@ -6,13 +6,20 @@ 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.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class TeleportHandler {
//Teleport from - teleport 2
private final Map<Location, Location> teleportFrom = new HashMap<>();
private EpicHoppers instance;
public TeleportHandler(EpicHoppers instance) {
@ -47,10 +54,56 @@ public class TeleportHandler {
}
}
Methods.tpPlayer(player, hopper);
tpPlayer(player, hopper);
instance.lastTp.put(player, new Date());
}
}
public void tpPlayer(Player player, Hopper hopper) {
try {
EpicHoppers instance = EpicHoppers.getInstance();
Block next = hopper.getLocation().getBlock();
int num = 1;
while (instance.getHopperManager().isHopper(next.getLocation()) && instance.getHopperManager().getHopper(next.getLocation()).getSyncedBlock() != null && num != 15) {
Hopper nextHopper = instance.getHopperManager().getHopper(next);
if (nextHopper.getSyncedBlock() != null) {
next = nextHopper.getSyncedBlock();
}
if (!next.getType().equals(Material.HOPPER)) {
instance.getHopperManager().removeHopper(nextHopper.getLocation());
break;
}
Location location = next.getLocation();
location.setX(location.getX() + 0.5);
location.setZ(location.getZ() + 0.5);
location.setY(location.getY() + 1);
location.setPitch(player.getLocation().getPitch());
location.setDirection(player.getLocation().getDirection());
player.teleport(location);
next = player.getLocation().subtract(0, 0.5, 0).getBlock();
num++;
}
if (num == 1 && teleportFrom.containsKey(hopper.getLocation())) {
Location location = teleportFrom.get(hopper.getLocation());
location.setX(location.getX() + 0.5);
location.setZ(location.getZ() + 0.5);
location.setY(location.getY() + 1);
location.setPitch(player.getLocation().getPitch());
location.setDirection(player.getLocation().getDirection());
player.teleport(location);
next = player.getLocation().subtract(0, 0.5, 0).getBlock();
num ++;
}
if (num != 1) {
teleportFrom.put(next.getLocation(), hopper.getLocation());
Methods.doParticles(player, hopper.getLocation());
Methods.doParticles(player, next.getLocation());
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
}

View File

@ -80,42 +80,6 @@ public class Methods {
return null;
}
public static void tpPlayer(Player player, Hopper hopper) {
try {
EpicHoppers instance = EpicHoppers.getInstance();
Block next = hopper.getLocation().getBlock();
int num = 1;
while (instance.getHopperManager().isHopper(next.getLocation()) && instance.getHopperManager().getHopper(next.getLocation()).getSyncedBlock() != null && num != 15) {
Hopper nextHopper = instance.getHopperManager().getHopper(next);
if (nextHopper.getSyncedBlock() != null) {
next = nextHopper.getSyncedBlock();
}
if (!next.getType().equals(Material.HOPPER)) {
instance.getHopperManager().removeHopper(nextHopper.getLocation());
break;
}
Location location = next.getLocation();
location.setX(location.getX() + 0.5);
location.setZ(location.getZ() + 0.5);
location.setY(location.getY() + 1);
location.setPitch(player.getLocation().getPitch());
location.setDirection(player.getLocation().getDirection());
player.teleport(location);
next = player.getLocation().subtract(0, 0.5, 0).getBlock();
num++;
}
if (num != 1) {
Methods.doParticles(player, hopper.getLocation());
Methods.doParticles(player, next.getLocation());
}
} catch (Exception e) {
Debugger.runReport(e);
}
}
public static void doParticles(Player p, Location location) {
try {
EpicHoppers instance = EpicHoppers.getInstance();