Warn Plugin

Discussion in 'Plugin Development' started by shotgun528, Nov 25, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    shotgun528

    I Will develope a warn plugin but i need to list all warnings with #1 #2 But i dont know how it must show so
    #1 Grund: Griefing um: XXX.XX.XXX von: shotgun528
    #2 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    #3 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx

    and when i warn another it looks like
    #4 XXXXXXXXXXXXXXXXX
    #5 XXXXXXXXXXXXXXXxxxxx

    And How i delete Warnings and When they reach 10 they got banned? pls help me with a code! THANKS! (Not really good English because im german:()

    CODE:
    Code:java
    1. package me.kingingo.plugin;
    2.  
    3. import java.sql.ResultSet;
    4. import java.text.SimpleDateFormat;
    5. import java.util.ArrayList;
    6. import java.util.Date;
    7. import java.util.List;
    8.  
    9.  
    10.  
    11. import org.bukkit.Bukkit;
    12. import org.bukkit.command.Command;
    13. import org.bukkit.command.CommandSender;
    14. import org.bukkit.entity.Player;
    15. import org.bukkit.event.Listener;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18.  
    19. public class Plugin extends JavaPlugin implements Listener{
    20.  
    21. public MySQL mysql;
    22.  
    23. public void onEnable(){
    24. Bukkit.getPluginManager().registerEvents(this, this);
    25. loadConfig();
    26. mysql=new MySQL(getConfig().getString("Config.MySQL.User"),getConfig().getString("Config.MySQL.Password"),getConfig().getString("Config.MySQL.Host"),getConfig().getString("Config.MySQL.DB"));
    27. mysql.connect();
    28. mysql.Update("CREATE TABLE IF NOT EXISTS list_warns(player varchar(30),warner varchar(30),time varchar(30),grund varchar(30))");
    29. }
    30.  
    31. public void onDisable(){
    32. mysql.close();
    33. }
    34.  
    35. public boolean onCommand(final CommandSender sender, Command cmd, String commandlabel,String[] args){
    36. Player p = (Player) sender;
    37.  
    38. if(cmd.getName().equalsIgnoreCase("warns")){
    39. if(args.length==0){
    40. p.sendMessage("§c/warns [Player]");
    41. return true;
    42. }
    43.  
    44. if(args.length==1){
    45. String player = args[0];
    46. List<String> list = getWarns(player);
    47. if(list.isEmpty()){
    48. p.sendMessage("§cEs wurden keine Einträge gefunden!");
    49. return true;
    50. }
    51.  
    52. p.sendMessage("§9Spieler: "+player);
    53. for(String g : list){
    54. p.sendMessage("§9"+g.replaceAll("&", "§"));
    55.  
    56.  
    57. }
    58.  
    59. }
    60. }
    61.  
    62. if(cmd.getName().equalsIgnoreCase("warn")){
    63. if(args.length==0||args.length==1){
    64. p.sendMessage("§c/warn [Player] [Grund]");
    65. return true;
    66. }
    67.  
    68. if(args.length>1){
    69. String player = args[0];
    70. String grund="";
    71.  
    72. for(int i = 1; i < args.length; i++){
    73. grund=grund+args[i]+" ";
    74.  
    75.  
    76.  
    77.  
    78. }
    79.  
    80.  
    81.  
    82.  
    83. Bukkit.broadcastMessage("§6[§bATC§6] Der Spieler§c "+player+"§6 wurde verwarnt! Grund:§e " +grund.replaceAll("&", "§"));
    84.  
    85. WarnUser(p,player,grund);
    86.  
    87.  
    88.  
    89.  
    90.  
    91.  
    92.  
    93. }
    94.  
    95.  
    96.  
    97.  
    98. }
    99.  
    100.  
    101.  
    102. return false;
    103. }
    104.  
    105. public List<String> getWarns(String user){
    106. List<String> list = new ArrayList<>();
    107. try{
    108.  
    109. ResultSet rs = mysql.Query("SELECT warner,time,grund FROM list_warns WHERE player='"+user.toLowerCase()+"'");
    110.  
    111. while(rs.next()){
    112. list.add("§6Grund:§r "+rs.getString(3).replaceAll("&", "§")+ "§6um §e"+rs.getString(2)+"§6 "+rs.getString(1));
    113. }
    114.  
    115. }catch(Exception err){
    116. System.err.println(err);
    117. }
    118. return list;
    119. }
    120.  
    121. public void WarnUser(Player warner,String user, String grund){
    122. Date myDate = new Date();
    123. SimpleDateFormat df2 = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
    124. mysql.Update("INSERT INTO list_warns(player,warner,time,grund) VALUES ('"+user.toLowerCase()+"','"+warner.getName()+"','"+df2.format(myDate)+"','"+grund+"')");
    125. }
    126.  
    127. public void loadConfig(){
    128. getConfig().addDefault("Config.MySQL.Host", "Eintragen");
    129. getConfig().addDefault("Config.MySQL.User", "Eintragen");
    130. getConfig().addDefault("Config.MySQL.Password", "Eintragen");
    131. getConfig().addDefault("Config.MySQL.DB", "Eintragen");
    132. getConfig().options().copyDefaults(true);
    133. saveConfig();
    134. }
    135.  
    136.  
    137. }[/i]
     
  2. Offline

    Onlineids

    shotgun528 Not quite sure what you are asking, hard to understand your english. However, if you're trying to ban a player when they exceed a certain amount of warnings then use a simple if statement and your getWarns() method
    Code:java
    1. if(getWarns("Notch") > 10){
    2. // Ban User
    3.  
    4. }
     
  3. Offline

    shotgun528

    I dont understand :confused:
     
  4. Offline

    bwfcwalshy Retired Staff

  5. Offline

    Skionz

    shotgun528 if(list.length >= 10) { //ban your guy }
     
  6. Offline

    bwfcwalshy Retired Staff

    shotgun528 Decompile my WzWarnings plugin. In my WarningManager there is a punish method, read that. Please do not just copy and paste it though.
     
  7. Offline

    fireblast709

    bwfcwalshy I rather not have him copy the static abuse ;3
     
    Rocoty and aaomidi like this.
  8. Offline

    bwfcwalshy Retired Staff

Thread Status:
Not open for further replies.

Share This Page