API

There are still much API changes and the page may be out of date! It is not recommened to use the API for public projects!

You can use the API of GrandTheftDiamond to create some addOns.

If you have some ideas to make the API better or you want to have more events, tell us!

There is an example code on the bottom of the page.


How to get and work with the main class

GrandTheftDiamond gtd = (GrandTheftDiamond) plugin.getServer().getPluginManager().getPlugin("GrandTheftDiamond");

In this class there are some important methods for you:

gtd.getFileManager();
GTDFileManager fm = gtd.getFileManager();
fm.getData() //returns the FileConfiguration of the data.yml
fm.getEventConfig() //returns the FileConfiguration of the eventConfig.yml
fm.getMessages() //returns the FileConfiguration of the messages.yml
fm.getOnlyGTDModeConfig() //returns the FileConfiguration of the onlyGTDModeConfig.yml

But you can also use the data API:

GTDData data = gtd.getData();

In this class there are some useful methods for getting/setting data, which is not temporary. For temporary data (like isIngame(Player)) use:

GTDTmpData tmpData = gtd.getTmpData();

There are some other useful classes:

GTDEconManager econ = gtd.getEconManager();
GTDJailManager jail = gtd.getJailManager();
GTDGangManager gm = gtd.getGangManager();
GTDItemManager im = gtd.getItemManager(); //This class is important for GTD objects

You can send some plugin messages with different methods in the main class:

  • CommandSender sender is the console or player which should get the message
  • String msg is the path in the messages.yml (Without 'messages.'!)
void sendPluginMessage(CommandSender sender, String msg) //sends a message from the message file
void sendPluginMessage(CommandSender sender, String msg, String[] toReplace, String[] replacement) //sends the message from the message file and replaces the index of 'toReplace' with the index of 'replacement'. You can use as much replacements as you want (if they are in the messages.yml)
void sendPluginMessage(CommandSender sender, String msg, CommandSender[] players) //Sends a plugin message from the messages.yml and replaces '%player%' with index 0 of 'players' and '%otherPlayer%' with index 1

There are some more methods. Write 'gtd.' and press 'CTRL + SPACE' in Eclipse/NetBeans.


Events (Most are cancellable!)

  • PlayerJoinGameEvent
    • boolean isCancelled()
    • void setCancelled(boolean newCancelled)
    • boolean isCancelledBecauseBanned()
    • Player getPlayer()
    • Location getJoinLocation()
    • void setJoinLocation(Location newJoinLocation)
    • String getJoinMessageGlobal()
    • void setJoinMessageGlobal(String msg)
    • String getJoinMessagePlayer()
    • void setJoinMessagePlayer(String msg)
    • Team getNewTeam()
    • void setNewTeam(Team newTeam)
    • Character getNewCharacter()
    • void setNewCharacter(Character newCharacter)
    • List<String> getKits()
    • setKits(List<String> kits)
  • PlayerLeaveGameEvent
    • boolean isCancelled()
    • void setCancelled(boolean newCancelled)
    • bolean isCancelledBecauseOnlyGTDMode()
    • Player getPlayer()
    • String getLeaveMessageGlobal()
    • void setLeaveMessageGlobal(String msg)
    • String getLeaveMessagePlayer()
    • void setLeaveMessagePlayer(String msg)
  • GangCreateEvent
    • boolean isCancelled()
    • void setCancelled(boolean newCancelled)
    • OfflinePlayer getOwner()
    • void setOwner(OfflinePlayer owner)
    • String getGangName()
    • void setGangName(String gangName)
  • BalanceChangeEvent
    • boolean isCancelled()
    • void setCancelled(boolean newCancelled)
    • Player getPlayer()
    • int getGTDBalance()
    • void setGTDBalance(int balance)
    • int getVaultBalance()
    • void setVaultBalance(int balance)
    • boolean vaultGetsChanged()
    • void setVaultGetsChanged(boolean newVaultGetsChanged)

This events are still in work:

  • PlayerGetHandcuffedEvent
    • boolean isCancelled()
    • void setCancelled(boolean newCancelled)
    • Player getPlayer()
    • Player getCop()
  • PlayerUseObjectEvent
    • boolean isCancelled()
    • setCancelled(boolean newCancelled)
    • Player getPlayer()
    • Object getObject()


Code example

A player must pay to enter the game.:

@EventHandler
public void onGameJoin(PlayerJoinGameEvent e) {
	Player p = e.getPlayer();
	int balanceToPay = 10;
	GrandTheftDiamond gtd = (GrandTheftDiamond) plugin.getServer().getPluginManager().getPlugin("GrandTheftDiamond");
	GTDEconManager econ = gtd.getEconManager();
	if (econ.hasBalance(p, balanceToPay)) {
		econ.withdraw(p, balanceToPay, false);
	} else {
		gtd.sendPluginMessage(p, "notEnaughtMoney");
		e.setCancelled(true);
	}
}