feat: player only pressure plates
All checks were successful
Gitea Actions Demo / Build-Gradle (push) Successful in 3m26s

This commit is contained in:
Your Name
2025-07-30 23:34:33 +02:00
parent 9c71b6db25
commit 795bb486d1
6 changed files with 172 additions and 16 deletions

1
.gitignore vendored
View File

@@ -18,7 +18,6 @@ out/
# OS-specific files
.DS_Store
./*/.DS_Store
Thumbs.db
# Environment

View File

@@ -15,6 +15,6 @@ TO RELEASE: Autocrafter
TO RELEASE: jukeboxes können mit Redstone gesteuert werden + crafted music
TO RELEASE: Squids won't spawn + GLOWSTONE DUST für Rahmen
TO RELEASE: MUTE FUNCTION FOR TAGGED MOBS
r3load command?
TO RELEASE: SHIFT RIGHT CLICK INV SORT
TO RELEASE: right click with bell on villager folow
TO RELEASE: right click with bell on villager folow
TO RELEASE: player pressure plates

View File

@@ -169,6 +169,8 @@ public NamespacedKey nskHopper;
main = this;
PlayerPressurePlates.registerCustomRecipe();
PlayerPressurePlates.loadPlates();
BetterHoppers.restoreAllDisplays();
nskPokeball = new NamespacedKey(this, "R3SPokeball");
nskUsedPokeball = new NamespacedKey(this, "R3SUsedPokeball");
@@ -586,6 +588,7 @@ for (Player p : Bukkit.getOnlinePlayers()) {
pM.registerEvents(new BetterHoppers(), this);
pM.registerEvents(new DailyQuests(), this);
pM.registerEvents(new Pokeballs(), this);
pM.registerEvents(new PlayerPressurePlates(), this);
getCommand("test").setExecutor(new EnvironmentExCommands());
getCommand("y").setExecutor(new EnvironmentExCommands());
getCommand("n").setExecutor(new EnvironmentExCommands());
@@ -594,7 +597,6 @@ for (Player p : Bukkit.getOnlinePlayers()) {
getCommand("pin").setExecutor(new EnvironmentExCommands());
getCommand("pin").setTabCompleter(new PinFeature());
getCommand("ignorevote").setExecutor(new EnvironmentExCommands());
getCommand("r3load").setExecutor(new EnvironmentExCommands());
getCommand("quest").setExecutor(new EnvironmentExCommands());
}

View File

@@ -236,11 +236,6 @@ public class EnvironmentExCommands implements CommandExecutor, Listener {
Player p = (Player) sender;
p.playerListName(App.helper.R3SMessage(Type.ERROR, "[AFK] " + p.getName()));
}
if (label.equalsIgnoreCase("r3load")) {
Bukkit.reload();
Player p = (Player) sender;
p.sendMessage(helper.R3SMessage(Type.SUCCESS, "Plugins neu geladen!"));
}
if (label.equalsIgnoreCase("ignorevote")) {
if (args.length != 1) {
@@ -557,10 +552,6 @@ public class EnvironmentExCommands implements CommandExecutor, Listener {
App.main.getLogger().info("Die angegebene UUID ist inkorrekt!");
}
}
if (label.equalsIgnoreCase("r3load")) {
Bukkit.reload();
App.main.getLogger().info("Plugins neu geladen!");
}
}
return true;
}

View File

@@ -0,0 +1,167 @@
//GPT'd
package de.hessj.environmentex;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextDecoration;
public class PlayerPressurePlates implements Listener {
private static NamespacedKey plateKey = new NamespacedKey(App.main, "player_only_plate");
private final static Set<Location> plateLocations = new HashSet<>();
private final static File dataFile = new File(App.main.getDataFolder(), "plates.yml");
private final static FileConfiguration config = YamlConfiguration.loadConfiguration(dataFile);
private boolean isPressurePlate(Material material) {
return material.name().endsWith("_PRESSURE_PLATE");
}
@EventHandler
public void onPrepareCraft(PrepareItemCraftEvent event) {
ItemStack result = event.getRecipe() != null ? event.getRecipe().getResult() : null;
if (result == null || !isPressurePlate(result.getType()))
return;
ItemStack newResult = result.clone();
CraftingInventory inv = event.getInventory();
ItemStack[] matrix = inv.getMatrix();
boolean isPlate = false, hasIron = false;
for (ItemStack item : matrix) {
if (item == null)
continue;
if (isPressurePlate(item.getType()))
isPlate = true;
if (item.getType() == Material.IRON_INGOT)
hasIron = true;
Material mat = item.getType();
if (isPressurePlate(mat)) {
newResult = new ItemStack(mat);
}
}
if (isPlate && hasIron) {
ItemMeta meta = newResult.getItemMeta();
if (meta != null) {
meta.displayName(Component.text("Spieler Druckplatte").decoration(TextDecoration.ITALIC, false));
meta.getPersistentDataContainer().set(plateKey, PersistentDataType.BYTE, (byte) 1);
newResult.setItemMeta(meta);
inv.setResult(newResult);
}
}
}
public static void registerCustomRecipe() {
Material[] plateTypes = {
Material.OAK_PRESSURE_PLATE,
Material.BIRCH_PRESSURE_PLATE,
Material.SPRUCE_PRESSURE_PLATE,
Material.JUNGLE_PRESSURE_PLATE,
Material.ACACIA_PRESSURE_PLATE,
Material.DARK_OAK_PRESSURE_PLATE,
Material.CRIMSON_PRESSURE_PLATE,
Material.WARPED_PRESSURE_PLATE,
Material.POLISHED_BLACKSTONE_PRESSURE_PLATE,
Material.MANGROVE_PRESSURE_PLATE,
Material.CHERRY_PRESSURE_PLATE,
Material.BAMBOO_PRESSURE_PLATE,
Material.PALE_OAK_PRESSURE_PLATE,
Material.STONE_PRESSURE_PLATE
};
for (Material plateType : plateTypes) {
ItemStack result = new ItemStack(plateType);
ItemMeta meta = result.getItemMeta();
meta.displayName(Component.text("Spieler Druckplatte").decoration(TextDecoration.ITALIC, false));
meta.getPersistentDataContainer().set(plateKey, PersistentDataType.BYTE, (byte) 1);
result.setItemMeta(meta);
ShapelessRecipe recipe = new ShapelessRecipe(
new NamespacedKey(App.main, "player_only_" + plateType.name().toLowerCase() + "_recipe"), result);
recipe.addIngredient(new ItemStack(Material.IRON_INGOT, 1));
recipe.addIngredient(plateType);
recipe.setGroup("player_only_plate");
Bukkit.addRecipe(recipe);
App.main.recipeKeys.add(recipe.getKey());
}
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
if (!isPressurePlate(event.getBlockPlaced().getType()))
return;
ItemMeta meta = event.getItemInHand().getItemMeta();
if (meta == null)
return;
if (meta.getPersistentDataContainer().has(plateKey, PersistentDataType.BYTE)) {
plateLocations.add(event.getBlockPlaced().getLocation());
event.getPlayer().sendMessage("§aPlayer-only pressure plate placed.");
savePlates();
}
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
Location loc = block.getLocation();
if (isPressurePlate(block.getType()) && plateLocations.contains(loc)) {
plateLocations.remove(loc);
savePlates();
}
}
@EventHandler
public void onEntityInteract(EntityInteractEvent event) {
Block block = event.getBlock();
if (isPressurePlate(block.getType()) && plateLocations.contains(block.getLocation())) {
if (!(event.getEntity() instanceof Player)) {
event.setCancelled(true);
}
}
}
public void savePlates() {
FileConfiguration out = new YamlConfiguration();
int i = 0;
for (Location loc : plateLocations) {
out.set("plate" + (i++), loc.serialize());
}
try {
out.save(dataFile);
} catch (IOException e) {
e.printStackTrace();
}
}
// Load plate locations from YAML
public static void loadPlates() {
for (String key : config.getKeys(false)) {
Location loc = Location.deserialize(config.getConfigurationSection(key).getValues(false));
plateLocations.add(loc);
}
}
}

View File

@@ -25,9 +25,6 @@ commands:
ignorevote:
description: Setzt den Ignorevote Status
usage: /<command>
r3load:
description: ----
usage: /<command>
quest:
description: Zeigt die heutigen Quests an
usage: /<command>