Git Product home page Git Product logo

guardianbeam's Introduction

GuardianBeam

Maven Central

An util to create easily Guardians and Ender Crystal Lasers via Packets and Reflection. No ProtocolLib, no dependency, compatible from Minecraft 1.9 to Minecraft 1.20!

Inspired by the plugin GuardianBeamAPI by Jaxon A Brown, which uses ProtocolLib.

There is a page on SpigotMC.

Static laser gif

How to install?

1st method: copying class

First, copy the Laser.java class to your project.

2nd method: using maven

Add this requirement to your maven pom.xml file:

<dependency>
  <groupId>io.github.skytasul</groupId>
  <artifactId>guardianbeam</artifactId>
  <version>2.3.3</version>
  <scope>compile</scope>
</dependency>

Additionnally, you can use the maven shade plugin to relocate the class location.

How to use?

  1. Create Location objects of where do you want your laser starts and ends.
  2. Create a Laser instance: new GuardianLaser(locationStart, locationEnd, duration, visibleDistance) - duration is the time (in seconds) when laser will be visible (if you set it to -1, the laser will exist infinitely), and visibleDistance is the amount of blocks where your laser will be visible. You can also use new CrystalLaser(...) to create an Ender Crystal laser.
  3. After this, call the method laser.start(plugin); (where "plugin" parameter is the instance of your JavaPlugin class).
  4. Ta-daaa! Your laser is created and shown to nearby players!
  5. You can move the laser with the methods laser.moveStart(newLocation); and laser.moveEnd(newLocation);
  6. To remove your laser before his end duration, just call laser.stop();

Demo

Here is something I quickly made to show what you can do with this API: a ray-gun.

Moving laser animation

You can see the system in action on this video, and the class is available here.

Advanced usage

Animations

The Laser#moveStart(Location location, int ticks, Runnable callback and Laser#moveEnd(Location location, int ticks, Runnable callback) methods can be used to make the laser move smoothly from one point to another.

Quick preview of the smooth movement:

Smooth laser animation

End runnable

If you want to execute some actions when the laser comes to its end, use the Laser#executeEnd(Runnable runnable) method.

In example:

new GuardianLaser(start, end, duration, distance).executeEnd(() -> Bukkit.broadcastMessage("Laser ended!")).start(plugin);

This will start a laser for 10 seconds, after that the message "Laser ended!" will be broadcasted to users.

Duration in ticks

The duration passed into the new GuardianLaser(Location start, Location end, int duration, int distance) constructor is in seconds. If you want it to be in ticks, call Laser#durationInTicks().

In example:

new GuardianLaser(start, end, durationInTicks, distance).durationInTicks().start(plugin);

This will start a laser for 10 ticks.

Make guardian laser follow entity smoothly

As the laser is made out of a guardian entity shooting a laser at an entity, it is possible to make the laser follow an existing entity of the world, without having to create a runnable which updates the laser position every tick.

To achieve this, you can either spawn the laser directly using this code:

new GuardianLaser(start, endEntity, duration, distance).start(plugin);

Or, after spawning a laser with a custom end location, use GuardianLaser#attachEndEntity(LivingEntity endEntity) to track the entity.

You can also use a combination of GuardianLaser#moveEnd(Location endLocation) and GuardianLaser#attachEndEntity(LivingEntity endEntity) as many times and in the order you want.

Quick preview:

Smooth entity follow

Troubleshooting

Sometimes, Guardian beams only renders as bubbles, the moving color part is invisible. It is not caused by this util but by a Minecraft bug.

It happens when your world gets too old (when its game time value reaches 2800000). The only way to fix it is to open the level.dat file with a NBT editor, and edit manually the Data.Time field to a lower value. Save the file, and start your server.

There is also a client bug which makes the Guardian beams completely invisible when too vertical. Adding a small offset to the top location when this issue occurs should fix it.

guardianbeam's People

Contributors

chrisgdt avatar skytasul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

guardianbeam's Issues

"team already exists" error appear on bungeecoord when using Laser

As said bungeecoord kick all players with message team already exists when using Laser.
Actuall first laser works correctly and only the second time I use it it breaks.
The solution of changing "noclip" to something else doesn't work as now the error says that team doesn't exists and gives new name given by me. Also now first time the laser works invisible mob pusheh player around.

ConcurrentModificationException

Idk know exactly how to reproduce it but when 2 players are getting shot at with 2 lasers at the same time with the laser view distance of 5 if you move back and forward and enter and exit the view distance ConcurrentModificationException happens

full stack trace:
java.util.ConcurrentModificationException: null
at java.util.HashMap$HashIterator.nextNode(HashMap.java:1493) ~[?:?]
at java.util.HashMap$KeyIterator.next(HashMap.java:1516) ~[?:?]
at ir.ciph3r.monstercrystal.utilities.Laser.moveInternal(Laser.java:230) ~[?:?]
at ir.ciph3r.monstercrystal.utilities.Laser.moveStart(Laser.java:171) ~[?:?]
at ir.ciph3r.monstercrystal.utilities.LaserRunnable.run(LaserRunnable.java:33) ~[?:?]
at org.bukkit.craftbukkit.v1_16_R3.scheduler.CraftTask.run(CraftTask.java:100) ~[patched_1.16.5.jar:git-Purpur-1171]
at org.bukkit.craftbukkit.v1_16_R3.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:58) ~[patched_1.16.5.jar:git-Purpur-1171]
at com.destroystokyo.paper.ServerSchedulerReportingWrapper.run(ServerSchedulerReportingWrapper.java:22) ~[patched_1.16.5.jar:git-Purpur-1171]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]

Add support for 1.20.4 (1.20 R3)

Hello!

It seems like a few changes have been made with the latest protocol update for 1.20.4, and I'd appreciate to have it updated.

Thanks!

Feature Request: Add support for 1.8.8

Hey, I would really appreciate if you at least try to add support for 1.8.8. I have tried to backport the API myself but I could never get it to work. I know there's probably a reason for you not having it work with 1.8.8, but I know it must be possible since there's the other people who have done it (although in a bit of a rough and glitchy way)

The reason it means so much to me is because there's only 1 API I know of that does this in 1.8.8 and that API is laggy, choppy and glitchy and the plugin I'm developing is heavily reliant on the guardian beams.

Edit: Btw I do completely realize the End Crystals Beams wouldn't work in 1.8.8, I only want the Guardian Beams :D

GuardianBeam error when using Advanced Slime World Manager

[17:13:11] [Server thread/INFO]: [GuardianBeam] [GuardianBeam] Found server version 1.20.4
[17:13:11] [Server thread/INFO]: [GuardianBeam] [GuardianBeam] Loaded mappings V1_20
[17:13:11] [Server thread/WARN]: java.lang.NoSuchMethodException: net.minecraft.world.entity.boss.enderdragon.EntityEnderCrystal.(net.minecraft.server.level.WorldServer,double,double,double)
[17:13:11] [Server thread/WARN]: at java.base/java.lang.Class.getConstructor0(Class.java:3585)
[17:13:11] [Server thread/WARN]: at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2754)
[17:13:11] [Server thread/WARN]: at MysteryBoxes-1.20.40-release.jar//com.xericker.mysteryboxes.compiled.Laser$Packets.(Laser.java:795)
[17:13:11] [Server thread/WARN]: at MysteryBoxes-1.20.40-release.jar//com.xericker.mysteryboxes.compiled.Laser.(Laser.java:54)
[17:13:11] [Server thread/WARN]: at MysteryBoxes-1.20.40-release.jar//com.xericker.mysteryboxes.compiled.Laser$GuardianLaser.(Laser.java:311)
[17:13:11] [Server thread/WARN]: at MysteryBoxes-1.20.40-release.jar//com.xericker.mysteryboxes.core.events.opening.themes.executors.UnderwaterTroubleTheme$1.run(UnderwaterTroubleTheme.java:102)
[17:13:11] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_20_R3.scheduler.CraftTask.run(CraftTask.java:101)
[17:13:11] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_20_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:480)
[17:13:11] [Server thread/WARN]: at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1650)
[17:13:11] [Server thread/WARN]: at net.minecraft.server.dedicated.DedicatedServer.b(DedicatedServer.java:446)
[17:13:11] [Server thread/WARN]: at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:1529)
[17:13:11] [Server thread/WARN]: at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1230)
[17:13:11] [Server thread/WARN]: at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:319)
[17:13:11] [Server thread/WARN]: at java.base/java.lang.Thread.run(Thread.java:840)
[17:13:11] [Server thread/ERROR]: [GuardianBeam] [GuardianBeam] Laser Beam reflection failed to initialize. The util is disabled. Please ensure your version (org.bukkit.craftbukkit.v1_20_R3) is supported.

Laser stop moving after first move

Hey.

I tried to make something like gobo, but when I firstly move laser's end it reach end location but isn't moving to another end location...

Laser endpoints extend out slightly farther than they should

2021-09-01_01 40 43
In the screenshot, you can see the end point of a laser sticking out farther than it should, since in code the location the beam is pointing at is at the exact intersection between these two beams. (One has their starting point at the intersection, one has their end point)
2021-09-01_01 42 46
In this screenshot you see the same issue, all these beams have their end points pointing at the exact same location (I have verified this!) yet they extend out slightly farther than they should.

1.20.6/1.21

Is there plans to update this api to 1.20.6 and 1.21??

Problem after the beam has timed out - solution

Based on your LaserDemo, I created a plugin idea which uses fixed locations for the start and end locations.
The problem I had was that when I used a fixed duration, the 'synchronized void cancel()' did not work!
Leaving the 'lasers.remove(p);' in this function, as not being applied.
I kept getting 'null' errors because the laser existed, but the runnable did not. (When repeating the (toggle) command).

I eventually discovered that instead of using the standard code
this.laser = new CrystalLaser(originLocation, endLocation, 5, 50);
I could use the extended code
this.laser = new CrystalLaser(originLocation, endLocation, 5, 50).executeEnd(() -> Bukkit.broadcastMessage("Laser ended!")).start(plugin);
But, NOT in this format! (NO .start(plugin)
To get around my problem I used
this.laser = (CrystalLaser) new CrystalLaser(originLocation, endLocation, 5, 50).executeEnd(() -> lasers.remove(p));

Perhaps you could adujst the plugin to accomodate something like this.
Or, add this solution to the Wiki guide?

Lasers can not be re-started after being stopped for the first time.

This bug has caused me very much headache as I need to constantly create new GuardianLaser instances every time I want a laser to turn back on from being stopped. Example code is below. In very rapid succession of stops and starts, this causes a very bad race condition for me EVEN AFTER USING A ReentrantLock AND the synchronized keyword!

`import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class TestCommand implements CommandExecutor {
Laser.GuardianLaser lsr;

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
    if(sender instanceof Player) {
        if (args[0].equals("new")) {
            try {
                lsr = new Laser.GuardianLaser(((Player) sender).getLocation(),((Player) sender).getLocation().add(0,5,0),-1,128);
            } catch (ReflectiveOperationException e) {
                e.printStackTrace();
            }
        } else if (args[0].equals("on")) {
            if(!lsr.isStarted()) lsr.start(// ADD PLUGIN HERE!);
        } else if (args[0].equals("off")) {
            if (lsr.isStarted()) lsr.stop();
        }
        return true;
    }
    return false;
}

}`
You can try this out for yourself by doing /test new, /test on, /test off, /test on. Nothing happens after the laser is turned off for the first time. This bug also affects the CrystalLasers.

Environment: 1.17.1, java 16, PaperMC server, no other related plugins that could cause issues. Latest 2.0.0 version of this resource.

The Laser Beam API is disabled. An error has occured during initialization.

The Laser Beam API is disabled. An error has occured during initialization.

I get this error. Any idea how I can solve it?

I'm using 1.16.5

[20:54:38 WARN]: java.lang.IllegalStateException: The Laser Beam API is disabled. An error has occured during initialization.
[20:54:38 WARN]: at me.arnaumas.altres.Laser.(Laser.java:61)
[20:54:38 WARN]: at me.arnaumas.altres.Laser$GuardianLaser.(Laser.java:309)
[20:54:38 WARN]: at me.arnaumas.commands.RaycastCommand.torre(RaycastCommand.java:85)
[20:54:38 WARN]: at me.arnaumas.events.EventsFacade.onMoures(EventsFacade.java:222)
[20:54:38 WARN]: at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor123.execute(Unknown Source)
[20:54:38 WARN]: at org.bukkit.plugin.EventExecutor.lambda$create$1(EventExecutor.java:69)
[20:54:38 WARN]: at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:80)
[20:54:38 WARN]: at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70)
[20:54:38 WARN]: at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:624)
[20:54:38 WARN]: at net.minecraft.server.v1_16_R3.PlayerConnection.a(PlayerConnection.java:1424)
[20:54:38 WARN]: at net.minecraft.server.v1_16_R3.PacketPlayInFlying.a(SourceFile:122)
[20:54:38 WARN]: at net.minecraft.server.v1_16_R3.PacketPlayInFlying$PacketPlayInPosition.a(SourceFile:56)
[20:54:38 WARN]: at net.minecraft.server.v1_16_R3.PlayerConnectionUtils.lambda$ensureMainThread$1(PlayerConnectionUtils.java:35)
[20:54:38 WARN]: at net.minecraft.server.v1_16_R3.TickTask.run(SourceFile:18)
[20:54:38 WARN]: at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeTask(IAsyncTaskHandler.java:136)
[20:54:38 WARN]: at net.minecraft.server.v1_16_R3.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23)
[20:54:38 WARN]: at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeNext(IAsyncTaskHandler.java:109)
[20:54:38 WARN]: at net.minecraft.server.v1_16_R3.MinecraftServer.bb(MinecraftServer.java:1266)
[20:54:38 WARN]: at net.minecraft.server.v1_16_R3.MinecraftServer.executeNext(MinecraftServer.java:1259)
[20:54:38 WARN]: at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.awaitTasks(IAsyncTaskHandler.java:119)
[20:54:38 WARN]: at net.minecraft.server.v1_16_R3.MinecraftServer.sleepForTick(MinecraftServer.java:1220)
[20:54:38 WARN]: at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:1134)
[20:54:38 WARN]: at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$a$0(MinecraftServer.java:291)
[20:54:38 WARN]: at java.lang.Thread.run(Unknown Source)

Runnable for the duration of the laser

If exists a better form but if i wanna make tasks during the beam i need make a parallel task, can be good a method like a runnable every second of the duration of laser.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.