spenk

Untitled

Mar 17th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.59 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.PreparedStatement;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.util.logging.Level;
  6. import java.util.logging.Logger;
  7. public class SignJoinJoin extends PluginListener
  8. {
  9.     Logger log = Logger.getLogger("Minecraft");
  10.       int i = 0;
  11.      
  12.   public boolean onSignChange(Player player, Sign sign)
  13.   {
  14.     Block b = sign.getBlock();
  15.     World world = player.getWorld();
  16.     if ((sign.getText(0).equals("[Join]")) &&
  17.       (player.canUseCommand("/signadmin"))) {
  18.       sign.setText(0, "[Join]");
  19.       if (sign.getText(1).isEmpty()) sign.setText(1, "§4White List");
  20.       if (sign.getText(2).isEmpty()) sign.setText(2, "§4add to Group:");
  21.       if (sign.getText(3).isEmpty()) sign.setText(3, "default");
  22.       player.sendMessage("§2Sign sucsessfully created.");
  23.       return false;
  24.     }
  25.  
  26.     if (sign.getText(0).equals("[Caste]")) {
  27.       if ((!player.canUseCommand("/signadmin")) ||
  28.         (sign.getText(1).isEmpty())) { player.notify("You have to fill in an group on line 2"); world.setBlockAt(0, sign.getX(), sign.getY(), sign.getZ()); world.dropItem(b.getLocation(), 323); return true; }
  29.       if (!etc.getDataSource().doesGroupExist(sign.getText(1))) { player.notify("The group on line 2 does not exist"); world.setBlockAt(0, sign.getX(), sign.getY(), sign.getZ()); world.dropItem(b.getLocation(), 323); return true; }
  30.       if (sign.getText(2).isEmpty()) { player.notify("You have to fill in an group on line 3"); world.setBlockAt(0, sign.getX(), sign.getY(), sign.getZ()); world.dropItem(b.getLocation(), 323); return true; }
  31.       if (!etc.getDataSource().doesGroupExist(sign.getText(2))) { player.notify("The group on line 3 does not exist"); world.setBlockAt(0, sign.getX(), sign.getY(), sign.getZ()); world.dropItem(b.getLocation(), 323); return true; }
  32.       if (sign.getText(3).isEmpty()) { player.notify("You have to fill in an price on line 4"); world.setBlockAt(0, sign.getX(), sign.getY(), sign.getZ()); world.dropItem(b.getLocation(), 323); return true; } try {
  33.         Double.parseDouble(sign.getText(3)); } catch (NumberFormatException nfe) { player.notify("Line 4 must be an number!"); world.setBlockAt(0, sign.getX(), sign.getY(), sign.getZ()); world.dropItem(b.getLocation(), 323); return true; }
  34.       player.sendMessage("§2Sign sucsessfully created.");
  35.       return false;
  36.     }else{
  37.         if (sign.getText(0).equals("[Exam]")){
  38.             if (player.canUseCommand("/signadmin")){
  39.                 if (sign.getText(1).isEmpty()){sign.setText(1, "§4Right Click");}
  40.                 if (sign.getText(2).isEmpty()){sign.setText(2, "§4This Sign To");}
  41.                 if (!sign.getText(3).isEmpty()){
  42.                       char[] c = sign.getText(3).toCharArray();
  43.                       while(!isNumber(c[i])){
  44.                           i++;
  45.                       }
  46.                       String ccs = c[i]+"";
  47.                       int cc = Integer.parseInt(ccs);
  48.                       if (cc != 1 && cc != 2 && cc != 3){
  49.                           player.notify("Line 4 has to contain a number between 1 - 3");
  50.                           i = 0;
  51.                           return true;
  52.                       }else{
  53.                           player.sendMessage("§2Sign successfully created");
  54.                           i = 0;
  55.                           return false;
  56.                       }
  57.             }else{
  58.                 sign.setText(3, "Do Exam 1"); i = 0; return false;
  59.         }
  60.                 }else{ player.sendMessage("§cYou cant create those signs!");return true;}
  61.             }
  62.     }
  63.     return false;
  64.   }
  65.   public boolean onBlockRightClick(Player player, Block bc, Item iih) {
  66.     if ((bc.getType() == 63) || (bc.getType() == 68)) {
  67.       Sign sign = (Sign)bc.getWorld().getComplexBlock(bc.getX(), bc.getY(), bc.getZ());
  68.       if (sign.getText(0).equalsIgnoreCase("[Join]")) {
  69.         if (player.canUseCommand("/signjoin")) {
  70.           if (!etc.getDataSource().isUserOnWhitelist(player.getName())) {
  71.             if ((player.getGroups()[0].equals("default")) || (player.getGroups()[0].equals("guest"))) {
  72.               player.setGroups(new String[] { sign.getText(3) });
  73.               etc.getDataSource().modifyPlayer(player);
  74.               etc.getDataSource().addToWhitelist(player.getName());
  75.               player.sendMessage("§2Your added to the whitelist and modified.");
  76.               return false;
  77.             }
  78.  
  79.             player.notify("You are already modified.");
  80.             return true;
  81.           }
  82.  
  83.           player.notify("You are already on the whitelist");
  84.         }
  85.         else {
  86.           player.notify("You are not allowed to preform this command");
  87.           return true;
  88.         }
  89.       }
  90.       if (sign.getText(0).equals("[Caste]")) {
  91.         if (sign.getText(1).equals(player.getGroups()[0])) {
  92.           double money = ((Double)etc.getLoader().callCustomHook("dCBalance", new Object[] { "Player-Balance", player.getName() })).doubleValue();
  93.           if (money < Double.parseDouble(sign.getText(3))) { player.notify("You dont have enough money to preform this action"); return true; }
  94.           player.setGroups(new String[] { sign.getText(2) });
  95.           etc.getDataSource().modifyPlayer(player);
  96.           etc.getLoader().callCustomHook("dCBalance", new Object[] { "Player-Charge", player.getName(), Double.valueOf(Double.parseDouble(sign.getText(3))) });
  97.           //newcode
  98.           char[] c = sign.getText(2).toCharArray();
  99.           while(!isNumber(c[i])){
  100.               i++;
  101.           }
  102.           String[] cmd = player.getCommands();
  103.           String teach = "/teach"+c[i];
  104.           String[] tcmd;
  105.           String t;
  106.           t = etc.combineSplit(0, cmd, ",") + teach; tcmd = t.split(",");
  107.           player.setCommands(tcmd);
  108.           player.chat("/teach"+c[i]+" "+player.getName()+" PASS");
  109.           player.setCommands(cmd);
  110.           i = 0;
  111.          
  112.           //newcode
  113.           player.sendMessage("§2You Changed from caste");
  114.           return false;
  115.         }
  116.         player.notify("You can not change from your current caste to this caste");
  117.         return true;
  118.       }else{
  119.           if (sign.getText(0).equals("[Exam]")){
  120.               char[] c = sign.getText(3).toCharArray();
  121.               while(!isNumber(c[i])){
  122.                   i++;
  123.               }
  124.               String CS = c[i]+"";
  125.               int CI = Integer.parseInt(CS);
  126.               if (ExStat(player.getName(), CI)){
  127.                   int x = bc.getX();
  128.                   int z = bc.getZ();
  129.                   int y = (int)player.getY()+1;
  130.                  
  131.                     int xpos = sign.getX(); int ypos = sign.getY(); int zpos = sign.getZ();
  132.                     switch (sign.getBlock().getData()) {
  133.                     case 2: zpos += 1; break; case 3: zpos -= 1; break; case 4:xpos += 1; break; case 5: xpos -= 1;
  134.                     }
  135.                     Block b = bc.getWorld().getBlockAt(xpos, ypos, zpos);
  136.                     if (b.getType() != 0){
  137.                   if (x - xpos == 1){
  138.                   player.teleportTo(x-3,y,z, 0, 0);
  139.                   }else
  140.                       if (x - xpos == -1){
  141.                           player.teleportTo(x+3,y,z,0,0);
  142.                       }else
  143.                           if(z - zpos == 1){
  144.                               player.teleportTo(x,y,z-3, 0,0);
  145.                   }else
  146.                       if (z - zpos == -1){
  147.                           player.teleportTo(x,y,z+3, 0,0);
  148.                   }
  149.                     }
  150.                  
  151.                   player.sendMessage("§2Your Exam started!");
  152.                   i = 0;
  153.                   return false;
  154.               }else{
  155.                  player.notify("You are not registered for this exam !");
  156.                    i = 0;
  157.                   return true;
  158.               }
  159.           }
  160.       }
  161.  
  162.     }
  163.  
  164.     return false;
  165.   }
  166.   public boolean isNumber(char c){try{Integer.parseInt(c+"");}catch(NumberFormatException nfe){return false;}
  167. return true;}
  168.  
  169.   @SuppressWarnings("deprecation")
  170. public boolean ExStat(String Name, int exam){
  171.       boolean isReg = false;
  172.       Connection conn = null;
  173.       ResultSet rs = null;
  174.       PreparedStatement ps = null;
  175.       try{
  176.               conn = etc.getSQLConnection();
  177.               ps = conn.prepareStatement("SELECT E"+exam+"Status FROM ExamReg WHERE PlayerName = ?");
  178.               ps.setString(1, Name);
  179.               rs = ps.executeQuery();
  180.               if (rs.next()){
  181.                       String check = rs.getString("E"+exam+"Status");
  182.                       if(check.matches("WAITING")){
  183.                               isReg = true;
  184.                       }
  185.               }
  186.       } catch (SQLException ex) {
  187.               log.log(Level.SEVERE, "Could not access database:", ex);
  188.       } finally {
  189.               try {
  190.                       if (rs != null)
  191.                               rs.close();
  192.                       if (conn != null)
  193.                               conn.close();
  194.               } catch (SQLException ex) {
  195.                       log.log(Level.SEVERE, "Could Not Close SQL Connection:", ex);
  196.               }
  197.       }
  198.       return isReg;
  199. }
  200. }
Advertisement
Add Comment
Please, Sign In to add comment