mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Allow toggling redstone
This commit is contained in:
parent
abf2aca0f2
commit
5fe48cfd7f
@ -31,6 +31,7 @@ public class ToggleCMD extends PlexCommand
|
|||||||
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Explosions" + status("explosions")));
|
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Explosions" + status("explosions")));
|
||||||
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Fluidspread" + status("fluidspread")));
|
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Fluidspread" + status("fluidspread")));
|
||||||
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Drops" + status("drops")));
|
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Drops" + status("drops")));
|
||||||
|
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Redstone" + status("redstone")));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
switch (args[0].toLowerCase())
|
switch (args[0].toLowerCase())
|
||||||
@ -47,6 +48,10 @@ public class ToggleCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
return toggle("drops");
|
return toggle("drops");
|
||||||
}
|
}
|
||||||
|
case "redstone" ->
|
||||||
|
{
|
||||||
|
return toggle("redstone");
|
||||||
|
}
|
||||||
default ->
|
default ->
|
||||||
{
|
{
|
||||||
return messageComponent("invalidToggle");
|
return messageComponent("invalidToggle");
|
||||||
|
@ -13,6 +13,7 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
import org.bukkit.event.block.BlockRedstoneEvent;
|
||||||
|
|
||||||
public class BlockListener extends PlexListener
|
public class BlockListener extends PlexListener
|
||||||
{
|
{
|
||||||
@ -38,9 +39,8 @@ public class BlockListener extends PlexListener
|
|||||||
{
|
{
|
||||||
blockedBlocks.add(Material.valueOf(block.toUpperCase()));
|
blockedBlocks.add(Material.valueOf(block.toUpperCase()));
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e)
|
catch (IllegalArgumentException ignored)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package dev.plex.listener.impl;
|
|||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.block.BlockFromToEvent;
|
import org.bukkit.event.block.BlockFromToEvent;
|
||||||
|
import org.bukkit.event.block.BlockRedstoneEvent;
|
||||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
|
|
||||||
@ -34,4 +35,18 @@ public class TogglesListener extends PlexListener
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* I have no idea if this is the best way to do this
|
||||||
|
There is a very weird bug where if you try to create a loop using two repeaters and a lever, after disabling
|
||||||
|
and re-enabling redstone, you are unable to recreate the loop with a lever. Using a redstone torch works fine.
|
||||||
|
Using a lever works fine also as long as you never toggle redstone.
|
||||||
|
*/
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockRedstone(BlockRedstoneEvent event)
|
||||||
|
{
|
||||||
|
if (!plugin.toggles.getBoolean("redstone"))
|
||||||
|
{
|
||||||
|
event.setNewCurrent(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,10 +21,11 @@ public class ToggleMenu extends AbstractMenu implements PlexBase
|
|||||||
public ToggleMenu()
|
public ToggleMenu()
|
||||||
{
|
{
|
||||||
super("§a§lToggles");
|
super("§a§lToggles");
|
||||||
Inventory inventory = Bukkit.createInventory(null, 54, PlexUtils.mmDeserialize("Toggles"));
|
Inventory inventory = Bukkit.createInventory(null, 9, PlexUtils.mmDeserialize("Toggles"));
|
||||||
resetExplosionItem(inventory);
|
resetExplosionItem(inventory);
|
||||||
resetFluidspreadItem(inventory);
|
resetFluidspreadItem(inventory);
|
||||||
resetDropsItem(inventory);
|
resetDropsItem(inventory);
|
||||||
|
resetRedstoneItem(inventory);
|
||||||
inventories.add(inventory);
|
inventories.add(inventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,6 +78,12 @@ public class ToggleMenu extends AbstractMenu implements PlexBase
|
|||||||
resetDropsItem(inv);
|
resetDropsItem(inv);
|
||||||
event.getWhoClicked().sendMessage(PlexUtils.mmDeserialize("<gray>Toggled drops."));
|
event.getWhoClicked().sendMessage(PlexUtils.mmDeserialize("<gray>Toggled drops."));
|
||||||
}
|
}
|
||||||
|
if (item.getType() == Material.REDSTONE)
|
||||||
|
{
|
||||||
|
plugin.toggles.set("redstone", !plugin.toggles.getBoolean("redstone"));
|
||||||
|
resetRedstoneItem(inv);
|
||||||
|
event.getWhoClicked().sendMessage(PlexUtils.mmDeserialize("<gray>Toggled redstone."));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCurrentInventoryIndex(Inventory inventory)
|
public int getCurrentInventoryIndex(Inventory inventory)
|
||||||
@ -125,4 +132,14 @@ public class ToggleMenu extends AbstractMenu implements PlexBase
|
|||||||
feather.setItemMeta(featherItemMeta);
|
feather.setItemMeta(featherItemMeta);
|
||||||
inventory.setItem(2, feather);
|
inventory.setItem(2, feather);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void resetRedstoneItem(Inventory inventory)
|
||||||
|
{
|
||||||
|
ItemStack redstone = new ItemStack(Material.REDSTONE);
|
||||||
|
ItemMeta redstoneItemMeta = redstone.getItemMeta();
|
||||||
|
redstoneItemMeta.displayName(PlexUtils.mmDeserialize("<light_purple>Redstone"));
|
||||||
|
redstoneItemMeta.lore(List.of(PlexUtils.mmDeserialize("<yellow>Redstone is " + (plugin.toggles.getBoolean("redstone") ? "<green>enabled" : "<red>disabled"))));
|
||||||
|
redstone.setItemMeta(redstoneItemMeta);
|
||||||
|
inventory.setItem(3, redstone);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,3 +8,6 @@ fluidspread: true
|
|||||||
|
|
||||||
# Should drops be enabled?
|
# Should drops be enabled?
|
||||||
drops: true
|
drops: true
|
||||||
|
|
||||||
|
# Should redstone be enabled?
|
||||||
|
redstone: true
|
Loading…
Reference in New Issue
Block a user