mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Reworked and fixed isDust and isWand check
This commit is contained in:
parent
10b8ba1ec8
commit
3e5efd4090
@ -179,6 +179,7 @@ public class Iris extends VolmitPlugin
|
|||||||
J.ar(this::checkConfigHotload, 50);
|
J.ar(this::checkConfigHotload, 50);
|
||||||
PaperLib.suggestPaper(this);
|
PaperLib.suggestPaper(this);
|
||||||
getServer().getPluginManager().registerEvents(new CommandLocate(), this);
|
getServer().getPluginManager().registerEvents(new CommandLocate(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new WandManager() ,this);
|
||||||
super.onEnable();
|
super.onEnable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
|
||||||
import org.bukkit.inventory.ItemFlag;
|
import org.bukkit.inventory.ItemFlag;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
@ -20,13 +19,17 @@ import org.bukkit.util.BlockVector;
|
|||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class WandManager implements Listener
|
public class WandManager implements Listener {
|
||||||
{
|
|
||||||
|
private static ItemStack wand;
|
||||||
|
private static ItemStack dust;
|
||||||
|
|
||||||
public WandManager()
|
public WandManager()
|
||||||
{
|
{
|
||||||
|
wand = createWand();
|
||||||
|
dust = createDust();
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, () ->
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, () ->
|
||||||
{
|
{
|
||||||
for(Player i : Bukkit.getOnlinePlayers())
|
for(Player i : Bukkit.getOnlinePlayers())
|
||||||
@ -34,7 +37,6 @@ public class WandManager implements Listener
|
|||||||
tick(i);
|
tick(i);
|
||||||
}
|
}
|
||||||
}, 0, 5);
|
}, 0, 5);
|
||||||
Bukkit.getPluginManager().registerEvents(this, Iris.instance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tick(Player p)
|
public void tick(Player p)
|
||||||
@ -48,7 +50,7 @@ public class WandManager implements Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
catch(Throwable e)
|
catch(Throwable ignored)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -94,9 +96,6 @@ public class WandManager implements Listener
|
|||||||
boolean jj = j == minx || j == maxx;
|
boolean jj = j == minx || j == maxx;
|
||||||
boolean kk = k == miny || k == maxy;
|
boolean kk = k == miny || k == maxy;
|
||||||
boolean ll = l == minz || l == maxz;
|
boolean ll = l == minz || l == maxz;
|
||||||
double aa = j;
|
|
||||||
double bb = k;
|
|
||||||
double cc = l;
|
|
||||||
|
|
||||||
if((jj && kk) || (jj && ll) || (ll && kk))
|
if((jj && kk) || (jj && ll) || (ll && kk))
|
||||||
{
|
{
|
||||||
@ -132,8 +131,8 @@ public class WandManager implements Listener
|
|||||||
push.add(new Vector(0, 0, 0.55));
|
push.add(new Vector(0, 0, 0.55));
|
||||||
}
|
}
|
||||||
|
|
||||||
Location lv = new Location(d[0].getWorld(), aa, bb, cc).clone().add(0.5, 0.5, 0.5).clone().add(push);
|
Location lv = new Location(d[0].getWorld(), j, k, l).clone().add(0.5, 0.5, 0.5).clone().add(push);
|
||||||
Color color = Color.getHSBColor((float) (0.5f + (Math.sin((aa + bb + cc + (p.getTicksLived() / 2)) / 20f) / 2)), 1, 1);
|
Color color = Color.getHSBColor((float) (0.5f + (Math.sin((j + k + l + (p.getTicksLived() / 2)) / 20f) / 2)), 1, 1);
|
||||||
int r = color.getRed();
|
int r = color.getRed();
|
||||||
int g = color.getGreen();
|
int g = color.getGreen();
|
||||||
int b = color.getBlue();
|
int b = color.getBlue();
|
||||||
@ -150,7 +149,7 @@ public class WandManager implements Listener
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(Objects.equals(e.getHand(), EquipmentSlot.HAND) && isWand(e.getPlayer().getInventory().getItemInMainHand()))
|
if(isWand(e.getPlayer()))
|
||||||
{
|
{
|
||||||
if(e.getAction().equals(Action.LEFT_CLICK_BLOCK))
|
if(e.getAction().equals(Action.LEFT_CLICK_BLOCK))
|
||||||
{
|
{
|
||||||
@ -169,7 +168,7 @@ public class WandManager implements Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(e.getHand().equals(EquipmentSlot.HAND) && isDust(e.getPlayer().getInventory().getItemInMainHand()))
|
if(isDust(e.getPlayer()))
|
||||||
{
|
{
|
||||||
if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK))
|
if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK))
|
||||||
{
|
{
|
||||||
@ -204,13 +203,8 @@ public class WandManager implements Listener
|
|||||||
Location[] f = getCuboid(wand);
|
Location[] f = getCuboid(wand);
|
||||||
Cuboid c = new Cuboid(f[0], f[1]);
|
Cuboid c = new Cuboid(f[0], f[1]);
|
||||||
IrisObject s = new IrisObject(c.getSizeX(), c.getSizeY(), c.getSizeZ());
|
IrisObject s = new IrisObject(c.getSizeX(), c.getSizeY(), c.getSizeZ());
|
||||||
Iterator<Block> bb = c.iterator();
|
for (Block b : c) {
|
||||||
while(bb.hasNext())
|
if (b.getType().equals(Material.AIR)) {
|
||||||
{
|
|
||||||
Block b = bb.next();
|
|
||||||
|
|
||||||
if(b.getType().equals(Material.AIR))
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +229,7 @@ public class WandManager implements Listener
|
|||||||
{
|
{
|
||||||
String[] f = s.split("\\Q in \\E");
|
String[] f = s.split("\\Q in \\E");
|
||||||
String[] g = f[0].split("\\Q,\\E");
|
String[] g = f[0].split("\\Q,\\E");
|
||||||
return new Location(Bukkit.getWorld(f[1]), Integer.valueOf(g[0]), Integer.valueOf(g[1]), Integer.valueOf(g[2]));
|
return new Location(Bukkit.getWorld(f[1]), Integer.parseInt(g[0]), Integer.parseInt(g[1]), Integer.parseInt(g[2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
catch(Throwable e)
|
catch(Throwable e)
|
||||||
@ -273,22 +267,18 @@ public class WandManager implements Listener
|
|||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDust(ItemStack is)
|
public boolean isDust(Player p)
|
||||||
{
|
{
|
||||||
if(is == null || is.getType().equals(Material.AIR))
|
ItemStack is = p.getInventory().getItemInMainHand();
|
||||||
{
|
return is != null && isDust(is);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(is.getType().equals(Material.GLOWSTONE_DUST))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack update(boolean left, Location a, ItemStack item)
|
public boolean isDust(ItemStack is)
|
||||||
|
{
|
||||||
|
return is.equals(dust);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack update(boolean left, Location a, ItemStack item)
|
||||||
{
|
{
|
||||||
if(!isWand(item))
|
if(!isWand(item))
|
||||||
{
|
{
|
||||||
@ -320,35 +310,24 @@ public class WandManager implements Listener
|
|||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isWand(Player p)
|
|
||||||
{
|
|
||||||
ItemStack is = p.getInventory().getItemInMainHand();
|
|
||||||
return !(is == null || !isWand(is));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Location[] getCuboid(ItemStack is)
|
public static Location[] getCuboid(ItemStack is)
|
||||||
{
|
{
|
||||||
ItemMeta im = is.getItemMeta();
|
ItemMeta im = is.getItemMeta();
|
||||||
return new Location[] {stringToLocation(im.getLore().get(0)), stringToLocation(im.getLore().get(1))};
|
return new Location[] {stringToLocation(im.getLore().get(0)), stringToLocation(im.getLore().get(1))};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isWand(ItemStack item)
|
public static boolean isWand(Player p)
|
||||||
{
|
{
|
||||||
if(!item.getType().equals(createWand().getType()))
|
ItemStack is = p.getInventory().getItemInMainHand();
|
||||||
{
|
return is != null && is.equals(wand);
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(!item.getItemMeta().getEnchants().equals(createWand().getItemMeta().getEnchants()))
|
public static boolean isWand(ItemStack is)
|
||||||
{
|
{
|
||||||
return false;
|
if (is.getItemMeta() == null) return false;
|
||||||
}
|
return is.getType().equals(wand.getType()) &&
|
||||||
|
is.getItemMeta().getDisplayName().equals(wand.getItemMeta().getDisplayName()) &&
|
||||||
if(!item.getItemMeta().getDisplayName().equals(createWand().getItemMeta().getDisplayName()))
|
is.getItemMeta().getEnchants().equals(wand.getItemMeta().getEnchants()) &&
|
||||||
{
|
is.getItemMeta().getItemFlags().equals(wand.getItemMeta().getItemFlags());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user