Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
caoli5288 committed Jun 12, 2019
1 parent 81f2f92 commit 8b67411
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies {
compileOnly 'net.md-5:bungeecord-api:1.12-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT'
compileOnly 'com.mengcraft:simpleorm:1.2-SNAPSHOT'
compileOnly 'org.avaje:ebean:2.8.1'
compileOnly 'com.comphenix.protocol:ProtocolLib:4.4.0-SNAPSHOT'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@

import lombok.Data;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;

import java.sql.Timestamp;

@Data
public class PlayerDataLockedEvent extends PlayerEvent {
public class PlayerDataLockedEvent extends Event {

public static final HandlerList HANDLER_LIST = new HandlerList();
private final Timestamp lastUpdate;
private Result result = Result.DEFAULT;
private final Player who;
private Event.Result result = Event.Result.DEFAULT;

public PlayerDataLockedEvent(Player who, Timestamp lastUpdate) {
super(who);
super(true);
this.who = who;
this.lastUpdate = lastUpdate;
}

@Override
public HandlerList getHandlers() {
return null;
return HANDLER_LIST;
}

public static HandlerList getHandlerList() {
Expand Down
30 changes: 16 additions & 14 deletions src/main/java/com/mengcraft/playersql/task/FetchUserTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,23 @@ public synchronized void run() {
} else {
cancel();

PlayerDataLockedEvent e = new PlayerDataLockedEvent(player, user.getLastUpdate());
Bukkit.getPluginManager().callEvent(e);
switch (e.getResult()) {
case DENY:
kickPlayer();
return;
case DEFAULT:
// Todo configurable lock hold time.
if (e.getLastUpdate().toInstant().until(Instant.now(), ChronoUnit.MINUTES) <= 10) {
if (user.isLocked()) {
PlayerDataLockedEvent e = new PlayerDataLockedEvent(player, user.getLastUpdate());
Bukkit.getPluginManager().callEvent(e);
switch (e.getResult()) {
case DENY:
kickPlayer();
return;
}
break;
case ALLOW:
break;
case DEFAULT:
// Todo configurable lock hold time.
if (e.getLastUpdate().toInstant().until(Instant.now(), ChronoUnit.MINUTES) <= 10) {
kickPlayer();
return;
}
break;
case ALLOW:
break;
}
}

LocalDataMgr.transfer(player);// TODO move to server thread if any exception
Expand All @@ -91,7 +93,7 @@ public synchronized void run() {
}

private void kickPlayer() {
player.kickPlayer("Your player data has been locked.\nYou should wait some minutes or contact server operator.");
main.run(() -> player.kickPlayer("Your player data has been locked.\nYou should wait some minutes or contact server operator."));
}

}

0 comments on commit 8b67411

Please sign in to comment.