diff --git a/api/src/main/java/com/lunarclient/apollo/module/tntcountdown/TntCountdownModule.java b/api/src/main/java/com/lunarclient/apollo/module/tntcountdown/TntCountdownModule.java
index f3a1ee79..77aa5d45 100644
--- a/api/src/main/java/com/lunarclient/apollo/module/tntcountdown/TntCountdownModule.java
+++ b/api/src/main/java/com/lunarclient/apollo/module/tntcountdown/TntCountdownModule.java
@@ -28,6 +28,7 @@
import com.lunarclient.apollo.module.ModuleDefinition;
import com.lunarclient.apollo.option.NumberOption;
import com.lunarclient.apollo.option.SimpleOption;
+import com.lunarclient.apollo.recipients.Recipients;
import io.leangen.geantyref.TypeToken;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Range;
@@ -85,4 +86,16 @@ public boolean isClientNotify() {
*/
public abstract void setTntCountdown(ApolloEntity entity, @Range(from = 0, to = Integer.MAX_VALUE) int ticks);
+ /**
+ * Set the amount of ticks before the specified TNT explodes.
+ *
+ *
The given ticks must be equal to or greater than 0.
+ *
+ * @param recipients the recipients that are receiving the packet
+ * @param entity the TNT entity
+ * @param ticks the ticks until explosion
+ * @since 1.1.8
+ */
+ public abstract void setTntCountdown(Recipients recipients, ApolloEntity entity, @Range(from = 0, to = Integer.MAX_VALUE) int ticks);
+
}
diff --git a/bukkit-example-api/src/main/java/com/lunarclient/apollo/example/api/module/TntCountdownApiExample.java b/bukkit-example-api/src/main/java/com/lunarclient/apollo/example/api/module/TntCountdownApiExample.java
index 1ee03cb6..c72a1796 100644
--- a/bukkit-example-api/src/main/java/com/lunarclient/apollo/example/api/module/TntCountdownApiExample.java
+++ b/bukkit-example-api/src/main/java/com/lunarclient/apollo/example/api/module/TntCountdownApiExample.java
@@ -25,20 +25,26 @@
import com.lunarclient.apollo.Apollo;
import com.lunarclient.apollo.common.ApolloEntity;
+import com.lunarclient.apollo.example.ApolloExamplePlugin;
import com.lunarclient.apollo.example.module.impl.TntCountdownExample;
import com.lunarclient.apollo.module.tntcountdown.TntCountdownModule;
-import com.lunarclient.apollo.player.ApolloPlayer;
-import java.util.Optional;
-import org.bukkit.Location;
-import org.bukkit.World;
+import com.lunarclient.apollo.recipients.Recipients;
+import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
+import org.bukkit.event.entity.EntitySpawnEvent;
public class TntCountdownApiExample extends TntCountdownExample implements Listener {
private final TntCountdownModule tntCountdownModule = Apollo.getModuleManager().getModule(TntCountdownModule.class);
+ public TntCountdownApiExample() {
+ Bukkit.getPluginManager().registerEvents(this, ApolloExamplePlugin.getInstance());
+ }
+
@Override
public void setTntCountdownExample() {
this.tntCountdownModule.getOptions().set(TntCountdownModule.TNT_TICKS, 160);
@@ -46,21 +52,42 @@ public void setTntCountdownExample() {
@Override
public void overrideTntCountdownExample(Player viewer) {
- Location location = viewer.getLocation();
- World world = viewer.getWorld();
- TNTPrimed entity = world.spawn(location, TNTPrimed.class);
+ int customTicks = 200;
- Optional apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
+ TNTPrimed entity = viewer.getWorld().spawn(viewer.getLocation(), TNTPrimed.class);
+ entity.setFuseTicks(customTicks);
- apolloPlayerOpt.ifPresent(apolloPlayer -> {
- ApolloEntity apolloEntity = new ApolloEntity(entity.getEntityId(), entity.getUniqueId());
- this.tntCountdownModule.setTntCountdown(apolloEntity, 200);
- });
+ ApolloEntity apolloEntity = new ApolloEntity(entity.getEntityId(), entity.getUniqueId());
+ this.tntCountdownModule.setTntCountdown(Recipients.ofEveryone(), apolloEntity, customTicks);
}
@Override
public void clearTntCountdownOptionExample() {
- this.tntCountdownModule.getOptions().remove(TntCountdownModule.TNT_TICKS, 80);
+ this.tntCountdownModule.getOptions().remove(TntCountdownModule.TNT_TICKS, 160);
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ private void onTntSpawn(EntitySpawnEvent event) {
+ String entityName = event.getEntityType().name();
+ if (!entityName.equals("PRIMED_TNT") && !entityName.equals("TNT")) {
+ return;
+ }
+
+ TNTPrimed primed = (TNTPrimed) event.getEntity();
+ int customTicks = this.tntCountdownModule.getOptions().get(TntCountdownModule.TNT_TICKS);
+ int defaultTicks = TntCountdownModule.TNT_TICKS.getDefaultValue();
+ int currentTicks = primed.getFuseTicks();
+
+ if (currentTicks != defaultTicks && !this.tntCountdownModule.getOptions().get(TntCountdownModule.OVERRIDE_CUSTOM_TICKS)) {
+ customTicks = currentTicks;
+
+ this.tntCountdownModule.setTntCountdown(Recipients.ofEveryone(),
+ new ApolloEntity(primed.getEntityId(), primed.getUniqueId()),
+ customTicks
+ );
+ }
+
+ primed.setFuseTicks(customTicks);
}
}
diff --git a/bukkit-example-json/src/main/java/com/lunarclient/apollo/example/json/module/TntCountdownJsonExample.java b/bukkit-example-json/src/main/java/com/lunarclient/apollo/example/json/module/TntCountdownJsonExample.java
index 4af63875..90483853 100644
--- a/bukkit-example-json/src/main/java/com/lunarclient/apollo/example/json/module/TntCountdownJsonExample.java
+++ b/bukkit-example-json/src/main/java/com/lunarclient/apollo/example/json/module/TntCountdownJsonExample.java
@@ -28,13 +28,9 @@
import com.lunarclient.apollo.example.json.util.JsonPacketUtil;
import com.lunarclient.apollo.example.json.util.JsonUtil;
import com.lunarclient.apollo.example.module.impl.TntCountdownExample;
-import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
-import java.util.UUID;
import org.bukkit.Bukkit;
-import org.bukkit.Location;
-import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
@@ -45,16 +41,6 @@
public class TntCountdownJsonExample extends TntCountdownExample implements Listener {
- private static Method entityGetter;
-
- static {
- try {
- TntCountdownJsonExample.entityGetter = Bukkit.class.getDeclaredMethod("getEntity", UUID.class);
- } catch (Throwable throwable) {
- // Ignore for legacy versions.
- }
- }
-
public TntCountdownJsonExample() {
Bukkit.getPluginManager().registerEvents(this, ApolloExamplePlugin.getInstance());
}
@@ -70,31 +56,10 @@ public void setTntCountdownExample() {
@Override
public void overrideTntCountdownExample(Player viewer) {
- Location location = viewer.getLocation();
- TNTPrimed entity = viewer.getWorld().spawn(location, TNTPrimed.class);
int customTicks = 200;
- TNTPrimed target = null;
- if (TntCountdownJsonExample.entityGetter != null) {
- try {
- target = (TNTPrimed) TntCountdownJsonExample.entityGetter.invoke(null, entity.getUniqueId());
- } catch (Throwable throwable) {
- throwable.printStackTrace();
- }
- } else {
- for (World world : Bukkit.getWorlds()) {
- for (TNTPrimed compare : world.getEntitiesByClass(TNTPrimed.class)) {
- if (compare.getUniqueId().equals(entity.getUniqueId())) {
- target = compare;
- break;
- }
- }
- }
- }
-
- if (target != null) {
- target.setFuseTicks(customTicks);
- }
+ TNTPrimed entity = viewer.getWorld().spawn(viewer.getLocation(), TNTPrimed.class);
+ entity.setFuseTicks(customTicks);
JsonPacketUtil.sendPacket(viewer, this.createTNTCountdownMessage(entity, customTicks));
}
diff --git a/bukkit-example-proto/src/main/java/com/lunarclient/apollo/example/proto/module/TntCountdownProtoExample.java b/bukkit-example-proto/src/main/java/com/lunarclient/apollo/example/proto/module/TntCountdownProtoExample.java
index b85fb2a9..d68b2c5f 100644
--- a/bukkit-example-proto/src/main/java/com/lunarclient/apollo/example/proto/module/TntCountdownProtoExample.java
+++ b/bukkit-example-proto/src/main/java/com/lunarclient/apollo/example/proto/module/TntCountdownProtoExample.java
@@ -30,13 +30,9 @@
import com.lunarclient.apollo.example.proto.util.ProtobufPacketUtil;
import com.lunarclient.apollo.example.proto.util.ProtobufUtil;
import com.lunarclient.apollo.tntcountdown.v1.SetTntCountdownMessage;
-import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
-import java.util.UUID;
import org.bukkit.Bukkit;
-import org.bukkit.Location;
-import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
@@ -46,16 +42,6 @@
public class TntCountdownProtoExample extends TntCountdownExample implements Listener {
- private static Method entityGetter;
-
- static {
- try {
- TntCountdownProtoExample.entityGetter = Bukkit.class.getDeclaredMethod("getEntity", UUID.class);
- } catch (Throwable throwable) {
- // Ignore for legacy versions.
- }
- }
-
public TntCountdownProtoExample() {
Bukkit.getPluginManager().registerEvents(this, ApolloExamplePlugin.getInstance());
}
@@ -71,44 +57,23 @@ public void setTntCountdownExample() {
@Override
public void overrideTntCountdownExample(Player viewer) {
- Location location = viewer.getLocation();
- TNTPrimed entity = viewer.getWorld().spawn(location, TNTPrimed.class);
int customTicks = 200;
- TNTPrimed target = null;
- if (TntCountdownProtoExample.entityGetter != null) {
- try {
- target = (TNTPrimed) TntCountdownProtoExample.entityGetter.invoke(null, entity.getUniqueId());
- } catch (Throwable throwable) {
- throwable.printStackTrace();
- }
- } else {
- for (World world : Bukkit.getWorlds()) {
- for (TNTPrimed compare : world.getEntitiesByClass(TNTPrimed.class)) {
- if (compare.getUniqueId().equals(entity.getUniqueId())) {
- target = compare;
- break;
- }
- }
- }
- }
-
- if (target != null) {
- target.setFuseTicks(customTicks);
- }
+ TNTPrimed entity = viewer.getWorld().spawn(viewer.getLocation(), TNTPrimed.class);
+ entity.setFuseTicks(customTicks);
SetTntCountdownMessage message = SetTntCountdownMessage.newBuilder()
.setEntityId(ProtobufUtil.createEntityIdProto(entity.getEntityId(), entity.getUniqueId()))
.setDurationTicks(customTicks)
.build();
- ProtobufPacketUtil.sendPacket(viewer, message);
+ ProtobufPacketUtil.broadcastPacket(message);
}
@Override
public void clearTntCountdownOptionExample() {
Map properties = new HashMap<>();
- properties.put("tnt-ticks", Value.newBuilder().setNumberValue(80).build());
+ properties.put("tnt-ticks", Value.newBuilder().setNumberValue(160).build());
ConfigurableSettings settings = ProtobufPacketUtil.createModuleMessage("tnt_countdown", properties);
ProtobufPacketUtil.broadcastPacket(settings);
diff --git a/bukkit/src/main/java/com/lunarclient/apollo/module/tntcountdown/TntCountdownModuleImpl.java b/bukkit/src/main/java/com/lunarclient/apollo/module/tntcountdown/TntCountdownModuleImpl.java
deleted file mode 100644
index 20c728b9..00000000
--- a/bukkit/src/main/java/com/lunarclient/apollo/module/tntcountdown/TntCountdownModuleImpl.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * This file is part of Apollo, licensed under the MIT License.
- *
- * Copyright (c) 2023 Moonsworth
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package com.lunarclient.apollo.module.tntcountdown;
-
-import com.lunarclient.apollo.Apollo;
-import com.lunarclient.apollo.ApolloBukkitPlatform;
-import com.lunarclient.apollo.common.ApolloEntity;
-import com.lunarclient.apollo.network.NetworkTypes;
-import com.lunarclient.apollo.player.AbstractApolloPlayer;
-import com.lunarclient.apollo.player.ApolloPlayer;
-import com.lunarclient.apollo.tntcountdown.v1.SetTntCountdownMessage;
-import java.lang.reflect.Method;
-import java.util.UUID;
-import org.bukkit.Bukkit;
-import org.bukkit.World;
-import org.bukkit.entity.TNTPrimed;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.EventPriority;
-import org.bukkit.event.Listener;
-import org.bukkit.event.entity.EntitySpawnEvent;
-
-import static com.lunarclient.apollo.util.Ranges.checkPositive;
-
-/**
- * Provides the tnt countdown module.
- *
- * @since 1.0.0
- */
-public final class TntCountdownModuleImpl extends TntCountdownModule implements Listener {
-
- private static Method entityGetter;
-
- static {
- try {
- TntCountdownModuleImpl.entityGetter = Bukkit.class.getDeclaredMethod("getEntity", UUID.class);
- } catch (Throwable throwable) {
- // Ignore for legacy versions.
- }
- }
-
- @Override
- protected void onEnable() {
- Bukkit.getPluginManager().registerEvents(this, ApolloBukkitPlatform.getInstance().getPlugin());
- }
-
- @Override
- public void setTntCountdown(ApolloEntity entity, int ticks) {
- checkPositive(ticks, "TntCountdown#ticks");
-
- TNTPrimed target = null;
- if (TntCountdownModuleImpl.entityGetter != null) {
- try {
- target = (TNTPrimed) TntCountdownModuleImpl.entityGetter.invoke(null, entity.getEntityUuid());
- } catch (Throwable throwable) {
- throwable.printStackTrace();
- }
- } else {
- for (World world : Bukkit.getWorlds()) {
- for (TNTPrimed compare : world.getEntitiesByClass(TNTPrimed.class)) {
- if (compare.getUniqueId().equals(entity.getEntityUuid())) {
- target = compare;
- break;
- }
- }
- }
- }
-
- if (target != null) {
- target.setFuseTicks(ticks);
- }
-
- SetTntCountdownMessage message = SetTntCountdownMessage.newBuilder()
- .setEntityId(NetworkTypes.toProtobuf(entity))
- .setDurationTicks(ticks)
- .build();
-
- for (ApolloPlayer viewer : Apollo.getPlayerManager().getPlayers()) {
- ((AbstractApolloPlayer) viewer).sendPacket(message);
- }
- }
-
- @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
- private void onTntSpawn(EntitySpawnEvent event) {
- String entityName = event.getEntityType().name();
- if (!entityName.equals("PRIMED_TNT") && !entityName.equals("TNT")) {
- return;
- }
-
- TNTPrimed primed = (TNTPrimed) event.getEntity();
- int customTicks = this.getOptions().get(TntCountdownModule.TNT_TICKS);
- int defaultTicks = TntCountdownModule.TNT_TICKS.getDefaultValue();
- int currentTicks = primed.getFuseTicks();
-
- if (currentTicks != defaultTicks && !this.getOptions().get(TntCountdownModule.OVERRIDE_CUSTOM_TICKS)) {
- customTicks = currentTicks;
-
- SetTntCountdownMessage message = SetTntCountdownMessage.newBuilder()
- .setEntityId(NetworkTypes.toProtobuf(new ApolloEntity(primed.getEntityId(), primed.getUniqueId())))
- .setDurationTicks(customTicks)
- .build();
-
- for (ApolloPlayer viewer : Apollo.getPlayerManager().getPlayers()) {
- ((AbstractApolloPlayer) viewer).sendPacket(message);
- }
- }
-
- primed.setFuseTicks(customTicks);
- }
-
-}
diff --git a/common/src/main/java/com/lunarclient/apollo/module/tntcountdown/TntCountdownModuleImpl.java b/common/src/main/java/com/lunarclient/apollo/module/tntcountdown/TntCountdownModuleImpl.java
new file mode 100644
index 00000000..d3629c20
--- /dev/null
+++ b/common/src/main/java/com/lunarclient/apollo/module/tntcountdown/TntCountdownModuleImpl.java
@@ -0,0 +1,57 @@
+/*
+ * This file is part of Apollo, licensed under the MIT License.
+ *
+ * Copyright (c) 2023 Moonsworth
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package com.lunarclient.apollo.module.tntcountdown;
+
+import com.lunarclient.apollo.common.ApolloEntity;
+import com.lunarclient.apollo.network.NetworkTypes;
+import com.lunarclient.apollo.player.AbstractApolloPlayer;
+import com.lunarclient.apollo.recipients.Recipients;
+import com.lunarclient.apollo.tntcountdown.v1.SetTntCountdownMessage;
+import lombok.NonNull;
+
+import static com.lunarclient.apollo.util.Ranges.checkPositive;
+
+/**
+ * Provides the tnt countdown module.
+ *
+ * @since 1.1.8
+ */
+public final class TntCountdownModuleImpl extends TntCountdownModule {
+
+ @Override
+ public void setTntCountdown(@NonNull ApolloEntity entity, int ticks) {
+ this.setTntCountdown(Recipients.ofEveryone(), entity, ticks);
+ }
+
+ @Override
+ public void setTntCountdown(@NonNull Recipients recipients, @NonNull ApolloEntity entity, int ticks) {
+ SetTntCountdownMessage message = SetTntCountdownMessage.newBuilder()
+ .setEntityId(NetworkTypes.toProtobuf(entity))
+ .setDurationTicks(checkPositive(ticks, "TntCountdown#ticks"))
+ .build();
+
+ recipients.forEach(player -> ((AbstractApolloPlayer) player).sendPacket(message));
+ }
+
+}
diff --git a/docs/developers/modules/tntcountdown.mdx b/docs/developers/modules/tntcountdown.mdx
index ec36f708..c1d9ebfe 100644
--- a/docs/developers/modules/tntcountdown.mdx
+++ b/docs/developers/modules/tntcountdown.mdx
@@ -34,16 +34,13 @@ public void setTntCountdownExample() {
```java
public void overrideTntCountdownExample(Player viewer) {
- Location location = viewer.getLocation();
- World world = viewer.getWorld();
- TNTPrimed entity = world.spawn(location, TNTPrimed.class);
+ int customTicks = 200;
- Optional apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
+ TNTPrimed entity = viewer.getWorld().spawn(viewer.getLocation(), TNTPrimed.class);
+ entity.setFuseTicks(customTicks);
- apolloPlayerOpt.ifPresent(apolloPlayer -> {
- ApolloEntity apolloEntity = new ApolloEntity(entity.getEntityId(), entity.getUniqueId());
- this.tntCountdownModule.setTntCountdown(apolloEntity, 200);
- });
+ ApolloEntity apolloEntity = new ApolloEntity(entity.getEntityId(), entity.getUniqueId());
+ this.tntCountdownModule.setTntCountdown(Recipients.ofEveryone(), apolloEntity, customTicks);
}
```
@@ -51,7 +48,35 @@ public void overrideTntCountdownExample(Player viewer) {
```java
public void clearTntCountdownOptionExample() {
- this.tntCountdownModule.getOptions().remove(TntCountdownModule.TNT_TICKS, 80);
+ this.tntCountdownModule.getOptions().remove(TntCountdownModule.TNT_TICKS, 160);
+}
+```
+
+### Modify Fuse Ticks on TNT Spawn
+
+```java
+@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+private void onTntSpawn(EntitySpawnEvent event) {
+ String entityName = event.getEntityType().name();
+ if (!entityName.equals("PRIMED_TNT") && !entityName.equals("TNT")) {
+ return;
+ }
+
+ TNTPrimed primed = (TNTPrimed) event.getEntity();
+ int customTicks = this.tntCountdownModule.getOptions().get(TntCountdownModule.TNT_TICKS);
+ int defaultTicks = TntCountdownModule.TNT_TICKS.getDefaultValue();
+ int currentTicks = primed.getFuseTicks();
+
+ if (currentTicks != defaultTicks && !this.tntCountdownModule.getOptions().get(TntCountdownModule.OVERRIDE_CUSTOM_TICKS)) {
+ customTicks = currentTicks;
+
+ this.tntCountdownModule.setTntCountdown(Recipients.ofEveryone(),
+ new ApolloEntity(primed.getEntityId(), primed.getUniqueId()),
+ customTicks
+ );
+ }
+
+ primed.setFuseTicks(customTicks);
}
```
@@ -81,49 +106,18 @@ public void setTntCountdownExample() {
**Spawn TNT with Custom Tick amount**
```java
-private static Method entityGetter;
-
-static {
- try {
- TntCountdownProtoExample.entityGetter = Bukkit.class.getDeclaredMethod("getEntity", UUID.class);
- } catch (Throwable throwable) {
- // Ignore for legacy versions.
- }
-}
-
public void overrideTntCountdownExample(Player viewer) {
- Location location = viewer.getLocation();
- TNTPrimed entity = viewer.getWorld().spawn(location, TNTPrimed.class);
int customTicks = 200;
- TNTPrimed target = null;
- if (TntCountdownProtoExample.entityGetter != null) {
- try {
- target = (TNTPrimed) TntCountdownProtoExample.entityGetter.invoke(null, entity.getUniqueId());
- } catch (Throwable throwable) {
- throwable.printStackTrace();
- }
- } else {
- for (World world : Bukkit.getWorlds()) {
- for (TNTPrimed compare : world.getEntitiesByClass(TNTPrimed.class)) {
- if (compare.getUniqueId().equals(entity.getUniqueId())) {
- target = compare;
- break;
- }
- }
- }
- }
-
- if (target != null) {
- target.setFuseTicks(customTicks);
- }
+ TNTPrimed entity = viewer.getWorld().spawn(viewer.getLocation(), TNTPrimed.class);
+ entity.setFuseTicks(customTicks);
SetTntCountdownMessage message = SetTntCountdownMessage.newBuilder()
.setEntityId(ProtobufUtil.createEntityIdProto(entity.getEntityId(), entity.getUniqueId()))
.setDurationTicks(customTicks)
.build();
- ProtobufPacketUtil.sendPacket(viewer, message);
+ ProtobufPacketUtil.broadcastPacket(message);
}
```
@@ -132,7 +126,7 @@ public void overrideTntCountdownExample(Player viewer) {
```java
public void clearTntCountdownOptionExample() {
Map properties = new HashMap<>();
- properties.put("tnt-ticks", Value.newBuilder().setNumberValue(80).build());
+ properties.put("tnt-ticks", Value.newBuilder().setNumberValue(160).build());
ConfigurableSettings settings = ProtobufPacketUtil.createModuleMessage("tnt_countdown", properties);
ProtobufPacketUtil.broadcastPacket(settings);
@@ -200,42 +194,11 @@ public void setTntCountdownExample() {
**Spawn TNT with Custom Tick amount**
```java
-private static Method entityGetter;
-
-static {
- try {
- TntCountdownJsonExample.entityGetter = Bukkit.class.getDeclaredMethod("getEntity", UUID.class);
- } catch (Throwable throwable) {
- // Ignore for legacy versions.
- }
-}
-
public void overrideTntCountdownExample(Player viewer) {
- Location location = viewer.getLocation();
- TNTPrimed entity = viewer.getWorld().spawn(location, TNTPrimed.class);
int customTicks = 200;
- TNTPrimed target = null;
- if (TntCountdownJsonExample.entityGetter != null) {
- try {
- target = (TNTPrimed) TntCountdownJsonExample.entityGetter.invoke(null, entity.getUniqueId());
- } catch (Throwable throwable) {
- throwable.printStackTrace();
- }
- } else {
- for (World world : Bukkit.getWorlds()) {
- for (TNTPrimed compare : world.getEntitiesByClass(TNTPrimed.class)) {
- if (compare.getUniqueId().equals(entity.getUniqueId())) {
- target = compare;
- break;
- }
- }
- }
- }
-
- if (target != null) {
- target.setFuseTicks(customTicks);
- }
+ TNTPrimed entity = viewer.getWorld().spawn(viewer.getLocation(), TNTPrimed.class);
+ entity.setFuseTicks(customTicks);
JsonPacketUtil.sendPacket(viewer, this.createTNTCountdownMessage(entity, customTicks));
}