Skip to content

Commit 9f15df1

Browse files
committed
Fundamental code there, works sorta?
Code works to despawn entity and respawn it with PDC. Need to know how to serialize entity to bytes then rebuild it when unbucketing. So nothing but PDC actually transfers, did not test to ensure PDC does maintain but no errors were thrown so...
0 parents  commit 9f15df1

File tree

9 files changed

+329
-0
lines changed

9 files changed

+329
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# User-specific stuff
2+
.idea/
3+
4+
*.iml
5+
*.ipr
6+
*.iws
7+
8+
# IntelliJ
9+
out/
10+
11+
# Compiled class file
12+
*.class
13+
14+
# Log file
15+
*.log
16+
17+
# BlueJ files
18+
*.ctxt
19+
20+
# Package Files #
21+
*.jar
22+
*.war
23+
*.nar
24+
*.ear
25+
*.zip
26+
*.tar.gz
27+
*.rar
28+
29+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
30+
hs_err_pid*
31+
32+
*~
33+
34+
# temporary files which can be created if a process still has a handle open of a deleted file
35+
.fuse_hidden*
36+
37+
# KDE directory preferences
38+
.directory
39+
40+
# Linux trash folder which might appear on any partition or disk
41+
.Trash-*
42+
43+
# .nfs files are created when an open file is removed but is still being accessed
44+
.nfs*
45+
46+
# General
47+
.DS_Store
48+
.AppleDouble
49+
.LSOverride
50+
51+
# Icon must end with two \r
52+
Icon
53+
54+
# Thumbnails
55+
._*
56+
57+
# Files that might appear in the root of a volume
58+
.DocumentRevisions-V100
59+
.fseventsd
60+
.Spotlight-V100
61+
.TemporaryItems
62+
.Trashes
63+
.VolumeIcon.icns
64+
.com.apple.timemachine.donotpresent
65+
66+
# Directories potentially created on remote AFP share
67+
.AppleDB
68+
.AppleDesktop
69+
Network Trash Folder
70+
Temporary Items
71+
.apdisk
72+
73+
# Windows thumbnail cache files
74+
Thumbs.db
75+
Thumbs.db:encryptable
76+
ehthumbs.db
77+
ehthumbs_vista.db
78+
79+
# Dump file
80+
*.stackdump
81+
82+
# Folder config file
83+
[Dd]esktop.ini
84+
85+
# Recycle Bin used on file shares
86+
$RECYCLE.BIN/
87+
88+
# Windows Installer files
89+
*.cab
90+
*.msi
91+
*.msix
92+
*.msm
93+
*.msp
94+
95+
# Windows shortcuts
96+
*.lnk
97+
98+
target/
99+
100+
pom.xml.tag
101+
pom.xml.releaseBackup
102+
pom.xml.versionsBackup
103+
pom.xml.next
104+
105+
release.properties
106+
dependency-reduced-pom.xml
107+
buildNumber.properties
108+
.mvn/timing.properties
109+
.mvn/wrapper/maven-wrapper.jar
110+
.flattened-pom.xml
111+
112+
# Common working directory
113+
run/

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Peashooter101
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SimpleBucketMobs
2+
Throw mobs into buckets! :D

pom.xml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>ADHDMC</groupId>
8+
<artifactId>SimpleBucketMobs</artifactId>
9+
<version>dev</version>
10+
<packaging>jar</packaging>
11+
12+
<name>SimpleBucketMobs</name>
13+
14+
<description>Shove your mobs into buckets like Axolotls! :D</description>
15+
<properties>
16+
<java.version>1.8</java.version>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
20+
<build>
21+
<plugins>
22+
<plugin>
23+
<groupId>org.apache.maven.plugins</groupId>
24+
<artifactId>maven-compiler-plugin</artifactId>
25+
<version>3.8.1</version>
26+
<configuration>
27+
<source>${java.version}</source>
28+
<target>${java.version}</target>
29+
</configuration>
30+
</plugin>
31+
<plugin>
32+
<groupId>org.apache.maven.plugins</groupId>
33+
<artifactId>maven-shade-plugin</artifactId>
34+
<version>3.2.4</version>
35+
<executions>
36+
<execution>
37+
<phase>package</phase>
38+
<goals>
39+
<goal>shade</goal>
40+
</goals>
41+
<configuration>
42+
<createDependencyReducedPom>false</createDependencyReducedPom>
43+
</configuration>
44+
</execution>
45+
</executions>
46+
</plugin>
47+
</plugins>
48+
<resources>
49+
<resource>
50+
<directory>src/main/resources</directory>
51+
<filtering>true</filtering>
52+
</resource>
53+
</resources>
54+
</build>
55+
56+
<repositories>
57+
<repository>
58+
<id>papermc-repo</id>
59+
<url>https://repo.papermc.io/repository/maven-public/</url>
60+
</repository>
61+
<repository>
62+
<id>sonatype</id>
63+
<url>https://oss.sonatype.org/content/groups/public/</url>
64+
</repository>
65+
</repositories>
66+
67+
<dependencies>
68+
<dependency>
69+
<groupId>io.papermc.paper</groupId>
70+
<artifactId>paper-api</artifactId>
71+
<version>1.19.3-R0.1-SNAPSHOT</version>
72+
<scope>provided</scope>
73+
</dependency>
74+
</dependencies>
75+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package adhdmc.simplebucketmobs;
2+
3+
import adhdmc.simplebucketmobs.listener.BucketMob;
4+
import org.bukkit.Bukkit;
5+
import org.bukkit.plugin.Plugin;
6+
import org.bukkit.plugin.java.JavaPlugin;
7+
8+
public final class SimpleBucketMobs extends JavaPlugin {
9+
10+
private static Plugin plugin;
11+
12+
@Override
13+
public void onEnable() {
14+
plugin = this;
15+
Bukkit.getPluginManager().registerEvents(new BucketMob(), this);
16+
}
17+
18+
@Override
19+
public void onDisable() {
20+
// Plugin shutdown logic
21+
}
22+
23+
public static Plugin getPlugin() { return plugin; }
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package adhdmc.simplebucketmobs.config;
2+
3+
public class Config {
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package adhdmc.simplebucketmobs.listener;
2+
3+
import adhdmc.simplebucketmobs.SimpleBucketMobs;
4+
import net.kyori.adventure.text.minimessage.MiniMessage;
5+
import org.bukkit.Location;
6+
import org.bukkit.Material;
7+
import org.bukkit.NamespacedKey;
8+
import org.bukkit.entity.Entity;
9+
import org.bukkit.entity.EntityType;
10+
import org.bukkit.entity.LivingEntity;
11+
import org.bukkit.event.EventHandler;
12+
import org.bukkit.event.EventPriority;
13+
import org.bukkit.event.Listener;
14+
import org.bukkit.event.entity.CreatureSpawnEvent;
15+
import org.bukkit.event.player.PlayerInteractEntityEvent;
16+
import org.bukkit.event.player.PlayerInteractEvent;
17+
import org.bukkit.inventory.EquipmentSlot;
18+
import org.bukkit.inventory.ItemStack;
19+
import org.bukkit.inventory.meta.ItemMeta;
20+
import org.bukkit.persistence.PersistentDataContainer;
21+
import org.bukkit.persistence.PersistentDataType;
22+
23+
import java.io.IOException;
24+
25+
public class BucketMob implements Listener {
26+
27+
NamespacedKey mobNBTKey = new NamespacedKey(SimpleBucketMobs.getPlugin(), "mob_nbt");
28+
NamespacedKey mobTypeKey = new NamespacedKey(SimpleBucketMobs.getPlugin(), "mob_type");
29+
30+
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
31+
public void bucketMob(PlayerInteractEntityEvent event) {
32+
if (event.getHand() != EquipmentSlot.HAND) return;
33+
if (!(event.getRightClicked() instanceof LivingEntity)) return;
34+
ItemStack bucket = event.getPlayer().getEquipment().getItemInMainHand();
35+
if (bucket.getType() != Material.BUCKET) return;
36+
if (bucket.getItemMeta().getPersistentDataContainer().has(mobTypeKey)) return;
37+
ItemStack mobBucket = new ItemStack(Material.BUCKET);
38+
byte[] serializedMob;
39+
try {
40+
serializedMob = event.getRightClicked().getPersistentDataContainer().serializeToBytes();
41+
} catch (IOException e) {
42+
event.getPlayer().sendRichMessage("<red>Failed to bucket mob (Serialization).");
43+
return;
44+
}
45+
ItemMeta meta = mobBucket.getItemMeta();
46+
PersistentDataContainer bucketPDC = meta.getPersistentDataContainer();
47+
bucketPDC.set(mobNBTKey, PersistentDataType.BYTE_ARRAY, serializedMob);
48+
bucketPDC.set(mobTypeKey, PersistentDataType.STRING, event.getRightClicked().getType().toString());
49+
meta.displayName(MiniMessage.miniMessage().deserialize("<aqua>Mob Bucket"));
50+
mobBucket.setItemMeta(meta);
51+
bucket.subtract();
52+
event.getPlayer().getInventory().addItem(mobBucket);
53+
event.getRightClicked().remove();
54+
}
55+
56+
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
57+
public void unbucketMob(PlayerInteractEvent event) {
58+
if (event.getHand() != EquipmentSlot.HAND) return;
59+
Location interactLoc = event.getInteractionPoint();
60+
if (interactLoc == null) return;
61+
ItemStack bucket = event.getPlayer().getEquipment().getItemInMainHand();
62+
if (bucket.getType() != Material.BUCKET) return;
63+
if (!bucket.getItemMeta().getPersistentDataContainer().has(mobNBTKey)) return;
64+
String mobTypeString = bucket.getItemMeta().getPersistentDataContainer().get(mobTypeKey, PersistentDataType.STRING);
65+
byte[] serializedMob = bucket.getItemMeta().getPersistentDataContainer().get(mobNBTKey, PersistentDataType.BYTE_ARRAY);
66+
EntityType mobType;
67+
try { mobType = EntityType.valueOf(mobTypeString); }
68+
catch (IllegalArgumentException e) {
69+
event.getPlayer().sendRichMessage("<red>Failed to unbucket mob (IllegalArgumentException).");
70+
return;
71+
}
72+
Entity entity = interactLoc.getWorld().spawnEntity(interactLoc, mobType, CreatureSpawnEvent.SpawnReason.CUSTOM);
73+
try { entity.getPersistentDataContainer().readFromBytes(serializedMob); }
74+
catch (IOException e) {
75+
event.getPlayer().sendRichMessage("<red>Failed to unbucket mob (Deserialization).");
76+
return;
77+
}
78+
bucket.subtract();
79+
event.getPlayer().getInventory().addItem(new ItemStack(Material.BUCKET));
80+
}
81+
82+
}

src/main/resources/plugin.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: SimpleBucketMobs
2+
version: '${project.version}'
3+
main: adhdmc.simplebucketmobs.SimpleBucketMobs
4+
api-version: 1.19
5+
authors: [ Rhythmic, Peashooter101 ]
6+
description: Shove your mobs into buckets like Axolotls! :D

0 commit comments

Comments
 (0)