Listeners added (only PlayerInteractListener not done)

This commit is contained in:
stijnb1234 2020-02-01 11:25:24 +01:00
parent edf3ee2db4
commit 77dccb3a59
12 changed files with 302 additions and 15 deletions

View file

@ -17,4 +17,17 @@ public class Floor {
this.y = y;
this.world = world;
}
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
Floor other = (Floor) obj;
if (getWorld() == null) {
if (other.getWorld() != null) return false;
} else if (!getWorld().equals(other.getWorld())) {
return false;
}
return getY() == other.getY();
}
}

View file

@ -67,4 +67,15 @@ public class LiftBlock implements Comparable<LiftBlock> {
return ret;
}
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof LiftBlock)) {
if (!(obj instanceof LiftSign)) return false;
LiftSign other = (LiftSign) obj;
return getWorld().equals(other.getWorld()) && getX() == other.getX() && getY() == other.getY() && getZ() == other.getZ();
}
LiftBlock other = (LiftBlock) obj;
return getWorld().equals(other.getWorld()) && getX() == other.getX() && getY() == other.getY() && getZ() == other.getZ();
}
}

View file

@ -27,4 +27,17 @@ public class LiftRope {
this.currently = minY;
this.currentWorld = endWorld;
}
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (!(obj instanceof LiftRope)) return false;
LiftRope other = (LiftRope) obj;
return getStartWorld().equals(other.getStartWorld())
&& endWorld.equals(other.getEndWorld())
&& getX() == other.getX()
&& getMinY() == other.getMinY()
&& getMaxY() == other.getMaxY()
&& getZ() == other.getZ();
}
}

View file

@ -21,4 +21,15 @@ public class LiftSign {
this.type = type;
this.state = state;
}
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof LiftSign)) {
if (!(obj instanceof LiftBlock)) return false;
LiftBlock other = (LiftBlock) obj;
return getWorld().equals(other.getWorld()) && getX() == other.getX() && getY() == other.getY() && getZ() == other.getZ();
}
LiftSign other = (LiftSign) obj;
return getWorld().equals(other.getWorld()) && getX() == other.getX() && getY() == other.getY() && getZ() == other.getZ();
}
}

View file

@ -5,29 +5,55 @@ import lombok.Setter;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import java.util.UUID;
@Getter
public class V10Entity {
private final Entity e;
private final Entity entity;
private final Location loc;
private final int y;
@Setter private short step;
public V10Entity(Entity e, Location loc, int y) {
this.e = e;
public V10Entity(Entity entity, Location loc, int y) {
this.entity = entity;
this.loc = loc;
this.y = y;
this.step = 0;
}
public void moveUp() {
if (e == null || e.isDead()) return;
if (entity == null || entity.isDead()) return;
loc.setY(y + step);
e.teleport(loc);
entity.teleport(loc);
}
public void moveDown() {
if (e == null || e.isDead()) return;
if (entity == null || entity.isDead()) return;
loc.setY(y - step);
e.teleport(loc);
entity.teleport(loc);
}
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
UUID uuid;
if (obj instanceof V10Entity) {
Entity ent = ((V10Entity) obj).getEntity();
if (ent == null || ent.isDead()) {
return getEntity() == null || getEntity().isDead();
}
uuid = ent.getUniqueId();
} else if (obj instanceof Entity) {
Entity ent = (Entity) obj;
if (ent.isDead()) {
return getEntity() == null || getEntity().isDead();
}
uuid = ent.getUniqueId();
} else {
return false;
}
if (getEntity() == null || getEntity().isDead()) return false;
return uuid == getEntity().getUniqueId();
}
}

View file

@ -1,9 +1,6 @@
package nl.SBDeveloper.V10Lift.API;
import nl.SBDeveloper.V10Lift.API.Objects.Floor;
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
import nl.SBDeveloper.V10Lift.API.Objects.LiftSign;
import nl.SBDeveloper.V10Lift.API.Objects.*;
import nl.SBDeveloper.V10Lift.API.Runnables.DoorCloser;
import nl.SBDeveloper.V10Lift.Managers.AntiCopyBlockManager;
import nl.SBDeveloper.V10Lift.Managers.DataManager;
@ -576,6 +573,35 @@ public class V10LiftAPI {
return 0;
}
public boolean containsRope(String liftName, Block block) {
if (liftName == null || block == null || !DataManager.containsLift(liftName)) return false;
Lift lift = DataManager.getLift(liftName);
if (lift.getRopes().isEmpty()) return false;
String world = block.getWorld().getName();
int x = block.getX();
int y = block.getY();
int z = block.getZ();
for (LiftRope rope : lift.getRopes()) {
if (x != rope.getX() || z != rope.getZ()) continue;
if (rope.getStartWorld().equals(rope.getEndWorld())) {
if (y >= rope.getMinY() && y <= rope.getMaxY()) {
return true;
}
}
}
return false;
}
public boolean isRope(Block b) {
for (String lift : DataManager.getLifts().keySet()) {
if (containsRope(lift, b)) return true;
}
return false;
}
public void sendLiftInfo(Player p, String liftName) {
if (p == null || liftName == null || !DataManager.containsLift(liftName)) return;

View file

@ -0,0 +1,59 @@
package nl.SBDeveloper.V10Lift.Listeners;
import nl.SBDeveloper.V10Lift.API.Objects.Floor;
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
import nl.SBDeveloper.V10Lift.API.Objects.LiftSign;
import nl.SBDeveloper.V10Lift.Managers.DataManager;
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import java.util.Map;
public class BlockBreakListener implements Listener {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent e) {
Block b = e.getBlock();
if (V10LiftPlugin.getAPI().isRope(b)) {
e.getPlayer().sendMessage(ChatColor.RED + "You can't do this! Remove the rope first.");
e.setCancelled(true);
return;
}
LiftBlock tlb = new LiftBlock(b.getWorld().getName(), b.getX(), b.getY(), b.getZ(), (String) null);
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
Lift lift = entry.getValue();
if (lift.getBlocks().contains(tlb)) {
e.getPlayer().sendMessage(ChatColor.RED + "You can't do this! Remove the lift first.");
e.setCancelled(true);
return;
}
for (Floor f : lift.getFloors().values()) {
if (f.getDoorBlocks().contains(tlb)) {
e.getPlayer().sendMessage(ChatColor.RED + "You can't do this! Remove the door first.");
e.setCancelled(true);
return;
}
}
if (!(b.getState() instanceof Sign)) continue;
if (!lift.getSigns().contains(tlb)) continue;
if (!lift.getOwners().contains(e.getPlayer().getUniqueId()) && !e.getPlayer().hasPermission("v10lift.admin")) {
e.getPlayer().sendMessage(ChatColor.RED + "You can't do this!");
e.setCancelled(true);
} else {
lift.getSigns().remove(tlb);
e.getPlayer().sendMessage(ChatColor.YELLOW + "Lift sign removed!");
}
}
}
}

View file

@ -0,0 +1,43 @@
package nl.SBDeveloper.V10Lift.Listeners;
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
import nl.SBDeveloper.V10Lift.Managers.DataManager;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
public class EntityDamageListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent e) {
if (e.getCause() != EntityDamageEvent.DamageCause.SUFFOCATION) return;
Entity entity = e.getEntity();
Location loc;
if (e instanceof LivingEntity) {
loc = ((LivingEntity) entity).getEyeLocation();
} else {
loc = entity.getLocation();
}
if (loc.getWorld() == null) return;
String world = loc.getWorld().getName();
int x = loc.getBlockX();
int y = loc.getBlockY();
int z = loc.getBlockZ();
for (Lift lift : DataManager.getLifts().values()) {
for (LiftBlock lb : lift.getBlocks()) {
if (world.equals(lb.getWorld()) && x == lb.getX() && y == lb.getY() && z == lb.getZ()) {
e.setCancelled(true);
return;
}
}
}
}
}

View file

@ -0,0 +1,20 @@
package nl.SBDeveloper.V10Lift.Listeners;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
public class PlayerInteractListener implements Listener {
//BUTTON CLICK
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerInteractButton(PlayerInteractEvent e) {
}
//BLOCK ADD
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent e) {
}
}

View file

@ -0,0 +1,53 @@
package nl.SBDeveloper.V10Lift.Listeners;
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
import nl.SBDeveloper.V10Lift.API.Objects.LiftSign;
import nl.SBDeveloper.V10Lift.Managers.DataManager;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
public class SignChangeListener implements Listener {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onSignChange(SignChangeEvent e) {
String[] lines = e.getLines();
if (!lines[0].equalsIgnoreCase("[v10lift]")) return;
Player p = e.getPlayer();
if (lines[1].isEmpty()) {
p.sendMessage(ChatColor.RED + "No lift name given!");
return;
}
if (!DataManager.containsLift(lines[1])) {
p.sendMessage(ChatColor.RED + "Lift " + lines[1] + " doesn't exists!");
return;
}
Lift lift = DataManager.getLift(lines[1]);
if (!lift.getOwners().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) {
p.sendMessage(ChatColor.RED + "You can't do this!");
e.setCancelled(true);
return;
}
byte type;
if (lift.getFloors().containsKey(lines[2])) {
type = 1;
e.setLine(3, ChatColor.GRAY + lines[2]);
} else {
type = 0;
}
e.setLine(2, "");
Block b = e.getBlock();
lift.getSigns().add(new LiftSign(b.getWorld().getName(), b.getX(), b.getY(), b.getZ(), type, (byte) 0));
p.sendMessage(ChatColor.GREEN + "Lift sign created!");
}
}

View file

@ -3,10 +3,7 @@ package nl.SBDeveloper.V10Lift.Managers;
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
import org.bukkit.block.Block;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.UUID;
import java.util.*;
public class DataManager {
/* A manager for general HashMaps */
@ -43,6 +40,8 @@ public class DataManager {
return lifts.get(liftName);
}
public static LinkedHashMap<String, Lift> getLifts() { return lifts; }
// //
public static boolean containsPlayer(UUID player) {
return builds.containsKey(player);

View file

@ -2,8 +2,14 @@ package nl.SBDeveloper.V10Lift;
import nl.SBDeveloper.V10Lift.API.V10LiftAPI;
import nl.SBDeveloper.V10Lift.Commands.V10LiftCommand;
import nl.SBDeveloper.V10Lift.Listeners.BlockBreakListener;
import nl.SBDeveloper.V10Lift.Listeners.EntityDamageListener;
import nl.SBDeveloper.V10Lift.Listeners.PlayerInteractListener;
import nl.SBDeveloper.V10Lift.Listeners.SignChangeListener;
import nl.SBDeveloper.V10Lift.Utils.SBSQLiteDB;
import nl.SBDeveloper.V10Lift.Utils.SBYamlFile;
import org.bukkit.Bukkit;
import org.bukkit.block.Sign;
import org.bukkit.plugin.java.JavaPlugin;
public class V10LiftPlugin extends JavaPlugin {
@ -24,6 +30,13 @@ public class V10LiftPlugin extends JavaPlugin {
api = new V10LiftAPI();
getCommand("v10lift").setExecutor(new V10LiftCommand());
Bukkit.getPluginManager().registerEvents(new PlayerInteractListener(), this);
Bukkit.getPluginManager().registerEvents(new BlockBreakListener(), this);
Bukkit.getPluginManager().registerEvents(new SignChangeListener(), this);
Bukkit.getPluginManager().registerEvents(new EntityDamageListener(), this);
getLogger().info("[V10Lift] Plugin loaded successfully!");
}
@Override