diff --git a/.gitignore b/.gitignore index 43eda98..50309d8 100755 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,6 @@ out/ # OS-specific files .DS_Store -./*/.DS_Store Thumbs.db # Environment diff --git a/README.md b/README.md index a74425e..205a44d 100755 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file +TO RELEASE: right click with bell on villager folow +TO RELEASE: player pressure plates diff --git a/environmentex/src/main/java/de/hessj/environmentex/App.java b/environmentex/src/main/java/de/hessj/environmentex/App.java index 525a090..63da995 100755 --- a/environmentex/src/main/java/de/hessj/environmentex/App.java +++ b/environmentex/src/main/java/de/hessj/environmentex/App.java @@ -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()); } diff --git a/environmentex/src/main/java/de/hessj/environmentex/EnvironmentExCommands.java b/environmentex/src/main/java/de/hessj/environmentex/EnvironmentExCommands.java index 79fadda..19486d1 100755 --- a/environmentex/src/main/java/de/hessj/environmentex/EnvironmentExCommands.java +++ b/environmentex/src/main/java/de/hessj/environmentex/EnvironmentExCommands.java @@ -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; } diff --git a/environmentex/src/main/java/de/hessj/environmentex/PlayerPressurePlates.java b/environmentex/src/main/java/de/hessj/environmentex/PlayerPressurePlates.java new file mode 100644 index 0000000..97fbc78 --- /dev/null +++ b/environmentex/src/main/java/de/hessj/environmentex/PlayerPressurePlates.java @@ -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 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); + } + } +} diff --git a/environmentex/src/main/resources/plugin.yml b/environmentex/src/main/resources/plugin.yml index baf39f7..09287db 100755 --- a/environmentex/src/main/resources/plugin.yml +++ b/environmentex/src/main/resources/plugin.yml @@ -25,9 +25,6 @@ commands: ignorevote: description: Setzt den Ignorevote Status usage: / - r3load: - description: ---- - usage: / quest: description: Zeigt die heutigen Quests an usage: / \ No newline at end of file