Skip to content

Commit 9e61f38

Browse files
Merge branch 'dev/patch' into dev/feature
2 parents 6d4582e + ba32d7a commit 9e61f38

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+555
-342
lines changed

.github/workflows/checkstyle.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: checkstyle
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- 'dev/**'
8+
pull_request:
9+
10+
jobs:
11+
build:
12+
if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')"
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
submodules: recursive
18+
- name: validate gradle wrapper
19+
uses: gradle/wrapper-validation-action@v2
20+
- name: Set up JDK 21
21+
uses: actions/setup-java@v4
22+
with:
23+
java-version: '21'
24+
distribution: 'adopt'
25+
cache: gradle
26+
- name: Grant execute permission for gradlew
27+
run: chmod +x gradlew
28+
- name: Run checkstyle
29+
run: ./gradlew clean checkstyleMain
30+
- name: Upload checkstyle report
31+
uses: actions/upload-artifact@v4
32+
if: success()
33+
with:
34+
name: checkstyle-report
35+
path: |
36+
build/reports/checkstyle/*.xml
37+
build/reports/checkstyle/*.html

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ plugins {
77
id 'com.github.johnrengelman.shadow' version '8.1.1'
88
id 'maven-publish'
99
id 'java'
10+
id 'checkstyle'
1011
}
1112

1213
configurations {
@@ -42,6 +43,11 @@ dependencies {
4243
testShadow group: 'org.easymock', name: 'easymock', version: '5.4.0'
4344
}
4445

46+
checkstyle {
47+
configFile = new File("checkstyle.xml")
48+
sourceSets = [] // disables checkstyle after build task
49+
}
50+
4551
task checkAliases {
4652
description 'Checks for the existence of the aliases.'
4753
doLast {

checkstyle.xml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
4+
"https://checkstyle.org/dtds/configuration_1_3.dtd">
5+
6+
<module name="Checker">
7+
8+
<!--Basic Settings-->
9+
<!--Warning severity so the builds do not fail because of checkstyle, this is mainly for the GitHub workflow-->
10+
<property name="severity" value="warning"/>
11+
<property name="fileExtensions" value="java"/>
12+
<module name="BeforeExecutionExclusionFileFilter">
13+
<property name="fileNamePattern" value="module\-info\.java$"/>
14+
</module>
15+
16+
<!--At most 120 characters per line-->
17+
<module name="LineLength">
18+
<property name="max" value="120"/>
19+
</module>
20+
21+
<!--New line at the end of the file-->
22+
<module name="NewlineAtEndOfFile"/>
23+
24+
<module name="TreeWalker">
25+
26+
<!--Tabs, no spaces-->
27+
<module name="RegexpSinglelineJava">
28+
<property name="format" value="^\t* "/>
29+
<property name="message" value="Indent must use tab characters"/>
30+
<property name="ignoreComments" value="true"/>
31+
</module>
32+
33+
<!--No trailing whitespace-->
34+
<module name="NoWhitespaceAfter" />
35+
36+
<!--When statements consume multiple lines, all lines but the first have two tabs of additional indentation-->
37+
<module name="Indentation">
38+
<property name="arrayInitIndent" value="8" />
39+
<property name="basicOffset" value="8" />
40+
<property name="caseIndent" value="8" />
41+
<property name="lineWrappingIndentation" value="8" />
42+
<property name="throwsIndent" value="8" />
43+
</module>
44+
45+
<!--Each class begins with an empty line-->
46+
<module name="EmptyLineSeparator">
47+
<property name="allowNoEmptyLineBetweenFields" value="true" />
48+
<property name="tokens"
49+
value="IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF,
50+
ENUM_DEF, STATIC_INIT, INSTANCE_INIT, METHOD_DEF,
51+
CTOR_DEF, VARIABLE_DEF, RECORD_DEF, COMPACT_CTOR_DEF" />
52+
</module>
53+
54+
<module name="OneStatementPerLine"/>
55+
56+
<!--Annotations for a structure go on the line before that structure-->
57+
<module name="AnnotationLocation"/>
58+
59+
<!--When splitting Strings into multiple lines the last part of the string must be (space character included) " " +-->
60+
<module name="OperatorWrap">
61+
<property name="option" value="eol" />
62+
<property name="tokens" value="PLUS" />
63+
</module>
64+
65+
<!--Class names are written in UpperCamelCase-->
66+
<module name="TypeName"/>
67+
68+
<!--Methods named in camelCase-->
69+
<module name="MethodName"/>
70+
71+
<!--Static constant fields should be named in UPPER_SNAKE_CASE-->
72+
<module name="ConstantName"/>
73+
74+
<!--We use JetBrains Annotations for specifying null-ness-->
75+
<module name="IllegalImport">
76+
<property name="illegalClasses"
77+
value="javax.annotation.Nonnull,
78+
javax.annotation.Nullable,
79+
org.eclipse.jdt.annotation.NonNull,
80+
org.eclipse.jdt.annotation.Nullable,
81+
org.eclipse.sisu.Nullable,
82+
org.checkerframework.checker.nullness.qual.NonNull,
83+
org.checkerframework.checker.nullness.qual.Nullable" />
84+
<property name="illegalPkgs" value="" />
85+
</module>
86+
87+
<!--Modules for code improvements-->
88+
<module name="MissingOverride"/>
89+
<module name="EmptyBlock"/>
90+
<module name="HideUtilityClassConstructor"/>
91+
<module name="EmptyStatement"/>
92+
<module name="EqualsHashCode"/>
93+
<module name="SimplifyBooleanExpression"/>
94+
<module name="SimplifyBooleanReturn"/>
95+
<module name="StringLiteralEquality"/>
96+
<module name="UnusedLocalVariable"/>
97+
98+
</module>
99+
100+
</module>

code-conventions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ If we need to remove or alter contributed code due to a licensing issue we will
9797
- The exception to this is breaking up conditional statements (e.g. `if (x || y)`) where the
9898
condition starts may be aligned
9999
* Each class begins with an empty line
100+
* Each Java file ends with an empty line
100101
* No squeezing of multiple lines of code on a single line
101102
* Separate method declarations with empty lines
102103
- Empty line after last method in a class is *not* required

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ org.gradle.parallel=true
55

66
groupid=ch.njol
77
name=skript
8-
version=2.9.2
8+
version=2.9.3
99
jarName=Skript.jar
1010
testEnv=java21/paper-1.21.0
1111
testEnvJavaVersion=21

src/main/java/ch/njol/skript/SkriptCommand.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
215215
if (scriptInfo.files == 0) {
216216
info(sender, "reload.empty folder", fileName);
217217
} else {
218-
reloaded(sender, logHandler, timingLogHandler, "x scripts in folder", fileName, scriptInfo.files);
218+
if (logHandler.numErrors() == 0) {
219+
reloaded(sender, logHandler, timingLogHandler, "x scripts in folder success", fileName, scriptInfo.files);
220+
} else {
221+
reloaded(sender, logHandler, timingLogHandler, "x scripts in folder error", fileName, scriptInfo.files);
222+
}
219223
}
220224
});
221225
}

src/main/java/ch/njol/skript/aliases/Aliases.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,17 +395,17 @@ public static void load() {
395395
}
396396

397397
/**
398-
* Temporarily create an alias for a material which may not have an alias yet.
398+
* Temporarily create an alias for materials which do not have aliases yet.
399399
*/
400400
private static void loadMissingAliases() {
401401
if (!Skript.methodExists(Material.class, "getKey"))
402402
return;
403403
for (Material material : Material.values()) {
404-
if (!provider.hasAliasForMaterial(material)) {
404+
if (!material.isLegacy() && !provider.hasAliasForMaterial(material)) {
405405
NamespacedKey key = material.getKey();
406406
String name = key.getKey().replace("_", " ");
407407
parser.loadAlias(name + "¦s", key.toString());
408-
Skript.debug(ChatColor.YELLOW + "Creating temporary alias for: " + key.toString());
408+
Skript.debug(ChatColor.YELLOW + "Creating temporary alias for: " + key);
409409
}
410410
}
411411
}

src/main/java/ch/njol/skript/aliases/ItemType.java

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
/**
2-
* This file is part of Skript.
3-
*
4-
* Skript is free software: you can redistribute it and/or modify
5-
* it under the terms of the GNU General Public License as published by
6-
* the Free Software Foundation, either version 3 of the License, or
7-
* (at your option) any later version.
8-
*
9-
* Skript is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
* GNU General Public License for more details.
13-
*
14-
* You should have received a copy of the GNU General Public License
15-
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
16-
*
17-
* Copyright Peter Güttinger, SkriptLang team and contributors
18-
*/
191
package ch.njol.skript.aliases;
202

213
import ch.njol.skript.aliases.ItemData.OldItemData;
@@ -41,6 +23,7 @@
4123
import org.bukkit.Material;
4224
import org.bukkit.OfflinePlayer;
4325
import org.bukkit.Tag;
26+
import org.bukkit.Bukkit;
4427
import org.bukkit.block.Block;
4528
import org.bukkit.block.BlockState;
4629
import org.bukkit.block.Skull;
@@ -391,22 +374,35 @@ public boolean hasType() {
391374
*/
392375
public boolean setBlock(Block block, boolean applyPhysics) {
393376
for (int i = random.nextInt(types.size()); i < types.size(); i++) {
394-
ItemData d = types.get(i);
395-
Material blockType = ItemUtils.asBlock(d.type);
377+
ItemData data = types.get(i);
378+
Material blockType = ItemUtils.asBlock(data.type);
379+
396380
if (blockType == null) // Ignore items which cannot be placed
397381
continue;
398-
if (BlockUtils.set(block, blockType, d.getBlockValues(), applyPhysics)) {
399-
ItemMeta itemMeta = getItemMeta();
400-
if (itemMeta instanceof SkullMeta) {
401-
OfflinePlayer offlinePlayer = ((SkullMeta) itemMeta).getOwningPlayer();
402-
if (offlinePlayer == null)
403-
continue;
404-
Skull skull = (Skull) block.getState();
382+
383+
if (!BlockUtils.set(block, blockType, data.getBlockValues(), applyPhysics))
384+
continue;
385+
386+
ItemMeta itemMeta = getItemMeta();
387+
388+
if (itemMeta instanceof SkullMeta) {
389+
OfflinePlayer offlinePlayer = ((SkullMeta) itemMeta).getOwningPlayer();
390+
if (offlinePlayer == null)
391+
continue;
392+
Skull skull = (Skull) block.getState();
393+
if (offlinePlayer.getName() != null) {
405394
skull.setOwningPlayer(offlinePlayer);
406-
skull.update(false, applyPhysics);
395+
} else if (ItemUtils.CAN_CREATE_PLAYER_PROFILE) {
396+
//noinspection deprecation
397+
skull.setOwnerProfile(Bukkit.createPlayerProfile(offlinePlayer.getUniqueId(), ""));
398+
} else {
399+
//noinspection deprecation
400+
skull.setOwner("");
407401
}
408-
return true;
402+
skull.update(false, applyPhysics);
409403
}
404+
405+
return true;
410406
}
411407
return false;
412408
}

src/main/java/ch/njol/skript/bukkitutil/BukkitUnsafe.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ public class BukkitUnsafe {
7070

7171
@Nullable
7272
public static Material getMaterialFromMinecraftId(String id) {
73-
// On 1.13, Vanilla and Spigot names are same
74-
if (id.length() > 9)
75-
return Material.matchMaterial(id.substring(10)); // Strip 'minecraft:' out
76-
else // Malformed material name
77-
return null;
73+
return Material.matchMaterial(id);
7874
}
7975

8076
public static void modifyItemStack(ItemStack stack, String arguments) {

src/main/java/ch/njol/skript/bukkitutil/ItemUtils.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import ch.njol.skript.Skript;
2222
import ch.njol.skript.aliases.ItemType;
2323
import ch.njol.skript.util.slot.Slot;
24+
import org.bukkit.Bukkit;
2425
import org.bukkit.Material;
26+
import org.bukkit.OfflinePlayer;
2527
import org.bukkit.Tag;
2628
import org.bukkit.TreeType;
2729
import org.bukkit.block.Block;
@@ -32,9 +34,11 @@
3234
import org.bukkit.inventory.ItemStack;
3335
import org.bukkit.inventory.meta.Damageable;
3436
import org.bukkit.inventory.meta.ItemMeta;
37+
import org.bukkit.inventory.meta.SkullMeta;
3538
import org.jetbrains.annotations.Nullable;
3639

3740
import java.util.HashMap;
41+
import java.util.UUID;
3842

3943
/**
4044
* Miscellaneous static utility methods related to items.
@@ -44,6 +48,7 @@ public class ItemUtils {
4448
public static final boolean HAS_MAX_DAMAGE = Skript.methodExists(Damageable.class, "getMaxDamage");
4549
// Introduced in Paper 1.21
4650
public static final boolean HAS_RESET = Skript.methodExists(Damageable.class, "resetDamage");
51+
public static final boolean CAN_CREATE_PLAYER_PROFILE = Skript.methodExists(Bukkit.class, "createPlayerProfile", UUID.class, String.class);
4752

4853
/**
4954
* Gets damage/durability of an item, or 0 if it does not have damage.
@@ -148,6 +153,30 @@ public static void setDamage(ItemType itemType, int damage) {
148153
}
149154
}
150155

156+
/**
157+
* Sets the owner of a player head.
158+
* @param skull player head item to modify
159+
* @param player owner of the head
160+
*/
161+
public static void setHeadOwner(ItemType skull, OfflinePlayer player) {
162+
ItemMeta meta = skull.getItemMeta();
163+
if (!(meta instanceof SkullMeta))
164+
return;
165+
166+
SkullMeta skullMeta = (SkullMeta) meta;
167+
168+
if (player.getName() != null) {
169+
skullMeta.setOwningPlayer(player);
170+
} else if (CAN_CREATE_PLAYER_PROFILE) {
171+
//noinspection deprecation
172+
skullMeta.setOwnerProfile(Bukkit.createPlayerProfile(player.getUniqueId(), ""));
173+
} else {
174+
skullMeta.setOwningPlayer(null);
175+
}
176+
177+
skull.setItemMeta(skullMeta);
178+
}
179+
151180
/**
152181
* Gets a block material corresponding to given item material, which might
153182
* be the given material. If no block material is found, null is returned.

src/main/java/ch/njol/skript/classes/data/DefaultOperations.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ public class DefaultOperations {
4747
return left.doubleValue() * right.doubleValue();
4848
});
4949
Arithmetics.registerOperation(Operator.DIVISION, Number.class, (left, right) -> left.doubleValue() / right.doubleValue());
50-
Arithmetics.registerOperation(Operator.EXPONENTIATION, Number.class, (left, right) -> {
51-
if (Utils.isInteger(left, right) && right.longValue() >= 0)
52-
return (long) Math.pow(left.longValue(), right.longValue());
53-
return Math.pow(left.doubleValue(), right.doubleValue());
54-
});
50+
Arithmetics.registerOperation(Operator.EXPONENTIATION, Number.class, (left, right) -> Math.pow(left.doubleValue(), right.doubleValue()));
5551
Arithmetics.registerDifference(Number.class, (left, right) -> {
5652
if (Utils.isInteger(left, right))
5753
return Math.abs(left.longValue() - right.longValue());

src/main/java/ch/njol/skript/conditions/CondIsWithin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ public boolean check(Event event) {
103103
Location one = loc1.getSingle(event);
104104
Location two = loc2.getSingle(event);
105105
if (one == null || two == null || one.getWorld() != two.getWorld())
106-
return false;
106+
return isNegated();
107107
AABB box = new AABB(one, two);
108108
return locsToCheck.check(event, box::contains, isNegated());
109109
}
110110

111111
// else, within an entity/block/chunk/world
112112
Object area = this.area.getSingle(event);
113113
if (area == null)
114-
return false;
114+
return isNegated();
115115

116116
// Entities
117117
if (area instanceof Entity) {

0 commit comments

Comments
 (0)