Skip to content

Commit

Permalink
Fix status bug
Browse files Browse the repository at this point in the history
  • Loading branch information
md-5 committed Nov 24, 2011
1 parent d0cb651 commit 7bf830f
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 39 deletions.
Binary file added release/AutoGroup-1.1.1.jar
Binary file not shown.
10 changes: 5 additions & 5 deletions src/main/java/com/md_5/autogroup/AutoGroup.java
Expand Up @@ -21,7 +21,7 @@ public class AutoGroup extends JavaPlugin {
static FileConfiguration config;

public void onEnable() {

//herp
PluginManager pm = this.getServer().getPluginManager();

WorldListener worldListener = new WorldListener(this);
Expand Down Expand Up @@ -92,10 +92,10 @@ public boolean onPlayerCommand(Player player, Command command, String label, Str
return true;
}
player.sendMessage(ChatColor.GOLD + "You joined the server "
+ (playerTimes.get(player.getName()).last - playerTimes.get(player.getName()).date) + " seconds ago");
+ (playerTimes.get(player.getName()).getLast() - playerTimes.get(player.getName()).getDate()) + " seconds ago");
player.sendMessage(ChatColor.GOLD + "You must reach " + Config.loyalty + " seconds before you are loyal");
player.sendMessage(ChatColor.GOLD + "You have played for "
+ playerTimes.get(player.getName()).time + " seconds in total");
+ playerTimes.get(player.getName()).getTime() + " seconds in total");
break;
case 1:
if (player.hasPermission("autogroup.playtime.others")) {
Expand All @@ -104,10 +104,10 @@ public boolean onPlayerCommand(Player player, Command command, String label, Str
return true;
}
player.sendMessage(ChatColor.GOLD + args[0] + " joined the server "
+ (playerTimes.get(args[0]).last - playerTimes.get(args[0]).date) + " seconds ago");
+ (playerTimes.get(args[0]).getLast() - playerTimes.get(args[0]).getDate()) + " seconds ago");
player.sendMessage(ChatColor.GOLD + args[0] + " must reach " + Config.loyalty + " seconds before they are loyal");
player.sendMessage(ChatColor.GOLD + args[0] + " has played for "
+ playerTimes.get(args[0]).time + " seconds in total");
+ playerTimes.get(args[0]).getTime() + " seconds in total");
} else {
player.sendMessage("You can only view your own time. Run this command without arguments");
}
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/com/md_5/autogroup/Database.java
Expand Up @@ -18,7 +18,7 @@ public static boolean load(String player) {
ResultSet rs = stat.executeQuery("select * from players WHERE name='" + player + "'");
while (rs.next()) {
Map map = new Map(rs.getInt("time"), rs.getInt("date"), rs.getInt("last"));
map.status = rs.getString("status");
map.setStatus(rs.getString("status"));
AutoGroup.playerTimes.put(rs.getString("name"), map);
}
stat.close();
Expand All @@ -27,11 +27,11 @@ public static boolean load(String player) {
} catch (ClassNotFoundException e) {
Errors.classNotFound();
} catch (SQLException e) {
if (Config.debug) {
//if (Config.debug) {
e.printStackTrace();
} else {
// } else {
Errors.SQLException();
}
//}
}
return true;
}
Expand All @@ -43,8 +43,7 @@ public static boolean save() {
Statement stat = conn.createStatement();
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
String name = player.getName();
AutoGroup.playerTimes.put(name, new Map(AutoGroup.playerTimes.get(name).time,
AutoGroup.playerTimes.get(name).date, (int) (System.currentTimeMillis() / 1000L)));
AutoGroup.playerTimes.get(name).setLast((int) (System.currentTimeMillis() / 1000L));
Database.update(name);
}
for (String player : AutoGroup.playerTimes.keySet()) {
Expand All @@ -69,7 +68,7 @@ public static boolean add(String player) {
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:plugins/AutoGroup/users.db");
Statement stat = conn.createStatement();
stat.executeUpdate("insert into players values ('" + player + "',0," + AutoGroup.playerTimes.get(player).date + ", 0, '')");
stat.executeUpdate("insert into players values ('" + player + "',0," + AutoGroup.playerTimes.get(player).getDate() + ", 0, '')");
stat.close();
conn.close();
} catch (ClassNotFoundException e) {
Expand All @@ -89,9 +88,9 @@ public static boolean update(String player) {
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:plugins/AutoGroup/users.db");
Statement stat = conn.createStatement();
stat.executeUpdate("update players set time=" + AutoGroup.playerTimes.get(player).time
+ ", last=" + AutoGroup.playerTimes.get(player).last + ", status='"
+ AutoGroup.playerTimes.get(player).status
stat.executeUpdate("update players set time=" + AutoGroup.playerTimes.get(player).getTime()
+ ", last=" + AutoGroup.playerTimes.get(player).getLast() + ", status='"
+ AutoGroup.playerTimes.get(player).getStatus()
+ "' WHERE name='" + player + "'");
stat.close();
conn.close();
Expand Down
40 changes: 36 additions & 4 deletions src/main/java/com/md_5/autogroup/Map.java
Expand Up @@ -2,14 +2,46 @@

public class Map {

public int time;
public int date;
public int last;
public String status = "";
private int time;
private int date;
private int last;
private String status = "";

public Map(int time, int date, int last) {
this.time = time;
this.date = date;
this.last = last;
}

public int getTime() {
return time;
}

public void setTime(int time) {
this.time = time;
}

public int getDate() {
return date;
}

public void setDate(int date) {
this.date = date;
}

public int getLast() {
return last;
}

public void setLast(int last) {
this.last = last;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}
}
29 changes: 15 additions & 14 deletions src/main/java/com/md_5/autogroup/Promote.java
Expand Up @@ -7,27 +7,28 @@
public class Promote {

public static void checkPromote(String player) {
if ((AutoGroup.playerTimes.get(player).last - AutoGroup.playerTimes.get(player).date) >= Config.loyalty
&& Config.loyalty != 0) {
if (!AutoGroup.playerTimes.get(player).status.equalsIgnoreCase(Config.loyalGroup)) {
int last = AutoGroup.playerTimes.get(player).getLast();
int date = AutoGroup.playerTimes.get(player).getDate();
int time = AutoGroup.playerTimes.get(player).getTime();
String status = AutoGroup.playerTimes.get(player).getStatus();

if ((last - date) >= Config.loyalty && Config.loyalty != 0) {
if (!status.equalsIgnoreCase(Config.loyalGroup)) {
promotePlayer(player, Config.loyalGroup);
}
}
if ((AutoGroup.playerTimes.get(player).time >= Config.addict1Time)
&& AutoGroup.playerTimes.get(player).time < Config.addict2Time && Config.addict1Time != 0) {
if (!AutoGroup.playerTimes.get(player).status.equalsIgnoreCase(Config.addictGroup1)) {
if ((time >= Config.addict1Time) && time < Config.addict2Time && Config.addict1Time != 0) {
if (!status.equalsIgnoreCase(Config.addictGroup1)) {
promotePlayer(player, Config.addictGroup1);
}
}
if ((AutoGroup.playerTimes.get(player).time >= Config.addict2Time)
&& AutoGroup.playerTimes.get(player).time < Config.addict3Time && Config.addict2Time != 0) {
if (!AutoGroup.playerTimes.get(player).status.equalsIgnoreCase(Config.addictGroup2)) {
if ((time >= Config.addict2Time) && AutoGroup.playerTimes.get(player).getTime() < Config.addict3Time && Config.addict2Time != 0) {
if (!status.equalsIgnoreCase(Config.addictGroup2)) {
promotePlayer(player, Config.addictGroup2);
}
}
if ((AutoGroup.playerTimes.get(player).time >= Config.addict3Time)
&& Config.addict3Time != 0) {
if (!AutoGroup.playerTimes.get(player).status.equalsIgnoreCase(Config.addictGroup3)) {
if ((time >= Config.addict3Time) && Config.addict3Time != 0) {
if (!status.equalsIgnoreCase(Config.addictGroup3)) {
promotePlayer(player, Config.addictGroup3);
}
}
Expand All @@ -37,14 +38,14 @@ public static void checkPromote(String player) {
}

public static void promotePlayer(String player, String group) {
if (Bukkit.getServer().getPlayer(player).hasPermission("autogroup.norank")){
if (Bukkit.getServer().getPlayer(player).hasPermission("autogroup.norank")) {
return;
}
AutoGroup.logger.info(String.format("AutoGroup: Trying to promote %1$s to group " + group, player));
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
p.sendMessage(ChatColor.LIGHT_PURPLE + "AutoGroup: Please welcome " + player + " to group " + group);
}
AutoGroup.playerTimes.get(player).status = group;
AutoGroup.playerTimes.get(player).setStatus(group);
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format(Config.command, player, group));
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/md_5/autogroup/Ticker.java
Expand Up @@ -12,8 +12,8 @@ public void run() {
AutoGroup.playerTimes.put(name, new Map(0, (int) (System.currentTimeMillis() / 1000L), 0));
Database.add(name);
}
AutoGroup.playerTimes.get(name).time += Config.interval;
AutoGroup.playerTimes.get(name).last = (int) (System.currentTimeMillis() / 1000L);
AutoGroup.playerTimes.get(name).setTime(AutoGroup.playerTimes.get(name).getTime() + Config.interval);
AutoGroup.playerTimes.get(name).setLast((int) (System.currentTimeMillis() / 1000L));
Promote.checkPromote(name);
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/md_5/autogroup/events/PlayerListener.java
Expand Up @@ -2,7 +2,6 @@

import com.md_5.autogroup.AutoGroup;
import com.md_5.autogroup.Database;
import com.md_5.autogroup.Map;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.event.player.PlayerJoinEvent;
Expand All @@ -26,8 +25,7 @@ public void registerEvents(final PluginManager pm) {
public void onPlayerQuit(PlayerQuitEvent event) {
String name = event.getPlayer().getName();
if (AutoGroup.playerTimes.containsKey(name)) {
AutoGroup.playerTimes.put(name, new Map(AutoGroup.playerTimes.get(name).time,
AutoGroup.playerTimes.get(name).date, (int) (System.currentTimeMillis() / 1000L)));
AutoGroup.playerTimes.get(name).setLast((int) (System.currentTimeMillis() / 1000L));
Database.update(name);
AutoGroup.playerTimes.remove(name);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
@@ -1,5 +1,5 @@
name: AutoGroup
version: 1.1
version: 1.1.1
description: Bukkit plugin to automatically group users based on the time they have spent online and donation amounts.
author: md_5
website: https://github.com/md-5/AutoGroup
Expand Down

0 comments on commit 7bf830f

Please sign in to comment.