commit 97e1405fc6fa1437434a5a819ac7140909109a7e
parent 0741c2335e78fa324a74ddad4c3834e7a90faf44
Author: chunksize <reisingerluca@gmail.com>
Date: Tue, 3 Jan 2023 14:52:12 +0100
Added spawn and invsee command
Diffstat:
5 files changed, 104 insertions(+), 6 deletions(-)
diff --git a/res/plugin.yml b/res/plugin.yml
@@ -12,4 +12,8 @@ commands:
usage: /standby <true, false>
kit:
world:
- usage: /world <name>
-\ No newline at end of file
+ usage: /world <name>
+ spawn:
+ usage: /spawn
+ invsee:
+ usage: /invsee <name> <enderchest>
+\ No newline at end of file
diff --git a/src/de/typable/minecrafthub/Main.java b/src/de/typable/minecrafthub/Main.java
@@ -9,6 +9,7 @@ import java.net.Socket;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
+import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.WorldCreator;
@@ -18,6 +19,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
+import org.bukkit.material.Tree;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
@@ -45,6 +47,11 @@ public class Main extends JavaPlugin
private Plugin plugin;
private BukkitTask task;
+
+ private static final int BLOCKS_PER_CHUNK = 16;
+ private static final int CHUNKS_PER_EMERALD = 25;
+ private static final int MIN_FEE = 1;
+ private static final int MAX_FEE = 64;
@Override
public void onEnable()
@@ -258,6 +265,67 @@ public class Main extends JavaPlugin
player.teleport(world.getSpawnLocation());
}
+
+ if(label.equals("spawn"))
+ {
+ ItemStack item = player.getInventory().getItemInMainHand();
+
+ Location locationSpawn = Bukkit.getWorld("world").getSpawnLocation();
+ Location locationPlayer = player.getLocation();
+
+ Double distance = locationPlayer.distance(locationSpawn);
+
+ int fee = (int) Math.floor(distance / (BLOCKS_PER_CHUNK * CHUNKS_PER_EMERALD));
+
+ if(fee < MIN_FEE)
+ {
+ fee = MIN_FEE;
+ }
+
+ if(fee > MAX_FEE)
+ {
+ fee = MAX_FEE;
+ }
+
+ if(item.getType() == Material.EMERALD && item.getAmount() >= fee)
+ {
+
+ item.setAmount(item.getAmount() - fee);
+ player.teleport(locationSpawn);
+ }
+ else
+ {
+ player.sendMessage(ChatColor.RED + "Not enough emeralds to teleport! You need " + fee + " emerald(s) in your main hand.");
+ }
+ }
+
+ if(label.equals("invsee"))
+ {
+ if(args.length == 0) {
+ return false;
+ }
+
+ if(Bukkit.getPlayer(args[0]) == null)
+ {
+ player.sendMessage(ChatColor.RED + "Player not found!");
+ return true;
+ }
+
+ if(!player.isOp())
+ {
+ player.sendMessage(DefaultConstants.Messages.NOT_ENOUGH_PERMISSION);
+ return true;
+ }
+
+ Player target = Bukkit.getPlayer(args[0]);
+
+ player.openInventory(target.getInventory());
+
+ if(args.length == 1 && args[1].toLowerCase() == "enderchest")
+ {
+ player.openInventory(target.getEnderChest());
+ }
+ }
}
return true;
diff --git a/src/de/typable/minecrafthub/event/EventListener.java b/src/de/typable/minecrafthub/event/EventListener.java
@@ -50,7 +50,8 @@ public class EventListener implements Listener
// farming with right click
EquipmentSlot equip = event.getHand();
- if(equip.equals(EquipmentSlot.HAND)) {
+ if(equip.equals(EquipmentSlot.HAND))
+ {
if(event.getAction() == Action.RIGHT_CLICK_BLOCK)
{
@@ -78,6 +79,8 @@ public class EventListener implements Listener
if(Util.isFarmable(material) && ageable.getAge() == ageable.getMaximumAge())
{
+ event.setCancelled(true);
+
if(blockdata instanceof Directional)
{
Directional directional = (Directional) blockdata;
@@ -92,15 +95,18 @@ public class EventListener implements Listener
}
else
{
+
block.breakNaturally(player.getItemInUse());
block.setType(material);
}
-
}
+ }
+ if(material == Material.MELON && Util.hasStem(block) || material == Material.PUMPKIN && Util.hasStem(block))
+ {
+ block.breakNaturally(player.getInventory().getItemInMainHand());
}
}
-
}
}
diff --git a/src/de/typable/minecrafthub/event/LeavesDecayListener.java b/src/de/typable/minecrafthub/event/LeavesDecayListener.java
@@ -17,7 +17,7 @@ import org.bukkit.plugin.Plugin;
public class LeavesDecayListener implements Listener
{
- private static final int DELAY = 50;
+ private static final int DELAY = 25;
private static final List<BlockFace> NEIGHBORS = Arrays.asList(
BlockFace.UP,
BlockFace.NORTH,
diff --git a/src/de/typable/minecrafthub/util/Util.java b/src/de/typable/minecrafthub/util/Util.java
@@ -1,7 +1,11 @@
package de.typable.minecrafthub.util;
+import javax.swing.text.Position;
+
import org.bukkit.Bukkit;
+import org.bukkit.Location;
import org.bukkit.Material;
+import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@@ -137,4 +141,20 @@ public class Util
{
return material == Material.WHEAT || material == Material.CARROTS || material == Material.POTATOES || material == Material.BEETROOTS || material == Material.NETHER_WART || material == Material.COCOA;
}
+
+ public static boolean isStem(Material material)
+ {
+ return material == Material.ATTACHED_PUMPKIN_STEM || material == Material.ATTACHED_MELON_STEM;
+ }
+
+ public static boolean hasStem(Block block)
+ {
+ Location blockLocation = block.getLocation();
+ Material blockNorth = blockLocation.clone().add(0, 0, -1).getBlock().getType();
+ Material blockEast = blockLocation.clone().add(1, 0, 0).getBlock().getType();
+ Material blockSouth = blockLocation.clone().add(0, 0, 1).getBlock().getType();
+ Material blockWest = blockLocation.clone().add(-1, 0, 0).getBlock().getType();
+
+ return isStem(blockNorth) || isStem(blockEast) || isStem(blockSouth) || isStem(blockWest);
+ }
}