Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.bubbleguj.mcadvert;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.plugin.java.JavaPlugin;
- import com.xemsdoom.mexdb.MexDB;
- import com.xemsdoom.mexdb.exception.EmptyIndexException;
- import com.xemsdoom.mexdb.system.Entry;
- public class McAdvert extends JavaPlugin{
- MexDB db = new MexDB("plugins/McAdvert","database");
- @Override
- public void onEnable() {
- loadConfig();
- registerEvent();
- System.out.println("[McAdvert] Plugin activated!");
- System.out.println("[McAdvert] Plugin by bubbleguj");
- }
- @Override
- public void onDisable() {
- System.out.println("[McAdvert] Plugin disabled!");
- }
- public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
- Player p = (Player) sender;
- String playername = p.getName();
- if(cmd.getName().equalsIgnoreCase("advert")) {
- if(p.hasPlayedBefore()) {
- String hpb = this.getConfig().getString("config.messages.has_played_before");
- p.sendMessage(hpb);
- return true;
- } else {
- if(args.length < 1) {
- String tfa = this.getConfig().getString("config.messages.too_few_arguments");
- p.sendMessage(tfa);
- return true;
- }
- if(args.length == 1 && (!args[0].equalsIgnoreCase(playername))) {
- Player target = this.getServer().getPlayer(args[0]);
- try {
- if(db.getIndices().contains(playername)) {
- String ot = this.getConfig().getString("config.messages.only_one_time");
- p.sendMessage(ot);
- return true;
- }
- if(target == null) {
- String no = this.getConfig().getString("config.messages.not_online");
- p.sendMessage(no);
- return true;
- }
- String targetname = target.getName();
- Entry name = new Entry(playername);
- name.addValue("advertised_from", targetname);
- db.addEntry(name);
- db.push();
- String thanks = this.getConfig().getString("config.messages.thanks");
- int ida = this.getConfig().getInt("config.id.advertiser");
- int idp = this.getConfig().getInt("config.id.player");
- int amountp = this.getConfig().getInt("config.amount.player");
- int amounta = this.getConfig().getInt("config.amount.advertiser");
- p.sendMessage(thanks);
- p.getInventory().addItem(new ItemStack(idp, amountp));
- target.getInventory().addItem(new ItemStack(ida, amounta));
- } catch (EmptyIndexException e) {
- p.sendMessage("spieler nicht in datenbank");
- return true;
- }
- return true;
- }
- if(args.length > 1) {
- String tma = this.getConfig().getString("config.messages.too_much_arguments");
- p.sendMessage(tma);
- return true;
- }
- }
- }
- return false;
- }
- public void registerEvent() {
- new McAdvertListener(this);
- }
- public void loadConfig() {
- String firstjoin = "config.messages.firstjoin";
- String howto = "config.messages.howto";
- String thanks = "config.messages.thanks";
- String tfa = "config.messages.too_few_arguments";
- String tma = "config.messages.too_much_arguments";
- String hpb = "config.messages.has_played_before";
- String no = "config.messages.not_online";
- String ot = "config.messages.only_one_time";
- String ida = "config.id.advertiser";
- String idp = "config.id.player";
- String amounta = "config.amount.advertiser";
- String amountp = "config.amount.player";
- this.getConfig().addDefault(firstjoin, "Hello, has someone advertised you?");
- this.getConfig().addDefault(howto, "If yes, type: /advert <name_of_the_player_who_advertised_you>");
- this.getConfig().addDefault(thanks, "Thanks for telling us! :)");
- this.getConfig().addDefault(tfa, "Too few arguments!");
- this.getConfig().addDefault(tma, "Too much arguments!");
- this.getConfig().addDefault(hpb, "You can't be advertised, beacause it's not your first join!");
- this.getConfig().addDefault(no, "The advertiser has to be online too!");
- this.getConfig().addDefault(ot, "You can't be advertiesd two times!");
- this.getConfig().addDefault(ida, 265);
- this.getConfig().addDefault(idp, 265);
- this.getConfig().addDefault(amounta, 10);
- this.getConfig().addDefault(amountp, 5);
- this.getConfig().options().copyDefaults(true);
- this.saveConfig();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement