Merge pull request #44 from RedstonerServer/dev
Removed `/anvil` and Added new Mods for BlockPlaceMods
This commit is contained in:
@@ -8,7 +8,8 @@ import com.redstoner.coremods.moduleLoader.ModuleLoader;
|
|||||||
import com.redstoner.misc.CommandHolderType;
|
import com.redstoner.misc.CommandHolderType;
|
||||||
import com.redstoner.misc.Main;
|
import com.redstoner.misc.Main;
|
||||||
import com.redstoner.modules.Module;
|
import com.redstoner.modules.Module;
|
||||||
import com.redstoner.modules.blockplacemods.mods.ModBetterDirectional;
|
import com.redstoner.modules.blockplacemods.mods.ModLogDirectional;
|
||||||
|
import com.redstoner.modules.blockplacemods.mods.ModPlayerDirectional;
|
||||||
import com.redstoner.modules.blockplacemods.mods.ModCauldron;
|
import com.redstoner.modules.blockplacemods.mods.ModCauldron;
|
||||||
import com.redstoner.modules.blockplacemods.mods.ModSlab;
|
import com.redstoner.modules.blockplacemods.mods.ModSlab;
|
||||||
import com.redstoner.modules.datamanager.DataManager;
|
import com.redstoner.modules.datamanager.DataManager;
|
||||||
@@ -27,7 +28,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
@Commands (CommandHolderType.File)
|
@Commands (CommandHolderType.File)
|
||||||
@AutoRegisterListener
|
@AutoRegisterListener
|
||||||
@Version (major = 4, minor = 1, revision = 1, compatible = 4)
|
@Version (major = 5, minor = 2, revision = 0, compatible = 4)
|
||||||
public class BlockPlaceMods implements Module, Listener {
|
public class BlockPlaceMods implements Module, Listener {
|
||||||
private static final Map<String, BlockPlaceMod> mods = new HashMap<>();
|
private static final Map<String, BlockPlaceMod> mods = new HashMap<>();
|
||||||
private static final List<BlockPlaceMod> enabledMods = new ArrayList<>();
|
private static final List<BlockPlaceMod> enabledMods = new ArrayList<>();
|
||||||
@@ -35,8 +36,10 @@ public class BlockPlaceMods implements Module, Listener {
|
|||||||
private final BlockPlaceMod[] modsToRegister = {
|
private final BlockPlaceMod[] modsToRegister = {
|
||||||
new ModCauldron(),
|
new ModCauldron(),
|
||||||
new ModSlab(),
|
new ModSlab(),
|
||||||
new ModBetterDirectional("Observer", Material.OBSERVER, "observers", false),
|
new ModLogDirectional("Observer", Material.OBSERVER, "observers", false),
|
||||||
new ModBetterDirectional("Piston", Material.PISTON, "pistons", false),
|
new ModLogDirectional("Piston", Material.PISTON, "pistons", false),
|
||||||
|
new ModPlayerDirectional("Repeater", Material.REPEATER, "repeaters", true, true, false),
|
||||||
|
new ModPlayerDirectional("Comparator", Material.COMPARATOR, "comparators", true, true, false),
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
|
||||||
public class ModBetterDirectional extends BlockPlaceMod {
|
public class ModLogDirectional extends BlockPlaceMod {
|
||||||
private static final BlockFace[][][] dirMap = {
|
private static final BlockFace[][][] dirMap = {
|
||||||
{
|
{
|
||||||
{ null, null, null },
|
{ null, null, null },
|
||||||
@@ -33,14 +33,14 @@ public class ModBetterDirectional extends BlockPlaceMod {
|
|||||||
|
|
||||||
private final Material material;
|
private final Material material;
|
||||||
|
|
||||||
public ModBetterDirectional(String name, Material material, String materialPlural, boolean enabledByDefault) {
|
public ModLogDirectional(String name, Material material, String materialPlural, boolean enabledByDefault) {
|
||||||
super(
|
super(
|
||||||
name,
|
name,
|
||||||
"With this mod enabled " + materialPlural + " are placed with the bottom on the block clicked.",
|
"With this mod enabled " + materialPlural + " are placed with the bottom on the block clicked.",
|
||||||
ModType.STATELESS,
|
ModType.STATELESS,
|
||||||
null,
|
null,
|
||||||
enabledByDefault,
|
enabledByDefault,
|
||||||
"BetterDirectional" + material.name().toLowerCase()
|
"LogDirectional" + material.name().toLowerCase()
|
||||||
);
|
);
|
||||||
|
|
||||||
this.material = material;
|
this.material = material;
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package com.redstoner.modules.blockplacemods.mods;
|
||||||
|
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.block.data.Directional;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
|
||||||
|
import com.redstoner.modules.blockplacemods.BlockPlaceMod;
|
||||||
|
import com.redstoner.modules.blockplacemods.ModType;
|
||||||
|
|
||||||
|
public class ModPlayerDirectional extends BlockPlaceMod{
|
||||||
|
|
||||||
|
private final Material material;
|
||||||
|
private final boolean towards;
|
||||||
|
|
||||||
|
public ModPlayerDirectional(String name, Material material, String materialPlural, boolean towards, boolean invertLogic, boolean enabledByDefault) {
|
||||||
|
super(
|
||||||
|
name,
|
||||||
|
"With this mod enabled " + materialPlural + " are placed facing " + (towards? "towards you." : "away from you."),
|
||||||
|
ModType.STATELESS, null,
|
||||||
|
enabledByDefault,
|
||||||
|
"PlayerDirectional" + material.name().toLowerCase()
|
||||||
|
);
|
||||||
|
|
||||||
|
this.material = material;
|
||||||
|
this.towards = invertLogic? !towards : towards;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
Block block = event.getBlock();
|
||||||
|
|
||||||
|
if (block.getType() == material && !player.isSneaking()
|
||||||
|
&& hasEnabled(player) && player.getGameMode() == GameMode.CREATIVE) {
|
||||||
|
|
||||||
|
Directional data = (Directional) block.getBlockData();
|
||||||
|
|
||||||
|
data.setFacing(getNewDirection(player, towards));
|
||||||
|
block.setBlockData(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private BlockFace getNewDirection(Player player, boolean towards) {
|
||||||
|
double rotation = normalAngle(player.getLocation().getYaw());
|
||||||
|
|
||||||
|
if (rotation >= 315 || rotation < 45) // South
|
||||||
|
return towards? BlockFace.NORTH : BlockFace.SOUTH;
|
||||||
|
if (rotation >= 45 && rotation < 135) // West
|
||||||
|
return towards? BlockFace.EAST : BlockFace.WEST;
|
||||||
|
if (rotation >= 135 && rotation < 225) // North
|
||||||
|
return towards? BlockFace.SOUTH : BlockFace.NORTH;
|
||||||
|
else // East
|
||||||
|
return towards? BlockFace.WEST : BlockFace.EAST;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double normalAngle(double angle) {
|
||||||
|
return (angle %= 360) >= 0 ? angle : (angle + 360);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,11 +1,3 @@
|
|||||||
command anvil {
|
|
||||||
perm utils.naming;
|
|
||||||
[empty] {
|
|
||||||
run anvil;
|
|
||||||
type player;
|
|
||||||
help Opens anvil GUI.;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
command name {
|
command name {
|
||||||
perm utils.naming;
|
perm utils.naming;
|
||||||
[string:name...] {
|
[string:name...] {
|
||||||
|
|||||||
@@ -3,12 +3,9 @@ package com.redstoner.modules.naming;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.InventoryType;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
@@ -21,17 +18,9 @@ import com.redstoner.modules.Module;
|
|||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
|
||||||
@Commands(CommandHolderType.File)
|
@Commands(CommandHolderType.File)
|
||||||
@Version(major = 5, minor = 1, revision = 0, compatible = 4)
|
@Version(major = 5, minor = 2, revision = 0, compatible = 4)
|
||||||
public class Naming implements Module
|
public class Naming implements Module
|
||||||
{
|
{
|
||||||
@Command(hook = "anvil")
|
|
||||||
public void anvil(CommandSender sender)
|
|
||||||
{
|
|
||||||
Player player = (Player) sender;
|
|
||||||
Inventory inv = Bukkit.getServer().createInventory(player, InventoryType.ANVIL);
|
|
||||||
player.openInventory(inv);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Command(hook = "name")
|
@Command(hook = "name")
|
||||||
public void name(CommandSender sender, String name)
|
public void name(CommandSender sender, String name)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user