forked from gecolay/GSit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'gecolay:main' into main
- Loading branch information
Showing
32 changed files
with
249 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
218 changes: 218 additions & 0 deletions
218
mcv1_21/src/main/java/dev/geco/gsit/mcv/x/objects/GCrawl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
package dev.geco.gsit.mcv.x.objects; | ||
|
||
import org.bukkit.*; | ||
import org.bukkit.block.*; | ||
import org.bukkit.block.data.*; | ||
import org.bukkit.event.*; | ||
import org.bukkit.event.entity.*; | ||
import org.bukkit.event.player.*; | ||
import org.bukkit.entity.*; | ||
import org.bukkit.inventory.*; | ||
import org.bukkit.craftbukkit.v1_21_R1.entity.*; | ||
|
||
import net.minecraft.network.protocol.game.*; | ||
import net.minecraft.server.level.*; | ||
|
||
import dev.geco.gsit.GSitMain; | ||
import dev.geco.gsit.objects.*; | ||
|
||
public class GCrawl implements IGCrawl { | ||
|
||
private final GSitMain GPM = GSitMain.getInstance(); | ||
|
||
private final Player player; | ||
|
||
private final ServerPlayer serverPlayer; | ||
|
||
protected final BoxEntity boxEntity; | ||
|
||
private Location blockLocation; | ||
|
||
private boolean boxPresent; | ||
|
||
protected final BlockData blockData = Material.BARRIER.createBlockData(); | ||
|
||
private final Listener listener; | ||
private final Listener moveListener; | ||
private final Listener stopListener; | ||
|
||
private final long spawnTime = System.nanoTime(); | ||
|
||
public GCrawl(Player Player) { | ||
|
||
player = Player; | ||
|
||
serverPlayer = ((CraftPlayer) player).getHandle(); | ||
|
||
boxEntity = new BoxEntity(player.getLocation()); | ||
|
||
listener = new Listener() { | ||
|
||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) | ||
public void ETogSE(EntityToggleSwimEvent Event) { if(Event.getEntity() == player) Event.setCancelled(true); } | ||
|
||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) | ||
public void PIntE(PlayerInteractEvent Event) { | ||
|
||
if(!Event.isAsynchronous() && Event.getPlayer() == player && blockLocation != null && Event.getClickedBlock().equals(blockLocation.getBlock()) && Event.getHand() == EquipmentSlot.HAND) { | ||
|
||
Event.setCancelled(true); | ||
|
||
GPM.getTManager().run(() -> { | ||
|
||
buildBlock(blockLocation); | ||
}, false, player); | ||
} | ||
} | ||
}; | ||
|
||
moveListener = new Listener() { | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
public void PMovE(PlayerMoveEvent Event) { | ||
|
||
if(!Event.isAsynchronous() && Event.getPlayer() == player) { | ||
|
||
Location locationFrom = Event.getFrom(), locationTo = Event.getTo(); | ||
|
||
if(locationFrom.getX() != locationTo.getX() || locationFrom.getZ() != locationTo.getZ() || locationFrom.getY() != locationTo.getY()) tick(locationFrom); | ||
} | ||
} | ||
}; | ||
|
||
stopListener = new Listener() { | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
public void PTogSE(PlayerToggleSneakEvent Event) { if(!Event.isAsynchronous() && Event.getPlayer() == player && Event.isSneaking()) GPM.getCrawlManager().stopCrawl(player, GetUpReason.GET_UP); } | ||
}; | ||
} | ||
|
||
public void start() { | ||
|
||
player.setSwimming(true); | ||
|
||
Bukkit.getPluginManager().registerEvents(listener, GPM); | ||
|
||
GPM.getTManager().runDelayed(() -> { | ||
|
||
Bukkit.getPluginManager().registerEvents(moveListener, GPM); | ||
|
||
if(GPM.getCManager().C_GET_UP_SNEAK) Bukkit.getPluginManager().registerEvents(stopListener, GPM); | ||
|
||
tick(player.getLocation()); | ||
}, false, player, 1); | ||
} | ||
|
||
private void tick(Location Location) { | ||
|
||
if(!checkCrawlValid()) return; | ||
|
||
Location location = Location.clone(); | ||
|
||
Block locationBlock = location.getBlock(); | ||
|
||
int blockSize = (int) ((location.getY() - location.getBlockY()) * 100); | ||
|
||
location.setY(location.getBlockY() + (blockSize >= 40 ? 2.49 : 1.49)); | ||
|
||
Block aboveBlock = location.getBlock(); | ||
|
||
boolean aboveBlockSolid = aboveBlock.getBoundingBox().contains(location.toVector()) && !aboveBlock.getCollisionShape().getBoundingBoxes().isEmpty(); | ||
boolean canPlaceBlock = isValidArea(locationBlock.getRelative(BlockFace.UP), aboveBlock, blockLocation != null ? blockLocation.getBlock() : null); | ||
boolean canSetBarrier = canPlaceBlock && (aboveBlock.getType().isAir() || aboveBlockSolid); | ||
|
||
if(blockLocation == null || !aboveBlock.equals(blockLocation.getBlock())) { | ||
|
||
destoryBlock(); | ||
|
||
if(canSetBarrier && !aboveBlockSolid) buildBlock(location); | ||
} | ||
|
||
if(!canSetBarrier && !aboveBlockSolid) { | ||
|
||
Location playerLocation = Location.clone(); | ||
|
||
GPM.getTManager().run(() -> { | ||
|
||
int height = locationBlock.getBoundingBox().getHeight() >= 0.4 || playerLocation.getY() % 0.015625 == 0.0 ? (player.getFallDistance() > 0.7 ? 0 : blockSize) : 0; | ||
|
||
playerLocation.setY(playerLocation.getY() + (height >= 40 ? 1.5 : 0.5)); | ||
|
||
boxEntity.setRawPeekAmount(height >= 40 ? 100 - height : 0); | ||
|
||
if(boxPresent) { | ||
|
||
serverPlayer.connection.send(new ClientboundSetEntityDataPacket(boxEntity.getId(), boxEntity.getEntityData().getNonDefaultValues())); | ||
boxEntity.teleportTo(playerLocation.getX(), playerLocation.getY(), playerLocation.getZ()); | ||
serverPlayer.connection.send(new ClientboundTeleportEntityPacket(boxEntity)); | ||
} else { | ||
|
||
boxEntity.setPos(playerLocation.getX(), playerLocation.getY(), playerLocation.getZ()); | ||
serverPlayer.connection.send(new ClientboundAddEntityPacket(boxEntity.getId(), boxEntity.getUUID(), boxEntity.getX(), boxEntity.getY(), boxEntity.getZ(), boxEntity.getXRot(), boxEntity.getYRot(), boxEntity.getType(), 0, boxEntity.getDeltaMovement(), boxEntity.getYHeadRot())); | ||
boxPresent = true; | ||
serverPlayer.connection.send(new ClientboundSetEntityDataPacket(boxEntity.getId(), boxEntity.getEntityData().getNonDefaultValues())); | ||
} | ||
}, true, playerLocation); | ||
} else destoryEntity(); | ||
} | ||
|
||
public void stop() { | ||
|
||
HandlerList.unregisterAll(listener); | ||
HandlerList.unregisterAll(moveListener); | ||
HandlerList.unregisterAll(stopListener); | ||
|
||
player.setSwimming(false); | ||
|
||
if(blockLocation != null) player.sendBlockChange(blockLocation, blockLocation.getBlock().getBlockData()); | ||
|
||
serverPlayer.connection.send(new ClientboundRemoveEntitiesPacket(boxEntity.getId())); | ||
} | ||
|
||
private void buildBlock(Location Location) { | ||
|
||
blockLocation = Location; | ||
|
||
player.sendBlockChange(blockLocation, blockData); | ||
} | ||
|
||
private void destoryBlock() { | ||
|
||
if(blockLocation != null) player.sendBlockChange(blockLocation, blockLocation.getBlock().getBlockData()); | ||
|
||
blockLocation = null; | ||
} | ||
|
||
private void destoryEntity() { | ||
|
||
if(!boxPresent) return; | ||
|
||
serverPlayer.connection.send(new ClientboundRemoveEntitiesPacket(boxEntity.getId())); | ||
|
||
boxPresent = false; | ||
} | ||
|
||
private boolean checkCrawlValid() { | ||
|
||
if(serverPlayer.isInWater() || player.isFlying()) { | ||
|
||
GPM.getTManager().run(() -> { | ||
|
||
GPM.getCrawlManager().stopCrawl(player, GetUpReason.ACTION); | ||
}, true, blockLocation != null ? blockLocation : player.getLocation()); | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private boolean isValidArea(Block BlockUp, Block AboveBlock, Block LocationBlock) { return BlockUp.equals(AboveBlock) || BlockUp.equals(LocationBlock); } | ||
|
||
public Player getPlayer() { return player; } | ||
|
||
public long getNano() { return System.nanoTime() - spawnTime; } | ||
|
||
public String toString() { return boxEntity.getUUID().toString(); } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.