Skocz do zawartości
  • 0

EssentialsXGroupManager - API ?


Arczi98

Pytanie

Witam. Potrzebuję pobrać nazwę grupy do której należy dany gracz z GroupManagera.

Wersja której używam to EssentialsXGroupManager-2.0.1. Używam takiego kodu napisanego pod wcześniejszą wersję jednak wywala on błąd:

Spoiler


import java.util.Arrays;
import java.util.List;
import org.anjocaido.groupmanager.GroupManager;
import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder;
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;

public class GMHook implements Listener 
{
	private GroupManager groupManager;
	private Plugin plugin;
 
	public GMHook(final Plugin plugin)
	{
		this.plugin = plugin;
	}
 
	@EventHandler(priority = EventPriority.MONITOR)
	public void onPluginEnable(final PluginEnableEvent event)
	{
		final PluginManager pluginManager = plugin.getServer().getPluginManager();
		final Plugin GMplugin = pluginManager.getPlugin("GroupManager");
 
		if (GMplugin != null && GMplugin.isEnabled())
		{
			groupManager = (GroupManager)GMplugin;
 
		}
	}
 
	@EventHandler(priority = EventPriority.MONITOR)
	public void onPluginDisable(PluginDisableEvent event)
	{
		if (groupManager != null)
		{
			if (event.getPlugin().getDescription().getName().equals("GroupManager"))
			{
				groupManager = null;
			}
		}
	}
 
	public String getGroup(final Player base)
	{
		final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base);
		if (handler == null)
		{
			return null;
		}
		return handler.getGroup(base.getName());
	}
 
	
	public boolean setGroup(final Player base, final String group)
	{
		final OverloadedWorldHolder handler = groupManager.getWorldsHolder().getWorldData(base);
		if (handler == null)
		{
			return false;
		}
		handler.getUser(base.getName()).setGroup(handler.getGroup(group));
		return true;
	}
 
	public List<String> getGroups(final Player base)
	{
		final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base);
		if (handler == null)
		{
			return null;
		}
		return Arrays.asList(handler.getGroups(base.getName()));
	}
 
	public String getPrefix(final Player base)
	{
		final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base);
		if (handler == null)
		{
			return null;
		}
		return handler.getUserPrefix(base.getName());
	}
 
	public String getSuffix(final Player base)
	{
		final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base);
		if (handler == null)
		{
			return null;
		}
		return handler.getUserSuffix(base.getName());
	}
 
	public boolean hasPermission(final Player base, final String node)
	{
		final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base);
		if (handler == null)
		{
			return false;
		}
		return handler.has(base, node);
	}
}

 

 

Błąd:

Spoiler

[20:12:39 INFO]: Arczi issued server command: /g
[20:12:39 ERROR]: null
org.bukkit.command.CommandException: Unhandled exception executing command 'g' in plugin PremiumAuth v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-93e20b3-f8500c0]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-93e20b3-f8500c0]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:651) ~[spigot.jar:git-Spigot-93e20b3-f8500c0]
        at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1392) [spigot.jar:git-Spigot-93e20b3-f8500c0]
        at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1227) [spigot.jar:git-Spigot-93e20b3-f8500c0]
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-93e20b3-f8500c0]
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-93e20b3-f8500c0]
        at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-93e20b3-f8500c0]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_144]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_144]
        at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot.jar:git-Spigot-93e20b3-f8500c0]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [spigot.jar:git-Spigot-93e20b3-f8500c0]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot.jar:git-Spigot-93e20b3-f8500c0]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot.jar:git-Spigot-93e20b3-f8500c0]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot.jar:git-Spigot-93e20b3-f8500c0]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_144]
Caused by: java.lang.NullPointerException
        at com.gmail.arczigames8991.PremiumAuth.Config.GMHook.getGroup(GMHook.java:54) ~[?:?]
        at com.gmail.arczigames8991.PremiumAuth.Commands.Grupa.onCommand(Grupa.java:21) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-93e20b3-f8500c0]
        ... 15 more

 

 

Kod komendy którą próbuje wyświetlić grupe:

Spoiler

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 com.gmail.arczigames8991.PremiumAuth.Config.GMHook;
import com.gmail.arczigames8991.PremiumAuth.Main.Main;


public class Grupa implements CommandExecutor{
	@Override
	public boolean onCommand(CommandSender sender, Command command, String label, String[] args) 
	{
		if (args.length == 0) {
		String n = sender.getName();
		Player p = Bukkit.getPlayer(n);
		GMHook gm = Main.groupManager;
		String grupa = gm.getGroup(p);
		sender.sendMessage("Grupa: " + grupa );
		return false; 
		}
		return false;
	}
}

 

Klasa główna:

Spoiler

import org.bukkit.Bukkit;


import org.bukkit.ChatColor;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import com.gmail.arczigames8991.PremiumAuth.SQL.MySQL;
import com.gmail.arczigames8991.PremiumAuth.Config.GMHook;
import com.gmail.arczigames8991.PremiumAuth.Commands.Grupa;
import com.gmail.arczigames8991.PremiumAuth.Commands.Login;
import com.gmail.arczigames8991.PremiumAuth.Commands.Register;
import com.gmail.arczigames8991.PremiumAuth.Config.Config;
import com.gmail.arczigames8991.PremiumAuth.Config.Default.config_yml;
import com.gmail.arczigames8991.PremiumAuth.Listeners.PlayerChat;
import com.gmail.arczigames8991.PremiumAuth.Listeners.PlayerJoin;
import com.gmail.arczigames8991.PremiumAuth.Listeners.PlayerMove;
import com.gmail.arczigames8991.PremiumAuth.Listeners.PlayerQuit;

public class Main extends JavaPlugin{
	
	public static MySQL mysql;
	public static Config config;
	public static GMHook groupManager;
	
	public void onEnable() {
		
		groupManager = new GMHook( this );
		config = new Config( this );
	
		config.createFile("config.yml");
		config.copyDefault("config.yml", config_yml.config_yml);
		config.initFile("config.yml");
		
		String ip = config.getString("config.yml", "ip");
		String port = config.getString("config.yml", "port");
		String user = config.getString("config.yml", "user");
		String password = config.getString("config.yml", "password");
		String database = config.getString("config.yml", "database");

		mysql = new MySQL(ip, port, user, password, database);
		mysql.open();
		mysql.createTable("pauth", "nick VARCHAR(32),pass VARCHAR(255),io INT(1)");
		
		PluginManager pm = Bukkit.getPluginManager();
		pm.registerEvents( new PlayerJoin(), 	this );
		pm.registerEvents( new PlayerQuit(), 	this );
		pm.registerEvents( new PlayerMove(), 	this );
		pm.registerEvents( new PlayerChat(), 	this );
		this.getCommand("g").setExecutor(new Grupa());
		this.getCommand("login").setExecutor(new Login());
		this.getCommand("l").setExecutor(new Login());
		this.getCommand("register").setExecutor(new Register());
		Bukkit.broadcastMessage(ChatColor.RED + "INFO: " + ChatColor.GOLD + "Plugin PremiumAuth zostal zaladowany.");
	}
}

 

plugin.yml:

Spoiler

name: PremiumAuth
main: com.gmail.arczigames8991.PremiumAuth.Main.Main
version: 1.0
commands:
   register:
      description: Rejestracja.
   login:
      description: Logowanie.
   r:
      description: Rejestracja.
   l:
      description: Logowanie.
   g:
      description: Grupku.

 

Proszę o pomoc. Sam już walczyłem z tym problemem parę dni ale nic nie wymyśliłem.

Pozwolę sobie oznaczyć @yooniks

Edytowane przez Arczi98
Oznaczenie
Odnośnik do komentarza
Udostępnij na innych stronach

0 odpowiedzi na to pytanie

Rekomendowane odpowiedzi

Nie udzielono jeszcze odpowiedzi na to pytanie

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ę...