mirror of
https://github.com/plexusorg/Module-TFMExtras.git
synced 2025-07-05 01:36:41 +00:00
Add slime world support for per player worlds
Move package to dev.plex.extras to prevent any possible conflicts with main plugin
This commit is contained in:
148
src/main/java/dev/plex/extras/TFMExtras.java
Executable file
148
src/main/java/dev/plex/extras/TFMExtras.java
Executable file
@ -0,0 +1,148 @@
|
||||
package dev.plex.extras;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.reflect.ClassPath;
|
||||
import dev.plex.extras.hook.SlimeWorldHook;
|
||||
import dev.plex.extras.listener.PlayerListener;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.config.ModuleConfig;
|
||||
import dev.plex.extras.jumppads.JumpPads;
|
||||
import dev.plex.extras.listener.JumpPadsListener;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.module.PlexModule;
|
||||
import dev.plex.util.PlexLog;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class TFMExtras extends PlexModule
|
||||
{
|
||||
@Getter
|
||||
private static TFMExtras module;
|
||||
|
||||
public JumpPads jumpPads;
|
||||
|
||||
@Getter
|
||||
private ModuleConfig config;
|
||||
|
||||
@Getter
|
||||
private final SlimeWorldHook slimeWorldHook = new SlimeWorldHook();
|
||||
|
||||
@Override
|
||||
public void load()
|
||||
{
|
||||
module = this;
|
||||
config = new ModuleConfig(this, "tfmextras/config.yml", "config.yml");
|
||||
config.load();
|
||||
jumpPads = new JumpPads();
|
||||
PlexLog.debug(String.valueOf(config.getInt("server.jumppad_strength")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable()
|
||||
{
|
||||
if (slimeWorldHook.plugin() != null)
|
||||
{
|
||||
slimeWorldHook.onEnable(this);
|
||||
}
|
||||
|
||||
getClassesFrom("dev.plex.extras.command").forEach(aClass ->
|
||||
{
|
||||
if (PlexCommand.class.isAssignableFrom(aClass) && aClass.isAnnotationPresent(CommandParameters.class) && aClass.isAnnotationPresent(CommandPermissions.class))
|
||||
{
|
||||
try
|
||||
{
|
||||
PlexCommand plexCommand = (PlexCommand) aClass.getConstructors()[0].newInstance();
|
||||
registerCommand(plexCommand);
|
||||
}
|
||||
catch (InstantiationException | IllegalAccessException | InvocationTargetException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
getClassesFrom("dev.plex.extras.listener").forEach(aClass ->
|
||||
{
|
||||
if (PlexListener.class.isAssignableFrom(aClass))
|
||||
{
|
||||
try
|
||||
{
|
||||
PlexListener plexListener = (PlexListener) aClass.getConstructors()[0].newInstance();
|
||||
registerListener(plexListener);
|
||||
}
|
||||
catch (InstantiationException | IllegalAccessException | InvocationTargetException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
addDefaultMessage("emptyAdminInfo", "<red>The admin information section of the config.yml file has not been configured.");
|
||||
addDefaultMessage("cakeLyrics", "<rainbow>But there's no sense crying over every mistake. You just keep on trying till you run out of cake.");
|
||||
addDefaultMessage("areaEffectCloudClear", "<red>{0} - Removing all area effect clouds", "0 - The command sender");
|
||||
addDefaultMessage("chatCleared", "<red>{0} - Cleared the chat", "0 - The command sender");
|
||||
addDefaultMessage("attributeList", "<gold>All possible attributes: <yellow>{0}", "0 - The attribute list, each split by a new line");
|
||||
addDefaultMessage("modifiedAutoClear", "<gold>{0} will {1} have their inventory cleared when they join.", "0 - The player who will have their inventory cleared on join", "1 - Whether they had this option toggled (returns: 'no longer', 'now')");
|
||||
addDefaultMessage("modifiedAutoTeleport", "<gold>{0} will {1} be teleported automatically when they join.", "0 - The player to be teleported automatically", "1 - Whether they had this option toggled (returns: 'no longer', 'now')");
|
||||
addDefaultMessage("createdPlayerWorld", "<green>Welcome to the server! We've created you a new private world where you can invite your friends! View how to use this using /myworld!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable()
|
||||
{
|
||||
// Unregistering listeners / commands is handled by Plex
|
||||
if (slimeWorldHook.plugin() != null)
|
||||
{
|
||||
slimeWorldHook.onDisable(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static Location getRandomLocation(World world)
|
||||
{
|
||||
double x = ThreadLocalRandom.current().nextDouble(-100000, 100000);
|
||||
double z = ThreadLocalRandom.current().nextDouble(-100000, 100000);
|
||||
double y = world.getHighestBlockYAt((int) x, (int) z) + 1;
|
||||
return new Location(world, x, y, z);
|
||||
}
|
||||
|
||||
private Set<Class<?>> getClassesFrom(String packageName)
|
||||
{
|
||||
Set<Class<?>> classes = new HashSet();
|
||||
|
||||
try
|
||||
{
|
||||
ClassPath path = ClassPath.from(TFMExtras.class.getClassLoader());
|
||||
ImmutableSet<ClassPath.ClassInfo> infoSet = path.getTopLevelClasses(packageName);
|
||||
infoSet.forEach((info) ->
|
||||
{
|
||||
try
|
||||
{
|
||||
Class<?> clazz = Class.forName(info.getName());
|
||||
classes.add(clazz);
|
||||
}
|
||||
catch (ClassNotFoundException var4)
|
||||
{
|
||||
PlexLog.error("Unable to find class " + info.getName() + " in " + packageName);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
catch (IOException var4)
|
||||
{
|
||||
PlexLog.error("Something went wrong while fetching classes from " + packageName);
|
||||
throw new RuntimeException(var4);
|
||||
}
|
||||
|
||||
return Collections.unmodifiableSet(classes);
|
||||
}
|
||||
}
|
34
src/main/java/dev/plex/extras/command/AdminInfoCommand.java
Executable file
34
src/main/java/dev/plex/extras/command/AdminInfoCommand.java
Executable file
@ -0,0 +1,34 @@
|
||||
package dev.plex.extras.command;
|
||||
|
||||
import dev.plex.extras.TFMExtras;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(name = "admininfo", description = "Information on how to apply for admin", aliases = "ai,si,staffinfo")
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.tfmextras.admininfo")
|
||||
public class AdminInfoCommand extends PlexCommand
|
||||
{
|
||||
private static final List<Component> ADMIN_INFO = TFMExtras.getModule().getConfig().getStringList("server.admininfo")
|
||||
.stream().map(info -> MiniMessage.miniMessage().deserialize(info)).toList();
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
if (ADMIN_INFO.isEmpty())
|
||||
{
|
||||
return messageComponent("emptyAdminInfo");
|
||||
}
|
||||
ADMIN_INFO.forEach(component -> send(sender, component));
|
||||
return null;
|
||||
}
|
||||
}
|
26
src/main/java/dev/plex/extras/command/AttributeListCommand.java
Executable file
26
src/main/java/dev/plex/extras/command/AttributeListCommand.java
Executable file
@ -0,0 +1,26 @@
|
||||
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.rank.enums.Rank;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@CommandParameters(name = "attributes", description = "Lists all possible attributes", aliases = "attributelist,attrlist")
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.tfmextras.attrlist")
|
||||
public class AttributeListCommand extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
return messageComponent("attributeList", StringUtils.join(Arrays.stream(Attribute.values()).map(Enum::name).toList(), ", "));
|
||||
}
|
||||
}
|
50
src/main/java/dev/plex/extras/command/AutoClearCommand.java
Executable file
50
src/main/java/dev/plex/extras/command/AutoClearCommand.java
Executable file
@ -0,0 +1,50 @@
|
||||
package dev.plex.extras.command;
|
||||
|
||||
import dev.plex.extras.TFMExtras;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(name = "autoclear", description = "Toggle whether or not a player has their inventory automatically cleared when they join", usage = "/<command> <player>", aliases = "aclear,ac")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.tfmextras.autoclear")
|
||||
public class AutoClearCommand extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
PlexPlayer target = DataUtils.getPlayer(args[0]);
|
||||
if (target == null)
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
List<String> names = TFMExtras.getModule().getConfig().getStringList("server.clear-on-join");
|
||||
boolean isEnabled = names.contains(target.getName());
|
||||
if (!isEnabled)
|
||||
{
|
||||
names.add(target.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
names.remove(target.getName());
|
||||
}
|
||||
TFMExtras.getModule().getConfig().set("server.clear-on-join", names);
|
||||
TFMExtras.getModule().getConfig().save();
|
||||
isEnabled = !isEnabled;
|
||||
return messageComponent("modifiedAutoClear", target.getName(), isEnabled ? "now" : "no longer");
|
||||
}
|
||||
}
|
57
src/main/java/dev/plex/extras/command/AutoTeleportCommand.java
Executable file
57
src/main/java/dev/plex/extras/command/AutoTeleportCommand.java
Executable file
@ -0,0 +1,57 @@
|
||||
package dev.plex.extras.command;
|
||||
|
||||
import dev.plex.extras.TFMExtras;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(name = "autoteleport", description = "If a player is specified, it will toggle whether or not the player is automatically teleported when they join. If no player is specified, you will be randomly teleported", usage = "/<command> [player]", aliases = "autotp,rtp,randomtp,tpr")
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.tfmextras.autotp")
|
||||
public class AutoTeleportCommand extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
if (sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
player.teleportAsync(TFMExtras.getRandomLocation(player.getWorld()));
|
||||
return null;
|
||||
}
|
||||
checkRank(sender, Rank.ADMIN, "plex.tfmextras.autotp.other");
|
||||
PlexPlayer target = DataUtils.getPlayer(args[0]);
|
||||
if (target == null)
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
List<String> names = TFMExtras.getModule().getConfig().getStringList("server.teleport-on-join");
|
||||
boolean isEnabled = names.contains(target.getName());
|
||||
if (!isEnabled)
|
||||
{
|
||||
names.add(target.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
names.remove(target.getName());
|
||||
}
|
||||
TFMExtras.getModule().getConfig().set("server.teleport-on-join", names);
|
||||
TFMExtras.getModule().getConfig().save();
|
||||
isEnabled = !isEnabled;
|
||||
return messageComponent("modifiedAutoTeleport", target.getName(), isEnabled ? "now" : "no longer");
|
||||
}
|
||||
}
|
53
src/main/java/dev/plex/extras/command/BanListCommand.java
Executable file
53
src/main/java/dev/plex/extras/command/BanListCommand.java
Executable file
@ -0,0 +1,53 @@
|
||||
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.punishment.Punishment;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandParameters(name = "banlist", description = "Manages the banlist", usage = "/<command> [purge]")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.tfmextras.banlist")
|
||||
public class BanListCommand extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
plugin.getPunishmentManager().getActiveBans().whenComplete((punishments, throwable) ->
|
||||
{
|
||||
send(sender, mmString("<gold>Active Bans (" + punishments.size() + "): <yellow>" + StringUtils.join(punishments.stream().map(Punishment::getPunishedUsername).collect(Collectors.toList()), ", ")));
|
||||
});
|
||||
return null;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("purge"))
|
||||
{
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
return messageComponent("noPermissionInGame");
|
||||
}
|
||||
if (!sender.getName().equalsIgnoreCase("console"))
|
||||
{
|
||||
if (!checkRank(sender, Rank.EXECUTIVE, "plex.tfmextras.banlist.clear"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
plugin.getPunishmentManager().getActiveBans().whenComplete((punishments, throwable) ->
|
||||
{
|
||||
punishments.forEach(plugin.getPunishmentManager()::unban);
|
||||
send(sender, mmString("<gold>Unbanned " + punishments.size() + " players."));
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
37
src/main/java/dev/plex/extras/command/CakeCommand.java
Executable file
37
src/main/java/dev/plex/extras/command/CakeCommand.java
Executable file
@ -0,0 +1,37 @@
|
||||
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.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.item.ItemBuilder;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "cake", description = "For the people that are still alive - gives a cake to everyone on the server")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.tfmextras.cake")
|
||||
public class CakeCommand extends PlexCommand
|
||||
{
|
||||
private static final ItemStack CAKE = new ItemBuilder(Material.CAKE)
|
||||
.displayName(MiniMessage.miniMessage().deserialize("<!italic><white>The <dark_gray>Lie"))
|
||||
.build();
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
Bukkit.getOnlinePlayers().forEach(p ->
|
||||
{
|
||||
p.getInventory().addItem(CAKE);
|
||||
});
|
||||
PlexUtils.broadcast(messageComponent("cakeLyrics"));
|
||||
return null;
|
||||
}
|
||||
}
|
85
src/main/java/dev/plex/extras/command/CartSitCommand.java
Executable file
85
src/main/java/dev/plex/extras/command/CartSitCommand.java
Executable file
@ -0,0 +1,85 @@
|
||||
package dev.plex.extras.command;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandParameters(name = "cartsit", description = "Sit in nearest minecart. If target is in a minecart already, they will be ejected", aliases = "minecartsit")
|
||||
@CommandPermissions(level = Rank.NONOP, permission = "plex.tfmextras.cartsit")
|
||||
public class CartSitCommand extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
if (!(sender instanceof Player) && args.length == 0)
|
||||
{
|
||||
return usage("/cartsit <player>");
|
||||
}
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
if (player.isInsideVehicle())
|
||||
{
|
||||
player.eject();
|
||||
}
|
||||
List<Entity> minecart = player.getNearbyEntities(100, 100, 100).stream().filter(entity -> entity.getType() == EntityType.MINECART).collect(Collectors.toList());
|
||||
if (minecart.isEmpty())
|
||||
{
|
||||
return MiniMessage.miniMessage().deserialize("<red>Could not find a nearby minecart!");
|
||||
}
|
||||
findNearestEntity(player, minecart).whenComplete((entity, throwable) ->
|
||||
{
|
||||
Bukkit.getScheduler().runTask(Plex.get(), () -> entity.addPassenger(player));
|
||||
});
|
||||
return null;
|
||||
}
|
||||
Player target = getNonNullPlayer(args[0]);
|
||||
if (target.isInsideVehicle())
|
||||
{
|
||||
target.eject();
|
||||
}
|
||||
List<Entity> minecart = target.getNearbyEntities(100, 100, 100).stream().filter(entity -> entity.getType() == EntityType.MINECART).collect(Collectors.toList());
|
||||
if (minecart.isEmpty())
|
||||
{
|
||||
return MiniMessage.miniMessage().deserialize("<red>Could not find a nearby minecart near " + target.getName() + "!");
|
||||
}
|
||||
findNearestEntity(target, minecart).whenComplete((entity, throwable) ->
|
||||
{
|
||||
Bukkit.getScheduler().runTask(Plex.get(), () -> entity.addPassenger(target));
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public CompletableFuture<Entity> findNearestEntity(Player player, List<Entity> entities)
|
||||
{
|
||||
return CompletableFuture.supplyAsync(() ->
|
||||
{
|
||||
Entity nearest = entities.get(0);
|
||||
for (int i = 0; i < entities.size(); i++)
|
||||
{
|
||||
Entity e = entities.get(i);
|
||||
if (player.getLocation().distance(e.getLocation()) < player.getLocation().distance(nearest.getLocation()))
|
||||
{
|
||||
nearest = e;
|
||||
}
|
||||
}
|
||||
return nearest;
|
||||
});
|
||||
}
|
||||
}
|
33
src/main/java/dev/plex/extras/command/ClearChatCommand.java
Executable file
33
src/main/java/dev/plex/extras/command/ClearChatCommand.java
Executable file
@ -0,0 +1,33 @@
|
||||
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.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "clearchat", description = "Clears the chat", aliases = "cc,cleanchat,chatclear")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.tfmextras.clearchat")
|
||||
public class ClearChatCommand extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
Bukkit.getOnlinePlayers().stream().filter(p -> !silentCheckRank(p, Rank.ADMIN, "plex.tfmextras.clearchat"))
|
||||
.forEach(p ->
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
send(p, "");
|
||||
}
|
||||
});
|
||||
PlexUtils.broadcast(messageComponent("chatCleared", sender.getName()));
|
||||
return null;
|
||||
}
|
||||
}
|
37
src/main/java/dev/plex/extras/command/CloudClearCommand.java
Executable file
37
src/main/java/dev/plex/extras/command/CloudClearCommand.java
Executable file
@ -0,0 +1,37 @@
|
||||
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.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@CommandParameters(name = "cloudclear", description = "Clears lingering potion area effect clouds", aliases = "clearcloud,aeclear")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.tfmextras.cloudclear")
|
||||
public class CloudClearCommand extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
AtomicInteger removed = new AtomicInteger();
|
||||
Bukkit.getWorlds().stream().map(World::getEntities).flatMap(Collection::stream).filter(entity -> entity.getType() == EntityType.AREA_EFFECT_CLOUD).peek(entity ->
|
||||
{
|
||||
entity.remove();
|
||||
removed.incrementAndGet();
|
||||
});
|
||||
PlexUtils.broadcast(messageComponent("areaEffectCloudClear", sender.getName()));
|
||||
return MiniMessage.miniMessage().deserialize("<gray>" + removed.get() + " area effect clouds removed.");
|
||||
}
|
||||
}
|
26
src/main/java/dev/plex/extras/command/EjectCommand.java
Executable file
26
src/main/java/dev/plex/extras/command/EjectCommand.java
Executable file
@ -0,0 +1,26 @@
|
||||
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.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "eject", description = "Removes all passengers from a player")
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.tfmextras.eject", source = RequiredCommandSource.IN_GAME)
|
||||
public class EjectCommand extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
final int passengers = player.getPassengers().size();
|
||||
player.eject();
|
||||
return MiniMessage.miniMessage().deserialize("<gray>Ejected " + passengers + " passengers.");
|
||||
}
|
||||
}
|
75
src/main/java/dev/plex/extras/command/EnchantCommand.java
Executable file
75
src/main/java/dev/plex/extras/command/EnchantCommand.java
Executable file
@ -0,0 +1,75 @@
|
||||
package dev.plex.extras.command;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
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 net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(name = "enchant", description = "Enchants an item", usage = "/<command> <add | reset | list | addall | remove>", aliases = "enchantment")
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.tfmextras.enchant", source = RequiredCommandSource.IN_GAME)
|
||||
public class EnchantCommand extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
if (item.getType() == Material.AIR)
|
||||
{
|
||||
return MiniMessage.miniMessage().deserialize("<red>You must be holding an enchantable item.");
|
||||
}
|
||||
|
||||
if (args.length == 1)
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
return MiniMessage.miniMessage().deserialize("<dark_gray>All possible enchantments are for this item are: <gray>" + StringUtils.join(getEnchantmentNames(item), ", "));
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("addall"))
|
||||
{
|
||||
getEnchantments(item).forEach(enchantment -> item.addEnchantment(enchantment, enchantment.getMaxLevel()));
|
||||
player.playSound(player, Sound.BLOCK_ANVIL_USE, 1, 1);
|
||||
return MiniMessage.miniMessage().deserialize("<gray>Added all possible enchantments for this item.");
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("reset"))
|
||||
{
|
||||
item.getEnchantments().keySet().forEach(item::removeEnchantment);
|
||||
player.playSound(player, Sound.BLOCK_ANVIL_USE, 1, 1);
|
||||
return MiniMessage.miniMessage().deserialize("<gray>Removed every enchantment from this item.");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<Enchantment> getEnchantments(ItemStack item)
|
||||
{
|
||||
List<Enchantment> enchants = Lists.newArrayList();
|
||||
Arrays.stream(Enchantment.values()).filter(enchantment -> enchantment.canEnchantItem(item)).forEach(enchants::add);
|
||||
return enchants;
|
||||
}
|
||||
|
||||
private String[] getEnchantmentNames(ItemStack item)
|
||||
{
|
||||
return getEnchantments(item).stream().map(enchantment -> enchantment.key().value()).toArray(String[]::new);
|
||||
}
|
||||
}
|
48
src/main/java/dev/plex/extras/command/EnglishMfCommand.java
Executable file
48
src/main/java/dev/plex/extras/command/EnglishMfCommand.java
Executable file
@ -0,0 +1,48 @@
|
||||
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.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Credit to AcidicCyanide <3
|
||||
* Credit to "TheDeus-Group" for the messages :)
|
||||
*/
|
||||
|
||||
@CommandParameters(name = "emf", description = "Speak english.", usage = "/<command> <player>")
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.tfmextras.emf")
|
||||
public class EnglishMfCommand extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
Player target = getNonNullPlayer(args[0]);
|
||||
target.sendMessage(mmString("<red>ENGLISH MOTHERFUCKER, Do you speak it!?"));
|
||||
PlexUtils.broadcast("<red>" + sender.getName() + " is sick of " + target.getName() + " not speaking English!");
|
||||
target.setHealth(0);
|
||||
target.getWorld().strikeLightningEffect(target.getLocation());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).collect(Collectors.toList());
|
||||
}
|
||||
}
|
137
src/main/java/dev/plex/extras/command/JumpPadsCommand.java
Executable file
137
src/main/java/dev/plex/extras/command/JumpPadsCommand.java
Executable file
@ -0,0 +1,137 @@
|
||||
package dev.plex.extras.command;
|
||||
|
||||
import dev.plex.extras.TFMExtras;
|
||||
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.extras.jumppads.JumpPads;
|
||||
import dev.plex.extras.jumppads.Mode;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(name = "jumppads", usage = "/jumppads <mode> [player]", description = "Enables jump pads for yourself or another player. Mode types available: none, regular, enhanced, extreme, ultimate", aliases = "jp,pads,launchpads")
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.tfmextras.jumppads", source = RequiredCommandSource.ANY)
|
||||
public class JumpPadsCommand extends PlexCommand
|
||||
{
|
||||
JumpPads jumpPads = TFMExtras.getModule().jumpPads;
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
if ((args.length < 1) || (args.length > 2))
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
if (args.length == 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
return MiniMessage.miniMessage().deserialize("<red>You must specify a player when running this command from console.");
|
||||
}
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("none") || args[0].equalsIgnoreCase("off"))
|
||||
{
|
||||
jumpPads.removePlayer(player);
|
||||
return MiniMessage.miniMessage().deserialize("<gray>You have disabled your jump pads.");
|
||||
}
|
||||
|
||||
Mode mode = Mode.valueOf(args[0].toUpperCase());
|
||||
|
||||
if (jumpPads.get(player) != null)
|
||||
{
|
||||
if (mode.equals(jumpPads.get(player)))
|
||||
{
|
||||
return MiniMessage.miniMessage().deserialize("<red>Your jump pads are already set to " + mode.name() + ".");
|
||||
}
|
||||
else
|
||||
{
|
||||
jumpPads.updatePlayer(player, mode);
|
||||
return MiniMessage.miniMessage().deserialize("<aqua>Successfully set your jump pads to " + mode.name() + ".");
|
||||
}
|
||||
}
|
||||
|
||||
jumpPads.addPlayer(player, mode);
|
||||
return MiniMessage.miniMessage().deserialize("<aqua>Successfully set your jump pads to " + mode.name() + ".");
|
||||
}
|
||||
catch (IllegalArgumentException ignored)
|
||||
{
|
||||
return MiniMessage.miniMessage().deserialize("<red>That is not a valid mode.");
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
Player p = Bukkit.getPlayer(args[1]);
|
||||
|
||||
if (p == null)
|
||||
{
|
||||
return MiniMessage.miniMessage().deserialize("<red>That player cannot be found.");
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("none"))
|
||||
{
|
||||
jumpPads.removePlayer(p);
|
||||
return MiniMessage.miniMessage().deserialize("<gray>Jump pads for " + p.getName() + " have been disabled.");
|
||||
}
|
||||
|
||||
Mode mode = Mode.valueOf(args[0]);
|
||||
|
||||
if (!checkRank(sender, Rank.ADMIN, "plex.tfmextras.jumppads.others"))
|
||||
{
|
||||
return permissionMessage();
|
||||
}
|
||||
|
||||
if (jumpPads.get(p) != null)
|
||||
{
|
||||
if (jumpPads.get(p).equals(mode))
|
||||
{
|
||||
return MiniMessage.miniMessage().deserialize("<red>Your jump pads are already set to " + mode.name() + ".");
|
||||
}
|
||||
|
||||
jumpPads.updatePlayer(p, mode);
|
||||
return MiniMessage.miniMessage().deserialize("<gray>Jump pads for " + p.getName() + " have been set to " + mode.name() + ".");
|
||||
}
|
||||
|
||||
jumpPads.addPlayer(p, mode);
|
||||
return MiniMessage.miniMessage().deserialize("<gray>Jump pads for " + p.getName() + " have been set to " + mode.name() + ".");
|
||||
}
|
||||
catch (IllegalArgumentException ignored)
|
||||
{
|
||||
return MiniMessage.miniMessage().deserialize("That is not a valid mode.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return Arrays.asList("none", "normal", "enhanced", "extreme", "ultimate");
|
||||
}
|
||||
else if (args.length == 2)
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
43
src/main/java/dev/plex/extras/command/RandomFishCommand.java
Executable file
43
src/main/java/dev/plex/extras/command/RandomFishCommand.java
Executable file
@ -0,0 +1,43 @@
|
||||
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.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
@CommandParameters(name = "randomfish", description = "Spawns a random type of fish at your location", aliases = "rfish,bird")
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.tfmextras.randomfish", source = RequiredCommandSource.IN_GAME)
|
||||
public class RandomFishCommand extends PlexCommand
|
||||
{
|
||||
private static final List<EntityType> FISH_TYPES = Arrays.asList(EntityType.COD, EntityType.SALMON, EntityType.PUFFERFISH, EntityType.TROPICAL_FISH);
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
@Nullable Block block = player.getTargetBlockExact(15);
|
||||
if (block == null)
|
||||
{
|
||||
return MiniMessage.miniMessage().deserialize("<red>There is no block within 15 blocks of you.");
|
||||
}
|
||||
player.getWorld().spawnEntity(block.getLocation().add(0, 1, 0), randomFish());
|
||||
return MiniMessage.miniMessage().deserialize(":goodbird:");
|
||||
}
|
||||
|
||||
private EntityType randomFish()
|
||||
{
|
||||
return FISH_TYPES.get(ThreadLocalRandom.current().nextInt(FISH_TYPES.size()));
|
||||
}
|
||||
}
|
16
src/main/java/dev/plex/extras/hook/IHook.java
Normal file
16
src/main/java/dev/plex/extras/hook/IHook.java
Normal file
@ -0,0 +1,16 @@
|
||||
package dev.plex.extras.hook;
|
||||
|
||||
import dev.plex.extras.TFMExtras;
|
||||
|
||||
/**
|
||||
* @author Taah
|
||||
* @since 2:16 PM [23-08-2023]
|
||||
*/
|
||||
public interface IHook<T> {
|
||||
|
||||
void onEnable(TFMExtras module);
|
||||
|
||||
void onDisable(TFMExtras module);
|
||||
|
||||
T plugin();
|
||||
}
|
193
src/main/java/dev/plex/extras/hook/SlimeWorldHook.java
Normal file
193
src/main/java/dev/plex/extras/hook/SlimeWorldHook.java
Normal file
@ -0,0 +1,193 @@
|
||||
package dev.plex.extras.hook;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.infernalsuite.aswm.api.SlimePlugin;
|
||||
import com.infernalsuite.aswm.api.exceptions.*;
|
||||
import com.infernalsuite.aswm.api.loaders.SlimeLoader;
|
||||
import com.infernalsuite.aswm.api.world.SlimeWorld;
|
||||
import com.infernalsuite.aswm.api.world.properties.SlimeProperties;
|
||||
import com.infernalsuite.aswm.api.world.properties.SlimePropertyMap;
|
||||
import dev.plex.extras.TFMExtras;
|
||||
import dev.plex.util.PlexLog;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* @author Taah
|
||||
* @since 2:19 PM [23-08-2023]
|
||||
*/
|
||||
public class SlimeWorldHook implements IHook<SlimePlugin>
|
||||
{
|
||||
private static final String WORLD_NOT_FOUND = "<red>This world could not be found!";
|
||||
private static final String STORAGE_FAILURE = "<red>This world cannot be stored!";
|
||||
|
||||
private final Set<String> LOADED_WORLDS = Sets.newHashSet();
|
||||
|
||||
private SlimeLoader loader;
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable(TFMExtras module)
|
||||
{
|
||||
if (plugin() == null)
|
||||
{
|
||||
PlexLog.error("Cannot find SlimeWorldManager plugin");
|
||||
return;
|
||||
}
|
||||
|
||||
PlexLog.log("<green>Enabling SWM Hook");
|
||||
|
||||
this.loader = plugin().getLoader("mysql");
|
||||
this.loadAllWorlds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable(TFMExtras module)
|
||||
{
|
||||
PlexLog.log("<green>Disabling SWM Hook");
|
||||
AtomicInteger i = new AtomicInteger();
|
||||
LOADED_WORLDS.forEach(s ->
|
||||
{
|
||||
final World world = Bukkit.getWorld(s);
|
||||
if (world != null)
|
||||
{
|
||||
world.save();
|
||||
i.getAndIncrement();
|
||||
}
|
||||
});
|
||||
PlexLog.log("<green>SWM Hook saved " + i.get() + " worlds");
|
||||
}
|
||||
|
||||
public void loadAllWorlds()
|
||||
{
|
||||
try
|
||||
{
|
||||
this.loader.listWorlds().forEach(s ->
|
||||
{
|
||||
final SlimePropertyMap slimePropertyMap = new SlimePropertyMap();
|
||||
slimePropertyMap.setValue(SlimeProperties.PVP, false);
|
||||
|
||||
try
|
||||
{
|
||||
SlimeWorld world = this.plugin().loadWorld(this.loader, s, false, slimePropertyMap);
|
||||
this.plugin().loadWorld(world);
|
||||
this.loader.unlockWorld(s);
|
||||
}
|
||||
catch (UnknownWorldException | WorldLockedException | CorruptedWorldException | NewerFormatException | IllegalArgumentException ex)
|
||||
{
|
||||
PlexLog.error(ex.getMessage());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
PlexLog.error(STORAGE_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
final World world = Bukkit.getWorld(s);
|
||||
if (world == null)
|
||||
{
|
||||
PlexLog.error(WORLD_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
world.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
|
||||
world.setGameRule(GameRule.DISABLE_RAIDS, true);
|
||||
world.setGameRule(GameRule.DO_INSOMNIA, false);
|
||||
world.setGameRule(GameRule.DO_FIRE_TICK, false);
|
||||
world.setSpawnLocation(0, 130, 0);
|
||||
world.setAutoSave(true);
|
||||
|
||||
LOADED_WORLDS.add(s);
|
||||
|
||||
double configuratedSize = TFMExtras.getModule().getConfig().getDouble("player-worlds.size");
|
||||
world.getWorldBorder().setCenter(world.getSpawnLocation());
|
||||
world.getWorldBorder().setSize(configuratedSize == 0 ? 500 : configuratedSize);
|
||||
world.getWorldBorder().setDamageAmount(0);
|
||||
world.getWorldBorder().setDamageBuffer(0);
|
||||
PlexLog.debug("Loaded {0}", s);
|
||||
});
|
||||
}
|
||||
catch (IOException | IllegalArgumentException ex)
|
||||
{
|
||||
PlexLog.error(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public Pair<World, Boolean> createPlayerWorld(UUID uuid)
|
||||
{
|
||||
final SlimePropertyMap slimePropertyMap = new SlimePropertyMap();
|
||||
slimePropertyMap.setValue(SlimeProperties.PVP, false);
|
||||
|
||||
boolean newWorld = false;
|
||||
try
|
||||
{
|
||||
slimePropertyMap.setValue(SlimeProperties.SPAWN_X, 0);
|
||||
slimePropertyMap.setValue(SlimeProperties.SPAWN_Y, 130);
|
||||
slimePropertyMap.setValue(SlimeProperties.SPAWN_Z, 0);
|
||||
final SlimeWorld slimeWorld = this.plugin().createEmptyWorld(this.loader, uuid.toString(), false, slimePropertyMap);
|
||||
this.plugin().loadWorld(slimeWorld);
|
||||
newWorld = true;
|
||||
}
|
||||
catch (WorldAlreadyExistsException e)
|
||||
{
|
||||
try
|
||||
{
|
||||
SlimeWorld world = this.plugin().loadWorld(this.loader, uuid.toString(), false, slimePropertyMap);
|
||||
this.plugin().loadWorld(world);
|
||||
this.loader.unlockWorld(uuid.toString());
|
||||
}
|
||||
catch (WorldLockedException | CorruptedWorldException | NewerFormatException | UnknownWorldException |
|
||||
IOException | IllegalArgumentException ex)
|
||||
{
|
||||
PlexLog.error(ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
PlexLog.error(STORAGE_FAILURE);
|
||||
}
|
||||
|
||||
final World world = Bukkit.getWorld(uuid.toString());
|
||||
if (world == null)
|
||||
{
|
||||
PlexLog.error(WORLD_NOT_FOUND);
|
||||
return null;
|
||||
}
|
||||
world.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
|
||||
world.setGameRule(GameRule.DISABLE_RAIDS, true);
|
||||
world.setGameRule(GameRule.DO_INSOMNIA, false);
|
||||
world.setGameRule(GameRule.DO_FIRE_TICK, false);
|
||||
world.setSpawnLocation(0, 130, 0);
|
||||
world.setAutoSave(true);
|
||||
|
||||
if (newWorld)
|
||||
{
|
||||
world.getBlockAt(0, 128, 0).setType(Material.STONE);
|
||||
}
|
||||
|
||||
LOADED_WORLDS.add(uuid.toString());
|
||||
|
||||
double configuratedSize = TFMExtras.getModule().getConfig().getDouble("player-worlds.size");
|
||||
world.getWorldBorder().setCenter(world.getSpawnLocation());
|
||||
world.getWorldBorder().setSize(configuratedSize == 0 ? 500 : configuratedSize);
|
||||
world.getWorldBorder().setDamageAmount(0);
|
||||
world.getWorldBorder().setDamageBuffer(0);
|
||||
|
||||
return Pair.of(world, newWorld);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SlimePlugin plugin()
|
||||
{
|
||||
return (SlimePlugin) Bukkit.getPluginManager().getPlugin("SlimeWorldManager");
|
||||
}
|
||||
}
|
64
src/main/java/dev/plex/extras/jumppads/JumpPads.java
Executable file
64
src/main/java/dev/plex/extras/jumppads/JumpPads.java
Executable file
@ -0,0 +1,64 @@
|
||||
package dev.plex.extras.jumppads;
|
||||
|
||||
import dev.plex.extras.TFMExtras;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class JumpPads
|
||||
{
|
||||
public final Map<UUID, Mode> playerModeMap = new HashMap<>();
|
||||
public final double SCALAR = 0.8;
|
||||
public final double STRENGTH = TFMExtras.getModule().getConfig().getInt("server.jumppad_strength", 1) + 0.1F;
|
||||
public final double EXTREME = STRENGTH + 0.5;
|
||||
public final Tag<Material> wool = Tag.WOOL;
|
||||
|
||||
public Vector extreme(Vector vector)
|
||||
{
|
||||
return vector.multiply(STRENGTH * SCALAR * ThreadLocalRandom.current().nextInt(3, 6));
|
||||
}
|
||||
|
||||
public void addPlayer(Player player, Mode mode)
|
||||
{
|
||||
playerModeMap.put(player.getUniqueId(), mode);
|
||||
}
|
||||
|
||||
public void updatePlayer(Player player, Mode mode)
|
||||
{
|
||||
playerModeMap.replace(player.getUniqueId(), mode);
|
||||
}
|
||||
|
||||
public void removePlayer(Player player)
|
||||
{
|
||||
playerModeMap.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
public Mode get(Player player)
|
||||
{
|
||||
return playerModeMap.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
public final Map<Block, Wrap> blockWrapMap(Block block)
|
||||
{
|
||||
return new HashMap<>()
|
||||
{{
|
||||
put(block.getRelative(BlockFace.DOWN), new Wrap(0, -1, 0));
|
||||
put(block.getRelative(BlockFace.EAST), new Wrap(1, 0, 0));
|
||||
put(block.getRelative(BlockFace.WEST), new Wrap(-1, 0, 0));
|
||||
put(block.getRelative(BlockFace.NORTH), new Wrap(0, 0, 1));
|
||||
put(block.getRelative(BlockFace.SOUTH), new Wrap(0, 0, -1));
|
||||
}};
|
||||
}
|
||||
|
||||
public record Wrap(int x, int y, int z)
|
||||
{
|
||||
}
|
||||
}
|
9
src/main/java/dev/plex/extras/jumppads/Mode.java
Executable file
9
src/main/java/dev/plex/extras/jumppads/Mode.java
Executable file
@ -0,0 +1,9 @@
|
||||
package dev.plex.extras.jumppads;
|
||||
|
||||
public enum Mode
|
||||
{
|
||||
NORMAL,
|
||||
ENHANCED,
|
||||
EXTREME,
|
||||
ULTIMATE
|
||||
}
|
145
src/main/java/dev/plex/extras/listener/JumpPadsListener.java
Executable file
145
src/main/java/dev/plex/extras/listener/JumpPadsListener.java
Executable file
@ -0,0 +1,145 @@
|
||||
package dev.plex.extras.listener;
|
||||
|
||||
import dev.plex.extras.TFMExtras;
|
||||
import dev.plex.extras.jumppads.JumpPads;
|
||||
import dev.plex.extras.jumppads.Mode;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.util.PlexLog;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class JumpPadsListener extends PlexListener
|
||||
{
|
||||
JumpPads jumpPads = TFMExtras.getModule().jumpPads;
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void jumppadsAction(PlayerMoveEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
Vector playerVector = player.getVelocity().clone();
|
||||
Block block = event.getTo().getBlock();
|
||||
Map<Block, JumpPads.Wrap> blockWrapMap = jumpPads.blockWrapMap(block);
|
||||
if (!jumpPads.playerModeMap.containsKey(player.getUniqueId()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Mode mode = jumpPads.playerModeMap.get(player.getUniqueId());
|
||||
if (mode == Mode.NORMAL)
|
||||
{
|
||||
Block below = block.getRelative(BlockFace.DOWN);
|
||||
if (jumpPads.wool.getValues().contains(below.getType()))
|
||||
{
|
||||
if (event.getFrom().getY() > block.getY() + 0.1 && ((int) event.getTo().getY() == block.getY()))
|
||||
{
|
||||
Vector vector = playerVector.multiply(new Vector(0.0, jumpPads.SCALAR * jumpPads.STRENGTH, 0.0));
|
||||
if (vector.getY() < 0)
|
||||
{
|
||||
vector = vector.multiply(new Vector(0, -1, 0));
|
||||
}
|
||||
PlexLog.debug("New Velocity: {0}", vector.toString());
|
||||
player.setFallDistance(0);
|
||||
player.setVelocity(vector);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (mode.equals(Mode.ENHANCED))
|
||||
{
|
||||
blockWrapMap.forEach((b, w) ->
|
||||
{
|
||||
if (jumpPads.wool.getValues().contains(b.getType()))
|
||||
{
|
||||
if (!(event.getFrom().getY() > block.getY() + 0.1 && ((int) event.getTo().getY() == block.getY())))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (w.y() == -1)
|
||||
{
|
||||
playerVector.add(new Vector(0.0, jumpPads.SCALAR * jumpPads.STRENGTH, 0.0));
|
||||
}
|
||||
|
||||
switch (w.x())
|
||||
{
|
||||
case (-1):
|
||||
playerVector.add(new Vector(-jumpPads.SCALAR * jumpPads.STRENGTH, 0.0, 0.0));
|
||||
case (1):
|
||||
playerVector.add(new Vector(jumpPads.SCALAR * jumpPads.STRENGTH, 0.0, 0.0));
|
||||
}
|
||||
|
||||
switch (w.z())
|
||||
{
|
||||
case (-1):
|
||||
playerVector.add(new Vector(0.0, 0.0, -jumpPads.SCALAR * jumpPads.STRENGTH));
|
||||
case (1):
|
||||
playerVector.add(new Vector(0.0, 0.0, jumpPads.SCALAR * jumpPads.STRENGTH));
|
||||
}
|
||||
|
||||
player.setVelocity(playerVector);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (mode == Mode.EXTREME)
|
||||
{
|
||||
Block below = block.getRelative(BlockFace.DOWN);
|
||||
if (jumpPads.wool.getValues().contains(below.getType()))
|
||||
{
|
||||
if (event.getFrom().getY() > block.getY() + 0.1 && ((int) event.getTo().getY() == block.getY()))
|
||||
{
|
||||
player.setVelocity(jumpPads.extreme(playerVector));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (mode.equals(Mode.ULTIMATE))
|
||||
{
|
||||
blockWrapMap.forEach((b, w) ->
|
||||
{
|
||||
if (jumpPads.wool.getValues().contains(b.getType()))
|
||||
{
|
||||
if (w.y() == -1)
|
||||
{
|
||||
jumpPads.extreme(playerVector.add(new Vector(0.0, jumpPads.SCALAR * jumpPads.STRENGTH, 0.0)));
|
||||
}
|
||||
|
||||
switch (w.x())
|
||||
{
|
||||
case (-1):
|
||||
jumpPads.extreme(playerVector.add(new Vector(-jumpPads.SCALAR * jumpPads.STRENGTH, 0.0, 0.0)));
|
||||
case (1):
|
||||
jumpPads.extreme(playerVector.add(new Vector(jumpPads.SCALAR * jumpPads.STRENGTH, 0.0, 0.0)));
|
||||
}
|
||||
|
||||
switch (w.z())
|
||||
{
|
||||
case (-1):
|
||||
jumpPads.extreme(playerVector.add(new Vector(0.0, 0.0, -jumpPads.SCALAR * jumpPads.STRENGTH)));
|
||||
case (1):
|
||||
jumpPads.extreme(playerVector.add(new Vector(0.0, 0.0, jumpPads.SCALAR * jumpPads.STRENGTH)));
|
||||
|
||||
}
|
||||
|
||||
player.setVelocity(playerVector);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void cleanup(PlayerQuitEvent event)
|
||||
{
|
||||
jumpPads.playerModeMap.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
53
src/main/java/dev/plex/extras/listener/PlayerListener.java
Executable file
53
src/main/java/dev/plex/extras/listener/PlayerListener.java
Executable file
@ -0,0 +1,53 @@
|
||||
package dev.plex.extras.listener;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.extras.TFMExtras;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class PlayerListener extends PlexListener
|
||||
{
|
||||
@EventHandler
|
||||
public void onAuto(PlayerJoinEvent event)
|
||||
{
|
||||
if (TFMExtras.getModule().getConfig().getStringList("server.clear-on-join").contains(event.getPlayer().getName()))
|
||||
{
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
event.getPlayer().getInventory().clear();
|
||||
}
|
||||
}.runTaskLater(Plex.get(), 1);
|
||||
}
|
||||
if (TFMExtras.getModule().getConfig().getStringList("server.teleport-on-join").contains(event.getPlayer().getName()))
|
||||
{
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
event.getPlayer().teleportAsync(TFMExtras.getRandomLocation(event.getPlayer().getWorld()));
|
||||
}
|
||||
}.runTaskLater(Plex.get(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void createPlayerWorld(PlayerJoinEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
final Pair<World, Boolean> world = TFMExtras.getModule().getSlimeWorldHook().createPlayerWorld(player.getUniqueId());
|
||||
if (world.getRight())
|
||||
{
|
||||
player.sendMessage(PlexUtils.messageComponent("createdPlayerWorld"));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user