[First Commit]

First version of the plugin.

Get spawners and budding amethysts dropped with silk touch.
This commit is contained in:
xoy 2023-10-19 13:17:33 +02:00
commit 21672e8468
11 changed files with 267 additions and 0 deletions

38
.gitignore vendored Normal file
View File

@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,8 @@
<component name="ArtifactManager">
<artifact type="jar" name="SilkBlocks-0.1">
<output-path>$USER_HOME$/Desktop/Minecraft Test Server/plugins</output-path>
<root id="archive" name="SilkBlocks-0.1.jar">
<element id="module-output" name="SilkBlocks" />
</root>
</artifact>
</component>

7
.idea/encodings.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

14
.idea/misc.xml Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

5
README.md Normal file
View File

@ -0,0 +1,5 @@
# Spigot SilkBlocks Plugin
Spigot plugin to get spawners and other blocks dropped with silk touch.
Tested version: 1.20.2

17
pom.xml Normal file
View File

@ -0,0 +1,17 @@
<?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>dev.xoy.silkblocks</groupId>
<artifactId>SilkBlocks</artifactId>
<version>0.1</version>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -0,0 +1,139 @@
package dev.xoy.silkblocks;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class BlockListener implements Listener {
public void sendMessageToChat(Player player, String msg) {
String formattedMsg = ChatColor.YELLOW + msg;
player.sendMessage(formattedMsg);
}
/*
public ItemStack getSpawnerItemStack(Block block) {
CreatureSpawner spawner = (CreatureSpawner) block.getState();
ItemStack spawnerItem = new ItemStack(Material.SPAWNER);
BlockStateMeta blockStateMeta = (BlockStateMeta) spawnerItem.getItemMeta();
if ( blockStateMeta != null ) {
blockStateMeta.setBlockState(spawner);
spawnerItem.setItemMeta(blockStateMeta);
return spawnerItem;
}
return null;
}
*/
public ItemStack[] getItemStack(Block block) {
Map<EntityType, Material> mobList = new HashMap<>();
mobList.put(EntityType.ZOMBIE, Material.ZOMBIE_SPAWN_EGG);
mobList.put(EntityType.SKELETON, Material.SKELETON_SPAWN_EGG);
mobList.put(EntityType.CREEPER, Material.CREEPER_SPAWN_EGG);
mobList.put(EntityType.SPIDER, Material.SPIDER_SPAWN_EGG);
mobList.put(EntityType.WITCH, Material.WITCH_SPAWN_EGG);
mobList.put(EntityType.ENDERMAN, Material.ENDERMAN_SPAWN_EGG);
mobList.put(EntityType.PIG, Material.PIG_SPAWN_EGG);
mobList.put(EntityType.COW, Material.COW_SPAWN_EGG);
mobList.put(EntityType.CHICKEN, Material.CHICKEN_SPAWN_EGG);
mobList.put(EntityType.HORSE, Material.HORSE_SPAWN_EGG);
mobList.put(EntityType.SHEEP, Material.SHEEP_SPAWN_EGG);
mobList.put(EntityType.OCELOT, Material.OCELOT_SPAWN_EGG);
mobList.put(EntityType.BAT, Material.BAT_SPAWN_EGG);
mobList.put(EntityType.VILLAGER, Material.VILLAGER_SPAWN_EGG);
mobList.put(EntityType.IRON_GOLEM, Material.IRON_GOLEM_SPAWN_EGG);
mobList.put(EntityType.WOLF, Material.WOLF_SPAWN_EGG);
mobList.put(EntityType.POLAR_BEAR, Material.POLAR_BEAR_SPAWN_EGG);
mobList.put(EntityType.RABBIT, Material.RABBIT_SPAWN_EGG);
mobList.put(EntityType.PARROT, Material.PARROT_SPAWN_EGG);
mobList.put(EntityType.SQUID, Material.SQUID_SPAWN_EGG);
mobList.put(EntityType.DOLPHIN, Material.DOLPHIN_SPAWN_EGG);
mobList.put(EntityType.TRADER_LLAMA, Material.TRADER_LLAMA_SPAWN_EGG);
mobList.put(EntityType.PANDA, Material.PANDA_SPAWN_EGG);
mobList.put(EntityType.FOX, Material.FOX_SPAWN_EGG);
mobList.put(EntityType.BEE, Material.BEE_SPAWN_EGG);
mobList.put(EntityType.PIGLIN, Material.PIGLIN_SPAWN_EGG);
mobList.put(EntityType.ZOGLIN, Material.ZOGLIN_SPAWN_EGG);
mobList.put(EntityType.COD, Material.COD_SPAWN_EGG);
mobList.put(EntityType.SALMON, Material.SALMON_SPAWN_EGG);
mobList.put(EntityType.PUFFERFISH, Material.PUFFERFISH_SPAWN_EGG);
mobList.put(EntityType.TROPICAL_FISH, Material.TROPICAL_FISH_SPAWN_EGG);
mobList.put(EntityType.STRIDER, Material.STRIDER_SPAWN_EGG);
mobList.put(EntityType.BLAZE, Material.BLAZE_SPAWN_EGG);
mobList.put(EntityType.MAGMA_CUBE, Material.MAGMA_CUBE_SPAWN_EGG);
mobList.put(EntityType.SLIME, Material.SLIME_SPAWN_EGG);
mobList.put(EntityType.GHAST, Material.GHAST_SPAWN_EGG);
mobList.put(EntityType.WITHER_SKELETON, Material.WITHER_SKELETON_SPAWN_EGG);
mobList.put(EntityType.HOGLIN, Material.HOGLIN_SPAWN_EGG);
mobList.put(EntityType.PILLAGER, Material.PILLAGER_SPAWN_EGG);
mobList.put(EntityType.VEX, Material.VEX_SPAWN_EGG);
mobList.put(EntityType.EVOKER, Material.EVOKER_SPAWN_EGG);
mobList.put(EntityType.RAVAGER, Material.RAVAGER_SPAWN_EGG);
mobList.put(EntityType.SNIFFER, Material.SNIFFER_SPAWN_EGG);
mobList.put(EntityType.CAVE_SPIDER, Material.CAVE_SPIDER_SPAWN_EGG);
ItemStack blockItemStack = new ItemStack(block.getType());
ItemStack additionalItem = null;
if (block.getState() instanceof CreatureSpawner spawner) {
if ( spawner.getSpawnedType() != null ) {
additionalItem = new ItemStack(mobList.get(spawner.getSpawnedType()));
}
}
return new ItemStack[]{
blockItemStack,
additionalItem
};
}
@EventHandler
public void blockBreakEvent(BlockBreakEvent event) {
Player player = event.getPlayer();
if ( player.getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH) ) {
Block block = event.getBlock();
Material[] allowedMaterials = {
Material.SPAWNER,
Material.BUDDING_AMETHYST
};
if (Arrays.asList(allowedMaterials).contains(block.getType())) {
Location blockLocation = block.getLocation();
if (blockLocation.getWorld() != null) {
if ( block.getType() == Material.SPAWNER ) {
event.setExpToDrop(0);
}
ItemStack[] itemStacks = getItemStack(block);
for (ItemStack itemStack : itemStacks) {
if (itemStack != null) {
blockLocation.getWorld().dropItemNaturally(blockLocation, itemStack);
}
}
}
}
}
}
}

View File

@ -0,0 +1,19 @@
package dev.xoy.silkblocks;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
public class SilkBlocks extends JavaPlugin {
@Override
public void onEnable() {
Bukkit.getLogger().info(ChatColor.GREEN + "[" + this.getName() + "] enabled!");
Bukkit.getPluginManager().registerEvents(new BlockListener(), this);
}
@Override
public void onDisable() {
Bukkit.getLogger().info(ChatColor.RED + "[" + this.getName() + "] disabled!");
}
}

View File

@ -0,0 +1,6 @@
name: SilkBlocks
version: 0.1
author: xoydev
main: dev.xoy.silkblocks.SilkBlocks
api-version: 1.20