Skocz do zawartości
  • 0

Nie wyswietla wiadomosci


Pytanie

Tu mam taki kod: https://code.skript.pl/biOkYq6a Tu mam messages.yml: https://code.skript.pl/X76rVHyr/

Problem jest taki, że nie wyświetla wiadomości z /chat on/off. Z /chat clear wyświetla. Poprawne użycie też. Dodam jeszcze Main'a: https://code.skript.pl/ElPsydk0

Edytowane przez bvcz
Odnośnik do komentarza
https://skript.pl/temat/25738-nie-wyswietla-wiadomosci/
Udostępnij na innych stronach

7 odpowiedzi na to pytanie

Rekomendowane odpowiedzi

  • 0

nauczcie sie pierw dobrze formatowac kod i robic go bardziej 'czytelnym' bo to razi w oczy i trudno takie cos zrozumiec ;/

public class ChatCommand implements CommandExecutor {

    public static ChatMode chatMode = ChatMode.ON;

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (sender instanceof Player) {
            final Player p = (Player) sender;
            final User u = UserManager.getUser(p);
            if (!u.can(Group.Helper)) {
                p.sendMessage(ChatUtil.fixColor("&8>> &cBrak uprawnien. &8(&7Helper&8)"));
                return true;
            }
        }
        if (args.length < 1) {
            sender.sendMessage(ChatUtil.fixColor("&8>> &cPoprawne uzycie: &7/chat [clear/on/off/vip]"));
            return true;
        }
        final String arg = args[0];
        if (arg.equalsIgnoreCase("vip")) {
            if (chatMode == ChatMode.VIP) {
                sender.sendMessage(ChatUtil.fixColor("&8>> &cTryb VIP na chacie jest juz wlaczony!"));
                return true;
            }
            chatMode = ChatMode.VIP;
            sender.sendMessage(ChatUtil.fixColor("&8>> &7Chat zostal przelaczony na &6tryb vip&7!"));
            for (Player pOnl : Bukkit.getServer().getOnlinePlayers()) {
                pOnl.sendMessage("\n\n\n"+ChatUtil.fixColor("&8>> &7Chat zostal przelaczony na tryb: &aVIP\n &8>> &7Przez: &a" + sender.getName() + "&7!"));
            }
        } else if (arg.equalsIgnoreCase("cc") || arg.equalsIgnoreCase("clear")) {
            for (Player pOnl : Bukkit.getServer().getOnlinePlayers()) {
                pOnl.sendMessage("\n\n\n"+ChatUtil.fixColor("&8>> &aChat zostal wyczyszczony przez: &7" + sender.getName() + "&a!"));
            }
            sender.sendMessage(ChatUtil.fixColor("&8>> &7Chat zostal &awyczyszczony&7!"));
        } else if (arg.equalsIgnoreCase("on") || arg.equalsIgnoreCase("enable")) {
            if (chatMode == ChatMode.ON) {
                sender.sendMessage(ChatUtil.fixColor("&8>> &7Chat jest juz &awlaczony&7!"));
                return true;
            }
            chatMode = ChatMode.ON;
            sender.sendMessage(ChatUtil.fixColor("&8>> &7Chat zostal &awlaczony&7!"));
            for (Player pOnl : Bukkit.getServer().getOnlinePlayers()) {
                pOnl.sendMessage("\n\n\n"+ChatUtil.fixColor("&8>> &7Chat zostal przez: &awlaczony &7przez: &a" + sender.getName() + "&7!"));
            }
        } else if (arg.equalsIgnoreCase("off") || arg.equalsIgnoreCase("disable")) {
            if (chatMode == ChatMode.OFF) {
                sender.sendMessage(ChatUtil.fixColor("&8>> &7Chat jest juz &cwylaczony&7!"));
                return true;
            }
            chatMode = ChatMode.OFF;
            sender.sendMessage(ChatUtil.fixColor("&8>> &7Chat zostal &cwylaczony&7!"));
            for (Player pOnl : Bukkit.getServer().getOnlinePlayers()) {
                pOnl.sendMessage("\n\n\n"+ChatUtil.fixColor("&8>> &7Chat zostal przez: &cwylaczony &7przez: &a" + sender.getName() + "&7!"));
            }
        } else {
            sender.sendMessage(ChatUtil.fixColor("&8>> &7Argument: &c" + arg + "&7 jest &cniepoprawny&7!"));
            sender.sendMessage(ChatUtil.fixColor("&8>> &cPoprawne uzycie: &7/chat [clear/on/off/vip]"));
        }
        return false;
    }
}
public enum ChatMode {

	ON,
	OFF,
	VIP;

}

jakis moj stary kod, zedytuj sobie

 

____________

	public static List<String> chaton;
	public static List<String> chatoff;
	public static List<String> chatclear;
	public static List<String> chatclearplayer;
	public static List<String> chatusage;

		chaton = FileManager.getMsg().getStringList("Chat.on");
		chatoff = FileManager.getMsg().getStringList("Chat.off");
		chatclear = FileManager.getMsg().getStringList("Chat.clear");
		chatclearplayer = FileManager.getMsg().getStringList("Chat.clearplayer");
		chatusage = FileManager.getMsg().getStringList("Chat.uzycie");

takie listy nie musza byc statyczne, mozesz robic to niestatycznie, bo czemu nie

			if (args.length == 0) {
				for (String chatusage : Main.chatusage) {
					sender.sendMessage(Utils.ChatUtil.fixColor(chatusage));
				}
				return true;
			} else if (args[0].equalsIgnoreCase("on")) {

te else jest tutaj niepotrzebne, samo 'if'.

					if (Bukkit.getPlayer(args[1]) != null) {
						Player p = Bukkit.getPlayer(args[1]);

takie sprawdzanie jest niewygodne, bo mozesz raz zrobic zmienna np. final Player target = Bukkit.getPlayerExact(args[1])

 

wiekszosc kodu wyglada dziwnie i az odechciewa sie czytac, + daj całą klase main bo tutaj tez moze byc w tym problem

https://code.skript.pl/11skWfpZ
					for (int i = 0; i <= 124; i++) {
						Bukkit.broadcastMessage("");
					}

nie rób broadcast bo wtedy wysylasz tez do konsoli, zrob cos typu

getPlayers().forEach(p->p.sendMessage("wyczyszczono"));

private List<Player> getPlayers () {
  	return ...;
}

 

 

i:

				if (Main.chat == true) {

mozesz robic

if (Main.chat)

a jezeli false:

if (!Main.chat)

 

			if (args.length == 0) {
				for (String chatusage : Main.chatusage) {
					sender.sendMessage(Utils.ChatUtil.fixColor(chatusage));
				}
				return true;
			} else if (args[0].equalsIgnoreCase("on")) {
			if (args.length < 1) {
				for (String chatusage : Main.chatusage) { //tak jak pisal gotofinal, mozna uzywac "\n" itp. zamiast uzywania list
					sender.sendMessage(Utils.ChatUtil.fixColor(chatusage));
				}
				return true;
			} 
           	if (args[0].equalsIgnoreCase("on")) { 
            }

no i tak jak pisalem daj klase Main, całą.

 

(jestem wykonczony i chce mi sie spac, jezeli popelnilem gdzies blad lub zle 'poprawilem' to sry)

Edytowane przez xAxee
Odnośnik do komentarza
https://skript.pl/temat/25738-nie-wyswietla-wiadomosci/#findComment-170281
Udostępnij na innych stronach

  • 0
package me.crystal.toolsy;
 
import java.util.List;
 
import org.bukkit.plugin.java.JavaPlugin;
 
import Managers.FileManager;
import me.crystal.toolsy.ChatCommand;
 
public class Main extends JavaPlugin {
 
    public static boolean chat = true;
    public List<String> chaton;
    public List<String> chatoff;
    public List<String> chatclear;
    public List<String> chatclearplayer;
    public List<String> chatusage;
 
    @Override
    public void onDisable() {
 
    }
 
    @Override
    public void onEnable() {
        chaton = FileManager.getMsg().getStringList("Chat.on");
        chatoff = FileManager.getMsg().getStringList("Chat.off");
        chatclear = FileManager.getMsg().getStringList("Chat.clear");
        chatclearplayer = FileManager.getMsg().getStringList("Chat.clearplayer");
        chatusage = FileManager.getMsg().getStringList("Chat.uzycie");
        getCommand("chat").setExecutor(new ChatCommand());
 
    }
}

gdzie ladujesz yaml dla filemanager?

Odnośnik do komentarza
https://skript.pl/temat/25738-nie-wyswietla-wiadomosci/#findComment-170819
Udostępnij na innych stronach

  • 0

Ja chce tylko rozwiać problem z wyświetlaniem wiadomości

W messages.yml wystarczyło zmienić z "on" na "wlacz" i "off" na "wylacz"

:)

Edytowane przez Crystal_PL
Odnośnik do komentarza
https://skript.pl/temat/25738-nie-wyswietla-wiadomosci/#findComment-171028
Udostępnij na innych stronach

Nieaktywny
Ten temat został zamknięty. Brak możliwości dodania odpowiedzi.
  • Ostatnio przeglądający   0 użytkowników

    • Brak zarejestrowanych użytkowników przeglądających tę stronę.
×
×
  • Dodaj nową pozycję...