5 Commits
1.0.2 ... 1.1

Author SHA1 Message Date
6a218f97f0 Version 1.1
First version of basic update checker included
Event priorities for Move and Teleport listeners now HIGHEST
2013-02-23 22:16:44 +01:00
46d19fa35e border info message now shows if border is enabled or disabled 2013-02-20 16:32:12 +01:00
785dc10644 Version 1.0.3-1 2013-02-20 16:11:04 +01:00
c671f04f65 Security Fix: added missing permission check for enable/disable border 2013-02-20 15:59:58 +01:00
0176ec3a3a version 1.0.3
softdepend Multiverse-Core added (should resolve issue #7)
removed a system.out.println
fixed: now checks if border is null before trying to on|off
2013-02-20 11:59:28 +01:00
11 changed files with 218 additions and 18 deletions

Binary file not shown.

View File

@ -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.2</version> <version>1.1</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -122,8 +122,6 @@ public class Border implements ConfigurationSerializable
map.put(rectPoint2Name, LocationSerializer.serializeLocation(rectPoint2)); map.put(rectPoint2Name, LocationSerializer.serializeLocation(rectPoint2));
map.put(isActiveKey, isActive); map.put(isActiveKey, isActive);
System.out.println(map);
return map; return map;
} }

View File

@ -71,7 +71,7 @@ public class Commands implements CommandExecutor
borderManager.setBorder(( (Player) sender ).getWorld(), Double.parseDouble(args[1])); borderManager.setBorder(( (Player) sender ).getWorld(), Double.parseDouble(args[1]));
Border border = Border.getBorders().get(world); Border border = Border.getBorders().get(world);
sender.sendMessage(Messages.borderCreationSuccessful); sender.sendMessage(Messages.borderCreationSuccessful);
sender.sendMessage(Messages.borderInfo(world.getName(), border.toString())); sender.sendMessage(Messages.borderInfo(world.getName(), border.toString(), border.isActive()));
} }
catch ( Exception e ) catch ( Exception e )
{ {
@ -86,7 +86,7 @@ public class Commands implements CommandExecutor
borderManager.setBorder(( (Player) sender ).getWorld(), args[1], args[2]); borderManager.setBorder(( (Player) sender ).getWorld(), args[1], args[2]);
Border border = Border.getBorders().get(world); Border border = Border.getBorders().get(world);
sender.sendMessage(Messages.borderCreationSuccessful); sender.sendMessage(Messages.borderCreationSuccessful);
sender.sendMessage(Messages.borderInfo(world.getName(), border.toString())); sender.sendMessage(Messages.borderInfo(world.getName(), border.toString(), border.isActive()));
} }
catch ( Exception e ) catch ( Exception e )
{ {
@ -120,20 +120,38 @@ public class Commands implements CommandExecutor
Border border = Border.getBorders().get(world); Border border = Border.getBorders().get(world);
sender.sendMessage(Messages.borderInfo(world.getName(), border.toString())); sender.sendMessage(Messages.borderInfo(world.getName(), border.toString(), border.isActive()));
return true; return true;
} }
// on // on
if ( args.length == 1 && ( args[0].equalsIgnoreCase("on") || args[0].equalsIgnoreCase("off") ) ) if ( args.length == 1 && ( args[0].equalsIgnoreCase("on") || args[0].equalsIgnoreCase("off") ) )
{ {
if ( !sender.hasPermission("craftinc.borderprotection.set") )
{
sender.sendMessage(Messages.noPermissionSet);
return false;
}
World world = ( (Player) sender ).getWorld(); World world = ( (Player) sender ).getWorld();
if (args[0].equalsIgnoreCase("on")) { Border border = Border.getBorders().get(world);
Border.getBorders().get(world).enable();
sender.sendMessage(Messages.borderEnabled); if ( border != null )
} else { {
Border.getBorders().get(world).disable(); if ( args[0].equalsIgnoreCase("on") )
sender.sendMessage(Messages.borderDisabled); {
border.enable();
sender.sendMessage(Messages.borderEnabled);
}
else
{
border.disable();
sender.sendMessage(Messages.borderDisabled);
}
}
else
{
sender.sendMessage(Messages.borderInfoNoBorderSet);
} }
// save the new border // save the new border

View File

@ -82,20 +82,28 @@ public class Messages
public static String commandIssuedByNonPlayer public static String commandIssuedByNonPlayer
= ChatColor.RED + "Only a player can use CraftInc BorderProtection commands!"; = ChatColor.RED + "Only a player can use CraftInc BorderProtection commands!";
public static String borderInfo( String worldName, String borderDef ) public static String borderInfo( String worldName, String borderDef, Boolean isBorderEnabled )
{ {
String borderEnabled;
if (isBorderEnabled)
{
borderEnabled = ChatColor.GREEN + "enabled";
} else {
borderEnabled = ChatColor.RED + "disabled";
}
return ChatColor.WHITE + "Borders of world " + return ChatColor.WHITE + "Borders of world " +
ChatColor.YELLOW + worldName + ChatColor.YELLOW + worldName +
ChatColor.WHITE + ": " + ChatColor.WHITE + ": " +
ChatColor.YELLOW + borderDef; ChatColor.YELLOW + borderDef + ChatColor.WHITE + "." + NEWLINE +
ChatColor.WHITE + "Border is " + borderEnabled + ChatColor.WHITE + ".";
} }
public static String borderInfoNoBorderSet = public static String borderInfoNoBorderSet =
ChatColor.YELLOW + "No border here."; ChatColor.YELLOW + "No border in this world.";
public static String noPermissionSet = public static String noPermissionSet =
ChatColor.RED + "Sorry, you don't have permission to set the border."; ChatColor.RED + "Sorry, you don't have permission to change the border.";
public static String borderEnabled = public static String borderEnabled =
ChatColor.YELLOW + "Border enabled."; ChatColor.YELLOW + "Border enabled.";
@ -108,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!";
}
} }

View File

@ -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);
}
}
}
}

View File

@ -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") )
{ {

View File

@ -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") )
{ {

View File

@ -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);
} }
} }

View 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());
}
}

View File

@ -17,6 +17,7 @@
name: Craft Inc. BorderProtection name: Craft Inc. BorderProtection
main: de.craftinc.borderprotection.Plugin main: de.craftinc.borderprotection.Plugin
version: ${project.version} version: ${project.version}
softdepend: [Multiverse-Core]
authors: [ddidderr, mice_on_drugs] authors: [ddidderr, mice_on_drugs]
website: http://www.craftinc.de/plugins/borderprotection website: http://www.craftinc.de/plugins/borderprotection
@ -32,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.