Allow toggling redstone

This commit is contained in:
Telesphoreo 2022-06-04 22:48:18 -05:00
parent abf2aca0f2
commit 5fe48cfd7f
5 changed files with 44 additions and 4 deletions

View File

@ -31,6 +31,7 @@ public class ToggleCMD extends PlexCommand
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Explosions" + status("explosions")));
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Fluidspread" + status("fluidspread")));
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Drops" + status("drops")));
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Redstone" + status("redstone")));
return null;
}
switch (args[0].toLowerCase())
@ -47,6 +48,10 @@ public class ToggleCMD extends PlexCommand
{
return toggle("drops");
}
case "redstone" ->
{
return toggle("redstone");
}
default ->
{
return messageComponent("invalidToggle");

View File

@ -13,6 +13,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockRedstoneEvent;
public class BlockListener extends PlexListener
{
@ -38,9 +39,8 @@ public class BlockListener extends PlexListener
{
blockedBlocks.add(Material.valueOf(block.toUpperCase()));
}
catch (IllegalArgumentException e)
catch (IllegalArgumentException ignored)
{
//
}
}
}

View File

@ -3,6 +3,7 @@ package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
@ -34,4 +35,18 @@ public class TogglesListener extends PlexListener
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);
}
}
}

View File

@ -21,10 +21,11 @@ public class ToggleMenu extends AbstractMenu implements PlexBase
public ToggleMenu()
{
super("§a§lToggles");
Inventory inventory = Bukkit.createInventory(null, 54, PlexUtils.mmDeserialize("Toggles"));
Inventory inventory = Bukkit.createInventory(null, 9, PlexUtils.mmDeserialize("Toggles"));
resetExplosionItem(inventory);
resetFluidspreadItem(inventory);
resetDropsItem(inventory);
resetRedstoneItem(inventory);
inventories.add(inventory);
}
@ -77,6 +78,12 @@ public class ToggleMenu extends AbstractMenu implements PlexBase
resetDropsItem(inv);
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)
@ -125,4 +132,14 @@ public class ToggleMenu extends AbstractMenu implements PlexBase
feather.setItemMeta(featherItemMeta);
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);
}
}

View File

@ -8,3 +8,6 @@ fluidspread: true
# Should drops be enabled?
drops: true
# Should redstone be enabled?
redstone: true