commit
dd896abc28
6 changed files with 337 additions and 0 deletions
@ -0,0 +1,115 @@ |
||||
# User-specific stuff |
||||
.idea/ |
||||
|
||||
*.iml |
||||
*.ipr |
||||
*.iws |
||||
|
||||
# IntelliJ |
||||
out/ |
||||
|
||||
# Compiled class file |
||||
*.class |
||||
|
||||
# Log file |
||||
*.log |
||||
|
||||
# BlueJ files |
||||
*.ctxt |
||||
|
||||
# Package Files # |
||||
*.jar |
||||
*.war |
||||
*.nar |
||||
*.ear |
||||
*.zip |
||||
*.tar.gz |
||||
*.rar |
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml |
||||
hs_err_pid* |
||||
|
||||
*~ |
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file |
||||
.fuse_hidden* |
||||
|
||||
# KDE directory preferences |
||||
.directory |
||||
|
||||
# Linux trash folder which might appear on any partition or disk |
||||
.Trash-* |
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed |
||||
.nfs* |
||||
|
||||
# General |
||||
.DS_Store |
||||
.AppleDouble |
||||
.LSOverride |
||||
|
||||
# Icon must end with two \r |
||||
Icon |
||||
|
||||
# Thumbnails |
||||
._* |
||||
|
||||
# Files that might appear in the root of a volume |
||||
.DocumentRevisions-V100 |
||||
.fseventsd |
||||
.Spotlight-V100 |
||||
.TemporaryItems |
||||
.Trashes |
||||
.VolumeIcon.icns |
||||
.com.apple.timemachine.donotpresent |
||||
|
||||
# Directories potentially created on remote AFP share |
||||
.AppleDB |
||||
.AppleDesktop |
||||
Network Trash Folder |
||||
Temporary Items |
||||
.apdisk |
||||
|
||||
# Windows thumbnail cache files |
||||
Thumbs.db |
||||
Thumbs.db:encryptable |
||||
ehthumbs.db |
||||
ehthumbs_vista.db |
||||
|
||||
# Dump file |
||||
*.stackdump |
||||
|
||||
# Folder config file |
||||
[Dd]esktop.ini |
||||
|
||||
# Recycle Bin used on file shares |
||||
$RECYCLE.BIN/ |
||||
|
||||
# Windows Installer files |
||||
*.cab |
||||
*.msi |
||||
*.msix |
||||
*.msm |
||||
*.msp |
||||
|
||||
# Windows shortcuts |
||||
*.lnk |
||||
|
||||
target/ |
||||
|
||||
pom.xml.tag |
||||
pom.xml.releaseBackup |
||||
pom.xml.versionsBackup |
||||
pom.xml.next |
||||
|
||||
release.properties |
||||
dependency-reduced-pom.xml |
||||
buildNumber.properties |
||||
.mvn/timing.properties |
||||
.mvn/wrapper/maven-wrapper.jar |
||||
.flattened-pom.xml |
||||
|
||||
# Common working directory |
||||
run/ |
||||
|
||||
server |
@ -0,0 +1,2 @@ |
||||
#!/usr/bin/env bash |
||||
cp target/SaplingsReplant-1.0.jar server/plugins |
@ -0,0 +1,71 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<groupId>eu.benjaminkraft</groupId> |
||||
<artifactId>SaplingsReplant</artifactId> |
||||
<version>1.0</version> |
||||
<packaging>jar</packaging> |
||||
|
||||
<name>SaplingsReplant</name> |
||||
|
||||
<properties> |
||||
<java.version>1.8</java.version> |
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||
</properties> |
||||
|
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-compiler-plugin</artifactId> |
||||
<version>3.8.1</version> |
||||
<configuration> |
||||
<source>${java.version}</source> |
||||
<target>${java.version}</target> |
||||
</configuration> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-shade-plugin</artifactId> |
||||
<version>3.2.4</version> |
||||
<executions> |
||||
<execution> |
||||
<phase>package</phase> |
||||
<goals> |
||||
<goal>shade</goal> |
||||
</goals> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
</plugins> |
||||
<resources> |
||||
<resource> |
||||
<directory>src/main/resources</directory> |
||||
<filtering>true</filtering> |
||||
</resource> |
||||
</resources> |
||||
</build> |
||||
|
||||
<repositories> |
||||
<repository> |
||||
<id>spigotmc-repo</id> |
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> |
||||
</repository> |
||||
<repository> |
||||
<id>sonatype</id> |
||||
<url>https://oss.sonatype.org/content/groups/public/</url> |
||||
</repository> |
||||
</repositories> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.spigotmc</groupId> |
||||
<artifactId>spigot-api</artifactId> |
||||
<version>1.19-R0.1-SNAPSHOT</version> |
||||
<scope>provided</scope> |
||||
</dependency> |
||||
</dependencies> |
||||
</project> |
@ -0,0 +1,142 @@ |
||||
package eu.benjaminkraft.saplingsreplant; |
||||
|
||||
import org.bukkit.Bukkit; |
||||
import org.bukkit.Material; |
||||
import org.bukkit.block.Block; |
||||
import org.bukkit.block.BlockFace; |
||||
import org.bukkit.entity.Item; |
||||
import org.bukkit.event.EventHandler; |
||||
import org.bukkit.event.Listener; |
||||
import org.bukkit.event.entity.*; |
||||
import org.bukkit.plugin.java.JavaPlugin; |
||||
|
||||
import java.util.EnumSet; |
||||
import java.util.HashSet; |
||||
import java.util.Set; |
||||
import java.util.logging.Logger; |
||||
|
||||
public final class SaplingsReplant extends JavaPlugin implements Listener { |
||||
|
||||
Logger logger; |
||||
|
||||
Set<Item> trackedSaplings = new HashSet<>(); |
||||
|
||||
@Override |
||||
public void onEnable() { |
||||
logger = getLogger(); |
||||
getServer().getPluginManager().registerEvents(this, this); |
||||
Bukkit.getScheduler().runTaskTimer(this, this::handleSaplings, 0, 20); |
||||
} |
||||
|
||||
@EventHandler |
||||
public void onItemSpawn(ItemSpawnEvent event) { |
||||
Item item = event.getEntity(); |
||||
|
||||
if (!isSapling(item)) |
||||
return; |
||||
|
||||
trackedSaplings.add(item); |
||||
logger.info("Spawn: Added Sapling to Tracking-list: " + item.getName()); |
||||
} |
||||
|
||||
@EventHandler |
||||
public void onEntityDropItem(EntityDropItemEvent event) { |
||||
|
||||
Item item = event.getItemDrop(); |
||||
|
||||
if (!isSapling(item)) |
||||
return; |
||||
|
||||
trackedSaplings.add(item); |
||||
logger.info("Drop: Added Sapling to Tracking-list: " + item.getName()); |
||||
} |
||||
|
||||
@EventHandler |
||||
public void onItemDespawn(ItemDespawnEvent event) { |
||||
Item item = event.getEntity(); |
||||
|
||||
boolean removed = trackedSaplings.remove(item); |
||||
if (removed){ |
||||
logger.info("Despawn: Removed Sapling from Tracking-list: " + item.getName()); |
||||
} |
||||
} |
||||
|
||||
@EventHandler |
||||
public void onItemMerge(ItemMergeEvent event) { |
||||
Item item = event.getEntity(); |
||||
|
||||
boolean removed = trackedSaplings.remove(item); |
||||
if (removed){ |
||||
logger.info("Merge: Removed Sapling from Tracking-list: " + item.getName()); |
||||
} |
||||
} |
||||
|
||||
@EventHandler |
||||
public void onEntityPickupItem(EntityPickupItemEvent event) { |
||||
boolean removed = trackedSaplings.remove(event.getItem()); |
||||
if (removed){ |
||||
logger.info("Pickup: Removed Sapling from Tracking-list: " + event.getItem().getName()); |
||||
} |
||||
} |
||||
|
||||
private void handleSaplings() { |
||||
Set<Item> toRemove = new HashSet<>(); |
||||
for (Item sapling : trackedSaplings) { |
||||
if (!sapling.isOnGround()) |
||||
continue; |
||||
|
||||
Block currentBlock = sapling.getLocation().getBlock(); |
||||
if (isSapling(currentBlock.getType())) |
||||
continue; |
||||
|
||||
Block ground = currentBlock.getRelative(BlockFace.DOWN); |
||||
Set<Material> allowedGrounds = EnumSet.of( |
||||
Material.DIRT, |
||||
Material.COARSE_DIRT, |
||||
Material.ROOTED_DIRT, |
||||
Material.GRASS_BLOCK |
||||
); |
||||
|
||||
if (!allowedGrounds.contains(ground.getType())) |
||||
continue; |
||||
|
||||
currentBlock.setType(sapling.getItemStack().getType()); |
||||
sapling.getItemStack().setAmount(sapling.getItemStack().getAmount() - 1); |
||||
logger.info("Planted: Reduced Sapling Stack amount"); |
||||
|
||||
if (sapling.getItemStack().getAmount() == 0){ |
||||
logger.info("Planted: Removed Sapling from Tracking-list"); |
||||
toRemove.add(sapling); |
||||
} |
||||
} |
||||
trackedSaplings.removeAll(toRemove); |
||||
} |
||||
|
||||
private boolean isSapling(Item item) { |
||||
return isSapling(item.getItemStack().getType()); |
||||
} |
||||
|
||||
private boolean isSapling(Material material) { |
||||
Set<Material> saplings = EnumSet.of( |
||||
Material.OAK_SAPLING, |
||||
Material.SPRUCE_SAPLING, |
||||
Material.ACACIA_SAPLING, |
||||
Material.BAMBOO_SAPLING, |
||||
Material.BIRCH_SAPLING, |
||||
Material.DARK_OAK_SAPLING, |
||||
Material.JUNGLE_SAPLING, |
||||
Material.POTTED_ACACIA_SAPLING, |
||||
Material.POTTED_BIRCH_SAPLING, |
||||
Material.POTTED_DARK_OAK_SAPLING, |
||||
Material.POTTED_JUNGLE_SAPLING, |
||||
Material.POTTED_OAK_SAPLING, |
||||
Material.POTTED_SPRUCE_SAPLING |
||||
); |
||||
return saplings.contains(material); |
||||
} |
||||
|
||||
@Override |
||||
public void onDisable() { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,4 @@ |
||||
name: SaplingsReplant |
||||
version: '${project.version}' |
||||
main: eu.benjaminkraft.saplingsreplant.SaplingsReplant |
||||
api-version: '1.19' |
Loading…
Reference in new issue