Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
* <p>The given ticks must be equal to or greater than 0.</p>
*
* @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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,69 @@

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

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
Expand All @@ -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<String, Value> 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);
Expand Down

This file was deleted.

Loading