This commit is contained in:
BongoCat 2022-07-21 10:59:51 -07:00
parent 683a57af8f
commit cb4affa931
4 changed files with 27 additions and 39 deletions

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>

View File

@ -63,8 +63,8 @@ public class BossBar {
public void delete() {
if (dragon != null) {
if (dragon.created) {
dragon.destroy();
t.cancel();
dragon.destroy();
}
}
}

View File

@ -23,9 +23,7 @@ public class FakeWitherCommand implements CommandExecutor {
// Count down
task = Bukkit.getServer().getScheduler().runTaskTimer(Main.getInstance(), new Runnable() {
@Override
public void run() {
task = Bukkit.getServer().getScheduler().runTaskTimer(Main.getInstance(), () -> {
// Count down
bar.setHealth(bar.getHealth() - 1);
@ -33,7 +31,6 @@ public class FakeWitherCommand implements CommandExecutor {
bar.delete();
task.cancel();
}
}
}, TICKS_PER_SECOND / 4, TICKS_PER_SECOND / 4);
}
return true;

View File

@ -44,10 +44,12 @@ public class SpawnFakeWither extends JavaPlugin {
public Location location;
public ProtocolManager manager;
public Player p;
public FakeWither(Player p, ProtocolManager manager) {
this.location = new Location(p.getWorld(), p.getLocation().getX(), -5, p.getLocation().getZ());
this.manager = manager;
this.p = p;
}
public int getHealth() {
@ -99,7 +101,11 @@ public class SpawnFakeWither extends JavaPlugin {
update.setEntityId(id);
update.setEntityMetadata(watcher.getWatchableObjects());
broadcastPacket(update.getHandle(), true);
try {
manager.sendServerPacket(p, update.getHandle());
} catch (InvocationTargetException e) {
Bukkit.getLogger().log(Level.WARNING, "Cannot send " + update.getHandle() + " to " + p, e);
}
}
public int getId() {
@ -125,7 +131,11 @@ public class SpawnFakeWither extends JavaPlugin {
spawnMob.setZ(location.getZ());
spawnMob.setMetadata(watcher);
broadcastPacket(spawnMob.getHandle(), true);
try {
manager.sendServerPacket(p, spawnMob.getHandle());
} catch (InvocationTargetException e) {
Bukkit.getLogger().log(Level.WARNING, "Cannot send " + spawnMob.getHandle() + " to " + p, e);
}
created = true;
}
@ -136,21 +146,12 @@ public class SpawnFakeWither extends JavaPlugin {
Packet1DDestroyEntity destroyMe = new Packet1DDestroyEntity();
destroyMe.setEntities(new int[]{id});
broadcastPacket(destroyMe.getHandle(), false);
try {
manager.sendServerPacket(p, destroyMe.getHandle());
} catch (InvocationTargetException e) {
Bukkit.getLogger().log(Level.WARNING, "Cannot send " + destroyMe.getHandle() + " to " + p, e);
}
created = false;
}
public void broadcastPacket(PacketContainer packet, boolean onlyNearby) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
// Must be within the range
if (!onlyNearby || player.getLocation().distanceSquared(location) < HEALTH_RANGE) {
try {
manager.sendServerPacket(player, packet);
} catch (InvocationTargetException e) {
Bukkit.getLogger().log(Level.WARNING, "Cannot send " + packet + " to " + player, e);
}
}
}
}
}
}