Skip to content

Commit

Permalink
Merge pull request #85 from Nookure/dev
Browse files Browse the repository at this point in the history
Merge Dev
  • Loading branch information
Angelillo15 authored Dec 22, 2023
2 parents 5285712 + 486a5a1 commit 2318f83
Show file tree
Hide file tree
Showing 18 changed files with 345 additions and 76 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
/MAStaff-API/build/
/.idea/

# Maven exclude paths
maven

# Ignore Gradle project-specific cache directory
.gradle

Expand Down
25 changes: 19 additions & 6 deletions MAStaff-API/API-Publish/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
`maven-publish`
id("com.github.johnrengelman.shadow") version "8.1.1"
id("org.ajoberstar.grgit") version "5.2.1"
id("org.ajoberstar.git-publish") version "4.2.1"
}

dependencies {
Expand All @@ -29,12 +31,8 @@ dependencies {
publishing {
repositories {
maven {
name = "nookureRepository"
url = uri("https://repo.nookure.com/releases")
credentials(PasswordCredentials::class)
authentication {
create<BasicAuthentication>("basic")
}
name = "local"
url = uri("${rootProject.rootDir}/maven")
}
}

Expand All @@ -54,4 +52,19 @@ tasks.shadowJar {
relocate(from, to)
}
exclude("META-INF/maven/**")
}

gitPublish {
repoUri = "https://github.com/Nookure/maven.git"
branch = "main"
fetchDepth = null
commitMessage = "MAStaff-API ${parent!!.version}"

contents {
from("${rootProject.rootDir}/maven")
}

preserve {
include("**")
}
}
2 changes: 1 addition & 1 deletion MAStaff-API/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.time.format.DateTimeFormatter
plugins {
id("java")
id("net.kyori.blossom") version "1.3.1"
id("org.ajoberstar.grgit") version "4.1.0"
id("org.ajoberstar.grgit") version "5.2.1"
}

group = "es.angelillo15"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Here you will find the config files API.
*/
package com.nookure.mast.api.config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* This package contains the classes related to the staff.
*/
package com.nookure.mast.api.staff;
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.List;
import java.util.Map;

import net.kyori.adventure.text.Component;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -208,4 +209,12 @@ default String getName() {
default void sendMessage(String message) {
TextUtils.sendMessage(getPlayer(), TextUtils.toMM(message));
}

/**
* Send a message to the player
* @param component - message to send
*/
default void sendMessage(Component component) {
TextUtils.getAudience(getPlayer()).sendMessage(component);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package es.angelillo15.mast.api;

public record Replace(String search, String replace) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ConfigLoader {
@Getter private static ConfigManager en;
@Getter private static ConfigManager customItems;
@Getter private static ConfigManager punishmentsGUI;
@Getter private static ConfigManager commands;
private final MAStaffInstance<JavaPlugin> plugin;
private final boolean isFree;

Expand All @@ -41,6 +42,8 @@ public void load() {
loadMessage();
logger.debug("Loading internal staff items...");
loadInternal();
logger.debug("Loading commands...");
loadCommands();

if (!isFree) {
logger.debug("Loading glow module...");
Expand Down Expand Up @@ -134,6 +137,15 @@ public void loadCustomItems() {
customItems.registerConfig();
}

public void loadCommands() {
commands =
new ConfigManager(
plugin.getPluginDataFolder().toPath(),
"Bukkit/commands.yml",
"/commands.yml");
commands.registerConfig();
}

public void loadGlowModule() {
glow =
new ConfigManager(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import es.angelillo15.mast.bukkit.cmd.VanishCMD;
import es.angelillo15.mast.bukkit.cmd.mast.MASTParent;
import es.angelillo15.mast.bukkit.cmd.staff.StaffParent;
import es.angelillo15.mast.bukkit.cmd.teleport.TpCommand;
import es.angelillo15.mast.bukkit.cmd.teleport.TphCommand;
import es.angelillo15.mast.bukkit.cmd.utils.CommandManager;
import es.angelillo15.mast.bukkit.cmd.utils.CommandTemplate;
import es.angelillo15.mast.bukkit.inject.BukkitInjector;
Expand Down Expand Up @@ -161,10 +163,12 @@ public void registerCommands() {
registerCommand(injector.getInstance(StaffChat.class));
registerCommand(injector.getInstance(MASTParent.class));
registerCommand(injector.getInstance(HelpOP.class));
registerCommand(injector.getInstance(TpCommand.class));
registerCommand(injector.getInstance(TphCommand.class));
if (Config.Addons.vanish())
registerCommand(injector.getInstance(VanishCMD.class));
if (Config.Freeze.enabled())
Objects.requireNonNull(getCommand("freeze")).setExecutor(injector.getInstance(FreezeCMD.class));
registerCommand(injector.getInstance(FreezeCMD.class));
if (Config.Freeze.enabled() && Config.Freeze.freezeChat())
registerCommand(injector.getInstance(FreezeChat.class));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,84 +1,102 @@
package es.angelillo15.mast.bukkit.cmd;

import com.google.inject.Inject;
import com.nookure.mast.api.cmd.Command;
import com.nookure.mast.api.cmd.CommandData;
import com.nookure.mast.api.cmd.sender.CommandSender;
import com.nookure.mast.api.cmd.sender.PlayerCommandSender;
import es.angelillo15.mast.api.IStaffPlayer;
import es.angelillo15.mast.api.TextUtils;
import es.angelillo15.mast.api.config.bukkit.Messages;
import es.angelillo15.mast.api.managers.StaffManager;
import com.nookure.mast.api.manager.FreezeManager;
import es.angelillo15.mast.bukkit.gui.SelectTargetGUI;

import java.util.List;
import java.util.Objects;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class FreezeCMD implements CommandExecutor {
@Inject
private StaffManager staffManager;
@Inject
private FreezeManager freezeManager;

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player p)) return false;
@CommandData(
name = "freeze",
permission = "mast.freeze",
aliases = {"fr"},
usage = "/freeze <player>",
description = "Freeze a player"
)
public class FreezeCMD extends Command {
@Inject
private StaffManager staffManager;
@Inject
private FreezeManager freezeManager;

if (!staffManager.isStaffPlayer(p.getName())) return false;
@Override
public void onCommand(@NotNull CommandSender sender, @NotNull String label, @NotNull String[] args) {
if (!(sender instanceof PlayerCommandSender pcs)) return;

IStaffPlayer staff = staffManager.getStaffPlayer(p.getName());
Player p = pcs.getPlayer();

assert staff != null;
if (!staffManager.isStaffPlayer(p.getName())) return;

if(!p.hasPermission("mast.freeze")){
TextUtils.colorize(Messages.GET_NO_PERMISSION_MESSAGE(), p);
return true;
}
IStaffPlayer staff = staffManager.getStaffPlayer(p.getName());

if(args.length < 1){
new SelectTargetGUI(p).callback( (target) -> {
execute(staff, target);
p.closeInventory();
}).open();
return false;
}
assert staff != null;

if (args[0].equalsIgnoreCase("/remove")) {
if (freezeManager.isFrozen(args[1]))
staff.unfreezePlayer(args[1]);
return true;
}
if (!p.hasPermission("mast.freeze")) {
TextUtils.colorize(Messages.GET_NO_PERMISSION_MESSAGE(), p);
return;
}

if (args[0].equalsIgnoreCase("/exec")) {
if (freezeManager.isFrozen(args[1]))
staff.executeFreezedPunishments(args[1]);
return true;
}
if (args.length < 1) {
new SelectTargetGUI(p).callback((target) -> {
execute(staff, target);
p.closeInventory();
}).open();
return;
}

if (onlineCheck(p, args, 0)) return true;
if (args[0].equalsIgnoreCase("/remove")) {
if (freezeManager.isFrozen(args[1]))
staff.unfreezePlayer(args[1]);
return;
}

if (Objects.requireNonNull(Bukkit.getPlayer(args[0])).hasPermission("mast.freeze.bypass")) {
TextUtils.colorize(Messages.GET_FREEZE_CANNOT_FREEZE_THAT_PLAYER_MESSAGE(), p);
return true;
}
if (args[0].equalsIgnoreCase("/exec")) {
if (freezeManager.isFrozen(args[1]))
staff.executeFreezedPunishments(args[1]);
return;
}

execute(staff, Bukkit.getPlayer(args[0]));
if (onlineCheck(p, args, 0)) return;

return true;
if (Objects.requireNonNull(Bukkit.getPlayer(args[0])).hasPermission("mast.freeze.bypass")) {
TextUtils.colorize(Messages.GET_FREEZE_CANNOT_FREEZE_THAT_PLAYER_MESSAGE(), p);
return;
}

public void execute(IStaffPlayer staff, Player target){
if (staff.isFreezed(target)) staff.unfreezePlayer(target.getName());
else staff.freezePlayer(target);
}
execute(staff, Bukkit.getPlayer(args[0]));
}

public void execute(IStaffPlayer staff, Player target) {
if (staff.isFreezed(target)) staff.unfreezePlayer(target.getName());
else staff.freezePlayer(target);
}

public boolean onlineCheck(Player p, String[] args, int index){
Player target = Bukkit.getPlayer(args[index]);
public boolean onlineCheck(Player p, String[] args, int index) {
Player target = Bukkit.getPlayer(args[index]);

if(target == null){
TextUtils.colorize(Messages.GET_NO_PLAYER_FOUND_MESSAGE(), p);
return true;
}
return false;
if (target == null) {
TextUtils.colorize(Messages.GET_NO_PLAYER_FOUND_MESSAGE(), p);
return true;
}
return false;
}

@NotNull
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull String[] args) {
return Bukkit.getOnlinePlayers().stream().map(Player::getName).toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package es.angelillo15.mast.bukkit.cmd.teleport;

import com.nookure.mast.api.cmd.CommandData;
import com.nookure.mast.api.cmd.StaffCommand;
import com.nookure.mast.api.cmd.sender.CommandSender;
import es.angelillo15.mast.api.IStaffPlayer;
import es.angelillo15.mast.api.Replace;
import es.angelillo15.mast.api.config.bukkit.Messages;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.List;

import static es.angelillo15.mast.bukkit.utils.ColorUtils.cmp;

@CommandData(
name = "mtp",
permission = "mast.teleport.tp",
usage = "/mtp <player> [target]",
description = "Teleport a player to another player"
)
public class TpCommand extends StaffCommand {
@Override
public void onStaffCommand(@NotNull IStaffPlayer sender, @NotNull String label, @NotNull String[] args) {
if (args.length < 1) {
sender.sendMessage(cmp("Teleport.tp.badUsage"));
return;
}

Player target = Bukkit.getPlayer(args[0]);

if (target == null) {
sender.sendMessage(cmp(Messages.GET_NO_PLAYER_FOUND_MESSAGE()));
return;
}

PaperLib.teleportAsync(sender.getPlayer(), target.getLocation());

sender.sendMessage(cmp("Teleport.tp.teleported",
new Replace("player", target.getName()))
);
}

@NotNull
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull String @NotNull [] args) {
return Bukkit.getOnlinePlayers().stream().map(Player::getName).toList();
}
}
Loading

0 comments on commit 2318f83

Please sign in to comment.