Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Fix Pet + debug command
Browse files Browse the repository at this point in the history
  • Loading branch information
en0tuk committed Oct 22, 2022
1 parent 2352558 commit 04b60b2
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group "ru.enis"
version "1.7.2"
version "1.7.3"

repositories {
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
Expand Down
6 changes: 5 additions & 1 deletion resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: eHideTags
version: 1.7.2
version: 1.7.3
main: ru.enis.ehidetags.Core
api-version: 1.13
author: Enis
Expand All @@ -19,6 +19,7 @@ permissions:
eht.command: true
eht.help: true
eht.updatenotify: true
eht.debug: true
eht.reload:
description: Allows you to reload plugin
default: op
Expand All @@ -28,6 +29,9 @@ permissions:
eht.help:
description: Allows you to use /eht help command
default: true
eht.debug:
description: Allows you to use /eht debug command
default: op
eht.updatenotify:
description: Allow you to get update notifications
default: op
17 changes: 17 additions & 0 deletions spigot/ru/enis/ehidetags/commands/MainCommand.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package ru.enis.ehidetags.commands;

import net.kyori.adventure.audience.Audience;
import org.bukkit.Bukkit;
import org.bukkit.command.*;
import org.jetbrains.annotations.NotNull;

import org.jetbrains.annotations.Nullable;
import ru.enis.ehidetags.*;
import ru.enis.ehidetags.misc.configs.Config;
import ru.enis.ehidetags.misc.configs.Messages;
import ru.enis.ehidetags.misc.other;

import static ru.enis.ehidetags.Core.adventure;
import static ru.enis.ehidetags.misc.Color.ColorFormat;

import java.sql.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -51,6 +55,16 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
audience.sendMessage(ColorFormat( Plugin_Prefix + " §f| " + Messages.Config_Reloaded));
return true;
}
if(args[0].equalsIgnoreCase("debug") && sender.hasPermission(cmdname + ".debug")) {
ArrayList playerlist = new ArrayList();
Bukkit.getServer().getOnlinePlayers().forEach(p -> playerlist.add(p.getName()));
audience.sendMessage(ColorFormat(" §f| " + Plugin_Prefix +
"\n &f| &aTeam Members: " + other.getScoreBoard().getTeam("eHideTags").getEntries().toString() +
"\n &f| &aPlayer List: " + playerlist +
"\n &f| &aPlugin Version: " + Core.getInstance().getDescription().getVersion() +
"\n &f| &aServer Version: " + Bukkit.getServer().getVersion()));
return true;
}
if(args[0].equalsIgnoreCase("help") && sender.hasPermission(cmdname + ".help")) {
audience.sendMessage(ColorFormat(" §f| " + Plugin_Prefix +
"\n §f| §a/" + cmdname + " reload - " + Messages.Reload_Help ));
Expand All @@ -70,6 +84,9 @@ public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull
if(commandSender.hasPermission(cmdname + ".help")) {
completions.add("help");
}
if(commandSender.hasPermission(cmdname + ".debug")) {
completions.add("debug");
}
Collections.sort(completions);
return completions;
}
Expand Down
15 changes: 14 additions & 1 deletion spigot/ru/enis/ehidetags/events/onInteract.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.kyori.adventure.text.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
Expand Down Expand Up @@ -34,7 +35,7 @@ public void interact(PlayerInteractAtEntityEvent e) {
Player rc = (Player) e.getRightClicked();

//Мои заменители
String placeholders = Format.replacePlaceholder(ActionBar.message, rc);
String placeholders = Format.playerPlaceholders(ActionBar.player_message, rc);

//Заменители из PAPI
placeholders = String.valueOf(new PlaceholderAPIHook(rc, placeholders, e.getPlayer()).REL);
Expand All @@ -46,5 +47,17 @@ public void interact(PlayerInteractAtEntityEvent e) {
audience.sendActionBar(color);
}
}
if (e.getRightClicked() instanceof Tameable && !e.getPlayer().isSneaking() && ((Tameable) e.getRightClicked()).isTamed()) {
//Берет игрока для Audience
final Audience audience = adventure().player(e.getPlayer());
//Берет моба на ПКМ
Tameable tm = (Tameable) e.getRightClicked();
//Мои заменители
String placeholders = Format.tameablePlaceholders(ActionBar.tameable_message, tm);
//Форматирование цвета
TextComponent color = Color.ColorFormat(placeholders);
//Отправка ЭкшнБара
audience.sendActionBar(color);
}
}
}
1 change: 0 additions & 1 deletion spigot/ru/enis/ehidetags/events/onJoin.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public void join(PlayerJoinEvent e) {

//Отправка сообщения об обновлении
audience.sendMessage(Color.ColorFormat("§6eHideTags §f| &7An update for plugin is available"));
audience.sendMessage(Color.ColorFormat("Text"));
}
//Добавление игрока в группу для скрытия ника
other.hideName(e.getPlayer());
Expand Down
1 change: 0 additions & 1 deletion spigot/ru/enis/ehidetags/misc/Color.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public static TextComponent ColorFormat(String translate){
return HexSerializer.deserialize(translate);
} else {
return LegacySerializer.deserialize(translate);

}
}
}
8 changes: 7 additions & 1 deletion spigot/ru/enis/ehidetags/misc/Format.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package ru.enis.ehidetags.misc;

import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;

public class Format {
public static String replacePlaceholder(String s, Player p) {
public static String playerPlaceholders(String s, Player p) {
return s
.replaceAll("%name%", p.getName())
.replaceAll("%displayname%", p.getDisplayName());
}
public static String tameablePlaceholders(String s, Tameable t) {
return s
.replaceAll("%name%", t.getName())
.replaceAll("%owner%", t.getOwner().getName());
}
}
3 changes: 2 additions & 1 deletion spigot/ru/enis/ehidetags/misc/configs/ActionBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

public class ActionBar {
public static Boolean enabled;
public static String message;
public static String player_message;
public static String tameable_message;
}
7 changes: 6 additions & 1 deletion spigot/ru/enis/ehidetags/misc/configs/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ public class Config {
public Config(Core plugin) {
CustomYML cfg = new CustomYML("MainСonfig", plugin);
ActionBar.enabled = cfg.getField("actionbar.enabled", true);
ActionBar.message = cfg.getField("actionbar.message", "&6%name%",
ActionBar.player_message = cfg.getField("actionbar.message", "&6%name%",
"Placeholders:\n%name% - Player Name\n%displayname% - Player Displayname");
ActionBar.tameable_message = cfg.getField("actionbar.tameable-message", "&f%name%",
"THIS CANNOT BE DISABLED\n" +
"This fixes bug when tameable entity do not shows their name\n" +
"Placeholders:\n" +
"%name% - Tameable Entity Name");
}
}

8 changes: 8 additions & 0 deletions spigot/ru/enis/ehidetags/misc/configs/CustomYML.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ public <T> T getField(String path, T whenNotFound) {
return whenNotFound;
}

/**
* @param <T> -> Tries to cast the field value to the Class T
* @param whenNotFound -> What should get created in the config if field not exist
* @param comment -> What should get created in the config if field comment not exist
* @param path -> path in this config
* @return Object T if found, null if cast failed
*/

@SuppressWarnings("unchecked")
@Nullable
public <T> T getField(String path, T whenNotFound, String comment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private String setRelationalPlaceholders(Player p, String s, Player P) {
return s;
}
}

private String returnInput(String s) {
return s;
}
Expand Down
4 changes: 4 additions & 0 deletions spigot/ru/enis/ehidetags/misc/other.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public static void hideName(Player p) {
p.setScoreboard(board);
}

public static Scoreboard getScoreBoard() {
return board;
}

public static void boardSettings() {
board = ((ScoreboardManager) requireNonNull(Bukkit.getScoreboardManager())).getNewScoreboard();
board.registerNewTeam("eHideTags");
Expand Down

0 comments on commit 04b60b2

Please sign in to comment.