added laser pointer
This commit is contained in:
@@ -64,9 +64,11 @@ public class GiveCustomCommand implements TabExecutor {
|
||||
p.getInventory().addItem(ItemPresets.PICKLER);
|
||||
p.sendMessage(Text.ofAll("&bGiven you a Pickler"));
|
||||
}
|
||||
case "Tazer" -> {
|
||||
case "IMPROPER" -> {
|
||||
p.getInventory().clear();
|
||||
p.updateInventory();
|
||||
p.getInventory().addItem(ItemPresets.TAZER);
|
||||
p.sendMessage(Text.ofAll("&bGiven you a Tazer"));
|
||||
p.getInventory().addItem(ItemPresets.LAZER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,10 @@ public abstract class Config {
|
||||
return sections;
|
||||
}
|
||||
|
||||
public static <T> T getOrDef(T val, T def) {
|
||||
return val != null ? val : def;
|
||||
}
|
||||
|
||||
public static class Plugin {
|
||||
private static final String path = "plugin.";
|
||||
public static String prefix() {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package fun.ogre.ogredupealias.events;
|
||||
|
||||
import fun.ogre.ogredupealias.data.Config;
|
||||
import fun.ogre.ogredupealias.utils.ItemUtils;
|
||||
import fun.ogre.ogredupealias.plugin.ItemPresets;
|
||||
import fun.ogre.ogredupealias.utils.ItemUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@@ -163,4 +163,11 @@ public abstract class ItemPresets {
|
||||
.customModelData(1111)
|
||||
.build();
|
||||
|
||||
public static ItemStack LAZER = ItemBuilder.create()
|
||||
.material(Material.REDSTONE_TORCH)
|
||||
.name("Lazer Pointer")
|
||||
.lore(Text.color("&7- A funny gadget!"))
|
||||
.customModelData(1111)
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@ import org.bukkit.inventory.ItemStack;
|
||||
public abstract class CustomItem {
|
||||
|
||||
private final ItemStack item;
|
||||
private final String name;
|
||||
|
||||
public CustomItem(ItemStack item) {
|
||||
public CustomItem(String name, ItemStack item) {
|
||||
this.item = item;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public abstract CustomItemInteractionCallback getCallback();
|
||||
@@ -24,4 +26,8 @@ public abstract class CustomItem {
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package fun.ogre.ogredupealias.plugin.custom.items;
|
||||
|
||||
import fun.ogre.ogredupealias.plugin.custom.items.customitems.LazerItem;
|
||||
import fun.ogre.ogredupealias.plugin.custom.items.customitems.TazerItem;
|
||||
import fun.ogre.ogredupealias.utils.ItemUtils;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -13,9 +14,11 @@ import java.util.Map;
|
||||
public final class CustomItems implements Listener {
|
||||
|
||||
private static final Map<String, CustomItemInteractionCallback> callbackList = new HashMap<>();
|
||||
private static final Map<Class<? extends CustomItem>, String> namesList = new HashMap<>();
|
||||
|
||||
public static void init() {
|
||||
register(new TazerItem());
|
||||
register(new LazerItem());
|
||||
}
|
||||
|
||||
public static ItemStack register(ItemStack item, CustomItemInteractionCallback interactionCallback) {
|
||||
@@ -25,7 +28,8 @@ public final class CustomItems implements Listener {
|
||||
|
||||
public static ItemStack register(CustomItem item) {
|
||||
item.registerThis();
|
||||
return register(item.getItem(), item.getCallback());
|
||||
namesList.put(item.getClass(), item.getName());
|
||||
return item.getItem();
|
||||
}
|
||||
|
||||
public static void onInteract(ItemStack item, PlayerInteractEvent event) {
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package fun.ogre.ogredupealias.plugin.custom.items.customitems;
|
||||
|
||||
import fun.ogre.ogredupealias.plugin.ItemPresets;
|
||||
import fun.ogre.ogredupealias.plugin.custom.items.CustomItem;
|
||||
import fun.ogre.ogredupealias.plugin.custom.items.CustomItemInteractionCallback;
|
||||
import fun.ogre.ogredupealias.utils.RaycastUtils;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class LazerItem extends CustomItem {
|
||||
|
||||
public LazerItem() {
|
||||
super("lazer", ItemPresets.LAZER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomItemInteractionCallback getCallback() {
|
||||
return (player, item, event) -> {
|
||||
event.setCancelled(true);
|
||||
|
||||
Location loc = player.getLocation().add(0, 1.4, 0);
|
||||
Vector dir = player.getLocation().getDirection().normalize();
|
||||
AtomicInteger attempts = new AtomicInteger(0);
|
||||
|
||||
castInDirection(loc, dir, true, 10, attempts);
|
||||
};
|
||||
}
|
||||
|
||||
private void castInDirection(Location loc, Vector dir, boolean again, int maxAttempts, AtomicInteger attempts) {
|
||||
AtomicBoolean hitSmth = new AtomicBoolean(false);
|
||||
Location hit = RaycastUtils.raycast(loc, dir, 64, 0.1, point -> {
|
||||
Particle.DustOptions dust = new Particle.DustOptions(Color.fromRGB(255, 0, 0), 0.5F);
|
||||
point.getWorld().spawnParticle(Particle.REDSTONE, point, 1, 0, 0, 0, 0, dust);
|
||||
hitSmth.set(!point.getBlock().isPassable() && loc.distance(point) > 1.0);
|
||||
return hitSmth.get();
|
||||
});
|
||||
Vector incoming = dir.clone().multiply(-1).normalize();
|
||||
Vector bounce = getContactingFace(hit, hit.getBlock());
|
||||
Vector reflect = bounce.multiply(-1).subtract(incoming).normalize();
|
||||
|
||||
if (again && maxAttempts > attempts.getAndIncrement()) {
|
||||
castInDirection(hit, reflect, hitSmth.get(), maxAttempts, attempts);
|
||||
}
|
||||
}
|
||||
|
||||
private Vector getContactingFace(Location pointOfContact, Block block) {
|
||||
Vector center = block.getLocation().add(0.5, 0.5, 0.5).toVector();
|
||||
Vector incoming = center.subtract(pointOfContact.toVector());
|
||||
double x = incoming.dot(new Vector(1, 0, 0));
|
||||
double y = incoming.dot(new Vector(0, 1, 0));
|
||||
double z = incoming.dot(new Vector(0, 0, 1));
|
||||
double ax = Math.abs(x);
|
||||
double ay = Math.abs(y);
|
||||
double az = Math.abs(z);
|
||||
|
||||
if (ax > ay && ax > az)
|
||||
return new Vector(x, 0, 0).normalize();
|
||||
else if (ay > ax && ay > az)
|
||||
return new Vector(0, y, 0).normalize();
|
||||
else
|
||||
return new Vector(0, 0, z).normalize();
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import java.util.function.Predicate;
|
||||
public class TazerItem extends CustomItem {
|
||||
|
||||
public TazerItem() {
|
||||
super(ItemPresets.TAZER);
|
||||
super("tazer", ItemPresets.TAZER);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user