|
|
@ -1,5 +1,7 @@ |
|
|
|
package cx.sfy.TheBridge.listeners; |
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
import java.io.DataOutputStream; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
@ -9,9 +11,9 @@ import org.bukkit.ChatColor; |
|
|
|
import org.bukkit.Location; |
|
|
|
import org.bukkit.Material; |
|
|
|
import org.bukkit.Sound; |
|
|
|
import org.bukkit.World; |
|
|
|
import org.bukkit.block.Sign; |
|
|
|
import org.bukkit.entity.Arrow; |
|
|
|
import org.bukkit.entity.Entity; |
|
|
|
import org.bukkit.entity.Item; |
|
|
|
import org.bukkit.entity.Player; |
|
|
|
import org.bukkit.entity.Projectile; |
|
|
@ -43,11 +45,8 @@ import org.bukkit.inventory.InventoryView; |
|
|
|
import org.bukkit.inventory.ItemStack; |
|
|
|
import org.bukkit.potion.PotionEffect; |
|
|
|
import org.bukkit.potion.PotionEffectType; |
|
|
|
import org.bukkit.projectiles.ProjectileSource; |
|
|
|
import org.bukkit.scheduler.BukkitRunnable; |
|
|
|
|
|
|
|
import com.google.common.io.ByteArrayDataOutput; |
|
|
|
import com.google.common.io.ByteStreams; |
|
|
|
import org.bukkit.scheduler.BukkitTask; |
|
|
|
|
|
|
|
import cx.sfy.TheBridge.Main; |
|
|
|
import cx.sfy.TheBridge.cosmetics.Cage; |
|
|
@ -75,35 +74,26 @@ public class PlayerListener implements Listener { |
|
|
|
this.plugin = plugin; |
|
|
|
} |
|
|
|
|
|
|
|
public void runTask() { |
|
|
|
Bukkit.getScheduler().runTaskTimer(this.plugin, () -> { |
|
|
|
for (GameDuo gd : plugin.getGm().getGames()) { |
|
|
|
for (Location loc : gd.getBuild()) { |
|
|
|
World world = loc.getWorld(); |
|
|
|
|
|
|
|
if (world == null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
for (Projectile proj : world.getEntitiesByClass(Projectile.class)) { |
|
|
|
ProjectileSource p = proj.getShooter(); |
|
|
|
|
|
|
|
if (!(p instanceof Player)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
private BukkitTask task; |
|
|
|
|
|
|
|
createTrail(proj.getLocation(), |
|
|
|
plugin.getArm().getArrowByName(PlayerStat.getPlayerStat((Player) p).getArrow())); |
|
|
|
} |
|
|
|
} |
|
|
|
public void runTask(Player p, Entity e) { |
|
|
|
task = Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(this.plugin, () -> { |
|
|
|
Location loc = e.getLocation(); |
|
|
|
if (e.isOnGround()) { |
|
|
|
task.cancel(); |
|
|
|
} |
|
|
|
}, 5, 5); |
|
|
|
createTrail(loc, plugin.getArm().getArrowByName(PlayerStat.getPlayerStat(p).getArrow())); |
|
|
|
}, 0, 1); |
|
|
|
} |
|
|
|
|
|
|
|
@EventHandler |
|
|
|
public void onShoot(ProjectileLaunchEvent e) { |
|
|
|
if (e.getEntity() instanceof Arrow) { |
|
|
|
runTask(); |
|
|
|
if (e.getEntity().getShooter() instanceof Player) { |
|
|
|
if (e.getEntity() instanceof Arrow) { |
|
|
|
Player p = (Player) e.getEntity().getShooter(); |
|
|
|
if (plugin.getGm().getGameByPlayer(p) != null || plugin.getGm().getGameFourByPlayer(p) != null) |
|
|
|
runTask(p, e.getEntity()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -424,13 +414,18 @@ public class PlayerListener implements Listener { |
|
|
|
plugin.getConfig().getString("items.lobby.nameItem").replaceAll("&", "§"), |
|
|
|
plugin.getConfig().getString("items.lobby.loreItem").replaceAll("&", "§")); |
|
|
|
if (item.equals(random)) { |
|
|
|
ByteArrayDataOutput out = ByteStreams.newDataOutput(); |
|
|
|
out.writeUTF("Connect"); |
|
|
|
out.writeUTF(plugin.getConfig().getString("items.lobby.server")); |
|
|
|
String broadcastMessage = "Yolo"; |
|
|
|
ByteArrayOutputStream bo = new ByteArrayOutputStream(); |
|
|
|
DataOutputStream out = new DataOutputStream(bo); |
|
|
|
byte[] data = broadcastMessage.getBytes(); |
|
|
|
try { |
|
|
|
p.sendPluginMessage(Main.get(), "BungeeCord", out.toByteArray()); |
|
|
|
out.writeUTF("Forward"); |
|
|
|
out.writeUTF(plugin.getConfig().getString("items.lobby.server")); |
|
|
|
out.writeShort(data.length); |
|
|
|
out.write(data); |
|
|
|
p.sendPluginMessage(Main.get(), "BungeeCord", bo.toByteArray()); |
|
|
|
} catch (Exception ex) { |
|
|
|
e.setCancelled(true); |
|
|
|
ex.printStackTrace(); |
|
|
|
plugin.getServer().getConsoleSender() |
|
|
|
.sendMessage(ChatColor.RED + "Server " + ChatColor.YELLOW |
|
|
|
+ plugin.getConfig().getString("items.lobby.server") + ChatColor.RED |
|
|
|