Merge pull request #357 from Mohamad82Bz/master

Running EnginePlayer Async  | Fixed DustRevealer was working with normal glowstones
This commit is contained in:
Dan
2021-05-25 12:54:40 -04:00
committed by GitHub
4 changed files with 75 additions and 62 deletions

View File

@@ -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();
} }

View File

@@ -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,25 @@ 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 && isWand(is);
return false; }
}
if(!item.getItemMeta().getEnchants().equals(createWand().getItemMeta().getEnchants())) public static boolean isWand(ItemStack is)
{ {
return false; ItemStack wand = createWand();
} if (is.getItemMeta() == null) return false;
return is.getType().equals(wand.getType()) &&
if(!item.getItemMeta().getDisplayName().equals(createWand().getItemMeta().getDisplayName())) is.getItemMeta().getDisplayName().equals(wand.getItemMeta().getDisplayName()) &&
{ is.getItemMeta().getEnchants().equals(wand.getItemMeta().getEnchants()) &&
return false; is.getItemMeta().getItemFlags().equals(wand.getItemMeta().getItemFlags());
}
return true;
} }
} }

View File

@@ -8,6 +8,7 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Particle; import org.bukkit.Particle;
import org.bukkit.Sound; import org.bukkit.Sound;
@@ -228,7 +229,16 @@ public class IrisEffect
if(sound != null) if(sound != null)
{ {
Location part = p.getLocation().clone().add(RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance)); Location part = p.getLocation().clone().add(RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance));
p.playSound(part, getSound(), (float) volume, (float) RNG.r.d(minPitch, maxPitch));
J.s(() -> {
p.playSound(part, getSound(), (float) volume, (float) RNG.r.d(minPitch, maxPitch));
Iris.instance.getLogger().info("§bPlayer Location: " +
p.getLocation().getBlockX() + " " + p.getLocation().getBlockY() + " " + p.getLocation().getBlockZ() +
" Sound Location: " + part.getBlockX() + " " + part.getBlockY() + " " + part.getBlockZ() +
" Sound's Name: " + getSound().name());
});
} else {
Bukkit.getConsoleSender().sendMessage("Sound is null :(");
} }
if(particleEffect != null) if(particleEffect != null)
@@ -239,12 +249,26 @@ public class IrisEffect
part.add(RNG.r.d(), 0, RNG.r.d()); part.add(RNG.r.d(), 0, RNG.r.d());
if(extra != 0) if(extra != 0)
{ {
p.spawnParticle(particleEffect, part.getX(), part.getY() + RNG.r.i(particleOffset), part.getZ(), particleCount, randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX, randomAltY ? RNG.r.d(-particleAltY, particleAltY) : particleAltY, randomAltZ ? RNG.r.d(-particleAltZ, particleAltZ) : particleAltZ, extra); J.s(() -> {
p.spawnParticle(particleEffect, part.getX(), part.getY() + RNG.r.i(particleOffset),
part.getZ(),
particleCount,
randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX,
randomAltY ? RNG.r.d(-particleAltY, particleAltY) : particleAltY,
randomAltZ ? RNG.r.d(-particleAltZ, particleAltZ) : particleAltZ,
extra);
});
} }
else else
{ {
p.spawnParticle(particleEffect, part.getX(), part.getY() + RNG.r.i(particleOffset), part.getZ(), particleCount, randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX, randomAltY ? RNG.r.d(-particleAltY, particleAltY) : particleAltY, randomAltZ ? RNG.r.d(-particleAltZ, particleAltZ) : particleAltZ); J.s(() -> {
p.spawnParticle(particleEffect, part.getX(), part.getY() + RNG.r.i(particleOffset), part.getZ(),
particleCount,
randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX,
randomAltY ? RNG.r.d(-particleAltY, particleAltY) : particleAltY,
randomAltZ ? RNG.r.d(-particleAltZ, particleAltZ) : particleAltZ);
});
} }
} }
@@ -258,10 +282,18 @@ public class IrisEffect
return; return;
} }
p.removePotionEffect(getRealType()); J.s(() -> {
p.removePotionEffect(getRealType());
});
} }
p.addPotionEffect(new PotionEffect(getRealType(), RNG.r.i(Math.min(potionTicksMax, potionTicksMin), Math.max(potionTicksMax, potionTicksMin)), getPotionStrength(), true, false, false)); J.s(() -> {
p.addPotionEffect(new PotionEffect(getRealType(),
RNG.r.i(Math.min(potionTicksMax, potionTicksMin),
Math.max(potionTicksMax, potionTicksMin)),
getPotionStrength(),
true, false, false));
});
} }
} }
} }

View File

@@ -31,7 +31,7 @@ public class EnginePlayer {
{ {
sample(); sample();
J.s(() -> { J.a(() -> {
if(region != null) if(region != null)
{ {
for(IrisEffect j : region.getEffects()) for(IrisEffect j : region.getEffects())