Browse Source

Update for 1.8.7-dev
- Fixed #62. No longer repeats, as it is a non-repeating task.
- Un-Syncronized main backup task, should fix issues with server lag.
- Updated README file.
- Implemented change hopefully fully supporting SuperPerms, Closes #21.
- Removed Permission dependency in POM.

gamerx 7 years ago
parent
commit
21e2cdca0b

+ 11 - 5
README

@@ -1,10 +1,14 @@
 /*
- *  Backup - CraftBukkit server Backup plugin (continued)
- *  Copyright (C) 2011-2012 Domenic Horner (gamerx) <https://github.com/gamerx/Backup>
- *  Copyright (C) 2011 Lycano <https://github.com/gamerx/Backup>
- *
+ *          -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+ * 
+ *  Backup - Bukkit server backup plugin. (continued development)
+ *  Copyright (C) 2012 Domenic Horner (gamerx) <https://github.com/gamerx>
+ *  Copyright (C) 2011 Lycano <https://github.com/lycano>
+ * 
  *  Backup - CraftBukkit server Backup plugin (original author)
- *  Copyright (C) 2011 Kilian Gaertner <https://github.com/Meldanor/Backup>
+ *  Copyright (C) 2011 Kilian Gaertner <https://github.com/Meldanor>
+ * 
+ *          -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  * 
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -18,4 +22,6 @@
  * 
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ *          -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  */

+ 1 - 8
pom.xml

@@ -2,7 +2,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>net.tgxn.bukkit</groupId>
     <artifactId>Backup</artifactId>
-    <version>1.8.6</version>
+    <version>1.8.7-dev</version>
     <name>Backup</name>
     <description>A Backup plugin for Bukkit's Server mod API.</description>
     <url>https://github.com/gamerx/Backup</url>
@@ -61,13 +61,6 @@
         </plugins>
     </build>
     <dependencies>
-        <dependency>
-            <groupId>com.nijikokun.bukkit</groupId>
-            <artifactId>Permissions</artifactId>
-            <version>2.7.3</version>
-            <type>jar</type>
-            <scope>compile</scope>
-        </dependency>
         <dependency>
             <groupId>org.bukkit</groupId>
             <artifactId>bukkit</artifactId>

+ 22 - 23
src/main/java/net/tgxn/bukkit/backup/BackupMain.java

@@ -1,7 +1,5 @@
 package net.tgxn.bukkit.backup;
 
-import com.nijiko.permissions.PermissionHandler;
-import com.nijikokun.bukkit.Permissions.Permissions;
 import java.io.File;
 import net.tgxn.bukkit.backup.config.Settings;
 import net.tgxn.bukkit.backup.config.Strings;
@@ -13,7 +11,6 @@ import net.tgxn.bukkit.backup.utils.SharedUtils;
 import org.bukkit.Server;
 import org.bukkit.event.Event.Priority;
 import org.bukkit.event.Event.Type;
-import org.bukkit.plugin.Plugin;
 import org.bukkit.plugin.PluginManager;
 import org.bukkit.plugin.java.JavaPlugin;
 
@@ -24,7 +21,7 @@ import org.bukkit.plugin.java.JavaPlugin;
  */
 public class BackupMain extends JavaPlugin {
     
-    public static PermissionHandler permissionsHandler;
+    //public static PermissionHandler permissionsHandler;
     public int mainBackupTaskID = -2;
     public File mainDataFolder;
     
@@ -62,7 +59,7 @@ public class BackupMain extends JavaPlugin {
     public void onEnable() {
         
         // Initalize permissions handler.
-        initPermissions();
+        //initPermissions();
 
         // Get server and plugin manager instances.
         Server pluginServer = getServer();
@@ -82,7 +79,7 @@ public class BackupMain extends JavaPlugin {
         int backupInterval = settings.getIntervalInMinutes();
         if (backupInterval != 0) {
             backupInterval *= 1200;
-            mainBackupTaskID = pluginServer.getScheduler().scheduleSyncRepeatingTask(this, prepareBackup, backupInterval, backupInterval);
+            mainBackupTaskID = pluginServer.getScheduler().scheduleAsyncRepeatingTask(this, prepareBackup, backupInterval, backupInterval);
         } else {
             LogUtils.sendLog(strings.getString("disbaledauto"));
         }
@@ -107,6 +104,8 @@ public class BackupMain extends JavaPlugin {
     @Override
     public void onDisable () {
         
+        //this.getServer().getScheduler().getPendingTasks().
+        
         // Stop and scheduled tasks.
         this.getServer().getScheduler().cancelTasks(this);
         
@@ -117,21 +116,21 @@ public class BackupMain extends JavaPlugin {
     /**
      * Check if the Permissions System is available, and setup the handler.
      */
-    private void initPermissions() {
-
-        // Check if not already initalized.
-        if (permissionsHandler != null)
-            return;
-                
-        // Get permissions plugin.
-        Plugin testPermissions = this.getServer().getPluginManager().getPlugin("Permissions");
-        
-        // If we were able to get the permissions plugin.
-        if (testPermissions != null) {
-            permissionsHandler = ((Permissions) testPermissions).getHandler();
-            LogUtils.sendLog(strings.getString("hookedperms"));
-        } else {
-            LogUtils.sendLog(strings.getString("defaultperms"));
-        }
-    }
+//    private void initPermissions() {
+//
+//        // Check if not already initalized.
+//        if (permissionsHandler != null)
+//            return;
+//                
+//        // Get permissions plugin.
+//        Plugin testPermissions = this.getServer().getPluginManager().getPlugin("Permissions");
+//        
+//        // If we were able to get the permissions plugin.
+//        if (testPermissions != null) {
+//            permissionsHandler = ((Permissions) testPermissions).getHandler();
+//            LogUtils.sendLog(strings.getString("hookedperms"));
+//        } else {
+//            LogUtils.sendLog(strings.getString("defaultperms"));
+//        }
+//    }
 }

+ 2 - 2
src/main/java/net/tgxn/bukkit/backup/listeners/CommandListener.java

@@ -177,8 +177,8 @@ public class CommandListener extends PlayerListener implements CommandExecutor {
     private boolean checkPerms(Player player, String permission) {
 
         // We hooked a perms system.
-        if (BackupMain.permissionsHandler != null) {
-            if (!BackupMain.permissionsHandler.has(player, permission)) {
+        if (player.isPermissionSet(permission)) {
+            if (player.hasPermission(permission)) {
                 player.sendMessage(strings.getString("norights"));
                 return false;
             } else {

+ 3 - 4
src/main/java/net/tgxn/bukkit/backup/listeners/LoginListener.java

@@ -61,12 +61,11 @@ public class LoginListener extends PlayerListener {
          // Check if it was the last player.
          if (onlinePlayers == 1) {
             prepareBackup.setAsLastBackup(true);
-            //plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, backupTask);
             int intervalInMinutes = settings.getIntervalInMinutes();
             if (intervalInMinutes != -1) {
                 int interval =  intervalInMinutes * 1200;
-                lastBackupID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, prepareBackup, interval, interval);
-                LogUtils.sendLog("Scheduled last backup for " + intervalInMinutes +" minutes;");
+                lastBackupID = plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, prepareBackup, interval);
+                LogUtils.sendLog("Scheduled last backup for " + intervalInMinutes +" minutes.");
             } else {
                 LogUtils.sendLog(strings.getString("disbaledauto"));
             }
@@ -78,7 +77,7 @@ public class LoginListener extends PlayerListener {
      *
      */
     private void playerJoin() {
-        if(prepareBackup.isLastBackup || lastBackupID != -2) {
+        if(lastBackupID != -2) {
             plugin.getServer().getScheduler().cancelTask(lastBackupID);
             lastBackupID = -2;
             prepareBackup.setAsLastBackup(false);

+ 8 - 13
src/main/java/net/tgxn/bukkit/backup/threading/BackupTask.java

@@ -4,7 +4,6 @@ import java.io.File;
 import java.io.FileFilter;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.lang.reflect.Array;
 import java.util.*;
 import java.util.logging.Level;
 import net.tgxn.bukkit.backup.BackupMain;
@@ -455,18 +454,14 @@ public class BackupTask implements Runnable {
                         server.broadcastMessage(completedBackupMessage);
                     } else {
                         // Verify Permissions
-                        if (BackupMain.permissionsHandler != null) {
-
-                            // Get all players.
-                            Player[] players = server.getOnlinePlayers();
-                            // Loop through all online players.
-                            for (int pos = 0; pos < players.length; pos++) {
-                                Player currentplayer = players[pos];
-
-                                // If the current player has the right permissions, notify them.
-                                if (BackupMain.permissionsHandler.has(currentplayer, "backup.notify")) {
-                                    currentplayer.sendMessage(completedBackupMessage);
-                                }
+                        Player[] players = server.getOnlinePlayers();
+                        // Loop through all online players.
+                        for (int pos = 0; pos < players.length; pos++) {
+                            Player currentplayer = players[pos];
+
+                            // If the current player has the right permissions, notify them.
+                            if (currentplayer.hasPermission("backup.notify")) {
+                                currentplayer.sendMessage(completedBackupMessage);
                             }
                         }
                     }

+ 17 - 22
src/main/java/net/tgxn/bukkit/backup/threading/PrepareBackup.java

@@ -14,24 +14,15 @@ import org.bukkit.command.ConsoleCommandSender;
 import org.bukkit.entity.Player;
 import org.bukkit.plugin.Plugin;
 
-/**
- * This task is running by a syncronized thread from the sheduler. It prepare
- * everything for the BackupTask. It checks, whether it can run a doBackup now,
- * stop the autosave, make a server wide save of all player, save all world data
- * from the RAM to the disc and collects finnaly all worlds and directories to
- * doBackup. If this is done, it create an asyncronized thread, the BackupTask.
- * @author Kilian Gaertner, Domenic Horner (gamerx)
- * @see BackupTask
- */
 public class PrepareBackup implements Runnable {
-
+    
     private final Server server;
     private final Settings settings;
     public Strings strings;
     private boolean isManualBackup;
     private Plugin plugin;
     public boolean isLastBackup;
-
+    
     public PrepareBackup (Server server, Settings settings, Strings strings) {
         this.server = server;
         this.settings = settings;
@@ -70,21 +61,26 @@ public class PrepareBackup implements Runnable {
                 } else {
                     // Permission checking for bypass node.
                     boolean doBackup = false;
-                    if(BackupMain.permissionsHandler != null) {
-
-                        // Get all players.
+                    
+                    // If every player on the server has the bypass permission, skip backup
+                    //
+                    // Check Every player
+                    // If any do not have permission, do backup.
+                    
+                    
+                    // Get all players.
                         Player[] players = server.getOnlinePlayers();
+                        
+                        // loop all online players
                         for (int player = 0; player < players.length; player++) {
                             Player currentplayer = players[player];
 
                             // If any players do not have the node, do the doBackup.
-                            if (!BackupMain.permissionsHandler.has(currentplayer, "backup.bypass")) {
+                            if (!currentplayer.hasPermission("backup.bypass")) {
                                 doBackup = true;
                             }
                         }
-                    } else {
-                        doBackup = true;
-                    }
+                        
                     if(doBackup) {
                         prepareBackup();
                     } else {
@@ -198,22 +194,21 @@ public class PrepareBackup implements Runnable {
                     Player currentplayer = players[pos];
 
                     // If the current player has the right permissions, notify them.
-                    if(BackupMain.permissionsHandler.has(currentplayer, "backup.notify")) {
+                    if(currentplayer.hasPermission("backup.notify")) {
                         currentplayer.sendMessage(startBackupMessage);
                     }
                 }
             }
         }
     }
-
-
+    
     /**
      * Set the doBackup as a manual doBackup. IE: Not scheduled.
      */
     public void setAsManualBackup() {
         this.isManualBackup = true;
     }
-   
+    
     /**
      * Set the doBackup as a last doBackup.
      */

+ 1 - 1
src/main/resources/config.yml

@@ -110,4 +110,4 @@ showconfigonstartup: true
 ###############################################
 
 requiredstrings: str-29
-version: 1.8.6
+version: 1.8.7-dev

+ 1 - 1
src/main/resources/plugin.yml

@@ -1,5 +1,5 @@
 name: Backup
-version: 1.8.6
+version: 1.8.7-dev
 description: A full and simple backup plugin.
 authors: [Meldanor, gamerx, lycano]
 website: http://dev.bukkit.org/server-mods/backup/

+ 1 - 1
src/main/resources/strings.yml

@@ -50,5 +50,5 @@ checkbackupinterval  : Please check your backupinterval setting is formatted cor
 ###############################################
 
 stringnotfound       : 'String not found - '
-packagedwith         : 1.8.6
+packagedwith         : 1.8.7-dev
 version              : str-29