Skip to content

Commit 2034c62

Browse files
committed
Merge branch 'dev/patch' into dev/addon-support
# Conflicts: # src/main/java/com/github/skriptdev/skript/plugin/elements/expressions/ExpressionHandler.java
2 parents 836ce69 + a93aafe commit 2034c62

File tree

6 files changed

+279
-6
lines changed

6 files changed

+279
-6
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ This way you can program your server to do marvelous things without having to le
88
## Docs/Tutorials:
99
Check out our [**wiki**](https://github.com/SkriptDev/HySkript/wiki)
1010

11+
## Support:
12+
You can find us on the [**SkriptHub Discord server**](https://discord.gg/phpWHGU)
13+
Make sure to check out the "HySkript" channels!
14+
1115
## Requirements:
1216
- Java 25
1317
- Hytale Server (version information will come in the future)

src/main/java/com/github/skriptdev/skript/api/hytale/Block.java

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
package com.github.skriptdev.skript.api.hytale;
22

3+
import com.hypixel.hytale.component.Ref;
4+
import com.hypixel.hytale.component.Store;
5+
import com.hypixel.hytale.math.util.ChunkUtil;
6+
import com.hypixel.hytale.math.vector.Location;
37
import com.hypixel.hytale.math.vector.Vector3i;
48
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
9+
import com.hypixel.hytale.server.core.asset.type.fluid.Fluid;
10+
import com.hypixel.hytale.server.core.universe.Universe;
511
import com.hypixel.hytale.server.core.universe.world.World;
12+
import com.hypixel.hytale.server.core.universe.world.chunk.ChunkColumn;
13+
import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
14+
import com.hypixel.hytale.server.core.universe.world.chunk.section.FluidSection;
15+
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
616
import org.jetbrains.annotations.NotNull;
717

818
/**
@@ -24,6 +34,16 @@ public Block(@NotNull World world, @NotNull Vector3i pos, @NotNull BlockType typ
2434
this.type = type;
2535
}
2636

37+
public Block(@NotNull Location location) {
38+
World world = Universe.get().getWorld(location.getWorld());
39+
if (world == null) {
40+
throw new IllegalArgumentException("World '" + location.getWorld() + "' not found.");
41+
}
42+
BlockType blockType = world.getBlockType(location.getPosition().toVector3i());
43+
assert blockType != null;
44+
this(world, location.getPosition().toVector3i(), blockType);
45+
}
46+
2747
public @NotNull BlockType getType() {
2848
return this.type;
2949
}
@@ -33,6 +53,80 @@ public void setType(@NotNull BlockType type) {
3353
this.world.setBlock(this.pos.getX(), this.pos.getY(), this.pos.getZ(), type.getId());
3454
}
3555

56+
public byte getFluidLevel() {
57+
long index = ChunkUtil.indexChunkFromBlock(this.pos.getX(), this.pos.getZ());
58+
Ref<ChunkStore> columnRef = this.world.getChunk(index).getReference();
59+
Store<ChunkStore> store = columnRef.getStore();
60+
ChunkColumn column = store.getComponent(columnRef, ChunkColumn.getComponentType());
61+
Ref<ChunkStore> section = column.getSection(ChunkUtil.chunkCoordinate(this.pos.getY()));
62+
if (section == null) {
63+
return 0;
64+
} else {
65+
FluidSection fluidSection = store.getComponent(section, FluidSection.getComponentType());
66+
return fluidSection.getFluidLevel(this.pos.getX(), this.pos.getY(), this.pos.getZ());
67+
}
68+
}
69+
70+
public void setFluidLevel(byte level) {
71+
long index = ChunkUtil.indexChunkFromBlock(this.pos.getX(), this.pos.getZ());
72+
this.world.getChunkAsync(index).thenApply((chunk) -> {
73+
Ref<ChunkStore> columnRef = chunk.getReference();
74+
Store<ChunkStore> store = columnRef.getStore();
75+
ChunkColumn column = store.getComponent(columnRef, ChunkColumn.getComponentType());
76+
if (column == null) return null;
77+
78+
Ref<ChunkStore> section = column.getSection(ChunkUtil.chunkCoordinate(this.pos.getY()));
79+
if (section == null) {
80+
return null;
81+
} else {
82+
FluidSection fluidSection = store.getComponent(section, FluidSection.getComponentType());
83+
if (fluidSection == null) {
84+
return null;
85+
}
86+
87+
88+
Fluid fluid = fluidSection.getFluid(this.pos.getX(), this.pos.getY(), this.pos.getZ());
89+
if (fluid == null) return null;
90+
fluidSection.setFluid(this.pos.getX(), this.pos.getY(), this.pos.getZ(), fluid, level);
91+
}
92+
return chunk;
93+
});
94+
}
95+
96+
public Fluid getFluid() {
97+
int fluidId = this.world.getFluidId(this.pos.getX(), this.pos.getY(), this.pos.getZ());
98+
if (fluidId == -1) {
99+
return null;
100+
}
101+
return Fluid.getAssetMap().getAsset(fluidId);
102+
}
103+
104+
public void setFluid(@NotNull Fluid fluid) {
105+
long index = ChunkUtil.indexChunkFromBlock(this.pos.getX(), this.pos.getZ());
106+
this.world.getChunkAsync(index).thenApply((chunk) -> {
107+
Ref<ChunkStore> columnRef = chunk.getReference();
108+
Store<ChunkStore> store = columnRef.getStore();
109+
ChunkColumn column = store.getComponent(columnRef, ChunkColumn.getComponentType());
110+
if (column == null) return null;
111+
112+
Ref<ChunkStore> section = column.getSection(ChunkUtil.chunkCoordinate(this.pos.getY()));
113+
if (section == null) {
114+
return null;
115+
} else {
116+
FluidSection fluidSection = store.getComponent(section, FluidSection.getComponentType());
117+
if (fluidSection == null) {
118+
return null;
119+
}
120+
121+
122+
byte level = fluidSection.getFluidLevel(this.pos.getX(), this.pos.getY(), this.pos.getZ());
123+
if (level <= 0) level = 8;
124+
fluidSection.setFluid(this.pos.getX(), this.pos.getY(), this.pos.getZ(), fluid, level);
125+
}
126+
return chunk;
127+
});
128+
}
129+
36130
public void breakBlock() {
37131
int setting = 0; // TODO not sure what to actually use here
38132
this.world.breakBlock(this.pos.getX(), this.pos.getY(), this.pos.getZ(), setting);

src/main/java/com/github/skriptdev/skript/plugin/elements/conditions/CondHasPermission.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
import io.github.syst3ms.skriptparser.registration.SkriptRegistration;
1111
import org.jetbrains.annotations.NotNull;
1212

13+
import java.util.UUID;
14+
1315
public class CondHasPermission extends ConditionalExpression {
1416

1517
public static void register(SkriptRegistration registration) {
1618
registration.newExpression(CondHasPermission.class, Boolean.class, true,
17-
"%players/playerrefs% (has|have) permission %strings%")
19+
"%players/playerrefs/uuid% (has|have) permission %strings%",
20+
"%players/playerrefs/uuid% (don't|do not|doesn't|does not) (has|have) permission %strings%")
1821
.name("Permission")
19-
.description("Checks if the specified player(s) have the specified permission.")
22+
.description("Checks if the specified players/playerrefs/uuids have/don't have the specified permissions.")
2023
.examples("if player has permission \"hytale.admin\":")
2124
.since("1.0.0")
2225
.register();
@@ -30,23 +33,26 @@ public static void register(SkriptRegistration registration) {
3033
public boolean init(Expression<?>[] expressions, int matchedPattern, @NotNull ParseContext parseContext) {
3134
this.players = expressions[0];
3235
this.permission = (Expression<String>) expressions[1];
36+
setNegated(matchedPattern == 1);
3337
return true;
3438
}
3539

36-
3740
@Override
3841
public boolean check(@NotNull TriggerContext ctx) {
42+
PermissionsModule permissionsModule = PermissionsModule.get();
3943
this.permission.check(ctx, string -> {
4044
this.players.check(ctx, p -> {
4145
if (p instanceof Player player) {
4246
return player.hasPermission(string);
4347
} else if (p instanceof PlayerRef playerRef) {
44-
return PermissionsModule.get().hasPermission(playerRef.getUuid(), string);
48+
return permissionsModule.hasPermission(playerRef.getUuid(), string);
49+
} else if (p instanceof UUID uuid) {
50+
return permissionsModule.hasPermission(uuid, string);
4551
}
4652
return false;
47-
});
53+
}, isNegated());
4854
return false;
49-
});
55+
}, isNegated());
5056
return false;
5157
}
5258

src/main/java/com/github/skriptdev/skript/plugin/elements/expressions/ExpressionHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import com.github.skriptdev.skript.api.skript.registration.SkriptRegistration;
44
import com.github.skriptdev.skript.plugin.elements.expressions.block.ExprBlockAt;
5+
import com.github.skriptdev.skript.plugin.elements.expressions.block.ExprBlockFluid;
56
import com.github.skriptdev.skript.plugin.elements.expressions.block.ExprBlockTypeAtLocation;
67
import com.github.skriptdev.skript.plugin.elements.expressions.block.ExprBlockTypeOfBlock;
8+
import com.github.skriptdev.skript.plugin.elements.expressions.block.ExprBlockFluidLevel;
79
import com.github.skriptdev.skript.plugin.elements.expressions.block.ExprTargetBlockOfPlayer;
810
import com.github.skriptdev.skript.plugin.elements.expressions.entity.ExprEntityHealth;
911
import com.github.skriptdev.skript.plugin.elements.expressions.entity.ExprEntityStat;
@@ -40,6 +42,8 @@ public class ExpressionHandler {
4042
public static void register(SkriptRegistration registration) {
4143
// BLOCK
4244
ExprBlockAt.register(registration);
45+
ExprBlockFluid.register(registration);
46+
ExprBlockFluidLevel.register(registration);
4347
ExprBlockTypeAtLocation.register(registration);
4448
ExprBlockTypeOfBlock.register(registration);
4549
ExprTargetBlockOfPlayer.register(registration);
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.github.skriptdev.skript.plugin.elements.expressions.block;
2+
3+
import com.github.skriptdev.skript.api.hytale.Block;
4+
import com.github.skriptdev.skript.api.skript.registration.SkriptRegistration;
5+
import com.hypixel.hytale.math.vector.Location;
6+
import com.hypixel.hytale.server.core.asset.type.fluid.Fluid;
7+
import io.github.syst3ms.skriptparser.lang.Expression;
8+
import io.github.syst3ms.skriptparser.lang.TriggerContext;
9+
import io.github.syst3ms.skriptparser.parsing.ParseContext;
10+
import io.github.syst3ms.skriptparser.types.changers.ChangeMode;
11+
import org.jetbrains.annotations.NotNull;
12+
13+
import java.util.ArrayList;
14+
import java.util.List;
15+
import java.util.Optional;
16+
17+
public class ExprBlockFluid implements Expression<Fluid> {
18+
19+
public static void register(SkriptRegistration reg) {
20+
reg.newExpression(ExprBlockFluid.class, Fluid.class, true,
21+
"fluid (at|of) %locations/blocks%")
22+
.name("Block Fluid")
23+
.description("Get the fluid at a location/block.")
24+
.examples("set {_fluid} to fluid at player's location",
25+
"set fluid of block at player's location to slime_red")
26+
.since("INSERT VERSION")
27+
.register();
28+
}
29+
30+
private Expression<?> locations;
31+
32+
@Override
33+
public boolean init(Expression<?> @NotNull [] expressions, int matchedPattern, @NotNull ParseContext parseContext) {
34+
this.locations = expressions[0];
35+
return true;
36+
}
37+
38+
@Override
39+
public Fluid[] getValues(@NotNull TriggerContext ctx) {
40+
List<Fluid> fluids = new ArrayList<>();
41+
42+
for (Object o : this.locations.getArray(ctx)) {
43+
if (o instanceof Block block) {
44+
fluids.add(block.getFluid());
45+
} else if (o instanceof Location location) {
46+
Block block = new Block(location);
47+
fluids.add(block.getFluid());
48+
}
49+
}
50+
51+
return fluids.toArray(Fluid[]::new);
52+
}
53+
54+
@Override
55+
public Optional<Class<?>[]> acceptsChange(@NotNull ChangeMode mode) {
56+
if (mode == ChangeMode.SET) return Optional.of(new Class<?>[]{Fluid.class});
57+
return Optional.empty();
58+
}
59+
60+
@SuppressWarnings("ConstantValue")
61+
@Override
62+
public void change(@NotNull TriggerContext ctx, @NotNull ChangeMode changeMode, Object @NotNull [] changeWith) {
63+
if (changeWith == null) return;
64+
65+
if (!(changeWith[0] instanceof Fluid fluid)) return;
66+
for (Object o : this.locations.getArray(ctx)) {
67+
if (o instanceof Block block) {
68+
block.setFluid(fluid);
69+
} else if (o instanceof Location location) {
70+
Block block = new Block(location);
71+
block.setFluid(fluid);
72+
}
73+
}
74+
}
75+
76+
@Override
77+
public boolean isSingle() {
78+
return this.locations.isSingle();
79+
}
80+
81+
@Override
82+
public String toString(@NotNull TriggerContext ctx, boolean debug) {
83+
return "fluid of " + this.locations.toString(ctx, debug);
84+
}
85+
86+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.github.skriptdev.skript.plugin.elements.expressions.block;
2+
3+
import com.github.skriptdev.skript.api.hytale.Block;
4+
import com.github.skriptdev.skript.api.skript.registration.SkriptRegistration;
5+
import com.hypixel.hytale.math.vector.Location;
6+
import io.github.syst3ms.skriptparser.lang.Expression;
7+
import io.github.syst3ms.skriptparser.lang.TriggerContext;
8+
import io.github.syst3ms.skriptparser.parsing.ParseContext;
9+
import io.github.syst3ms.skriptparser.types.changers.ChangeMode;
10+
import org.jetbrains.annotations.NotNull;
11+
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
import java.util.Optional;
15+
16+
public class ExprBlockFluidLevel implements Expression<Number> {
17+
18+
public static void register(SkriptRegistration reg) {
19+
reg.newExpression(ExprBlockFluidLevel.class, Number.class, true,
20+
"[block] fluid level of %locations/blocks%")
21+
.name("Block Fluid Level")
22+
.description("Get.set the fluid level of a block.")
23+
.examples("set fluid level of block at player's location to 8")
24+
.since("INSERT VERSION")
25+
.register();
26+
}
27+
28+
private Expression<?> locations;
29+
30+
@Override
31+
public boolean init(Expression<?>[] expressions, int matchedPattern, @NotNull ParseContext parseContext) {
32+
this.locations = expressions[0];
33+
return true;
34+
}
35+
36+
@Override
37+
public Number[] getValues(@NotNull TriggerContext ctx) {
38+
List<Number> levels = new ArrayList<>();
39+
40+
for (Object o : this.locations.getArray(ctx)) {
41+
if (o instanceof Block block) {
42+
levels.add(block.getFluidLevel());
43+
} else if (o instanceof Location location) {
44+
Block block = new Block(location);
45+
levels.add(block.getFluidLevel());
46+
}
47+
}
48+
49+
return levels.toArray(Number[]::new);
50+
}
51+
52+
@Override
53+
public Optional<Class<?>[]> acceptsChange(@NotNull ChangeMode mode) {
54+
if (mode == ChangeMode.SET) return Optional.of(new Class<?>[]{Number.class});
55+
return Optional.empty();
56+
}
57+
58+
@SuppressWarnings("ConstantValue")
59+
@Override
60+
public void change(@NotNull TriggerContext ctx, @NotNull ChangeMode changeMode, Object @NotNull [] changeWith) {
61+
if (changeWith == null) return;
62+
if (!(changeWith[0] instanceof Number level)) return;
63+
64+
for (Object o : this.locations.getArray(ctx)) {
65+
if (o instanceof Block block) {
66+
block.setFluidLevel(level.byteValue());
67+
} else if (o instanceof Location location) {
68+
Block block = new Block(location);
69+
block.setFluidLevel(level.byteValue());
70+
}
71+
}
72+
}
73+
74+
@Override
75+
public String toString(@NotNull TriggerContext ctx, boolean debug) {
76+
return "fluid level of " + this.locations.toString(ctx, debug);
77+
}
78+
79+
}

0 commit comments

Comments
 (0)