Reintroduced the clownfish and fixed an issue with orbit

This commit is contained in:
Sceptor 2024-03-25 02:00:48 +00:00
parent aa0938b869
commit d6e2287b6a
4 changed files with 176 additions and 0 deletions

View File

@ -0,0 +1,72 @@
package dev.plex.extras.command;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.extras.TFMExtras;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
@CommandParameters(name = "clownfish", description = "Gives a player a clownfish capable of knocking people back")
@CommandPermissions(permission = "plex.tfmextras.clownfish")
public class ClownfishCommand extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args)
{
if (args.length == 0)
{
ItemStack clownfish = new ItemStack(Material.TROPICAL_FISH);
ItemMeta meta = clownfish.getItemMeta();
meta.displayName(Component.text("Clownfish"));
clownfish.setItemMeta(meta);
player.getInventory().addItem(clownfish);
return MiniMessage.miniMessage().deserialize("<rainbow>blub blub... ><_>");
}
else if (args[0].equals("toggle"))
{
List<String> toggledPlayers = TFMExtras.getModule().getConfig().getStringList("server.clownfish.toggled_players");
boolean isToggled = toggledPlayers.contains(player.getName());
if (isToggled)
{
toggledPlayers.remove(player.getName());
}
else
{
toggledPlayers.add(player.getName());
}
TFMExtras.getModule().getConfig().set("server.clownfish.toggled_players", toggledPlayers);
TFMExtras.getModule().getConfig().save();
return MiniMessage.miniMessage().deserialize("<gray>You " + (isToggled ? "<green>will" : "<red>will no longer") + "<gray> be affected by the clownfish");
}
else
{
return MiniMessage.miniMessage().deserialize("<red>Incorrect usage. Use either /clownfish or /clownfish toggle");
}
}
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
if (args.length == 1)
{
return List.of("toggle");
}
return Collections.emptyList();
}
}

View File

@ -0,0 +1,83 @@
package dev.plex.extras.listener;
import dev.plex.extras.TFMExtras;
import dev.plex.listener.PlexListener;
import net.kyori.adventure.text.Component;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;
import org.bukkit.Particle;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class ClownfishListener extends PlexListener
{
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
Player player = event.getPlayer();
if (!player.hasPermission("plex.tfmextras.clownfish"))
{
return;
}
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)
{
ItemStack item = player.getInventory().getItemInMainHand();
if (item.getType() == Material.TROPICAL_FISH && item.hasItemMeta())
{
ItemMeta meta = item.getItemMeta();
if (meta.hasDisplayName() && Objects.equals(meta.displayName(), Component.text("Clownfish")))
{
double radius = TFMExtras.getModule().getConfig().getInt("server.clownfish.radius");
double strength = TFMExtras.getModule().getConfig().getInt("server.clownfish.strength");
List<String> pushedPlayers = new ArrayList<>();
final Vector senderPos = player.getLocation().toVector();
final List<Player> players = player.getWorld().getPlayers();
final List<String> toggledPlayers = TFMExtras.getModule().getConfig().getStringList("server.clownfish.toggled_players");
for (final Player target : players)
{
if (target.equals(player) || toggledPlayers.contains(target.getName()))
{
continue;
}
final Location targetPos = target.getLocation();
final Vector targetPosVec = targetPos.toVector();
if (targetPosVec.distanceSquared(senderPos) < (radius * radius))
{
target.playSound(target.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, SoundCategory.PLAYERS, 1.0f, 1.0f);
target.getWorld().spawnParticle(Particle.EXPLOSION_LARGE, target.getLocation(), 1);
target.setVelocity(targetPosVec.subtract(senderPos).normalize().multiply(strength));
pushedPlayers.add(target.getName());
}
}
if (!pushedPlayers.isEmpty())
{
player.playSound(player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, SoundCategory.PLAYERS, 1.0f, 1.0f);
}
}
}
}
}
}

View File

@ -3,11 +3,13 @@ package dev.plex.extras.listener;
import dev.plex.Plex;
import dev.plex.extras.command.OrbitCommand;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import dev.plex.listener.PlexListener;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@ -32,4 +34,18 @@ public class OrbitEffectListener extends PlexListener
}
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event)
{
Player player = event.getPlayer();
Bukkit.getScheduler().runTaskLater(Plex.get(), () ->
{
if (OrbitCommand.isPlayerOrbited(player.getUniqueId()) && event.getNewGameMode() != GameMode.SURVIVAL)
{
player.setGameMode(GameMode.SURVIVAL);
}
}, 2);
}
}

View File

@ -12,5 +12,10 @@ server:
teleport-on-join:
- "Taahh"
allow-unsafe-enchantments: true
clownfish:
radius: 5
strength: 2.5
toggled_players:
- "shdwo"
player-worlds:
size: 500