forked from codename-B/bPermissions
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Initial commit of bPermissions Sponge
Not ready for any sort of use yet
- Loading branch information
1 parent
2e9e284
commit afb794a
Showing
11 changed files
with
322 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
bukkit/src/main/java/de/bananaco/bpermissions/imp/Permissions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
bukkit/src/main/java/de/bananaco/bpermissions/imp/YamlWorld.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
260 changes: 130 additions & 130 deletions
260
...rmissions/imp/loadmanager/MainThread.java → ...missions/util/loadmanager/MainThread.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +1,130 @@ | ||
package de.bananaco.bpermissions.imp.loadmanager; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import de.bananaco.bpermissions.imp.loadmanager.TaskRunnable.TaskType; | ||
import de.bananaco.bpermissions.util.Debugger; | ||
|
||
public class MainThread extends Thread implements TaskThread { | ||
|
||
private static MainThread thread = new MainThread(); | ||
|
||
public static MainThread getInstance() { | ||
return thread; | ||
} | ||
// a list of tasks | ||
private List<Runnable> load = new ArrayList<Runnable>(); | ||
private List<Runnable> save = new ArrayList<Runnable>(); | ||
private List<Runnable> server = new ArrayList<Runnable>(); | ||
private boolean running = true; | ||
private boolean started = false; | ||
|
||
@Override | ||
public void run() { | ||
while (running) { | ||
check(); | ||
} | ||
} | ||
|
||
/** | ||
* Internal method, check scheduler | ||
*/ | ||
private synchronized void check() { | ||
try { | ||
if (hasTasks()) { | ||
TaskRunnable run = null; | ||
List tasks = null; | ||
if (getTasks(TaskRunnable.TaskType.LOAD).size() > 0) { | ||
tasks = getTasks(TaskRunnable.TaskType.LOAD); | ||
} else if (getTasks(TaskRunnable.TaskType.SAVE).size() > 0) { | ||
tasks = getTasks(TaskRunnable.TaskType.SAVE); | ||
} else if (getTasks(TaskRunnable.TaskType.SERVER).size() > 0) { | ||
tasks = getTasks(TaskRunnable.TaskType.SERVER); | ||
} | ||
|
||
if (tasks != null) { | ||
run = (TaskRunnable) tasks.get(0); | ||
tasks.remove(0); | ||
TaskRunnable r = run; | ||
|
||
r.run(); | ||
} | ||
} else { | ||
sleep(10L); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
/** | ||
* Internal method, concurrent modification exception prevention | ||
* | ||
* @return List<Runnable> | ||
*/ | ||
private List<Runnable> getTasks(TaskType type) { | ||
if (type == TaskType.LOAD) { | ||
return load; | ||
} | ||
if (type == TaskType.SAVE) { | ||
return save; | ||
} | ||
if (type == TaskType.SERVER) { | ||
return server; | ||
} | ||
return new ArrayList<Runnable>(); | ||
} | ||
|
||
// from the interface | ||
public boolean hasTasks() { | ||
return load.size() + save.size() + server.size() > 0; | ||
} | ||
|
||
public boolean isRunning() { | ||
return running; | ||
} | ||
|
||
public void setRunning(final boolean running) { | ||
clearTasks(); | ||
if (!running) { | ||
thread.running = false; | ||
thread = null; | ||
} | ||
} | ||
|
||
public void clearTasks() { | ||
load.clear(); | ||
save.clear(); | ||
server.clear(); | ||
} | ||
|
||
public boolean getStarted() { | ||
return started; | ||
} | ||
|
||
public void setStarted(final boolean started) { | ||
TaskRunnable r = new TaskRunnable() { | ||
public void run() { | ||
thread.started = started; | ||
Debugger.log("Set started: " + started); | ||
} | ||
|
||
public TaskType getType() { | ||
return TaskType.SERVER; | ||
} | ||
}; | ||
schedule(r); | ||
} | ||
|
||
public void schedule(TaskRunnable r) { | ||
if (tasksCount() > 10 && (r.getType() == TaskType.LOAD || r.getType() == TaskType.SAVE)) | ||
return; | ||
|
||
getTasks(r.getType()).add(r); | ||
} | ||
|
||
public int tasksCount() { | ||
return load.size() + save.size(); | ||
} | ||
} | ||
package de.bananaco.bpermissions.util.loadmanager; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import de.bananaco.bpermissions.util.loadmanager.TaskRunnable.TaskType; | ||
import de.bananaco.bpermissions.util.Debugger; | ||
|
||
public class MainThread extends Thread implements TaskThread { | ||
|
||
private static MainThread thread = new MainThread(); | ||
|
||
public static MainThread getInstance() { | ||
return thread; | ||
} | ||
// a list of tasks | ||
private List<Runnable> load = new ArrayList<Runnable>(); | ||
private List<Runnable> save = new ArrayList<Runnable>(); | ||
private List<Runnable> server = new ArrayList<Runnable>(); | ||
private boolean running = true; | ||
private boolean started = false; | ||
|
||
@Override | ||
public void run() { | ||
while (running) { | ||
check(); | ||
} | ||
} | ||
|
||
/** | ||
* Internal method, check scheduler | ||
*/ | ||
private synchronized void check() { | ||
try { | ||
if (hasTasks()) { | ||
TaskRunnable run = null; | ||
List tasks = null; | ||
if (getTasks(TaskRunnable.TaskType.LOAD).size() > 0) { | ||
tasks = getTasks(TaskRunnable.TaskType.LOAD); | ||
} else if (getTasks(TaskRunnable.TaskType.SAVE).size() > 0) { | ||
tasks = getTasks(TaskRunnable.TaskType.SAVE); | ||
} else if (getTasks(TaskRunnable.TaskType.SERVER).size() > 0) { | ||
tasks = getTasks(TaskRunnable.TaskType.SERVER); | ||
} | ||
|
||
if (tasks != null) { | ||
run = (TaskRunnable) tasks.get(0); | ||
tasks.remove(0); | ||
TaskRunnable r = run; | ||
|
||
r.run(); | ||
} | ||
} else { | ||
sleep(10L); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
/** | ||
* Internal method, concurrent modification exception prevention | ||
* | ||
* @return List<Runnable> | ||
*/ | ||
private List<Runnable> getTasks(TaskType type) { | ||
if (type == TaskType.LOAD) { | ||
return load; | ||
} | ||
if (type == TaskType.SAVE) { | ||
return save; | ||
} | ||
if (type == TaskType.SERVER) { | ||
return server; | ||
} | ||
return new ArrayList<Runnable>(); | ||
} | ||
|
||
// from the interface | ||
public boolean hasTasks() { | ||
return load.size() + save.size() + server.size() > 0; | ||
} | ||
|
||
public boolean isRunning() { | ||
return running; | ||
} | ||
|
||
public void setRunning(final boolean running) { | ||
clearTasks(); | ||
if (!running) { | ||
thread.running = false; | ||
thread = null; | ||
} | ||
} | ||
|
||
public void clearTasks() { | ||
load.clear(); | ||
save.clear(); | ||
server.clear(); | ||
} | ||
|
||
public boolean getStarted() { | ||
return started; | ||
} | ||
|
||
public void setStarted(final boolean started) { | ||
TaskRunnable r = new TaskRunnable() { | ||
public void run() { | ||
thread.started = started; | ||
Debugger.log("Set started: " + started); | ||
} | ||
|
||
public TaskType getType() { | ||
return TaskType.SERVER; | ||
} | ||
}; | ||
schedule(r); | ||
} | ||
|
||
public void schedule(TaskRunnable r) { | ||
if (tasksCount() > 10 && (r.getType() == TaskType.LOAD || r.getType() == TaskType.SAVE)) | ||
return; | ||
|
||
getTasks(r.getType()).add(r); | ||
} | ||
|
||
public int tasksCount() { | ||
return load.size() + save.size(); | ||
} | ||
} |
24 changes: 12 additions & 12 deletions
24
...issions/imp/loadmanager/TaskRunnable.java → ...ssions/util/loadmanager/TaskRunnable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
package de.bananaco.bpermissions.imp.loadmanager; | ||
|
||
public interface TaskRunnable extends Runnable { | ||
|
||
static enum TaskType { | ||
SAVE, | ||
LOAD, | ||
SERVER | ||
} | ||
|
||
public TaskType getType(); | ||
} | ||
package de.bananaco.bpermissions.util.loadmanager; | ||
|
||
public interface TaskRunnable extends Runnable { | ||
|
||
static enum TaskType { | ||
SAVE, | ||
LOAD, | ||
SERVER | ||
} | ||
|
||
public TaskType getType(); | ||
} |
Oops, something went wrong.