mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 09:07:37 +00:00
Begin work on toggles
This commit is contained in:
parent
92c07f89fe
commit
4d77d514fd
@ -50,6 +50,7 @@ public class Plex extends PlexPlugin implements PlexApiProvider
|
||||
public Config messages;
|
||||
public Config indefBans;
|
||||
public Config commands;
|
||||
public Config toggles;
|
||||
|
||||
private PlexProvider provider;
|
||||
|
||||
@ -95,6 +96,7 @@ public class Plex extends PlexPlugin implements PlexApiProvider
|
||||
messages = new Config(this, "messages.yml");
|
||||
indefBans = new Config(this, "indefbans.yml");
|
||||
commands = new Config(this, "commands.yml");
|
||||
toggles = new Config(this, "toggles.yml");
|
||||
build.load(this);
|
||||
|
||||
modulesFolder = new File(this.getDataFolder() + File.separator + "modules");
|
||||
@ -116,6 +118,7 @@ public class Plex extends PlexPlugin implements PlexApiProvider
|
||||
{
|
||||
config.load();
|
||||
messages.load();
|
||||
toggles.load();
|
||||
|
||||
// Don't add default entries to indefinite ban file
|
||||
indefBans.load(false);
|
||||
|
67
server/src/main/java/dev/plex/command/impl/ToggleCMD.java
Normal file
67
server/src/main/java/dev/plex/command/impl/ToggleCMD.java
Normal file
@ -0,0 +1,67 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.menu.ToggleMenu;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "toggle", usage = "/<command>", description = "Allows toggling various server aspects through a GUI")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.toggle", source = RequiredCommandSource.ANY)
|
||||
public class ToggleCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (isConsole(sender) || playerSender == null)
|
||||
{
|
||||
sender.sendMessage(PlexUtils.mmDeserialize("<gray>Available toggles:"));
|
||||
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Explosions " + status("explosions")));
|
||||
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Fluidspread " + status("fluidspread")));
|
||||
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Drops " + status("drops")));
|
||||
switch (args[0].toLowerCase())
|
||||
{
|
||||
case "explosions":
|
||||
{
|
||||
toggle("explosions");
|
||||
}
|
||||
case "fluidspread":
|
||||
{
|
||||
toggle("fluidspread");
|
||||
}
|
||||
case "drops":
|
||||
{
|
||||
toggle("drops");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
new ToggleMenu().openInv(playerSender, 0);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
|
||||
private String status(String toggle)
|
||||
{
|
||||
return plugin.toggles.getBoolean(toggle) ? "(enabled)" : "(disabled)";
|
||||
}
|
||||
|
||||
private void toggle(String toggle)
|
||||
{
|
||||
plugin.toggles.set(toggle, !plugin.getToggles().getBoolean(toggle));
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.toggledrops", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "toggledrops", description = "Toggle immediately removing drops.", usage = "/<command>", aliases = "td")
|
||||
public class ToggleDropsCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||
{
|
||||
plugin.config.set("allowdrops", !plugin.config.getBoolean("allowdrops"));
|
||||
plugin.config.save();
|
||||
send(sender, plugin.config.getBoolean("allowdrops") ? messageComponent("allowDropsEnabled") : messageComponent("allowDropsDisabled"));
|
||||
return null;
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ public class DropListener extends PlexListener
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event)
|
||||
{
|
||||
if (!plugin.config.getBoolean("allowdrops"))
|
||||
if (!plugin.toggles.getBoolean("drops"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class SpawnListener extends PlexListener
|
||||
public class MobListener extends PlexListener
|
||||
{
|
||||
private static final List<Material> SPAWN_EGGS = Arrays.stream(Material.values()).filter((mat) -> mat.name().endsWith("_SPAWN_EGG")).toList();
|
||||
|
@ -0,0 +1,37 @@
|
||||
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.entity.ExplosionPrimeEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
|
||||
public class TogglesListener extends PlexListener
|
||||
{
|
||||
@EventHandler
|
||||
public void onEntityExplode(ExplosionPrimeEvent event)
|
||||
{
|
||||
if (!plugin.toggles.getBoolean("explosions"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFluidSpread(BlockFromToEvent event)
|
||||
{
|
||||
if (!plugin.toggles.getBoolean("fluidspread"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFluidSpread(PlayerDropItemEvent event)
|
||||
{
|
||||
if (!plugin.toggles.getBoolean("drops"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
128
server/src/main/java/dev/plex/menu/ToggleMenu.java
Normal file
128
server/src/main/java/dev/plex/menu/ToggleMenu.java
Normal file
@ -0,0 +1,128 @@
|
||||
package dev.plex.menu;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.PlexBase;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.menu.AbstractMenu;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class ToggleMenu extends AbstractMenu implements PlexBase
|
||||
{
|
||||
private final List<Inventory> inventories = Lists.newArrayList();
|
||||
|
||||
public ToggleMenu()
|
||||
{
|
||||
super("§a§lToggles");
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, PlexUtils.mmDeserialize("Toggles"));
|
||||
resetExplosionItem(inventory);
|
||||
resetFluidspreadItem(inventory);
|
||||
resetDropsItem(inventory);
|
||||
inventories.add(inventory);
|
||||
}
|
||||
|
||||
public void openInv(Player player, int index)
|
||||
{
|
||||
player.openInventory(inventories.get(index));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent event)
|
||||
{
|
||||
if (event.getClickedInventory() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Inventory inv = event.getClickedInventory();
|
||||
if (!isValidInventory(inv))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.getCurrentItem() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!event.getCurrentItem().hasItemMeta())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!event.getCurrentItem().getItemMeta().hasDisplayName())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ItemStack item = event.getCurrentItem();
|
||||
event.setCancelled(true);
|
||||
if (item.getType() == Material.TNT)
|
||||
{
|
||||
plugin.toggles.set("explosions", !plugin.toggles.getBoolean("explosions"));
|
||||
resetExplosionItem(inv);
|
||||
event.getWhoClicked().sendMessage(PlexUtils.mmDeserialize("<gray>Toggled explosions."));
|
||||
}
|
||||
if (item.getType() == Material.WATER_BUCKET)
|
||||
{
|
||||
plugin.toggles.set("fluidspread", !plugin.toggles.getBoolean("fluidspread"));
|
||||
resetFluidspreadItem(inv);
|
||||
event.getWhoClicked().sendMessage(PlexUtils.mmDeserialize("<gray>Toggled fluid spread."));
|
||||
}
|
||||
if (item.getType() == Material.FEATHER)
|
||||
{
|
||||
plugin.toggles.set("drops", !plugin.toggles.getBoolean("drops"));
|
||||
resetDropsItem(inv);
|
||||
event.getWhoClicked().sendMessage(PlexUtils.mmDeserialize("<gray>Toggled drops."));
|
||||
}
|
||||
}
|
||||
|
||||
public int getCurrentInventoryIndex(Inventory inventory)
|
||||
{
|
||||
for (int i = 0; i <= inventories.size() - 1; i++)
|
||||
{
|
||||
if (inventories.get(i).hashCode() == inventory.hashCode())
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private boolean isValidInventory(Inventory inventory)
|
||||
{
|
||||
return inventories.contains(inventory);
|
||||
}
|
||||
|
||||
private void resetExplosionItem(Inventory inventory)
|
||||
{
|
||||
ItemStack explosions = new ItemStack(Material.TNT);
|
||||
ItemMeta explosionsItemMeta = explosions.getItemMeta();
|
||||
explosionsItemMeta.displayName(PlexUtils.mmDeserialize("<light_purple>Toggle explosions"));
|
||||
explosionsItemMeta.lore(List.of(PlexUtils.mmDeserialize("<yellow>Explosions are " + (plugin.toggles.getBoolean("explosions") ? "<red>enabled" : "<green>disabled"))));
|
||||
explosions.setItemMeta(explosionsItemMeta);
|
||||
inventory.setItem(0, explosions);
|
||||
}
|
||||
|
||||
private void resetFluidspreadItem(Inventory inventory)
|
||||
{
|
||||
ItemStack water = new ItemStack(Material.WATER_BUCKET);
|
||||
ItemMeta waterItemMeta = water.getItemMeta();
|
||||
waterItemMeta.displayName(PlexUtils.mmDeserialize("<light_purple>Toggle fluid spread"));
|
||||
waterItemMeta.lore(List.of(PlexUtils.mmDeserialize("<yellow>Fluid spread is " + (plugin.toggles.getBoolean("fluidspread") ? "<green>enabled" : "<red>disabled"))));
|
||||
water.setItemMeta(waterItemMeta);
|
||||
inventory.setItem(1, water);
|
||||
}
|
||||
|
||||
private void resetDropsItem(Inventory inventory)
|
||||
{
|
||||
ItemStack feather = new ItemStack(Material.FEATHER);
|
||||
ItemMeta featherItemMeta = feather.getItemMeta();
|
||||
featherItemMeta.displayName(PlexUtils.mmDeserialize("<light_purple>Toggle drops"));
|
||||
featherItemMeta.lore(List.of(PlexUtils.mmDeserialize("<yellow>Drops are " + (plugin.toggles.getBoolean("drops") ? "<green>enabled" : "<red>disabled"))));
|
||||
feather.setItemMeta(featherItemMeta);
|
||||
inventory.setItem(2, feather);
|
||||
}
|
||||
}
|
@ -137,9 +137,6 @@ autowipe:
|
||||
entities:
|
||||
- "DROPPED_ITEM"
|
||||
|
||||
# Should we allow drops from players?
|
||||
allowdrops: true
|
||||
|
||||
# What blocks should be blocked?
|
||||
blocked_blocks:
|
||||
- "SPAWNER"
|
||||
|
@ -165,8 +165,6 @@ noRemovedEntities: "<gray>No entities were removed."
|
||||
# 1 - Number of mobs removed
|
||||
removedMobs: "<red>{0} - Removed {1} mobs"
|
||||
autoWipeDisabled: "<gray>Item wiping is currently disabled in the config!"
|
||||
allowDropsDisabled: "<gray>No longer allowing drops from players."
|
||||
allowDropsEnabled: "<gray>Now allowing drops from players."
|
||||
commandBlocked: "<gray>That command is blocked."
|
||||
# 0 - The command sender
|
||||
# 1 - The message being said
|
||||
|
10
server/src/main/resources/toggles.yml
Normal file
10
server/src/main/resources/toggles.yml
Normal file
@ -0,0 +1,10 @@
|
||||
# Plex Toggles
|
||||
|
||||
# Should explosions be enabled?
|
||||
explosions: false
|
||||
|
||||
# Should fluid spread be enabled?
|
||||
fluidspread: true
|
||||
|
||||
# Should drops be enabled?
|
||||
drops: true
|
Loading…
Reference in New Issue
Block a user