mirror of
https://github.com/songoda/EpicHoppers.git
synced 2024-11-05 18:19:38 +01:00
Fixed an issue with negitave durability with synctouch
This commit is contained in:
parent
36f839ef50
commit
ee099c4d43
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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()) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user