Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paper Plugin Implementation #51

Merged
merged 5 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.wolfyscript.utilities.common.chat.Chat;
import com.wolfyscript.utilities.bukkit.language.LangAPISpigot;
import me.wolfyscript.utilities.api.Permissions;
import me.wolfyscript.utilities.api.WolfyUtilCore;
import me.wolfyscript.utilities.api.WolfyUtilities;
import com.wolfyscript.utilities.bukkit.chat.ChatImpl;
import me.wolfyscript.utilities.api.config.ConfigAPI;
Expand All @@ -25,7 +26,7 @@

public class WolfyUtilsBukkit extends WolfyUtils {

private final WolfyCoreBukkit core;
private final WolfyUtilCore core;

private final Plugin plugin;

Expand All @@ -43,7 +44,7 @@ public class WolfyUtilsBukkit extends WolfyUtils {

private final boolean initialize;

protected WolfyUtilsBukkit(WolfyCoreBukkit core, Plugin plugin, Class<? extends CustomCache> cacheType, boolean init) {
protected WolfyUtilsBukkit(WolfyUtilCore core, Plugin plugin, Class<? extends CustomCache> cacheType, boolean init) {
this.core = core;
this.plugin = plugin;
this.languageAPI = new LangAPISpigot(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
/*
* WolfyUtilities, APIs and Utilities for Minecraft Spigot plugins
* Copyright (C) 2021 WolfyScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.wolfyscript.utilities.bukkit.commands;

import com.wolfyscript.utilities.bukkit.chat.ChatImpl;
import java.util.UUID;
import me.wolfyscript.utilities.api.WolfyUtilCore;
import me.wolfyscript.utilities.api.chat.PlayerAction;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.UUID;
public class ChatActionCommand extends Command implements PluginIdentifiableCommand {

public class ChatActionCommand implements TabExecutor {
private final WolfyUtilCore core;

public ChatActionCommand(WolfyUtilCore core) {
super("wua");
this.core = core;
setDescription("Used to handle code execution on chat click events.");
}

@NotNull
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
public Plugin getPlugin() {
return core;
}

@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (!(sender instanceof Player player)) return true;
if (args.length > 0) {
UUID uuid;
Expand All @@ -52,9 +47,4 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}
return true;
}

@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,48 @@

package com.wolfyscript.utilities.bukkit.commands;

import com.wolfyscript.utilities.bukkit.WolfyCoreBukkit;
import java.util.List;
import me.wolfyscript.utilities.api.WolfyUtilCore;
import me.wolfyscript.utilities.api.chat.Chat;
import me.wolfyscript.utilities.util.version.ServerVersion;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
public class InfoCommand extends Command implements PluginIdentifiableCommand {

public class InfoCommand implements TabExecutor {
private final WolfyUtilCore core;

private final WolfyCoreBukkit plugin;
public InfoCommand(WolfyUtilCore core) {
super("wolfyutils");
this.core = core;
setDescription("Displays info about the plugin version, etc.");
}

public InfoCommand(WolfyCoreBukkit plugin) {
this.plugin = plugin;
@NotNull
@Override
public Plugin getPlugin() {
return core;
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (!(sender instanceof Player)) return true;
plugin.getWolfyUtilities().getChat().sendMessages((Player) sender, true,
((Chat) core.getWolfyUtils().getChat()).sendMessages((Player) sender, true,
Component.text("——————— ", NamedTextColor.GRAY).append(Component.text("WolfyUtilities", NamedTextColor.AQUA, TextDecoration.BOLD)).append(Component.text(" ———————")),
Component.empty(),
Component.text("Author: ", NamedTextColor.GRAY).append(Component.text(String.join(", ", plugin.getDescription().getAuthors()), null, TextDecoration.BOLD)),
Component.text("Author: ", NamedTextColor.GRAY).append(Component.text(String.join(", ", core.getDescription().getAuthors()), null, TextDecoration.BOLD)),
Component.empty(),
Component.text("Version: ", NamedTextColor.GRAY).append(Component.text(ServerVersion.getWUVersion().getVersion(), null, TextDecoration.BOLD)),
Component.text("———————————————————————", NamedTextColor.GRAY)
);
return true;
}

@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,75 +1,64 @@
/*
* WolfyUtilities, APIs and Utilities for Minecraft Spigot plugins
* Copyright (C) 2021 WolfyScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.wolfyscript.utilities.bukkit.commands;

import com.wolfyscript.utilities.bukkit.WolfyCoreBukkit;
import java.util.List;
import java.util.Objects;
import me.wolfyscript.utilities.api.WolfyUtilCore;
import me.wolfyscript.utilities.api.WolfyUtilities;
import me.wolfyscript.utilities.api.inventory.gui.GuiHandler;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Objects;
public final class InputCommand extends Command implements PluginIdentifiableCommand {

public class InputCommand implements TabExecutor {
private final WolfyUtilCore core;

private final WolfyCoreBukkit plugin;
public InputCommand(WolfyUtilCore core) {
super("wui");
this.core = core;
setUsage("/wui <input>");
setDescription("Input for chat input actions");
}

public InputCommand(WolfyCoreBukkit plugin) {
this.plugin = plugin;
@NotNull
@Override
public Plugin getPlugin() {
return core;
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (sender instanceof Player player) {
plugin.getAPIList().parallelStream()
.filter(WolfyUtilities::hasInventoryAPI)
.map(wolfyUtilities -> wolfyUtilities.getInventoryAPI().getGuiHandler(player))
.filter(GuiHandler::isChatEventActive)
.forEach(guiHandler -> Bukkit.getScheduler().runTask(WolfyUtilities.getWUPlugin(), () -> {
//Handles ChatInput
if (!guiHandler.onChat(player, String.join(" ", args).trim(), args)) {
guiHandler.setChatInputAction(null);
guiHandler.openCluster();
}
if (guiHandler.isChatEventActive()) {
guiHandler.cancelChatInput();
}
}));
}
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (!(sender instanceof Player player)) return true;
core.getAPIList().parallelStream()
.filter(WolfyUtilities::hasInventoryAPI)
.map(wolfyUtilities -> wolfyUtilities.getInventoryAPI().getGuiHandler(player))
.filter(GuiHandler::isChatEventActive)
.forEach(guiHandler -> Bukkit.getScheduler().runTask(WolfyUtilities.getWUPlugin(), () -> {
//Handles ChatInput
if (!guiHandler.onChat(player, String.join(" ", args).trim(), args)) {
guiHandler.setChatInputAction(null);
guiHandler.openCluster();
}
if (guiHandler.isChatEventActive()) {
guiHandler.cancelChatInput();
}
}));
return true;
}

@NotNull
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
if (sender instanceof Player player) {
return plugin.getAPIList().stream()
.filter(WolfyUtilities::hasInventoryAPI)
.map(wolfyUtilities -> wolfyUtilities.getInventoryAPI().getGuiHandler(player))
.filter(guiHandler -> guiHandler.isChatEventActive() && guiHandler.hasChatTabComplete())
.map(guiHandler -> guiHandler.getChatTabComplete().onTabComplete(guiHandler, player, args)).filter(Objects::nonNull).findFirst().orElse(null);
}
return null;
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
if (!(sender instanceof Player player)) return List.of();
return core.getAPIList().stream()
.filter(WolfyUtilities::hasInventoryAPI)
.map(wolfyUtilities -> wolfyUtilities.getInventoryAPI().getGuiHandler(player))
.filter(guiHandler -> guiHandler.isChatEventActive() && guiHandler.hasChatTabComplete())
.map(guiHandler -> guiHandler.getChatTabComplete().onTabComplete(guiHandler, player, args))
.filter(Objects::nonNull).findFirst().orElseGet(() -> super.tabComplete(sender, alias, args));
}
}
Original file line number Diff line number Diff line change
@@ -1,55 +1,43 @@
/*
* WolfyUtilities, APIs and Utilities for Minecraft Spigot plugins
* Copyright (C) 2021 WolfyScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.wolfyscript.utilities.bukkit.commands;

import com.wolfyscript.utilities.bukkit.WolfyCoreBukkit;
import com.wolfyscript.utilities.bukkit.nbt.NBTQuery;
import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTItem;
import java.io.File;
import me.wolfyscript.utilities.api.WolfyUtilCore;
import me.wolfyscript.utilities.util.inventory.ItemUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.util.List;
public final class QueryDebugCommand extends Command implements PluginIdentifiableCommand {

public class QueryDebugCommand implements TabExecutor {
private final WolfyUtilCore core;

private final WolfyCoreBukkit plugin;
public QueryDebugCommand(WolfyUtilCore core) {
super("query_item");
this.core = core;
setUsage("/query_item");
setPermission("wolfyutilities.command.query_debug");
}

public QueryDebugCommand(WolfyCoreBukkit plugin) {
this.plugin = plugin;
@NotNull
@Override
public Plugin getPlugin() {
return core;
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player player)) return true;
if (!player.hasPermission("wolfyutilities.command.query_debug")) return true;
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (!(sender instanceof Player player) || !testPermission(sender)) return true;
ItemStack stack = player.getEquipment().getItem(EquipmentSlot.HAND);
if (!ItemUtils.isAirOrNull(stack)) {
File file = new File(plugin.getDataFolder(), "query_debug.json");
File file = new File(core.getDataFolder(), "query_debug.json");
if (file.exists()) {
NBTQuery.of(file).ifPresent(nbtQuery -> {
NBTItem nbtItem = new NBTItem(stack);
Expand All @@ -70,8 +58,4 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
return true;
}

@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
return null;
}
}