NEWS: Welcome to my new homepage! <3

Fixed chair and added crop harvest - poppy - A feature-rich Minecraft plugin which enhances gaming experience

poppy

A feature-rich Minecraft plugin which enhances gaming experience
git clone git://192.168.2.2/poppy
Log | Files | Refs | README

commit 0741c2335e78fa324a74ddad4c3834e7a90faf44
parent 25fffa973a7efd260709065feac86e9f08deab67
Author: chunksize <reisingerluca@gmail.com>
Date:   Fri, 30 Dec 2022 18:22:29 +0100

Fixed chair and added crop harvest

Diffstat:
Dsrc/de/typable/minecrafthub/Config.java | 40----------------------------------------
Msrc/de/typable/minecrafthub/Main.java | 7-------
Msrc/de/typable/minecrafthub/event/ChairListener.java | 10++++++++++
Msrc/de/typable/minecrafthub/event/EventListener.java | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/de/typable/minecrafthub/game/Game.java | 86-------------------------------------------------------------------------------
Dsrc/de/typable/minecrafthub/game/PlayerState.java | 133-------------------------------------------------------------------------------
Dsrc/de/typable/minecrafthub/game/kit/KitGame.java | 59-----------------------------------------------------------
Msrc/de/typable/minecrafthub/util/Util.java | 5+++++
8 files changed, 82 insertions(+), 325 deletions(-)

diff --git a/src/de/typable/minecrafthub/Config.java b/src/de/typable/minecrafthub/Config.java @@ -1,40 +0,0 @@ -package de.typable.minecrafthub; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; - -import com.google.gson.Gson; - - -public class Config -{ - private static final Gson gson = new Gson(); - - public static Config open(String path) - { - File file = new File(path); - - try - { - if(!file.exists()) - { - file.createNewFile(); - } - - String content = Files.readString(Paths.get(path)); - - if(content != null) - { - // TODO: convert string to json object - } - } - catch(IOException ex) - { - ex.printStackTrace(); - } - - return new Config(); - } -} diff --git a/src/de/typable/minecrafthub/Main.java b/src/de/typable/minecrafthub/Main.java @@ -30,7 +30,6 @@ import de.typable.minecrafthub.event.DoubleDoorListener; import de.typable.minecrafthub.event.EventListener; import de.typable.minecrafthub.event.LeavesDecayListener; import de.typable.minecrafthub.event.StandbyListener; -import de.typable.minecrafthub.game.kit.KitGame; import de.typable.minecrafthub.util.Util; @@ -44,8 +43,6 @@ public class Main extends JavaPlugin private LeavesDecayListener leavesDecayListener; private EventListener eventListener; - private KitGame kitGame; - private Plugin plugin; private BukkitTask task; @@ -73,10 +70,6 @@ public class Main extends JavaPlugin eventListener = new EventListener(); pluginManager.registerEvents(eventListener, this); - - kitGame = new KitGame(); - this.getCommand("kit").setExecutor(kitGame); - pluginManager.registerEvents(kitGame, this); task = Bukkit.getScheduler().runTaskAsynchronously(this, new Runnable() { diff --git a/src/de/typable/minecrafthub/event/ChairListener.java b/src/de/typable/minecrafthub/event/ChairListener.java @@ -18,6 +18,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.util.Vector; import org.spigotmc.event.entity.EntityDismountEvent; import de.typable.minecrafthub.util.Util; @@ -112,6 +113,15 @@ public class ChairListener implements Listener } } + Location location = entity.getLocation(); + location.add(0, 1, 0); + + for(Entity passenger : entity.getPassengers()) { + location.setPitch(passenger.getLocation().getPitch()); + location.setYaw(passenger.getLocation().getYaw()); + passenger.teleport(location); + } + entity.remove(); } } diff --git a/src/de/typable/minecrafthub/event/EventListener.java b/src/de/typable/minecrafthub/event/EventListener.java @@ -2,6 +2,11 @@ package de.typable.minecrafthub.event; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.Ageable; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Directional; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -15,16 +20,22 @@ import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import de.typable.minecrafthub.util.Util; + public class EventListener implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { + + Player player = event.getPlayer(); + if(event.getAction() == Action.PHYSICAL) { if(event.getClickedBlock() != null) @@ -35,6 +46,62 @@ public class EventListener implements Listener } } } + + // farming with right click + + EquipmentSlot equip = event.getHand(); + if(equip.equals(EquipmentSlot.HAND)) { + + if(event.getAction() == Action.RIGHT_CLICK_BLOCK) + { + Block block = event.getClickedBlock(); + + if(block == null) + { + return; + } + + Material material = block.getType(); + + if(player.isSneaking()) + { + return; + } + + BlockData blockdata = block.getBlockData(); + + if(blockdata instanceof Ageable) + { + + Ageable ageable = (Ageable) blockdata; + + if(Util.isFarmable(material) && ageable.getAge() == ageable.getMaximumAge()) + { + + if(blockdata instanceof Directional) + { + Directional directional = (Directional) blockdata; + BlockFace blockface = directional.getFacing(); + + block.breakNaturally(player.getItemInUse()); + block.setType(material); + directional = (Directional) blockdata; + ageable.setAge(0); + directional.setFacing(blockface); + block.setBlockData(blockdata); + } + else + { + block.breakNaturally(player.getItemInUse()); + block.setType(material); + } + + } + + } + } + + } } @EventHandler diff --git a/src/de/typable/minecrafthub/game/Game.java b/src/de/typable/minecrafthub/game/Game.java @@ -1,86 +0,0 @@ -package de.typable.minecrafthub.game; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; - -import org.bukkit.command.CommandExecutor; -import org.bukkit.entity.Player; -import org.bukkit.event.Listener; - -import de.typable.minecrafthub.Config; -import de.typable.minecrafthub.constant.DefaultConstants; - -public abstract class Game implements CommandExecutor, Listener -{ - private Map<Player, PlayerState> players; - private Config config; - - public Game() - { - players = new HashMap<>(); - } - - public void join(Player player) - { - if(players.containsKey(player)) - { - player.sendMessage(DefaultConstants.Messages.ALREADY_INGAME); - - return; - } - - players.put(player, PlayerState.of(player)); - } - - public void leave(Player player) - { - PlayerState playerState = players.get(player); - - if(playerState == null) - { - player.sendMessage(DefaultConstants.Messages.NOT_INGAME); - - return; - } - - playerState.apply(player); - players.remove(player); - } - - public void leaveAll() - { - Iterator<Entry<Player, PlayerState>> iterator = players.entrySet().iterator(); - - while(iterator.hasNext()) - { - Entry<Player, PlayerState> entry = iterator.next(); - Player player = entry.getKey(); - PlayerState playerState = entry.getValue(); - - playerState.apply(player); - iterator.remove(); - } - } - - public boolean isIngame(Player player) - { - return player != null && players.containsKey(player); - } - - public Map<Player, PlayerState> getPlayers() - { - return players; - } - - public void setConfig(Config config) - { - this.config = config; - } - - public Config getConfig() - { - return config; - } -} diff --git a/src/de/typable/minecrafthub/game/PlayerState.java b/src/de/typable/minecrafthub/game/PlayerState.java @@ -1,133 +0,0 @@ -package de.typable.minecrafthub.game; - -import java.util.UUID; - -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public class PlayerState -{ - private UUID uuid; - private Double health; - private Integer foodLevel; - private Integer level; - private Float exp; - private Location location; - private GameMode gameMode; - private ItemStack[] equipment; - - public static PlayerState of(Player player) - { - PlayerState playerState = new PlayerState(); - - playerState.setUUID(player.getUniqueId()); - playerState.setHealth(player.getHealth()); - playerState.setFoodLevel(player.getFoodLevel()); - playerState.setLevel(player.getLevel()); - playerState.setExp(player.getExp()); - playerState.setLocation(player.getLocation()); - playerState.setGameMode(player.getGameMode()); - playerState.setEquipment(player.getInventory().getContents()); - - return playerState; - } - - public void apply(Player player) - { - if(!player.getUniqueId().equals(uuid)) - { - throw new IllegalArgumentException("Only the player with the same UUID as the state can recieve it!"); - } - - player.setHealth(health); - player.setFoodLevel(foodLevel); - player.setLevel(level); - player.setExp(exp); - player.teleport(location); - player.setGameMode(gameMode); - player.getInventory().setContents(equipment); - // equipment - } - - public UUID getUUID() - { - return uuid; - } - - public void setUUID(UUID uuid) - { - this.uuid = uuid; - } - - public Double getHealth() - { - return health; - } - - public void setHealth(Double health) - { - this.health = health; - } - - public Integer getFoodLevel() - { - return foodLevel; - } - - public void setFoodLevel(Integer foodLevel) - { - this.foodLevel = foodLevel; - } - - public Integer getLevel() - { - return level; - } - - public void setLevel(Integer level) - { - this.level = level; - } - - public Float getExp() - { - return exp; - } - - public void setExp(Float exp) - { - this.exp = exp; - } - - public Location getLocation() - { - return location; - } - - public void setLocation(Location location) - { - this.location = location; - } - - public GameMode getGameMode() - { - return gameMode; - } - - public void setGameMode(GameMode gameMode) - { - this.gameMode = gameMode; - } - - public ItemStack[] getEquipment() - { - return equipment; - } - - public void setEquipment(ItemStack[] equipment) - { - this.equipment = equipment; - } -} diff --git a/src/de/typable/minecrafthub/game/kit/KitGame.java b/src/de/typable/minecrafthub/game/kit/KitGame.java @@ -1,59 +0,0 @@ -package de.typable.minecrafthub.game.kit; - -import org.bukkit.GameMode; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.block.BlockBreakEvent; - -import de.typable.minecrafthub.game.Game; - -public class KitGame extends Game -{ - public KitGame() - { - super(); - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) - { - if(sender instanceof Player) - { - Player player = (Player) sender; - - if(args.length > 0) - { - if(args[0].equals("join")) - { - join(player); - } - - if(args[0].equals("leave")) - { - leave(player); - } - } - } - - return false; - } - - @Override - public void join(Player player) - { - super.join(player); - player.setGameMode(GameMode.SURVIVAL); - player.getInventory().clear(); - } - - @EventHandler - public void onBlockBreak(BlockBreakEvent event) - { - if(isIngame(event.getPlayer())) - { - event.setCancelled(true); - } - } -} diff --git a/src/de/typable/minecrafthub/util/Util.java b/src/de/typable/minecrafthub/util/Util.java @@ -132,4 +132,9 @@ public class Util { return material == Material.AIR || material == Material.CAVE_AIR || material == Material.VOID_AIR; } + + public static boolean isFarmable(Material material) + { + return material == Material.WHEAT || material == Material.CARROTS || material == Material.POTATOES || material == Material.BEETROOTS || material == Material.NETHER_WART || material == Material.COCOA; + } }