Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit 1f59a80

Browse files
authored
Merge pull request #3 from Hynse/folia
so far now working 80%
2 parents edb6618 + c5740cc commit 1f59a80

File tree

2 files changed

+71
-37
lines changed

2 files changed

+71
-37
lines changed

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
rootProject.name = 'bbsdfia'
1+
rootProject.name = 'FoliaFlow'
Lines changed: 70 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,66 @@
11
package xyz.hynse.foliaflow;
22

3-
import org.bukkit.Bukkit;
4-
import org.bukkit.Location;
5-
import org.bukkit.Material;
6-
import org.bukkit.World;
3+
import org.bukkit.*;
74
import org.bukkit.block.Block;
85
import org.bukkit.entity.Entity;
96
import org.bukkit.entity.EntityType;
107
import org.bukkit.entity.FallingBlock;
118
import org.bukkit.event.EventHandler;
129
import org.bukkit.event.Listener;
1310
import org.bukkit.event.entity.EntityChangeBlockEvent;
11+
import org.bukkit.event.world.ChunkLoadEvent;
1412
import org.bukkit.plugin.java.JavaPlugin;
1513
import org.bukkit.util.Vector;
1614

15+
import java.util.HashSet;
16+
import java.util.Set;
17+
1718
public class FoliaFlow extends JavaPlugin implements Listener {
1819
private final Vector velocity1 = new Vector(0, 0.5, -1);
1920
private final Vector velocity2 = new Vector(-1, 0.5, 0);
2021
private final Vector velocity3 = new Vector(0, 0.5, 1);
2122
private final Vector velocity4 = new Vector(1, 0.5, 0);
22-
private final Vector[] velocities = { velocity1, velocity2, velocity3, velocity4 };
23+
private final Vector[] velocities = {velocity1, velocity2, velocity3, velocity4};
2324
private int counter = 0;
25+
//private final Set<Location> movingBlocks = new HashSet<>();
2426

2527

2628
@Override
2729
public void onEnable() {
2830
super.onEnable();
2931
getServer().getPluginManager().registerEvents(this, this);
30-
getServer().getLogger().info("Bbsdfia plugin started");
32+
getServer().getConsoleSender().sendMessage("");
33+
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " ______________ ");
34+
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " / ____/ ____/ /___ _ __");
35+
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " / /_ / /_ / / __ \\ | /| / /");
36+
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " / __/ / __/ / / /_/ / |/ |/ / ");
37+
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "/_/ /_/ /_/\\____/|__/|__/ ");
38+
getServer().getConsoleSender().sendMessage("");
39+
getServer().getConsoleSender().sendMessage(ChatColor.YELLOW + "Plugin started successfully!");
40+
getServer().getConsoleSender().sendMessage("");
3141
}
3242

3343
@Override
3444
public void onDisable() {
3545
super.onDisable();
36-
getServer().getLogger().info("Bbsdfia plugin stopped");
46+
debug("Plugin stopped successfully!");
47+
}
48+
49+
/*
50+
@EventHandler
51+
public void onChunkLoad(ChunkLoadEvent event) {
52+
Block obsidianBlock = obsidianLocation.getBlock();
53+
if (event.getWorld() == endWorld && obsidianBlock.getType() == Material.OBSIDIAN) { // check if the chunk is in the end and the block is obsidian
54+
obsidianBlock.setType(Material.AIR); // set the block to air
55+
}
3756
}
3857
58+
@EventHandler
59+
public void onBlockChange(org.bukkit.event.block.BlockFromToEvent event) {
60+
if (event.getBlock().getLocation().equals(obsidianLocation)) { // check if the block change event is for the obsidian block location
61+
event.setCancelled(true); // cancel the event to prevent the obsidian block from changing
62+
}
63+
}*/
3964

4065
@EventHandler
4166
public void onFallingBlockToBlock(EntityChangeBlockEvent e){
@@ -48,64 +73,68 @@ public void onFallingBlockToBlock(EntityChangeBlockEvent e){
4873
if(movingTo != null && movingTo.getType() == Material.END_PORTAL){
4974
Location spawnLoc = movingTo.getLocation();
5075
spawnLoc.setX(spawnLoc.getX()+0.5);
51-
spawnLoc.setY(spawnLoc.getY()+0.5);
76+
spawnLoc.setY(spawnLoc.getY()-0.25);
5277
spawnLoc.setZ(spawnLoc.getZ()+0.5);
5378

5479
FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData());
80+
dummy.setDropItem(false);
81+
dummy.setHurtEntities(false);
82+
dummy.setGravity(true);
5583
Vector dummyVel = vel.clone();
5684
dummyVel.setY(-dummyVel.getY());
57-
dummyVel.multiply(new Vector(2, 2, 2));
85+
dummyVel.multiply(new Vector(2, 1, 2));
5886

59-
dummyVel.add(new Vector(0, -0.2, 0));
87+
dummyVel.add(new Vector(0, 1, 0));
6088

6189
dummy.setVelocity(dummyVel);
6290
}
6391
}
6492
}
6593

6694

67-
68-
6995
@EventHandler
70-
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
71-
Entity entity = event.getEntity();
72-
if (!(entity instanceof FallingBlock)) {
73-
return;
74-
}
75-
if (entity.getWorld().getEnvironment() != World.Environment.THE_END) {
76-
return;
96+
public void onChunkLoadend(ChunkLoadEvent e) {
97+
Chunk chunk = e.getChunk();
98+
World world = chunk.getWorld();
99+
if (world.getEnvironment() == World.Environment.THE_END) {
100+
// Iterate through all the entities in the chunk
101+
for (Entity entity : chunk.getEntities()) {
102+
if (entity.getType() == EntityType.FALLING_BLOCK) {
103+
Location loc = entity.getLocation();
104+
105+
debug("Falling block spawned at location " + loc);
106+
107+
// Set the initial velocity of the falling block
108+
int index = counter % 4;
109+
counter ++;
110+
Vector velocity = velocities[index];
111+
entity.setVelocity(velocity);
112+
113+
// Remove the block from the movingBlocks set after a delay, to prevent it from being immediately moved again
114+
//getServer().getScheduler().runTaskLater(this, () -> movingBlocks.remove(loc.getBlock().getLocation()), 20L);
115+
}
116+
}
77117
}
78-
entity.remove();
79-
Location fuck = new Location(Bukkit.getWorld("world_the_end"), 100, 49 ,0);
80-
fuck.getBlock().setType(Material.AIR);
81-
World world = entity.getWorld();
82-
Location location = entity.getLocation();
83-
byte data = ((FallingBlock) entity).getBlockData().getAsString().getBytes()[0];
84-
Material material = ((FallingBlock) entity).getBlockData().getMaterial();
85-
86-
int index = counter % 4;
87-
Vector velocity = velocities[index];
88-
counter++;
89-
FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data);
90-
newFallingBlock.setVelocity(velocity);
91118
}
92119

93120

94-
Block getBlockMovingTo(Location loc, Vector vel){
121+
122+
123+
Block getBlockMovingTo(Location loc, Vector vel) {
95124
double absMax = 0, max = 0;
96125
char dir = ' ';
97126
Block relative = null;
98-
if(Math.abs(vel.getX()) > absMax){
127+
if (Math.abs(vel.getX()) > absMax) {
99128
max = vel.getX();
100129
absMax = Math.abs(vel.getX());
101130
dir = 'x';
102131
}
103-
if(Math.abs(vel.getY()) > absMax){
132+
if (Math.abs(vel.getY()) > absMax) {
104133
max = vel.getY();
105134
absMax = Math.abs(vel.getY());
106135
dir = 'y';
107136
}
108-
if(Math.abs(vel.getZ()) > absMax){
137+
if (Math.abs(vel.getZ()) > absMax) {
109138
max = vel.getZ();
110139
dir = 'z';
111140
}
@@ -114,6 +143,11 @@ Block getBlockMovingTo(Location loc, Vector vel){
114143
case 'y' -> relative = loc.getBlock().getRelative(0, (int) Math.signum(max), 0);
115144
case 'z' -> relative = loc.getBlock().getRelative(0, 0, (int) Math.signum(max));
116145
}
146+
debug("Moving falling block from location " + loc.toString() + " to location " + dir);
117147
return relative;
118148
}
149+
150+
private void debug(String message) {
151+
getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "[FoliaFlow] " + message);
152+
}
119153
}

0 commit comments

Comments
 (0)