Skip to content

Commit

Permalink
various cleanups (firework_data, etc)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 26, 2022
1 parent 4dd904c commit 52d5322
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
Expand Up @@ -115,21 +115,22 @@ public static void registerTags() {
// @group properties
// @mechanism ItemTag.firework
// @description
// Returns the firework's property value as a list, matching the format of the mechanism.
// Returns the firework's property value as a list, matching the non-MapTag format of the mechanism.
// Consider instead using <@link tag ItemTag.firework_data>
// -->
PropertyParser.<ItemFirework, ListTag>registerTag(ListTag.class, "firework", (attribute, object) -> {
return object.getFireworkData();
});

// <--[tag]
// @attribute <ItemTag.firework_map>
// @returns MapTag
// @attribute <ItemTag.firework_data>
// @returns ListTag
// @group properties
// @mechanism ItemTag.firework
// @description
// Returns the firework's property value as a list, matching the MapTag format of the mechanism.
// Returns the firework's property value as a ListTag of MapTags, matching the MapTag format of the mechanism.
// -->
PropertyParser.<ItemFirework, ListTag>registerTag(ListTag.class, "firework_map", (attribute, object) -> {
PropertyParser.<ItemFirework, ListTag>registerTag(ListTag.class, "firework_data", (attribute, object) -> {
return object.getFireworkDataMap();
});

Expand All @@ -140,6 +141,7 @@ public static void registerTags() {
// @mechanism ItemTag.firework_power
// @description
// Returns the firework's power.
// Power primarily affects how high the firework flies, with each level of power corresponding to approximately half a second of additional flight them.
// -->
PropertyParser.<ItemFirework, ElementTag>registerTag(ElementTag.class, "firework_power", (attribute, object) -> {
ItemMeta meta = object.item.getItemMeta();
Expand Down Expand Up @@ -187,16 +189,17 @@ public void adjust(Mechanism mechanism) {
// @input ListTag
// @description
// Sets the firework's settings.
// Each item in the list is formatted as:
// A list of comma-separated values, in TRAIL,FLICKER,TYPE,RED,GREEN,BLUE,RED,GREEN,BLUE format.
// Each item in the list can be any of the following:
// 1: Comma-separated effect data in the format: TRAIL,FLICKER,TYPE,RED,GREEN,BLUE,RED,GREEN,BLUE
// For example: true,false,BALL,255,0,0,0,255,0 would create a trailing ball firework that fades from red to green.
// A list of MapTags, with "type", "color", "fade_color", "trail", and "flicker" keys.
// Can optionally input a MapTag, with each key/value pair being equivalent to a value in the list.
// 2: A MapTag, with "type", "color", "fade_color", "trail", and "flicker" keys.
// For example: [type=ball;color=red;fade_color=green;trail=true;flicker=false]
// 3: A single number, to set the power.
// Types: ball, ball_large, star, burst, or creeper
// Notice that this is an ADD operation, provide no input to clear all effects.
// Note that this is an add operation, provide no input to clear all effects.
// @tags
// <ItemTag.firework>
// <ItemTag.firework_map>
// <ItemTag.firework_data>
// -->
if (mechanism.matches("firework")) {
ItemMeta meta = item.getItemMeta();
Expand All @@ -211,7 +214,7 @@ public void adjust(Mechanism mechanism) {
else {
Collection<ObjectTag> list = CoreUtilities.objectToList(mechanism.getValue(), mechanism.context);
for (ObjectTag object : list) {
if (object instanceof MapTag) {
if (object.canBeType(MapTag.class)) {
MapTag effectMap = object.asType(MapTag.class, mechanism.context);
FireworkEffect.Builder builder = FireworkEffect.builder();
ObjectTag type = effectMap.getObject("type");
Expand Down
Expand Up @@ -208,7 +208,7 @@ public void sendTo(List<PlayerTag> players) {
return;
}
if (toOthers == null) {
toOthers = NMSHandler.getPlayerHelper().sendEntitySpawn(players, as.getEntityType(), entity.getLocation(), as.getWaitingMechanisms(), entity.getBukkitEntity().getEntityId(), entity.getUUID(), false);
toOthers = NMSHandler.getPlayerHelper().sendEntitySpawn(players, as.getEntityType(), entity.getLocation(), as.mechanisms == null ? null : new ArrayList<>(as.mechanisms), entity.getBukkitEntity().getEntityId(), entity.getUUID(), false);
toOthers.overrideUUID = UUID.randomUUID();
toOthers.entity.uuid = toOthers.overrideUUID;
FakeEntity.idsToEntities.put(toOthers.overrideUUID, toOthers);
Expand Down Expand Up @@ -335,7 +335,7 @@ public void execute(ScriptEntry scriptEntry) {
}
if (!cancel) {
TrackedDisguise disguise = new TrackedDisguise(entity, as);
disguise.as.entity = NMSHandler.getPlayerHelper().sendEntitySpawn(new ArrayList<>(), as.getEntityType(), entity.getLocation(), as.getWaitingMechanisms(), -1, null, false).entity.getBukkitEntity();
disguise.as.entity = NMSHandler.getPlayerHelper().sendEntitySpawn(new ArrayList<>(), as.getEntityType(), entity.getLocation(), as.mechanisms == null ? null : new ArrayList<>(as.mechanisms), -1, null, false).entity.getBukkitEntity();
if (global) {
playerMap = disguises.computeIfAbsent(entity.getUUID(), k -> new HashMap<>());
playerMap.put(null, disguise);
Expand Down
Expand Up @@ -53,7 +53,7 @@ public FakeEntity(List<PlayerTag> player, LocationTag location, int id) {

public static FakeEntity showFakeEntityTo(List<PlayerTag> players, EntityTag typeToSpawn, LocationTag location, DurationTag duration) {
NetworkInterceptHelper.enable();
FakeEntity fakeEntity = NMSHandler.getPlayerHelper().sendEntitySpawn(players, typeToSpawn.getEntityType(), location, typeToSpawn.getWaitingMechanisms(), -1, null, true);
FakeEntity fakeEntity = NMSHandler.getPlayerHelper().sendEntitySpawn(players, typeToSpawn.getEntityType(), location, typeToSpawn.mechanisms == null ? null : new ArrayList<>(typeToSpawn.mechanisms), -1, null, true);
idsToEntities.put(fakeEntity.overrideUUID == null ? fakeEntity.entity.getUUID() : fakeEntity.overrideUUID, fakeEntity);
for (PlayerTag player : players) {
UUID uuid = player.getPlayerEntity().getUniqueId();
Expand Down
Expand Up @@ -56,6 +56,7 @@ public static FakePlayer spawnFakePlayer(Location location, String name, String
String prefix = null;
String suffix = null;
if (name == null) {
Debug.echoError("FAKE_PLAYER: null name, cannot spawn");
return null;
}
else if (fullName.length() > 16) {
Expand Down
Expand Up @@ -5,6 +5,7 @@
import com.denizenscript.denizen.nms.v1_18.impl.BiomeNMSImpl;
import com.denizenscript.denizen.objects.BiomeTag;
import com.denizenscript.denizencore.utilities.ReflectionHelper;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
Expand All @@ -14,8 +15,12 @@
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;

import java.lang.invoke.MethodHandle;

public class WorldHelperImpl implements WorldHelper {

public static MethodHandle DIMENSION_SETTER = ReflectionHelper.getFinalSetter(Level.class, ReflectionMappingsInfo.Level_dimension);

@Override
public boolean isStatic(World world) {
return ((CraftWorld) world).getHandle().isClientSide;
Expand All @@ -42,8 +47,13 @@ public void setDimension(World world, World.Environment environment) {
break;
}
if (dimension != null) {
ServerLevel worldServer = ((CraftWorld) world).getHandle();
ReflectionHelper.setFieldValue(Level.class, ReflectionMappingsInfo.Level_dimension, worldServer, dimension);
try {
ServerLevel worldServer = ((CraftWorld) world).getHandle();
DIMENSION_SETTER.invoke(worldServer, dimension);
}
catch (Throwable ex) {
Debug.echoError(ex);
}
}
}

Expand Down

0 comments on commit 52d5322

Please sign in to comment.