better hitboxes for blockhunt
This commit is contained in:
parent
4d737afc4f
commit
055abc11bd
6 changed files with 109 additions and 67 deletions
|
@ -96,6 +96,7 @@ public class Main extends JavaPlugin implements Listener {
|
|||
|
||||
Bukkit.getServer().getMessenger().unregisterOutgoingPluginChannel(this);
|
||||
board.cleanup();
|
||||
disguiser.cleanUp();
|
||||
}
|
||||
|
||||
private void onTick() {
|
||||
|
|
|
@ -103,6 +103,9 @@ public class Board {
|
|||
}
|
||||
|
||||
public void addHider(Player player) {
|
||||
if(!Main.getInstance().supports(9)){
|
||||
player.spigot().setCollidesWithEntities(false);
|
||||
}
|
||||
Hider.add(player.getUniqueId().toString());
|
||||
Seeker.remove(player.getUniqueId().toString());
|
||||
Spectator.remove(player.getUniqueId().toString());
|
||||
|
@ -110,6 +113,9 @@ public class Board {
|
|||
}
|
||||
|
||||
public void addSeeker(Player player) {
|
||||
if(!Main.getInstance().supports(9)){
|
||||
player.spigot().setCollidesWithEntities(false);
|
||||
}
|
||||
Hider.remove(player.getUniqueId().toString());
|
||||
Seeker.add(player.getUniqueId().toString());
|
||||
Spectator.remove(player.getUniqueId().toString());
|
||||
|
@ -117,6 +123,9 @@ public class Board {
|
|||
}
|
||||
|
||||
public void addSpectator(Player player) {
|
||||
if(!Main.getInstance().supports(9)){
|
||||
player.spigot().setCollidesWithEntities(false);
|
||||
}
|
||||
Hider.remove(player.getUniqueId().toString());
|
||||
Seeker.remove(player.getUniqueId().toString());
|
||||
Spectator.add(player.getUniqueId().toString());
|
||||
|
@ -124,6 +133,9 @@ public class Board {
|
|||
}
|
||||
|
||||
public void remove(Player player) {
|
||||
if(!Main.getInstance().supports(9)){
|
||||
player.spigot().setCollidesWithEntities(true);
|
||||
}
|
||||
Hider.remove(player.getUniqueId().toString());
|
||||
Seeker.remove(player.getUniqueId().toString());
|
||||
Spectator.remove(player.getUniqueId().toString());
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
package net.tylermurphy.hideAndSeek.game;
|
||||
|
||||
import net.tylermurphy.hideAndSeek.game.util.Disguise;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.BlockVector;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Vector;
|
||||
|
||||
public class Disguiser {
|
||||
|
||||
|
@ -32,11 +28,8 @@ public class Disguiser {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
public Disguise getByBlockLocation(BlockVector loc){
|
||||
return disguises.values().stream().filter(disguise -> {
|
||||
if(disguise.getSolidLocation() == null) return false;
|
||||
return disguise.getSolidLocation().toVector().toBlockVector() == loc;
|
||||
}).findFirst().orElse(null);
|
||||
public Disguise getByHitBoxID(int ID){
|
||||
return disguises.values().stream().filter(disguise -> disguise.getHitBoxID() == ID).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public void check(){
|
||||
|
@ -66,4 +59,8 @@ public class Disguiser {
|
|||
disguises.remove(player);
|
||||
}
|
||||
|
||||
public void cleanUp() {
|
||||
disguises.values().forEach(Disguise::remove);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -65,34 +65,20 @@ public class DisguiseHandler implements Listener {
|
|||
// }
|
||||
|
||||
private PacketAdapter createProtocol(){
|
||||
return new PacketAdapter(Main.getInstance(), USE_ITEM, USE_ENTITY) {
|
||||
return new PacketAdapter(Main.getInstance(), USE_ENTITY) {
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event){
|
||||
PacketContainer packet = event.getPacket();
|
||||
Player player = event.getPlayer();
|
||||
// if(!Main.getInstance().getBoard().isSeeker(player)) return;
|
||||
if(packet.getType() == USE_ITEM) {
|
||||
System.out.print("\nUse Item: ");
|
||||
BlockPosition data;
|
||||
try { data = packet.getBlockPositionModifier().read(0); }
|
||||
catch (Exception e) { return; }
|
||||
System.out.print(data + " ");
|
||||
BlockVector loc = new BlockVector(data.getX(), data.getY(), data.getZ());
|
||||
System.out.print(loc + " ");
|
||||
Disguise disguise = Main.getInstance().getDisguiser().getByBlockLocation(loc);
|
||||
System.out.print("FOUND");
|
||||
handleAttack(disguise, player);
|
||||
} else if(packet.getType() == USE_ENTITY) {
|
||||
System.out.print("\nUse Entity: ");
|
||||
int id = packet.getIntegers().read(0);
|
||||
System.out.print(id + " ");
|
||||
Disguise disguise = Main.getInstance().getDisguiser().getByEntityID(id);
|
||||
System.out.print("FOUND");
|
||||
handleAttack(disguise, player);
|
||||
}
|
||||
int id = packet.getIntegers().read(0);
|
||||
Disguise disguise = Main.getInstance().getDisguiser().getByEntityID(id);
|
||||
if(disguise == null) disguise = Main.getInstance().getDisguiser().getByHitBoxID(id);
|
||||
if(disguise == null) return;
|
||||
event.setCancelled(true);
|
||||
handleAttack(disguise, player);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -100,6 +86,8 @@ public class DisguiseHandler implements Listener {
|
|||
|
||||
private void handleAttack(Disguise disguise, Player seeker){
|
||||
|
||||
if(disguise.getPlayer() == seeker) return;
|
||||
|
||||
double amount;
|
||||
if(Main.getInstance().supports(9)) {
|
||||
amount = seeker.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE).getValue();
|
||||
|
@ -107,7 +95,6 @@ public class DisguiseHandler implements Listener {
|
|||
amount = getItemDamageValue(seeker.getItemInHand(), disguise.getPlayer(), seeker);
|
||||
}
|
||||
|
||||
if(disguise == null) return;
|
||||
disguise.setSolidify(false);
|
||||
if(debounce.contains(disguise.getPlayer())) return;
|
||||
debounce.add(disguise.getPlayer());
|
||||
|
@ -197,4 +184,5 @@ public class DisguiseHandler implements Listener {
|
|||
|
||||
return (int) Math.round(Math.max(damageValue, 0.0));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ public class MovementHandler implements Listener {
|
|||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onMove(PlayerMoveEvent event) {
|
||||
|
||||
if (event.getTo() == null || event.getTo().getWorld() == null) return;
|
||||
checkJumping(event);
|
||||
checkBounds(event);
|
||||
|
|
|
@ -10,11 +10,11 @@ import net.tylermurphy.hideAndSeek.Main;
|
|||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
|
@ -24,62 +24,94 @@ public class Disguise {
|
|||
|
||||
final Player hider;
|
||||
final Material material;
|
||||
FallingBlock entity;
|
||||
FallingBlock block;
|
||||
Horse hitBox;
|
||||
Location solidLocation;
|
||||
boolean solid, solidify;
|
||||
static Team hidden;
|
||||
|
||||
static {
|
||||
if(Main.getInstance().supports(9)) {
|
||||
Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
|
||||
hidden = board.getTeam("KenshinHideAndSeek_CollisionGroup");
|
||||
if (hidden == null) {
|
||||
hidden = board.registerNewTeam("KenshinHideAndSeek_CollisionGroup");
|
||||
}
|
||||
hidden.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
|
||||
hidden.setCanSeeFriendlyInvisibles(false);
|
||||
}
|
||||
}
|
||||
|
||||
public Disguise(Player player, Material material){
|
||||
this.hider = player;
|
||||
this.material = material;
|
||||
this.solid = false;
|
||||
respawnEntity();
|
||||
respawnFallingBlock();
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1000000, 0,false, false));
|
||||
if(Main.getInstance().supports(9)) {
|
||||
hidden.addEntry(player.getName());
|
||||
} else {
|
||||
hider.spigot().setCollidesWithEntities(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
if(entity != null)
|
||||
entity.remove();
|
||||
if(block != null)
|
||||
block.remove();
|
||||
if(hitBox != null){
|
||||
if(Main.getInstance().supports(9))
|
||||
hidden.removeEntry(hitBox.getUniqueId().toString());
|
||||
hitBox.remove();
|
||||
}
|
||||
if(solid)
|
||||
sendBlockUpdate(Material.AIR);
|
||||
hider.removePotionEffect(PotionEffectType.INVISIBILITY);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Location getSolidLocation() {
|
||||
return solidLocation;
|
||||
if(Main.getInstance().supports(9)) {
|
||||
hidden.removeEntry(hider.getName());
|
||||
} else {
|
||||
hider.spigot().setCollidesWithEntities(true);
|
||||
}
|
||||
}
|
||||
|
||||
public int getEntityID() {
|
||||
if(entity == null) return -1;
|
||||
return entity.getEntityId();
|
||||
if(block == null) return -1;
|
||||
return block.getEntityId();
|
||||
}
|
||||
|
||||
public int getHitBoxID() {
|
||||
if(hitBox == null) return -1;
|
||||
return hitBox.getEntityId();
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return hider;
|
||||
}
|
||||
|
||||
public boolean isSolid(){
|
||||
return solid;
|
||||
}
|
||||
|
||||
public void update(){
|
||||
|
||||
if(entity == null || entity.isDead()){
|
||||
if(entity != null) entity.remove();
|
||||
respawnEntity();
|
||||
if(block == null || block.isDead()){
|
||||
if(block != null) block.remove();
|
||||
respawnFallingBlock();
|
||||
}
|
||||
|
||||
if(solidify){
|
||||
if(!solid)
|
||||
if(!solid) {
|
||||
solid = true;
|
||||
solidLocation = hider.getLocation().getBlock().getLocation();
|
||||
solid = true;
|
||||
respawnHotbox();
|
||||
teleportEntity(hitBox, false);
|
||||
}
|
||||
sendBlockUpdate(material);
|
||||
} else if(solid){
|
||||
solid = false;
|
||||
if(Main.getInstance().supports(9))
|
||||
hidden.removeEntry(hitBox.getUniqueId().toString());
|
||||
hitBox.remove();
|
||||
hitBox = null;
|
||||
sendBlockUpdate(Material.AIR);
|
||||
}
|
||||
sendToggleFallingBlock(!solid);
|
||||
sendFallingBlockUpdate();
|
||||
toggleEntityVisibility(block, !solid);
|
||||
teleportEntity(block, solid);
|
||||
}
|
||||
|
||||
public void setSolidify(boolean value){
|
||||
|
@ -99,16 +131,12 @@ public class Disguise {
|
|||
});
|
||||
}
|
||||
|
||||
private void sendFallingBlockUpdate() {
|
||||
if(entity == null || entity.isDead()){
|
||||
if(entity != null) entity.remove();
|
||||
respawnEntity();
|
||||
}
|
||||
private void teleportEntity(Entity entity, boolean center) {
|
||||
final PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_TELEPORT);
|
||||
Location location = hider.getLocation();
|
||||
packet.getModifier().writeDefaults();
|
||||
packet.getIntegers().write(0, entity.getEntityId());
|
||||
if(solid){
|
||||
if(center){
|
||||
packet.getDoubles().write(0, Math.round(location.getX()+.5)-.5);
|
||||
packet.getDoubles().write(1, (double)Math.round(location.getY()));
|
||||
packet.getDoubles().write(2, Math.round(location.getZ()+.5)-.5);
|
||||
|
@ -124,7 +152,8 @@ public class Disguise {
|
|||
});
|
||||
}
|
||||
|
||||
private void sendToggleFallingBlock(boolean show){
|
||||
private void toggleEntityVisibility(Entity entity, boolean show){
|
||||
if(entity == null) return;
|
||||
Bukkit.getOnlinePlayers().forEach(receiver -> {
|
||||
if(receiver == hider) return;
|
||||
if(show)
|
||||
|
@ -134,10 +163,24 @@ public class Disguise {
|
|||
});
|
||||
}
|
||||
|
||||
private void respawnEntity(){
|
||||
entity = hider.getLocation().getWorld().spawnFallingBlock(hider.getLocation(), material, (byte)0);
|
||||
entity.setGravity(false);
|
||||
entity.setDropItem(false);
|
||||
private void respawnFallingBlock(){
|
||||
block = hider.getLocation().getWorld().spawnFallingBlock(hider.getLocation(), material, (byte)0);
|
||||
block.setGravity(false);
|
||||
block.setDropItem(false);
|
||||
block.setInvulnerable(true);
|
||||
}
|
||||
|
||||
private void respawnHotbox(){
|
||||
hitBox = (Horse) hider.getLocation().getWorld().spawnEntity(hider.getLocation().add(0, 1000, 0), EntityType.HORSE);
|
||||
hitBox.setAI(false);
|
||||
hitBox.setGravity(false);
|
||||
hitBox.setInvulnerable(true);
|
||||
hitBox.setCanPickupItems(false);
|
||||
hitBox.setCollidable(false);
|
||||
hitBox.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1000000, 0,false, false));
|
||||
if(Main.getInstance().supports(9)){
|
||||
hidden.addEntry(hitBox.getUniqueId().toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue