Skip to content

Commit

Permalink
Update to 2.5
Browse files Browse the repository at this point in the history
Fix #40
  • Loading branch information
caoli5288 committed Jun 12, 2017
1 parent b7a71ca commit 2df0650
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
9 changes: 4 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.mengcraft</groupId>
<artifactId>playersql</artifactId>
<version>2.4.2</version>
<version>2.5</version>
<name>PlayerSQL</name>

<properties>
Expand All @@ -31,7 +31,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.7.10-R0.1-SNAPSHOT</version>
<version>1.12-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -43,7 +43,7 @@
<dependency>
<groupId>com.mengcraft</groupId>
<artifactId>simpleorm</artifactId>
<version>0.3.3</version>
<version>0.4</version>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
Expand All @@ -64,15 +64,14 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<version>3.0.0</version>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<phase>package</phase>
<configuration>
<minimizeJar>true</minimizeJar>
<relocations>
<relocation>
<pattern>com.mengcraft.simpleorm</pattern>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/mengcraft/playersql/EventExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void handle(InventoryClickEvent event) {
public void handle(PlayerLoginEvent event) {
UUID uuid = event.getPlayer().getUniqueId();
if (Config.DEBUG) {
main.info("Lock user " + uuid + " done!");
main.log("Lock user " + uuid + " done!");
}
this.manager.lockUser(uuid);
}
Expand All @@ -114,7 +114,7 @@ public void handle(PlayerJoinEvent event) {
FetchUserTask task = new FetchUserTask();
task.setUuid(event.getPlayer().getUniqueId());
task.setExecutor(this);
task.setTaskId(this.main.runTaskTimerAsynchronously(task, Config.SYN_DELAY).getTaskId());
task.setTaskId(this.main.runTimerAsync(task, Config.SYN_DELAY).getTaskId());
}

@EventHandler(priority = MONITOR)
Expand All @@ -123,7 +123,7 @@ public void handle(PlayerQuitEvent event) {
if (manager.isNotLocked(uuid)) {
manager.cancelTask(uuid);
User user = manager.getUserData(event.getPlayer(), true);
main.runTaskAsynchronously(() -> {
main.runAsync(() -> {
manager.saveUser(user, false);
});
} else {
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/com/mengcraft/playersql/PluginMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.bukkit.scheduler.BukkitTask;

import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;

/**
Expand Down Expand Up @@ -72,27 +73,27 @@ public Player getPlayer(UUID uuid) {
return getServer().getPlayer(uuid);
}

public void info(Exception e) {
getLogger().log(Level.WARNING, e.toString(), e);
public void log(Exception e) {
getLogger().log(Level.SEVERE, e.toString(), e);
}

public void info(String info) {
public void log(String info) {
getLogger().info(info);
}

public BukkitTask runTaskTimerAsynchronously(Runnable r, int i) {
public BukkitTask runTimerAsync(Runnable r, int i) {
return getServer().getScheduler().runTaskTimerAsynchronously(this, r, i, i);
}

public BukkitTask runTaskAsynchronously(Runnable r) {
return getServer().getScheduler().runTaskAsynchronously(this, r);
public void runAsync(Runnable r) {
CompletableFuture.runAsync(r);
}

public BukkitTask runTask(Runnable r) {
return getServer().getScheduler().runTask(this, r);
public void run(Runnable r) {
getServer().getScheduler().runTask(this, r);
}

public BukkitTask runTaskTimer(Runnable r, int i) {
public BukkitTask runTimer(Runnable r, int i) {
return getServer().getScheduler().runTaskTimer(this, r, i, i);
}

Expand Down
24 changes: 12 additions & 12 deletions src/main/java/com/mengcraft/playersql/UserManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private UserManager() {
}

public void addFetched(User user) {
main.runTask(() -> pend(user));
main.run(() -> pend(user));
}

/**
Expand All @@ -65,7 +65,7 @@ public void saveUser(User user, boolean lock) {
user.setLocked(lock);
db.update(user);
if (Config.DEBUG) {
main.info("Save user data " + user.getUuid() + " done!");
main.log("Save user data " + user.getUuid() + " done!");
}
}

Expand All @@ -76,9 +76,9 @@ public void lockUserData(UUID uuid) {
int result = update.execute();
if (Config.DEBUG) {
if (result == 1) {
main.info("Lock user data " + uuid + " done.");
main.log("Lock user data " + uuid + " done.");
} else {
main.info("Lock user data " + uuid + " faid!");
main.log("Lock user data " + uuid + " faid!");
}
}
}
Expand Down Expand Up @@ -134,7 +134,7 @@ public void lockUser(UUID uuid) {

public void unlockUser(UUID uuid, boolean scheduled) {
if (scheduled) {
main.runTask(() -> unlockUser(uuid));
main.run(() -> unlockUser(uuid));
} else {
unlockUser(uuid);
}
Expand All @@ -151,7 +151,7 @@ private void pend(User user) {
if (player != null && player.isOnline()) {
pend(user, player);
} else if (Config.DEBUG) {
this.main.info(new PluginException("User " + user.getUuid() + " not found!"));
this.main.log(new PluginException("User " + user.getUuid() + " not found!"));
}
}

Expand Down Expand Up @@ -218,7 +218,7 @@ private ItemStack[] toStack(String data) {
} else try {
output.add(this.itemUtil.convert(s));
} catch (Exception e) {
this.main.info(e);
this.main.log(e);
}
return output.toArray(new ItemStack[parsed.size()]);
}
Expand All @@ -232,7 +232,7 @@ private String toString(ItemStack[] stacks) {
} else try {
array.add(this.itemUtil.convert(stack));
} catch (Exception e) {
this.main.info(e);
this.main.log(e);
}
return array.toString();
}
Expand All @@ -258,23 +258,23 @@ public void cancelTask(UUID uuid) {
if (task != null) {
task.cancel();
} else if (Config.DEBUG) {
this.main.info("No task can be canceled for " + uuid + '!');
this.main.log("No task can be canceled for " + uuid + '!');
}
}

public void createTask(UUID uuid) {
if (Config.DEBUG) {
this.main.info("Scheduling daily save task for user " + uuid + '.');
this.main.log("Scheduling daily save task for user " + uuid + '.');
}
DailySaveTask saveTask = new DailySaveTask();
BukkitTask task = this.main.runTaskTimer(saveTask, 6000);
BukkitTask task = this.main.runTimer(saveTask, 6000);
saveTask.setUuid(uuid);
saveTask.setUserManager(this);
saveTask.setTaskId(task.getTaskId());
BukkitTask old = this.taskMap.put(uuid, task);
if (old != null) {
if (Config.DEBUG) {
this.main.info("Already scheduled task for user " + uuid + '!');
this.main.log("Already scheduled task for user " + uuid + '!');
}
old.cancel();
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/mengcraft/playersql/task/DailySaveTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public synchronized void run() {
User user = userManager.getUserData(this.uuid, false);
if (user == null) {
if (Config.DEBUG) {
userManager.getMain().info("Cancel task for " + uuid + " offline!");
userManager.getMain().log("Cancel task for " + uuid + " offline!");
}
Bukkit.getScheduler().cancelTask(taskId);
} else {
this.saveCount++;
if (Config.DEBUG) {
userManager.getMain().info("Save user " + this.uuid + " count " + this.saveCount + '.');
userManager.getMain().log("Save user " + this.uuid + " count " + this.saveCount + '.');
}
userManager.getMain().runTaskAsynchronously(() -> userManager.saveUser(user, true));
userManager.getMain().runAsync(() -> userManager.saveUser(user, true));
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/mengcraft/playersql/task/FetchUserTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ public synchronized void run() {
if (user == null) {
this.executor.cancelTask(this.taskId);
if (Config.DEBUG) {
this.executor.getMain().info("User data " + uuid + " not found!");
this.executor.getMain().log("User data " + uuid + " not found!");
}

this.executor.getManager().unlockUser(this.uuid, true);
this.executor.getManager().newUser(this.uuid);
this.executor.getManager().createTask(this.uuid);

if (Config.DEBUG) {
this.executor.getMain().info("New user data for" + uuid + '.');
this.executor.getMain().log("New user data for" + uuid + '.');
}
} else if (user.isLocked() && this.retry++ < 8) {
if (Config.DEBUG) {
this.executor.getMain().info("Load user data " + uuid + " fail " + retry + '.');
this.executor.getMain().log("Load user data " + uuid + " fail " + retry + '.');
}
} else {
this.executor.getManager().addFetched(user);
if (Config.DEBUG) {
this.executor.getMain().info("Load user data " + uuid + " done.");
this.executor.getMain().log("Load user data " + uuid + " done.");
}

this.executor.cancelTask(this.taskId);
Expand Down

0 comments on commit 2df0650

Please sign in to comment.