Version 1.1
First version of basic update checker included Event priorities for Move and Teleport listeners now HIGHEST
This commit is contained in:
parent
46d19fa35e
commit
6a218f97f0
Binary file not shown.
2
pom.xml
2
pom.xml
@ -5,7 +5,7 @@
|
|||||||
<groupId>de.craftinc</groupId>
|
<groupId>de.craftinc</groupId>
|
||||||
<artifactId>CraftincBorderProtection</artifactId>
|
<artifactId>CraftincBorderProtection</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>1.0.3-1</version>
|
<version>1.1</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
@ -116,4 +116,14 @@ public class Messages
|
|||||||
|
|
||||||
public static String borderEnableDisableException =
|
public static String borderEnableDisableException =
|
||||||
ChatColor.RED + "Error: Could not save border state on server. After the next reload this border state will be lost!";
|
ChatColor.RED + "Error: Could not save border state on server. After the next reload this border state will be lost!";
|
||||||
|
|
||||||
|
public static String UpdateMessage( String newVersion, String curVersion )
|
||||||
|
{
|
||||||
|
return ChatColor.RED + "Craft Inc. BorderProtection: New version available!" + NEWLINE +
|
||||||
|
ChatColor.YELLOW + "Current version: " + ChatColor.WHITE + curVersion + NEWLINE +
|
||||||
|
ChatColor.YELLOW + "New version: " + ChatColor.WHITE + newVersion + NEWLINE +
|
||||||
|
ChatColor.YELLOW + "Please visit:" + NEWLINE +
|
||||||
|
ChatColor.AQUA + "http://dev.bukkit.org/server-mods/craftinc-borderprotection" + NEWLINE +
|
||||||
|
ChatColor.YELLOW + "to get the latest version!";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
/* Craft Inc. BorderProtection
|
||||||
|
Copyright (C) 2013 Paul Schulze
|
||||||
|
|
||||||
|
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
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.borderprotection;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
|
|
||||||
|
public class PlayerLoginListener implements Listener
|
||||||
|
{
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onPlayerLogin( PlayerLoginEvent e )
|
||||||
|
{
|
||||||
|
final Player player = e.getPlayer();
|
||||||
|
|
||||||
|
if ( e.getPlayer().hasPermission("craftinc.borderprotection.update") )
|
||||||
|
{
|
||||||
|
if ( UpdateHelper.newVersionAvailable() )
|
||||||
|
{
|
||||||
|
// Schedule a task which delays 20 ticks (1 second) and then sends a message to the player
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(Plugin.getPlugin(), new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
player.sendMessage(Messages.UpdateMessage(UpdateHelper.cachedLatestVersion,
|
||||||
|
UpdateHelper.getCurrentVersion()));
|
||||||
|
}
|
||||||
|
}, 20L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -56,9 +56,15 @@ public class PlayerMoveListener implements Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerMove( PlayerMoveEvent e )
|
public void onPlayerMove( PlayerMoveEvent e )
|
||||||
{
|
{
|
||||||
|
// do nothing if the event is already cancelled
|
||||||
|
if (e.isCancelled())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// do nothing if player has the ignoreborders permission
|
// do nothing if player has the ignoreborders permission
|
||||||
if ( e.getPlayer().hasPermission("craftinc.borderprotection.ignoreborders") )
|
if ( e.getPlayer().hasPermission("craftinc.borderprotection.ignoreborders") )
|
||||||
{
|
{
|
||||||
|
@ -33,9 +33,15 @@ public class PlayerTeleportListener implements Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerMove( PlayerTeleportEvent e )
|
public void onPlayerMove( PlayerTeleportEvent e )
|
||||||
{
|
{
|
||||||
|
// do nothing if the event is already cancelled
|
||||||
|
if (e.isCancelled())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// do nothing if player has the ignoreborders permission
|
// do nothing if player has the ignoreborders permission
|
||||||
if ( e.getPlayer().hasPermission("craftinc.borderprotection.ignoreborders") )
|
if ( e.getPlayer().hasPermission("craftinc.borderprotection.ignoreborders") )
|
||||||
{
|
{
|
||||||
|
@ -48,6 +48,7 @@ public class Plugin extends JavaPlugin
|
|||||||
BorderManager borderManager = new BorderManager();
|
BorderManager borderManager = new BorderManager();
|
||||||
PlayerMoveListener playerMoveListener = new PlayerMoveListener(borderManager);
|
PlayerMoveListener playerMoveListener = new PlayerMoveListener(borderManager);
|
||||||
PlayerTeleportListener playerTeleportListener = new PlayerTeleportListener(borderManager);
|
PlayerTeleportListener playerTeleportListener = new PlayerTeleportListener(borderManager);
|
||||||
|
PlayerLoginListener playerLoginListener = new PlayerLoginListener();
|
||||||
|
|
||||||
// commands
|
// commands
|
||||||
Commands commandExecutor = new Commands(borderManager);
|
Commands commandExecutor = new Commands(borderManager);
|
||||||
@ -57,5 +58,6 @@ public class Plugin extends JavaPlugin
|
|||||||
PluginManager pm = this.getServer().getPluginManager();
|
PluginManager pm = this.getServer().getPluginManager();
|
||||||
pm.registerEvents(playerMoveListener, this);
|
pm.registerEvents(playerMoveListener, this);
|
||||||
pm.registerEvents(playerTeleportListener, this);
|
pm.registerEvents(playerTeleportListener, this);
|
||||||
|
pm.registerEvents(playerLoginListener, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
98
src/main/java/de/craftinc/borderprotection/UpdateHelper.java
Normal file
98
src/main/java/de/craftinc/borderprotection/UpdateHelper.java
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
/* Craft Inc. BorderProtection
|
||||||
|
Copyright (C) 2013 Paul Schulze
|
||||||
|
|
||||||
|
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
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package de.craftinc.borderprotection;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
|
||||||
|
public class UpdateHelper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The URL from which the Plugin tries to get the latest version.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("FieldCanBeLocal")
|
||||||
|
private static final String updateUrl = "http://www.craftinc.de/plugins/update/craftinc-borderprotection";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The latest version which was seen on last check.
|
||||||
|
*/
|
||||||
|
public static String cachedLatestVersion = null;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the latest version from the updateURL and returns it as <code>String</code>.
|
||||||
|
*
|
||||||
|
* @return latest version as <code>String</code>.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("StringBufferMayBeStringBuilder")
|
||||||
|
public static String getLatestVersion()
|
||||||
|
{
|
||||||
|
// StringBuffer is thread-safe. Don't know if this is really important here, but safe is safe :).
|
||||||
|
StringBuffer s = new StringBuffer();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
URLConnection c = new URL(updateUrl).openConnection();
|
||||||
|
BufferedReader br = new BufferedReader(new InputStreamReader(c.getInputStream()));
|
||||||
|
String inputLine;
|
||||||
|
while ( ( inputLine = br.readLine() ) != null )
|
||||||
|
{
|
||||||
|
s.append(inputLine);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
catch ( MalformedURLException e )
|
||||||
|
{
|
||||||
|
Plugin.getPlugin().getLogger().warning("Could not check for latest version. Update URL is malformed.");
|
||||||
|
}
|
||||||
|
catch ( IOException e )
|
||||||
|
{
|
||||||
|
Plugin.getPlugin().getLogger().warning("Could not check for latest version. Update URL was not readable.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// update cached latest version
|
||||||
|
cachedLatestVersion = s.toString();
|
||||||
|
|
||||||
|
return s.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current version of this plugin directly from the plugin.yml version entry.
|
||||||
|
*
|
||||||
|
* @return current version as <code>String</code>.
|
||||||
|
*/
|
||||||
|
public static String getCurrentVersion()
|
||||||
|
{
|
||||||
|
return Plugin.getPlugin().getDescription().getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a newer version is available.
|
||||||
|
*
|
||||||
|
* @return Boolean
|
||||||
|
*/
|
||||||
|
public static Boolean newVersionAvailable()
|
||||||
|
{
|
||||||
|
return !getCurrentVersion().equals(getLatestVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -33,3 +33,6 @@ permissions:
|
|||||||
craftinc.borderprotection.ignoreborders:
|
craftinc.borderprotection.ignoreborders:
|
||||||
default: op
|
default: op
|
||||||
description: Allows to be everywhere on the map (ignoring the borders).
|
description: Allows to be everywhere on the map (ignoring the borders).
|
||||||
|
craftinc.borderprotection.update:
|
||||||
|
default: op
|
||||||
|
description: Allows to get notified on login, when a new update is available.
|
Loading…
x
Reference in New Issue
Block a user