Skip to content

Commit 1624250

Browse files
committed
Update to 1.21.3 - mostly - textures still don't work
Fix bug where if you bucket-ed a mob while your inventory was full, the mob and bucket would be deleted
1 parent 393ee31 commit 1624250

File tree

7 files changed

+92
-77
lines changed

7 files changed

+92
-77
lines changed

build.gradle.kts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,39 @@
1-
version = "0.2"
1+
version = "1.0"
22

33
plugins {
44
`java-library`
5-
id("io.papermc.paperweight.userdev") version "1.5.3"
6-
id("xyz.jpenilla.run-paper") version "2.0.1" // Adds runServer and runMojangMappedServer tasks for testing
5+
id("io.papermc.paperweight.userdev") version "1.7.3"
6+
id("xyz.jpenilla.run-paper") version "2.3.1" // Adds runServer and runMojangMappedServer tasks for testing
77
}
88

99
java {
10-
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
10+
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
1111
}
1212

1313
repositories {
1414
maven("https://repo.papermc.io/repository/maven-public/")
1515
}
1616

1717
dependencies {
18-
paperweight.paperDevBundle("1.20-R0.1-SNAPSHOT")
18+
paperweight.paperDevBundle("1.21.3-R0.1-SNAPSHOT")
1919
}
2020

2121
tasks {
2222
assemble {
23-
dependsOn(reobfJar)
23+
dependsOn("reobfJar")
2424
}
2525

2626
compileJava {
27-
options.encoding = Charsets.UTF_8.name()
28-
options.release.set(17)
27+
options.encoding = "UTF-8"
28+
options.release.set(21)
2929
}
3030
javadoc {
31-
options.encoding = Charsets.UTF_8.name()
31+
options.encoding = "UTF-8"
3232
}
3333
processResources {
34-
filteringCharset = Charsets.UTF_8.name()
34+
filteringCharset = "UTF-8"
3535
filesMatching("plugin.yml") {
36-
expand(
37-
"version" to project.version
38-
)
36+
expand("version" to project.version)
3937
}
4038
}
4139
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
44
networkTimeout=10000
5+
validateDistributionUrl=true
56
zipStoreBase=GRADLE_USER_HOME
67
zipStorePath=wrapper/dists

gradlew

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
# Darwin, MinGW, and NonStop.
5656
#
5757
# (3) This script is generated from the Groovy template
58-
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
58+
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
5959
# within the Gradle project.
6060
#
6161
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -83,10 +83,8 @@ done
8383
# This is normally unused
8484
# shellcheck disable=SC2034
8585
APP_BASE_NAME=${0##*/}
86-
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
87-
88-
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89-
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
86+
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87+
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
9088

9189
# Use the maximum available, or set MAX_FD != -1 to use that value.
9290
MAX_FD=maximum
@@ -133,26 +131,29 @@ location of your Java installation."
133131
fi
134132
else
135133
JAVACMD=java
136-
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
134+
if ! command -v java >/dev/null 2>&1
135+
then
136+
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137137
138138
Please set the JAVA_HOME variable in your environment to match the
139139
location of your Java installation."
140+
fi
140141
fi
141142

142143
# Increase the maximum file descriptors if we can.
143144
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144145
case $MAX_FD in #(
145146
max*)
146147
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
147-
# shellcheck disable=SC3045
148+
# shellcheck disable=SC2039,SC3045
148149
MAX_FD=$( ulimit -H -n ) ||
149150
warn "Could not query maximum file descriptor limit"
150151
esac
151152
case $MAX_FD in #(
152153
'' | soft) :;; #(
153154
*)
154155
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
155-
# shellcheck disable=SC3045
156+
# shellcheck disable=SC2039,SC3045
156157
ulimit -n "$MAX_FD" ||
157158
warn "Could not set maximum file descriptor limit to $MAX_FD"
158159
esac
@@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then
197198
done
198199
fi
199200

200-
# Collect all arguments for the java command;
201-
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
202-
# shell script including quotes and variable substitutions, so put them in
203-
# double quotes to make sure that they get re-expanded; and
204-
# * put everything else in single quotes, so that it's not re-expanded.
201+
202+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
203+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
204+
205+
# Collect all arguments for the java command:
206+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
207+
# and any embedded shellness will be escaped.
208+
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
209+
# treated as '${Hostname}' itself on the command line.
205210

206211
set -- \
207212
"-Dorg.gradle.appname=$APP_BASE_NAME" \

gradlew.bat

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
4343
%JAVA_EXE% -version >NUL 2>&1
4444
if %ERRORLEVEL% equ 0 goto execute
4545

46-
echo.
47-
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48-
echo.
49-
echo Please set the JAVA_HOME variable in your environment to match the
50-
echo location of your Java installation.
46+
echo. 1>&2
47+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
48+
echo. 1>&2
49+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
50+
echo location of your Java installation. 1>&2
5151

5252
goto fail
5353

@@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
5757

5858
if exist "%JAVA_EXE%" goto execute
5959

60-
echo.
61-
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62-
echo.
63-
echo Please set the JAVA_HOME variable in your environment to match the
64-
echo location of your Java installation.
60+
echo. 1>&2
61+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
62+
echo. 1>&2
63+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
64+
echo location of your Java installation. 1>&2
6565

6666
goto fail
6767

src/main/java/simplexity/simplebucketmobs/config/Config.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,48 @@ public class Config {
1414

1515
private static Config instance;
1616

17-
private final Set<EntityType> allowedTypes;
17+
private final Set<EntityType> allowedBasicTypes;
1818
private String bucketTitle;
1919
private boolean noHostileTargeting;
20-
// TODO: Allowed Types dependent on Bucket
2120
// TODO: Disallowed Attributes
2221

2322
private Config() {
24-
allowedTypes = new HashSet<>();
23+
allowedBasicTypes = new HashSet<>();
2524
}
2625

2726
public static Config getInstance() {
2827
if (instance == null) instance = new Config();
2928
return instance;
3029
}
3130

32-
public Set<EntityType> getAllowedTypes() { return Collections.unmodifiableSet(allowedTypes); }
31+
public Set<EntityType> getAllowedBasicTypes() { return Collections.unmodifiableSet(allowedBasicTypes); }
3332
public String getBucketTitle() { return bucketTitle; }
3433
public boolean isNoHostileTargeting() { return noHostileTargeting; }
3534

3635
public void reloadConfig() {
3736
SimpleBucketMobs.getPlugin().reloadConfig();
3837
FileConfiguration config = SimpleBucketMobs.getPlugin().getConfig();
39-
List<String> types = config.getStringList("allowed-types");
40-
allowedTypes.clear();
41-
for (String type : types) {
38+
setupTypes(config);
39+
bucketTitle = config.getString("bucket-title", "<aqua><type> Bucket");
40+
noHostileTargeting = config.getBoolean("no-hostile-targeting", true);
41+
}
42+
43+
private void setupTypes(FileConfiguration config) {
44+
List<String> basicTypes = config.getStringList("allowed-types");
45+
allowedBasicTypes.clear();
46+
validateTypes(basicTypes, allowedBasicTypes);
47+
}
48+
49+
private void validateTypes(List<String> stringList, Set<EntityType> entityList){
50+
for (String type : stringList) {
4251
try {
4352
EntityType entityType = EntityType.valueOf(type.toUpperCase());
44-
allowedTypes.add(entityType);
53+
entityList.add(entityType);
4554
}
4655
catch (IllegalArgumentException e) {
4756
SimpleBucketMobs.getPlugin().getLogger().warning(Message.LOGGER_INVALID_MOB_TYPE.getMessage() + type);
4857
}
4958
}
50-
bucketTitle = config.getString("bucket-title", "<aqua><type> Bucket");
51-
noHostileTargeting = config.getBoolean("no-hostile-targeting", true);
5259
}
5360

5461
}

src/main/java/simplexity/simplebucketmobs/listener/BucketMob.java

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package simplexity.simplebucketmobs.listener;
22

3+
import org.bukkit.craftbukkit.entity.CraftLivingEntity;
34
import simplexity.simplebucketmobs.SimpleBucketMobs;
45
import simplexity.simplebucketmobs.config.Config;
56
import simplexity.simplebucketmobs.config.Texture;
@@ -14,7 +15,7 @@
1415
import org.bukkit.*;
1516
import org.bukkit.block.Block;
1617
import org.bukkit.block.BlockFace;
17-
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftLivingEntity;
18+
1819
import org.bukkit.entity.*;
1920
import org.bukkit.event.EventHandler;
2021
import org.bukkit.event.EventPriority;
@@ -47,13 +48,13 @@ public void bucketMob(PlayerInteractEntityEvent event) {
4748
if (!(clicked instanceof LivingEntity entity)) return;
4849
if (entity.getType() == EntityType.PLAYER) return;
4950
if (Config.getInstance().isNoHostileTargeting()
50-
&& entity instanceof Monster monster
51-
&& monster.getTarget() != null
52-
&& monster.getTarget().equals(player)) {
51+
&& entity instanceof Monster monster
52+
&& monster.getTarget() != null
53+
&& monster.getTarget().equals(player)) {
5354
player.sendMessage(Message.ERROR_BUCKET_HOSTILE_TARGETING.getParsedMessage());
5455
return;
5556
}
56-
if (!Config.getInstance().getAllowedTypes().contains(entity.getType())) return;
57+
if (!Config.getInstance().getAllowedBasicTypes().contains(entity.getType())) return;
5758
if (!(player.hasPermission(Permission.BUCKET_ALL.get()) || player.hasPermission(Permission.BUCKET_MOB.get() + entity.getType()))) {
5859
player.sendMessage(Message.ERROR_BUCKET_NO_PERMISSION.getParsedMessage());
5960
return;
@@ -67,7 +68,6 @@ public void bucketMob(PlayerInteractEntityEvent event) {
6768
event.setCancelled(true);
6869
return;
6970
}
70-
7171
ItemStack mobBucket = new ItemStack(Material.BUCKET);
7272
Entity vehicle = entity.getVehicle();
7373
if (vehicle != null) vehicle.removePassenger(entity);
@@ -91,12 +91,17 @@ public void bucketMob(PlayerInteractEntityEvent event) {
9191
Texture.getInstance().setCustomData(entity.getType(), meta, tag);
9292
mobBucket.setItemMeta(meta);
9393
if (player.getGameMode() != GameMode.CREATIVE) bucket.subtract();
94-
player.getInventory().addItem(mobBucket);
94+
if (player.getInventory().firstEmpty() == -1) {
95+
player.getWorld().dropItemNaturally(player.getLocation(), mobBucket);
96+
} else {
97+
player.getInventory().addItem(mobBucket);
98+
}
9599
try {
96100
// TODO: Configurable?
97101
String soundName = "ENTITY_" + entity.getType() + "_HURT";
98102
player.playSound(player.getLocation(), Sound.valueOf(soundName), 0.75f, 1.0f);
99-
} catch (IllegalArgumentException ignored) { }
103+
} catch (IllegalArgumentException ignored) {
104+
}
100105
entity.remove();
101106
}
102107

@@ -115,13 +120,13 @@ public void unbucketMob(PlayerInteractEvent event) {
115120

116121
String serializedNbt = bucket.getItemMeta().getPersistentDataContainer().get(mobNBTKey, PersistentDataType.STRING);
117122

118-
try { if (serializedNbt != null) applyNBT(location, serializedNbt, event.getBlockFace()); }
119-
catch (IOException | CommandSyntaxException e) {
123+
try {
124+
if (serializedNbt != null) applyNBT(location, serializedNbt, event.getBlockFace());
125+
} catch (IOException | CommandSyntaxException e) {
120126
player.sendMessage(Message.ERROR_FAILED_DESERIALIZATION.getParsedMessage());
121127
e.printStackTrace();
122128
return;
123-
}
124-
catch (IllegalArgumentException e) {
129+
} catch (IllegalArgumentException e) {
125130
player.sendMessage(Message.ERROR_NO_BUCKET_MOB.getParsedMessage());
126131
e.printStackTrace();
127132
return;
@@ -148,6 +153,7 @@ public void noBucketLiquid(PlayerBucketFillEvent event) {
148153

149154
/**
150155
* Serializes the NBT Data from the LivingEntity.
156+
*
151157
* @param e LivingEntity
152158
* @return String serialization of the LivingEntity.
153159
*/
@@ -159,22 +165,20 @@ private CompoundTag serializeNBT(LivingEntity e) {
159165

160166
/**
161167
* Deserializes the NBT Data into the LivingEntity.
162-
* @param location Location to spawn Mob.
168+
*
169+
* @param location Location to spawn Mob.
163170
* @param serializedNbt NBT as a String
164-
* @exception IllegalArgumentException Invalid Mob Type Found
165-
* @exception IOException Failed to read NBT Tags.
166-
* @exception CommandSyntaxException What.
171+
* @throws IllegalArgumentException Invalid Mob Type Found
172+
* @throws IOException Failed to read NBT Tags.
173+
* @throws CommandSyntaxException What.
167174
*/
168175
private void applyNBT(Location location, String serializedNbt, BlockFace face) throws IllegalArgumentException, IOException, CommandSyntaxException {
169176
CompoundTag tag = TagParser.parseTag(serializedNbt);
170177
Tag idTag = tag.get("id");
171178
// TODO: Maybe throw exception.
172179
if (idTag == null) return;
173180
String id = idTag.getAsString().split(":")[1].toUpperCase();
174-
EntityType mobType;
175-
// Special cases where minecraft:id != Bukkit Name.
176-
if (id.equals("MOOSHROOM")) mobType = EntityType.MUSHROOM_COW;
177-
else mobType = EntityType.valueOf(id);
181+
EntityType mobType = EntityType.valueOf(id);
178182
Entity entity = location.getWorld().spawnEntity(location, mobType, CreatureSpawnEvent.SpawnReason.CUSTOM, spawned -> {
179183
CompoundTag newLoc = new CompoundTag();
180184
((CraftLivingEntity) spawned).getHandle().save(newLoc);
@@ -189,6 +193,7 @@ private void applyNBT(Location location, String serializedNbt, BlockFace face) t
189193

190194
/**
191195
* Converts a string to Name Case
196+
*
192197
* @param input String
193198
* @return String but using Name Case
194199
* @implNote Thanks Baeldung (https://www.baeldung.com/java-string-title-case)
@@ -203,8 +208,7 @@ private String nameCase(String input) {
203208
else if (toUpper) {
204209
c = Character.toTitleCase(c);
205210
toUpper = false;
206-
}
207-
else {
211+
} else {
208212
c = Character.toLowerCase(c);
209213
}
210214
nameCased.append(c);
@@ -214,20 +218,21 @@ else if (toUpper) {
214218

215219
/**
216220
* Adjusts the location given
221+
*
217222
* @param interactionPoint Location of Interaction Point
218-
* @param face Block Face of Interaction
223+
* @param face Block Face of Interaction
219224
* @return The same Location.
220225
*/
221226
private Location adjustLoc(Location interactionPoint, BlockFace face, BoundingBox entityBox) {
222227
double height = entityBox.getHeight();
223228
double widthX = entityBox.getWidthX();
224229
double widthZ = entityBox.getWidthZ();
225230
switch (face) {
226-
case DOWN -> interactionPoint.add(0, -1*height, 0);
227-
case EAST -> interactionPoint.add(.5*widthX, 0, 0);
228-
case WEST -> interactionPoint.add(-.5*widthX, 0, 0);
229-
case NORTH -> interactionPoint.add(0, 0, -.5*widthZ);
230-
case SOUTH -> interactionPoint.add(0, 0, .5*widthZ);
231+
case DOWN -> interactionPoint.add(0, -1 * height, 0);
232+
case EAST -> interactionPoint.add(.5 * widthX, 0, 0);
233+
case WEST -> interactionPoint.add(-.5 * widthX, 0, 0);
234+
case NORTH -> interactionPoint.add(0, 0, -.5 * widthZ);
235+
case SOUTH -> interactionPoint.add(0, 0, .5 * widthZ);
231236
}
232237
return interactionPoint;
233238
}

0 commit comments

Comments
 (0)