General cleanup
Removing outdated comments Removing outdated annotations Adding new annotations Removing deprecation
This commit is contained in:
@@ -24,7 +24,7 @@ import com.redstoner.utils.CommandException;
|
|||||||
import com.redstoner.utils.CommandMap;
|
import com.redstoner.utils.CommandMap;
|
||||||
|
|
||||||
@AutoRegisterListener
|
@AutoRegisterListener
|
||||||
@Version(major = 3, minor = 2, revision = 4, compatible = 3)
|
@Version(major = 3, minor = 2, revision = 5, compatible = 3)
|
||||||
public final class BlockPlaceMods implements Module, Listener
|
public final class BlockPlaceMods implements Module, Listener
|
||||||
{
|
{
|
||||||
public static String PREFIX = ChatColor.GRAY + "[" + ChatColor.DARK_GREEN + "BPM" + ChatColor.GRAY + "]"
|
public static String PREFIX = ChatColor.GRAY + "[" + ChatColor.DARK_GREEN + "BPM" + ChatColor.GRAY + "]"
|
||||||
@@ -38,8 +38,6 @@ public final class BlockPlaceMods implements Module, Listener
|
|||||||
{
|
{
|
||||||
mod.registerListeners();
|
mod.registerListeners();
|
||||||
}
|
}
|
||||||
// CommandManager.registerCommand(getCommandString(), this, Main.plugin);
|
|
||||||
// Sorry but this stuff isn't working for me. Not gonna spend more time on it.
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Map<String, org.bukkit.command.Command> commandMap = CommandMap.getCommandMap();
|
Map<String, org.bukkit.command.Command> commandMap = CommandMap.getCommandMap();
|
||||||
@@ -82,19 +80,6 @@ public final class BlockPlaceMods implements Module, Listener
|
|||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @Override
|
|
||||||
* public String getCommandString() {
|
|
||||||
* return "command mod {\n" +
|
|
||||||
* "perm utils.blockplacemods.command;\n" +
|
|
||||||
* "type player;\n" +
|
|
||||||
* "[empty] {\n" +
|
|
||||||
* "run mod_empty;\n" +
|
|
||||||
* "}\n" +
|
|
||||||
* "[string:args...] {\n" +
|
|
||||||
* "run mod args;\n" +
|
|
||||||
* "}\n" +
|
|
||||||
* "}\n";
|
|
||||||
* } */
|
|
||||||
@Command(hook = "mod_empty")
|
@Command(hook = "mod_empty")
|
||||||
public void onModEmptyCommand(CommandSender sender)
|
public void onModEmptyCommand(CommandSender sender)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package com.redstoner.modules.blockplacemods.mods;
|
package com.redstoner.modules.blockplacemods.mods;
|
||||||
|
|
||||||
import com.redstoner.modules.datamanager.DataManager;
|
import java.util.Arrays;
|
||||||
import com.redstoner.utils.CommandException;
|
|
||||||
import com.redstoner.utils.ItemProperties;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
@@ -17,13 +15,16 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import com.redstoner.modules.datamanager.DataManager;
|
||||||
|
import com.redstoner.utils.CommandException;
|
||||||
|
import com.redstoner.utils.ItemProperties;
|
||||||
|
|
||||||
public class ModInventory extends ModAbstract
|
public class ModInventory extends ModAbstract
|
||||||
{
|
{
|
||||||
protected InventoryType inventoryType;
|
protected InventoryType inventoryType;
|
||||||
|
|
||||||
public ModInventory(String name, InventoryType inventoryType) {
|
public ModInventory(String name, InventoryType inventoryType)
|
||||||
|
{
|
||||||
super(name);
|
super(name);
|
||||||
this.inventoryType = inventoryType;
|
this.inventoryType = inventoryType;
|
||||||
}
|
}
|
||||||
@@ -69,7 +70,7 @@ public class ModInventory extends ModAbstract
|
|||||||
throw new CommandException("Slot number " + slot + " is negative");
|
throw new CommandException("Slot number " + slot + " is negative");
|
||||||
}
|
}
|
||||||
// Set the stored item to the item in the sender's hand
|
// Set the stored item to the item in the sender's hand
|
||||||
ItemStack item = sender.getItemInHand();
|
ItemStack item = sender.getInventory().getItemInMainHand();
|
||||||
if (item == null || item.getType() == Material.AIR || item.getAmount() == 0)
|
if (item == null || item.getType() == Material.AIR || item.getAmount() == 0)
|
||||||
{
|
{
|
||||||
// Remove the item.
|
// Remove the item.
|
||||||
@@ -125,33 +126,38 @@ public class ModInventory extends ModAbstract
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
protected ItemStack[] get(Player player)
|
protected ItemStack[] get(Player player)
|
||||||
{
|
{
|
||||||
Object obj = DataManager.getData(player.getUniqueId().toString(), "BlockPlaceMods", getName());
|
Object obj = DataManager.getData(player.getUniqueId().toString(), "BlockPlaceMods", getName());
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
return getDefault();
|
return getDefault();
|
||||||
JSONArray array = (JSONArray) obj;
|
JSONArray array = (JSONArray) obj;
|
||||||
|
|
||||||
ItemStack[] items = new ItemStack[Math.min(inventoryType.getDefaultSize(), array.size())];
|
ItemStack[] items = new ItemStack[Math.min(inventoryType.getDefaultSize(), array.size())];
|
||||||
for (int i = 0, n = items.length; i < n; i++) {
|
for (int i = 0, n = items.length; i < n; i++)
|
||||||
|
{
|
||||||
Object obj2 = array.get(i);
|
Object obj2 = array.get(i);
|
||||||
if (obj2 instanceof JSONObject) { // if null, items[i] remains null
|
if (obj2 instanceof JSONObject)
|
||||||
|
{ // if null, items[i] remains null
|
||||||
items[i] = new ItemProperties().loadFrom((JSONObject) obj2).toItemStack();
|
items[i] = new ItemProperties().loadFrom((JSONObject) obj2).toItemStack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void set(Player player, int index, ItemStack item) {
|
protected void set(Player player, int index, ItemStack item)
|
||||||
|
{
|
||||||
ItemStack[] data = get(player);
|
ItemStack[] data = get(player);
|
||||||
if (item == null) {
|
if (item == null)
|
||||||
if (index < data.length) {
|
{
|
||||||
|
if (index < data.length)
|
||||||
|
{
|
||||||
data[index] = null;
|
data[index] = null;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
if (index >= data.length) {
|
else
|
||||||
|
{
|
||||||
|
if (index >= data.length)
|
||||||
|
{
|
||||||
data = Arrays.copyOf(data, index + 1);
|
data = Arrays.copyOf(data, index + 1);
|
||||||
}
|
}
|
||||||
data[index] = item;
|
data[index] = item;
|
||||||
@@ -159,6 +165,7 @@ public class ModInventory extends ModAbstract
|
|||||||
set(player, data);
|
set(player, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected void set(Player player, ItemStack[] data)
|
protected void set(Player player, ItemStack[] data)
|
||||||
{
|
{
|
||||||
if (highestUsedIndex(data) == -1)
|
if (highestUsedIndex(data) == -1)
|
||||||
@@ -166,7 +173,8 @@ public class ModInventory extends ModAbstract
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
JSONArray array = new JSONArray();
|
JSONArray array = new JSONArray();
|
||||||
for (int i = 0, n = highestUsedIndex(data); i < n; i++) {
|
for (int i = 0, n = highestUsedIndex(data); i < n; i++)
|
||||||
|
{
|
||||||
ItemStack item = data[i];
|
ItemStack item = data[i];
|
||||||
array.add(item == null ? null : new ItemProperties(item).toJSONObject());
|
array.add(item == null ? null : new ItemProperties(item).toJSONObject());
|
||||||
}
|
}
|
||||||
@@ -180,8 +188,8 @@ public class ModInventory extends ModAbstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack[] getDefault() {
|
public ItemStack[] getDefault()
|
||||||
|
{
|
||||||
return new ItemStack[0];
|
return new ItemStack[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
|||||||
|
|
||||||
public class ModToggledCauldron extends ModToggledAbstract
|
public class ModToggledCauldron extends ModToggledAbstract
|
||||||
{
|
{
|
||||||
|
public ModToggledCauldron()
|
||||||
public ModToggledCauldron() {
|
{
|
||||||
super("cauldron", false);
|
super("cauldron", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,6 +21,7 @@ public class ModToggledCauldron extends ModToggledAbstract
|
|||||||
return "If active, placed cauldrons are filled, and they cycle on right click";
|
return "If active, placed cauldrons are filled, and they cycle on right click";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event)
|
public void onPlayerInteract(PlayerInteractEvent event)
|
||||||
{
|
{
|
||||||
@@ -32,6 +33,7 @@ public class ModToggledCauldron extends ModToggledAbstract
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onBlockPlace(BlockPlaceEvent event)
|
public void onBlockPlace(BlockPlaceEvent event)
|
||||||
{
|
{
|
||||||
@@ -41,5 +43,4 @@ public class ModToggledCauldron extends ModToggledAbstract
|
|||||||
event.getBlock().setData((byte) 3);
|
event.getBlock().setData((byte) 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
|||||||
|
|
||||||
public class ModToggledPiston extends ModToggledAbstract
|
public class ModToggledPiston extends ModToggledAbstract
|
||||||
{
|
{
|
||||||
|
public ModToggledPiston()
|
||||||
public ModToggledPiston() {
|
{
|
||||||
super("piston", false);
|
super("piston", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,6 +22,7 @@ public class ModToggledPiston extends ModToggledAbstract
|
|||||||
return "If active, pistons face the block you place them against";
|
return "If active, pistons face the block you place them against";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onBlockPlace(BlockPlaceEvent event)
|
public void onBlockPlace(BlockPlaceEvent event)
|
||||||
{
|
{
|
||||||
@@ -59,5 +60,4 @@ public class ModToggledPiston extends ModToggledAbstract
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
|||||||
|
|
||||||
public class ModToggledStep extends ModToggledAbstract
|
public class ModToggledStep extends ModToggledAbstract
|
||||||
{
|
{
|
||||||
|
public ModToggledStep()
|
||||||
public ModToggledStep() {
|
{
|
||||||
super("step", true);
|
super("step", true);
|
||||||
getAliases().add("slab");
|
getAliases().add("slab");
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,7 @@ public class ModToggledStep extends ModToggledAbstract
|
|||||||
return "If active, placed steps will always turn upside-down";
|
return "If active, placed steps will always turn upside-down";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onBlockPlace(BlockPlaceEvent event)
|
public void onBlockPlace(BlockPlaceEvent event)
|
||||||
{
|
{
|
||||||
@@ -36,5 +37,4 @@ public class ModToggledStep extends ModToggledAbstract
|
|||||||
{
|
{
|
||||||
return block == Material.STEP || block == Material.STONE_SLAB2;
|
return block == Material.STEP || block == Material.STONE_SLAB2;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package com.redstoner.modules.blockplacemods.mods;
|
package com.redstoner.modules.blockplacemods.mods;
|
||||||
|
|
||||||
import com.redstoner.misc.Main;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -11,15 +14,14 @@ 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;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import com.redstoner.misc.Main;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class ModToggledTorch extends ModToggledAbstract
|
public class ModToggledTorch extends ModToggledAbstract
|
||||||
{
|
{
|
||||||
private final Set<Block> torchesPlaced = new HashSet<>();
|
private final Set<Block> torchesPlaced = new HashSet<>();
|
||||||
|
|
||||||
public ModToggledTorch() {
|
public ModToggledTorch()
|
||||||
|
{
|
||||||
super("torch", true);
|
super("torch", true);
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.plugin, this::updateTorches, 2, 2);
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.plugin, this::updateTorches, 2, 2);
|
||||||
}
|
}
|
||||||
@@ -44,6 +46,7 @@ public class ModToggledTorch extends ModToggledAbstract
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private boolean isAttachedToRedstoneBlock(Block block)
|
private boolean isAttachedToRedstoneBlock(Block block)
|
||||||
{
|
{
|
||||||
BlockFace towardsAgainst = getFaceTowardsBlockAgainst(block.getData());
|
BlockFace towardsAgainst = getFaceTowardsBlockAgainst(block.getData());
|
||||||
@@ -85,5 +88,4 @@ public class ModToggledTorch extends ModToggledAbstract
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,29 @@
|
|||||||
package com.redstoner.utils;
|
package com.redstoner.utils;
|
||||||
|
|
||||||
public class CommandException extends Exception {
|
public class CommandException extends Exception
|
||||||
|
{
|
||||||
public CommandException(String message, Throwable cause) {
|
private static final long serialVersionUID = -7176634557736106754L;
|
||||||
super(message, cause);
|
|
||||||
}
|
public CommandException(String message, Throwable cause)
|
||||||
|
{
|
||||||
public CommandException(Throwable cause) {
|
super(message, cause);
|
||||||
super(cause);
|
}
|
||||||
}
|
|
||||||
|
public CommandException(Throwable cause)
|
||||||
public CommandException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
{
|
||||||
super(message, cause, enableSuppression, writableStackTrace);
|
super(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandException() {
|
public CommandException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace)
|
||||||
}
|
{
|
||||||
|
super(message, cause, enableSuppression, writableStackTrace);
|
||||||
public CommandException(String message) {
|
}
|
||||||
super(message);
|
|
||||||
}
|
public CommandException()
|
||||||
|
{}
|
||||||
|
|
||||||
|
public CommandException(String message)
|
||||||
|
{
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
package com.redstoner.utils;
|
package com.redstoner.utils;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.SimpleCommandMap;
|
import org.bukkit.command.SimpleCommandMap;
|
||||||
import org.bukkit.plugin.SimplePluginManager;
|
import org.bukkit.plugin.SimplePluginManager;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
public class CommandMap
|
||||||
import java.util.Map;
|
{
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public class CommandMap {
|
public static Map<String, Command> getCommandMap() throws ReflectiveOperationException, ClassCastException
|
||||||
|
{
|
||||||
public static Map<String, Command> getCommandMap() throws ReflectiveOperationException, ClassCastException {
|
|
||||||
Field field = SimplePluginManager.class.getDeclaredField("commandMap");
|
Field field = SimplePluginManager.class.getDeclaredField("commandMap");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
Object map = field.get(Bukkit.getPluginManager());
|
Object map = field.get(Bukkit.getPluginManager());
|
||||||
@@ -18,5 +20,4 @@ public class CommandMap {
|
|||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
return (Map<String, Command>) field.get(map);
|
return (Map<String, Command>) field.get(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public class ItemProperties
|
|||||||
public ItemProperties()
|
public ItemProperties()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public ItemProperties(ItemStack item)
|
public ItemProperties(ItemStack item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
@@ -55,6 +56,7 @@ public class ItemProperties
|
|||||||
unbreakable = meta.isUnbreakable();
|
unbreakable = meta.isUnbreakable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public ItemStack toItemStack()
|
public ItemStack toItemStack()
|
||||||
{
|
{
|
||||||
ItemStack result = new ItemStack(id, amount, data);
|
ItemStack result = new ItemStack(id, amount, data);
|
||||||
|
|||||||
Reference in New Issue
Block a user