Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLimeGlass committed Oct 12, 2022
1 parent a7c4b1f commit 94f982c
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 25 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/java-17-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ jobs:
run: chmod +x gradlew
- name: Build Skript and run test scripts
run: ./gradlew clean skriptTestJava17
- name: Rename file
run: mv build/libs/Skript.jar build/libs/Skript-test.jar
- name: Build Skript nightly
run: ./gradlew clean nightlyRelease
- name: Rename file
run: mv build/libs/Skript.jar build/libs/Skript-nightly.jar
- name: Upload Nightly Build
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/java-8-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ jobs:
run: chmod +x gradlew
- name: Build Skript and run test scripts
run: ./gradlew clean skriptTestJava8
- name: Rename file
run: mv build/libs/Skript.jar build/libs/Skript-test.jar
- name: Build Skript nightly
run: ./gradlew clean nightlyRelease
- name: Rename file
run: mv build/libs/Skript.jar build/libs/Skript-nightly.jar
- name: Upload Nightly Build
Expand Down
47 changes: 30 additions & 17 deletions src/main/java/ch/njol/skript/classes/data/DefaultChangers.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,30 @@ public void change(final Inventory[] invis, final @Nullable Object[] delta, fina
public final static Changer<Block> blockChanger = new Changer<Block>() {
@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
public Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.RESET)
return null; // REMIND regenerate?
if (mode == ChangeMode.SET)
return CollectionUtils.array(ItemType.class, BlockData.class);
return CollectionUtils.array(ItemType[].class, BlockData[].class);
return CollectionUtils.array(ItemType[].class, Inventory[].class);
}

@Override
public void change(final Block[] blocks, final @Nullable Object[] delta, final ChangeMode mode) {
for (final Block block : blocks) {
public void change(Block[] blocks, @Nullable Object[] delta, ChangeMode mode) {
// Allows for 'set blocks within ... to (block datas ...)'
// set blocks within {pos1} to {pos2} to {data::saves::*}
if (mode == ChangeMode.SET && delta != null && delta.length > 0 && delta.length == blocks.length) {
for (int i = 0; i < blocks.length; i++) {
Block block = blocks[i];
Object object = delta[i];
if (object instanceof ItemType) {
((ItemType) delta[0]).getBlock().setBlock(block, true);
} else if (object instanceof BlockData) {
block.setBlockData(((BlockData) object));
}
}
}
for (Block block : blocks) {
assert block != null;
switch (mode) {
case SET:
Expand All @@ -311,30 +324,30 @@ public void change(final Block[] blocks, final @Nullable Object[] delta, final C
case REMOVE:
case REMOVE_ALL:
assert delta != null;
final BlockState state = block.getState();
BlockState state = block.getState();
if (!(state instanceof InventoryHolder))
break;
final Inventory invi = ((InventoryHolder) state).getInventory();
Inventory inventory = ((InventoryHolder) state).getInventory();
if (mode == ChangeMode.ADD) {
for (final Object d : delta) {
if (d instanceof Inventory) {
for (final ItemStack i : (Inventory) d) {
if (i != null)
invi.addItem(i);
for (Object object : delta) {
if (object instanceof Inventory) {
for (ItemStack item : (Inventory) object) {
if (item != null)
inventory.addItem(item);
}
} else {
((ItemType) d).addTo(invi);
((ItemType) object).addTo(inventory);
}
}
} else {
for (final Object d : delta) {
if (d instanceof Inventory) {
invi.removeItem(((Inventory) d).getContents());
for (Object object : delta) {
if (object instanceof Inventory) {
inventory.removeItem(((Inventory) object).getContents());
} else {
if (mode == ChangeMode.REMOVE)
((ItemType) d).removeFrom(invi);
((ItemType) object).removeFrom(inventory);
else
((ItemType) d).removeAll(invi);
((ItemType) object).removeAll(inventory);
}
}
}
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/ch/njol/skript/expressions/ExprEnvironment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.expressions;

import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.eclipse.jdt.annotation.Nullable;

@Name("World Environment")
@Description("The environment of a world")
@Examples({
"if environment of player's world is nether:",
"\tapply fire resistance to player for 10 minutes"
})
@Since("INSERT VERSION")
public class ExprEnvironment extends SimplePropertyExpression<World, Environment> {

static {
register(ExprEnvironment.class, Environment.class, "[world] environment", "worlds");
}

@Override
@Nullable
public Environment convert(World world) {
return world.getEnvironment();
}

@Override
public Class<? extends Environment> getReturnType() {
return Environment.class;
}

@Override
protected String getPropertyName() {
return "environment";
}

}
5 changes: 5 additions & 0 deletions src/test/skript/tests/syntaxes/expressions/ExprEnvironment.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test "world environment":
assert environment of world "world" is normal with "main overworld was not ""normal"""
assert environment of world "world_the_end" is the end with "world_the_end was not ""the end"""
set {_environment} to environment of world "world"
assert {_environment} is overworld with "environment of world didn't compare with a variable. Value = %{_environment}%"

0 comments on commit 94f982c

Please sign in to comment.