Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.04 KB | None | 0 0
  1. public class DataUser extends Entry
  2. {
  3.     private boolean cX;
  4.     private boolean cY;
  5.     private boolean cZ;
  6.     private boolean cHomeX;
  7.     private boolean cHomeY;
  8.     private boolean cHomeZ;
  9.     private boolean cNick;
  10.     private boolean cWorld;
  11.     private boolean cMute;
  12.     private boolean cHomeWorld;
  13.     private boolean cFly;
  14.     private boolean cGod;
  15.     private boolean cMuteTime;
  16.     private boolean cGamemode;
  17.     private int userID;
  18.     private int x;
  19.     private int y;
  20.     private int z;
  21.     private int homeX;
  22.     private int homeY;
  23.     private int homeZ;
  24.     private String nick;
  25.     private String world;
  26.     private String mute;
  27.     private String homeWorld;
  28.     private byte fly;
  29.     private byte god;
  30.     private long muteTime;
  31.     private GameMode gamemode;
  32.     private String oldNick;
  33.    
  34.     public DataUser(final Datasource db) {
  35.         super(db);
  36.     }
  37.    
  38.     public DataUser(final Datasource db, final ResultSet rs) throws SQLException {
  39.         super(db);
  40.         this.userID = rs.getInt("userID");
  41.         this.x = rs.getInt("x");
  42.         this.y = rs.getInt("y");
  43.         this.z = rs.getInt("z");
  44.         this.homeX = rs.getInt("homeX");
  45.         this.homeY = rs.getInt("homeY");
  46.         this.homeZ = rs.getInt("homeZ");
  47.         this.nick = rs.getString("nick");
  48.         this.world = rs.getString("world");
  49.         this.mute = rs.getString("mute");
  50.         this.homeWorld = rs.getString("homeWorld");
  51.         this.fly = rs.getByte("fly");
  52.         this.god = rs.getByte("god");
  53.         this.muteTime = rs.getLong("muteTime");
  54.         this.gamemode = GameMode.getByValue((int)rs.getByte("gamemode"));
  55.     }
  56.    
  57.     @Override
  58.     protected void setPrimary(final int id) {
  59.         this.userID = id;
  60.     }
  61.    
  62.     @Override
  63.     public int getPrimary() {
  64.         return this.userID;
  65.     }
  66.    
  67.     public int getX() {
  68.         return this.x;
  69.     }
  70.    
  71.     public int getY() {
  72.         return this.y;
  73.     }
  74.    
  75.     public int getZ() {
  76.         return this.z;
  77.     }
  78.    
  79.     public int getHomeX() {
  80.         return this.homeX;
  81.     }
  82.    
  83.     public int getHomeY() {
  84.         return this.homeY;
  85.     }
  86.    
  87.     public int getHomeZ() {
  88.         return this.homeZ;
  89.     }
  90.    
  91.     public String getNick() {
  92.         return this.nick;
  93.     }
  94.    
  95.     public String getWorld() {
  96.         return this.world;
  97.     }
  98.    
  99.     public String getMute() {
  100.         return this.mute;
  101.     }
  102.    
  103.     public String getHomeWorld() {
  104.         return this.homeWorld;
  105.     }
  106.    
  107.     public boolean getFly() {
  108.         return this.fly > 0;
  109.     }
  110.    
  111.     public boolean getGod() {
  112.         return this.god > 0;
  113.     }
  114.    
  115.     public long getMuteTime() {
  116.         return this.muteTime;
  117.     }
  118.    
  119.     public GameMode getGamemode() {
  120.         return this.gamemode;
  121.     }
  122.    
  123.     public void setX(final int v) {
  124.         this.x = v;
  125.         this.cX = true;
  126.     }
  127.    
  128.     public void setY(final int v) {
  129.         this.y = v;
  130.         this.cY = true;
  131.     }
  132.    
  133.     public void setZ(final int v) {
  134.         this.z = v;
  135.         this.cZ = true;
  136.     }
  137.    
  138.     public void setHomeX(final int v) {
  139.         this.homeX = v;
  140.         this.cHomeX = true;
  141.     }
  142.    
  143.     public void setHomeY(final int v) {
  144.         this.homeY = v;
  145.         this.cHomeY = true;
  146.     }
  147.    
  148.     public void setHomeZ(final int v) {
  149.         this.homeZ = v;
  150.         this.cHomeZ = true;
  151.     }
  152.    
  153.     public void setNick(final String v) {
  154.         this.nick = v;
  155.         this.cNick = true;
  156.     }
  157.    
  158.     public void setWorld(final String v) {
  159.         this.world = v;
  160.         this.cWorld = true;
  161.     }
  162.    
  163.     public void setMute(final String v) {
  164.         this.mute = v;
  165.         this.cMute = true;
  166.     }
  167.    
  168.     public void setHomeWorld(final String v) {
  169.         this.homeWorld = v;
  170.         this.cHomeWorld = true;
  171.     }
  172.    
  173.     public void setFly(final boolean v) {
  174.         this.fly = (byte)(v ? 1 : 0);
  175.         this.cFly = true;
  176.     }
  177.    
  178.     public void setGod(final boolean v) {
  179.         this.god = (byte)(v ? 1 : 0);
  180.         this.cGod = true;
  181.     }
  182.    
  183.     public void setMuteTime(final long v) {
  184.         this.muteTime = v;
  185.         this.cMuteTime = true;
  186.     }
  187.    
  188.     public void setGamemode(final GameMode v) {
  189.         this.gamemode = v;
  190.         this.cGamemode = true;
  191.     }
  192.    
  193.     @Override
  194.     public UpdateSet prepareUpdate(final Boolean vals, final Boolean where) {
  195.         String v = "";
  196.         String w = "";
  197.         final ArrayList args = new ArrayList();
  198.         final ArrayList types = new ArrayList();
  199.         if (vals) {
  200.             String comma = "";
  201.             if (this.cX) {
  202.                 this.cX = false;
  203.                 v = String.valueOf(v) + comma + "x=?";
  204.                 args.add(this.x);
  205.                 types.add(4);
  206.                 comma = ", ";
  207.             }
  208.             if (this.cY) {
  209.                 this.cY = false;
  210.                 v = String.valueOf(v) + comma + "y=?";
  211.                 args.add(this.y);
  212.                 types.add(4);
  213.                 comma = ", ";
  214.             }
  215.             if (this.cZ) {
  216.                 this.cZ = false;
  217.                 v = String.valueOf(v) + comma + "z=?";
  218.                 args.add(this.z);
  219.                 types.add(4);
  220.                 comma = ", ";
  221.             }
  222.             if (this.cHomeX) {
  223.                 this.cHomeX = false;
  224.                 v = String.valueOf(v) + comma + "homeX=?";
  225.                 args.add(this.homeX);
  226.                 types.add(4);
  227.                 comma = ", ";
  228.             }
  229.             if (this.cHomeY) {
  230.                 this.cHomeY = false;
  231.                 v = String.valueOf(v) + comma + "homeY=?";
  232.                 args.add(this.homeY);
  233.                 types.add(4);
  234.                 comma = ", ";
  235.             }
  236.             if (this.cHomeZ) {
  237.                 this.cHomeZ = false;
  238.                 v = String.valueOf(v) + comma + "homeZ=?";
  239.                 args.add(this.homeZ);
  240.                 types.add(4);
  241.                 comma = ", ";
  242.             }
  243.             if (this.cNick) {
  244.                 this.cNick = false;
  245.                 v = String.valueOf(v) + comma + "nick=?";
  246.                 args.add(this.nick);
  247.                 types.add(12);
  248.                 comma = ", ";
  249.             }
  250.             if (this.cWorld) {
  251.                 this.cWorld = false;
  252.                 v = String.valueOf(v) + comma + "world=?";
  253.                 args.add(this.world);
  254.                 types.add(12);
  255.                 comma = ", ";
  256.             }
  257.             if (this.cMute) {
  258.                 this.cMute = false;
  259.                 v = String.valueOf(v) + comma + "mute=?";
  260.                 args.add(this.mute);
  261.                 types.add(12);
  262.                 comma = ", ";
  263.             }
  264.             if (this.cHomeWorld) {
  265.                 this.cHomeWorld = false;
  266.                 v = String.valueOf(v) + comma + "homeWorld=?";
  267.                 args.add(this.homeWorld);
  268.                 types.add(12);
  269.                 comma = ", ";
  270.             }
  271.             if (this.cFly) {
  272.                 this.cFly = false;
  273.                 v = String.valueOf(v) + comma + "fly=?";
  274.                 args.add(this.fly);
  275.                 types.add(-6);
  276.                 comma = ", ";
  277.             }
  278.             if (this.cGod) {
  279.                 this.cGod = false;
  280.                 v = String.valueOf(v) + comma + "god=?";
  281.                 args.add(this.god);
  282.                 types.add(-6);
  283.                 comma = ", ";
  284.             }
  285.             if (this.cMuteTime) {
  286.                 this.cMuteTime = false;
  287.                 v = String.valueOf(v) + comma + "muteTime=?";
  288.                 args.add(this.muteTime);
  289.                 types.add(-5);
  290.                 comma = ", ";
  291.             }
  292.             if (this.cGamemode) {
  293.                 this.cGamemode = false;
  294.                 v = String.valueOf(v) + comma + "gamemode=?";
  295.                 args.add((byte)this.gamemode.getValue());
  296.                 types.add(-6);
  297.             }
  298.         }
  299.         if (where) {
  300.             w = "userID=?";
  301.             args.add(this);
  302.             types.add(4);
  303.         }
  304.         return new UpdateSet("users", v, w, args, types, this);
  305.     }
  306.    
  307.     public Player getPlayer() {
  308.         return Bukkit.getPlayer(this.getNick());
  309.     }
  310.    
  311.     public OfflinePlayer getOfflinePlayer() {
  312.         return Bukkit.getOfflinePlayer(this.getNick());
  313.     }
  314.    
  315.     @Override
  316.     public void insert() {
  317.         super.insert();
  318.         this.db.users.add(this);
  319.         Datasource.usersByNick.put(this.nick.toLowerCase(), this);
  320.         this.oldNick = this.nick;
  321.     }
  322.    
  323.     @Override
  324.     public void update() {
  325.         super.update();
  326.         if (this.cNick) {
  327.             Datasource.usersByNick.remove(this.oldNick.toLowerCase());
  328.             Datasource.usersByNick.put(this.nick.toLowerCase(), this);
  329.             this.oldNick = this.nick;
  330.         }
  331.     }
  332.    
  333.     @Override
  334.     public void delete() {
  335.         super.delete();
  336.         this.db.users.remove(this);
  337.         Datasource.usersByNick.remove(this.oldNick.toLowerCase());
  338.     }
  339. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement