change to use onspawn
This commit is contained in:
parent
0fd6ebce95
commit
239774167f
3 changed files with 37 additions and 30 deletions
|
|
@ -5,7 +5,7 @@ plugins {
|
||||||
def loader = 'folia'
|
def loader = 'folia'
|
||||||
def server = '1.19.4'
|
def server = '1.19.4'
|
||||||
group = 'xyz.hynse'
|
group = 'xyz.hynse'
|
||||||
version = "1.4a-${server}-${loader}"
|
version = "1.4b-${server}-${loader}"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import org.bukkit.entity.FallingBlock;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||||
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
|
@ -55,34 +56,6 @@ public class FoliaFlow extends JavaPlugin implements Listener {
|
||||||
} catch (NullPointerException block) {
|
} catch (NullPointerException block) {
|
||||||
getServer().getLogger().info("Region Scheduler erorr (likly chunky it not load)");
|
getServer().getLogger().info("Region Scheduler erorr (likly chunky it not load)");
|
||||||
}
|
}
|
||||||
AsyncScheduler scheduler = getServer().getAsyncScheduler();
|
|
||||||
task = scheduler.runAtFixedRate(this, (scheduledTask) -> Bukkit.getScheduler().runTask(this, () -> {
|
|
||||||
for (World world : Bukkit.getWorlds()) {
|
|
||||||
for (Entity entity : world.getEntities()) {
|
|
||||||
if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) {
|
|
||||||
Location centerLoc = new Location(entity.getWorld(), 100, 48.5, 0);
|
|
||||||
Location loc = entity.getLocation();
|
|
||||||
if (loc.distance(centerLoc) <= 1) {
|
|
||||||
// Set the initial velocity of the falling block only if it doesn't have a velocity stored
|
|
||||||
if (!velocitiesMap.containsKey(entity)) {
|
|
||||||
try {
|
|
||||||
int index = counter % 4;
|
|
||||||
counter++;
|
|
||||||
Vector velocity = velocities[index];
|
|
||||||
entity.setVelocity(velocity);
|
|
||||||
velocitiesMap.put(entity, velocity); // Store the velocity in the map
|
|
||||||
movingBlocks.add(entity.getLocation()); // Add the location to the set
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
// Handle the exception here, for example:
|
|
||||||
e.printStackTrace();
|
|
||||||
getServer().getLogger().info("An error occurred: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}), 0L, 1L, TimeUnit.MILLISECONDS);
|
|
||||||
getServer().getPluginManager().registerEvents(this, this);
|
getServer().getPluginManager().registerEvents(this, this);
|
||||||
getServer().getConsoleSender().sendMessage("");
|
getServer().getConsoleSender().sendMessage("");
|
||||||
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " ______________ ");
|
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " ______________ ");
|
||||||
|
|
@ -102,6 +75,36 @@ public class FoliaFlow extends JavaPlugin implements Listener {
|
||||||
super.onDisable();
|
super.onDisable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onEntitySpawn(EntitySpawnEvent e) {
|
||||||
|
if (e.getEntityType() == EntityType.FALLING_BLOCK && e.getLocation().getWorld().getEnvironment() == World.Environment.THE_END) {
|
||||||
|
for (World world : Bukkit.getWorlds()) {
|
||||||
|
for (Entity entity : world.getEntities()) {
|
||||||
|
if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) {
|
||||||
|
Location centerLoc = new Location(entity.getWorld(), 100, 48.5, 0);
|
||||||
|
Location loc = entity.getLocation();
|
||||||
|
if (loc.distance(centerLoc) <= 1) {
|
||||||
|
// Set the initial velocity of the falling block only if it doesn't have a velocity stored
|
||||||
|
if (!velocitiesMap.containsKey(entity)) {
|
||||||
|
try {
|
||||||
|
int index = counter % 4;
|
||||||
|
counter++;
|
||||||
|
Vector velocity = velocities[index];
|
||||||
|
entity.setVelocity(velocity);
|
||||||
|
velocitiesMap.put(entity, velocity); // Store the velocity in the map
|
||||||
|
movingBlocks.add(entity.getLocation()); // Add the location to the set
|
||||||
|
} catch (NullPointerException x) {
|
||||||
|
// Handle the exception here, for example:
|
||||||
|
x.printStackTrace();
|
||||||
|
getServer().getLogger().info("An error occurred: " + x.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onFallingBlockToBlock(EntityChangeBlockEvent e){
|
public void onFallingBlockToBlock(EntityChangeBlockEvent e){
|
||||||
if(e.getEntityType() == EntityType.FALLING_BLOCK){
|
if(e.getEntityType() == EntityType.FALLING_BLOCK){
|
||||||
|
|
@ -158,7 +161,6 @@ public class FoliaFlow extends JavaPlugin implements Listener {
|
||||||
case 'y' -> relative = loc.getBlock().getRelative(0, (int) Math.signum(max), 0);
|
case 'y' -> relative = loc.getBlock().getRelative(0, (int) Math.signum(max), 0);
|
||||||
case 'z' -> relative = loc.getBlock().getRelative(0, 0, (int) Math.signum(max));
|
case 'z' -> relative = loc.getBlock().getRelative(0, 0, (int) Math.signum(max));
|
||||||
}
|
}
|
||||||
//debug("Moving falling block from location " + loc.toString() + " to location " + dir);
|
|
||||||
return relative;
|
return relative;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
5
src/main/resources/plugin.yml
Normal file
5
src/main/resources/plugin.yml
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
name: FoliaFlow
|
||||||
|
version: '${version}'
|
||||||
|
main: xyz.hynse.foliaflow.FoliaFlow
|
||||||
|
api-version: 1.19
|
||||||
|
folia-supported: true
|
||||||
Loading…
Add table
Add a link
Reference in a new issue