4 changed files with 88 additions and 147 deletions
@ -0,0 +1,81 @@
|
||||
package ru.simsonic.rscPermissions.Bukkit; |
||||
import java.util.Set; |
||||
import java.util.logging.Level; |
||||
import org.bukkit.entity.Player; |
||||
import ru.simsonic.rscPermissions.API.Settings; |
||||
import ru.simsonic.rscPermissions.Backends.DatabaseContents; |
||||
import ru.simsonic.rscPermissions.BukkitPluginMain; |
||||
import ru.simsonic.rscUtilityLibrary.RestartableThread; |
||||
import ru.simsonic.rscUtilityLibrary.TextProcessing.GenericChatCodes; |
||||
|
||||
public class BukkitDatabaseFetcher extends RestartableThread |
||||
{ |
||||
private final BukkitPluginMain rscp; |
||||
public BukkitDatabaseFetcher(BukkitPluginMain plugin) |
||||
{ |
||||
this.rscp = plugin; |
||||
} |
||||
@Override |
||||
public void run() |
||||
{ |
||||
final long queryStartTime = System.currentTimeMillis(); |
||||
Thread.currentThread().setName("rscp:DatabaseFetchingThread"); |
||||
Thread.currentThread().setPriority(Thread.MIN_PRIORITY); |
||||
if(rscp.connection.isConnected() == false) |
||||
if(rscp.connection.connect() == false) |
||||
{ |
||||
BukkitPluginMain.consoleLog.warning("[rscp] Cannot connect to database! Using local cache only."); |
||||
return; |
||||
} |
||||
final DatabaseContents contents = rscp.connection.retrieveContents(); |
||||
rscp.connection.disconnect(); |
||||
if(contents != null) |
||||
{ |
||||
contents.normalize(); |
||||
rscp.localStorage.cleanup(); |
||||
rscp.localStorage.saveContents(contents); |
||||
contents.filterServerId(rscp.getServer().getServerId()); |
||||
rscp.internalCache.fill(contents); |
||||
final Runnable syncTask = new Runnable() |
||||
{ |
||||
@Override |
||||
public synchronized void run() |
||||
{ |
||||
BukkitPluginMain.consoleLog.log(Level.INFO, "[rscp] Fetched {0} entities, {1} permissions and {2} inheritances", |
||||
new Integer[] |
||||
{ |
||||
contents.entities.length, |
||||
contents.permissions.length, |
||||
contents.inheritance.length |
||||
}); |
||||
rscp.permissionManager.recalculateOnlinePlayers(); |
||||
notify(); |
||||
} |
||||
}; |
||||
try |
||||
{ |
||||
synchronized(syncTask) |
||||
{ |
||||
rscp.getServer().getScheduler().runTask(rscp, syncTask); |
||||
syncTask.wait(); |
||||
} |
||||
} catch(InterruptedException ex) { |
||||
} |
||||
final long queryTime = System.currentTimeMillis() - queryStartTime; |
||||
final Set<Player> debuggers = rscp.permissionManager.getDebuggers(); |
||||
if(!debuggers.isEmpty()) |
||||
rscp.getServer().getScheduler().runTask(rscp, new Runnable() |
||||
{ |
||||
@Override |
||||
public void run() |
||||
{ |
||||
for(Player debugger : debuggers) |
||||
debugger.sendMessage(GenericChatCodes.processStringStatic(Settings.chatPrefix |
||||
+ "Database has been fetched in " + queryTime + " milliseconds.")); |
||||
} |
||||
}); |
||||
} |
||||
else |
||||
BukkitPluginMain.consoleLog.warning("[rscp] Cannot load data from database."); |
||||
} |
||||
} |
@ -1,72 +0,0 @@
|
||||
# Users Section |
||||
users: |
||||
# Player Name |
||||
t3hk0d3: |
||||
# Player Group(s) Section |
||||
group: |
||||
# Player Group Name |
||||
- default |
||||
# Player Specific Permissions Section |
||||
permissions: |
||||
# Permissions node |
||||
- permissions.* |
||||
# World Specific Permission Section |
||||
worlds: |
||||
# World designator |
||||
world: |
||||
# World Specific Permission Group |
||||
permissions: |
||||
# World Specific Permission |
||||
- test.* |
||||
# World Specific Group Section |
||||
group: |
||||
# World Specific Group |
||||
- testers |
||||
# World Specific Prefix |
||||
prefix: '&5[YARR]&f' |
||||
|
||||
# Group Section |
||||
groups: |
||||
# Group Name |
||||
default: |
||||
# Default Group Setting |
||||
default: true |
||||
# Group Permissions Section |
||||
permissions: |
||||
# Negated Permission Node |
||||
- -modifyworld.blocks.interact.23 |
||||
# Permission Node |
||||
- modifyworld.* |
||||
admins: |
||||
# Group Inheritance Section |
||||
inheritance: |
||||
# Groups To Inherit From |
||||
- default |
||||
permissions: |
||||
- example.permission |
||||
- -punish.noobs |
||||
# Group Options Section |
||||
options: |
||||
# Extra Data |
||||
test.test: '100500' |
||||
# Rank Designator |
||||
rank: '1' |
||||
worlds: |
||||
nether: |
||||
permissions: |
||||
- nocheat.fly |
||||
prefix: '&7[ADMIN FROM HELL]' |
||||
testers: |
||||
inheritance: |
||||
- admins |
||||
options: |
||||
test.test: '9000' |
||||
|
||||
# World Specific Section |
||||
worlds: |
||||
# World Name |
||||
nether: |
||||
# World Inheritance Section |
||||
inheritance: |
||||
# World To Inherit From |
||||
- world |
Loading…
Reference in new issue