Advertisement
bubbleguj

McAdvert.java

Aug 5th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.35 KB | None | 0 0
  1. package me.bubbleguj.mcadvert;
  2.  
  3. import org.bukkit.command.Command;
  4. import org.bukkit.command.CommandSender;
  5.  
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.inventory.ItemStack;
  8. import org.bukkit.plugin.java.JavaPlugin;
  9.  
  10. import com.xemsdoom.mexdb.MexDB;
  11. import com.xemsdoom.mexdb.exception.EmptyIndexException;
  12. import com.xemsdoom.mexdb.system.Entry;
  13.  
  14. public class McAdvert extends JavaPlugin{
  15.    
  16.     MexDB db = new MexDB("plugins/McAdvert","database");
  17.    
  18.     @Override
  19.     public void onEnable() {
  20.        
  21.         loadConfig();
  22.         registerEvent();
  23.         System.out.println("[McAdvert] Plugin activated!");
  24.         System.out.println("[McAdvert] Plugin by bubbleguj");
  25.     }
  26.    
  27.     @Override
  28.     public void onDisable() {
  29.        
  30.         System.out.println("[McAdvert] Plugin disabled!");
  31.     }
  32.    
  33.     public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
  34.        
  35.         Player p = (Player) sender;
  36.         String playername = p.getName();
  37.        
  38.         if(cmd.getName().equalsIgnoreCase("advert")) {
  39.            
  40.             if(p.hasPlayedBefore()) {
  41.                
  42.                 String hpb = this.getConfig().getString("config.messages.has_played_before");
  43.                 p.sendMessage(hpb);
  44.                 return true;
  45.             } else {
  46.            
  47.             if(args.length < 1) {
  48.            
  49.                 String tfa = this.getConfig().getString("config.messages.too_few_arguments");
  50.                 p.sendMessage(tfa);
  51.                 return true;
  52.             }
  53.            
  54.             if(args.length == 1 && (!args[0].equalsIgnoreCase(playername))) {
  55.                
  56.                 Player target = this.getServer().getPlayer(args[0]);
  57.                
  58.                 try {
  59.                    
  60.                     if(db.getIndices().contains(playername)) {
  61.                         String ot = this.getConfig().getString("config.messages.only_one_time");
  62.                         p.sendMessage(ot);
  63.                         return true;
  64.                     }
  65.                    
  66.                     if(target == null) {
  67.                         String no = this.getConfig().getString("config.messages.not_online");
  68.                         p.sendMessage(no);
  69.                         return true;
  70.                     }
  71.                    
  72.                     String targetname = target.getName();
  73.                    
  74.                     Entry name = new Entry(playername);
  75.                     name.addValue("advertised_from", targetname);
  76.                     db.addEntry(name);
  77.                     db.push();
  78.  
  79.                     String thanks = this.getConfig().getString("config.messages.thanks");
  80.                     int ida = this.getConfig().getInt("config.id.advertiser");
  81.                     int idp = this.getConfig().getInt("config.id.player");
  82.                     int amountp = this.getConfig().getInt("config.amount.player");
  83.                     int amounta = this.getConfig().getInt("config.amount.advertiser");
  84.                    
  85.                     p.sendMessage(thanks); 
  86.                     p.getInventory().addItem(new ItemStack(idp, amountp));
  87.                     target.getInventory().addItem(new ItemStack(ida, amounta));
  88.                 } catch (EmptyIndexException e) {
  89.                     p.sendMessage("spieler nicht in datenbank");
  90.                     return true;
  91.                 }
  92.                 return true;
  93.             }
  94.            
  95.             if(args.length > 1) {
  96.                
  97.                 String tma = this.getConfig().getString("config.messages.too_much_arguments");
  98.                 p.sendMessage(tma);
  99.                 return true;
  100.             }
  101.             }
  102.         }
  103.         return false;
  104.     }
  105.    
  106.     public void registerEvent() {
  107.        
  108.         new McAdvertListener(this);
  109.     }
  110.    
  111.     public void loadConfig() {
  112.        
  113.         String firstjoin = "config.messages.firstjoin";
  114.         String howto = "config.messages.howto";
  115.         String thanks = "config.messages.thanks";
  116.         String tfa = "config.messages.too_few_arguments";
  117.         String tma = "config.messages.too_much_arguments";
  118.         String hpb = "config.messages.has_played_before";
  119.         String no = "config.messages.not_online";
  120.         String ot = "config.messages.only_one_time";
  121.         String ida = "config.id.advertiser";
  122.         String idp = "config.id.player";
  123.         String amounta = "config.amount.advertiser";
  124.         String amountp = "config.amount.player";
  125.        
  126.         this.getConfig().addDefault(firstjoin, "Hello, has someone advertised you?");
  127.         this.getConfig().addDefault(howto, "If yes, type: /advert <name_of_the_player_who_advertised_you>");
  128.         this.getConfig().addDefault(thanks, "Thanks for telling us! :)");
  129.         this.getConfig().addDefault(tfa, "Too few arguments!");
  130.         this.getConfig().addDefault(tma, "Too much arguments!");
  131.         this.getConfig().addDefault(hpb, "You can't be advertised, beacause it's not your first join!");
  132.         this.getConfig().addDefault(no, "The advertiser has to be online too!");
  133.         this.getConfig().addDefault(ot, "You can't be advertiesd two times!");
  134.         this.getConfig().addDefault(ida, 265);
  135.         this.getConfig().addDefault(idp, 265);
  136.         this.getConfig().addDefault(amounta, 10);
  137.         this.getConfig().addDefault(amountp, 5);
  138.        
  139.         this.getConfig().options().copyDefaults(true);
  140.         this.saveConfig();
  141.     }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement