Permalink
Browse files

Merge pull request #1 from NOS-Gamers/master

Basically, A complete code overhaul by b-turchyn. (Adding some new features as well) Thanks!
  • Loading branch information...
shadrxninga
shadrxninga committed Dec 12, 2011
2 parents 1b14428 + 06cc031 commit 90e7f4c1089eb67b329413054182b2100416d369
View
@@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
- <classpathentry kind="lib" path="/Users/josephbennett/Public/Drop Box/bukkit-0.0.1-SNAPSHOT.jar"/>
- <classpathentry kind="lib" path="/Users/josephbennett/Downloads/Permissions-bin-7/Permissions.jar"/>
+ <classpathentry kind="lib" path="lib/bukkit-1.0.0-R1-SNAPSHOT.jar"/>
+ <classpathentry kind="lib" path="lib/Vault.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,4 @@
+#Mon Dec 05 17:10:33 CST 2011
+eclipse.preferences.version=1
+formatter_profile=_HeroSpawn
+formatter_settings_version=12
View
@@ -0,0 +1,2 @@
+Manifest-Version: 1.0
+Class-Path: ../lib/
View
@@ -0,0 +1,40 @@
+<?xml version="1.0" ?>
+<project name="HeroSpawn" default="jar" basedir=".">
+ <property name="src" value="ant-source" />
+ <property name="output" value="dist" />
+
+ <target name="compile" depends="init">
+ <javac destdir="bin" debug="true" debuglevel="lines, vars, and source">
+ <src path="src" />
+ <classpath refid="libs" />
+ </javac>
+ </target>
+
+ <target name="jar" depends="compile">
+ <jar destfile="dist/HeroSpawn.jar" compress="true" manifest="Manifest.mf">
+ <fileset file="plugin.yml" />
+ <fileset dir="bin" />
+ </jar>
+ </target>
+
+ <target name="init">
+ <mkdir dir="bin" />
+ <mkdir dir="dist" />
+ </target>
+
+ <target name="execute" depends="compile">
+ <java classname="com.herocraftonline.shadrxninga.herospawn" classpath="build/classes" />
+ </target>
+
+ <target name="clean">
+ <delete dir="bin" />
+ <delete dir="dist" />
+ </target>
+
+ <path id="libs">
+ <fileset dir="lib">
+ <include name="bukkit-1.0.0-SNAPSHOT.jar" />
+ <include name="Vault.jar" />
+ </fileset>
+ </path>
+</project>
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
Binary file not shown.
Binary file not shown.
View
@@ -2,6 +2,7 @@ name: HeroSpawn
author: shadrxninga
main: com.herocraftonline.shadrxninga.herospawn.HeroSpawn
version: 0.2
+depend: [Vault]
commands:
HEROSPAWN:
description: Teleports a player to a different location on their first login
@@ -3,146 +3,165 @@
import java.io.File;
import java.util.logging.Logger;
+import net.milkbowl.vault.permission.Permission;
+
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.plugin.PluginManager;
+import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.config.Configuration;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
-import com.nijiko.permissions.PermissionHandler;
-import com.nijikokun.bukkit.Permissions.Permissions;
-import org.bukkit.plugin.Plugin;
-
-public class HeroSpawn extends JavaPlugin{
+public class HeroSpawn extends JavaPlugin {
+ public static final String PERM_TP = "herospawn.tp";
+ public static final String PERM_SET = "herospawn.set";
static String mainDirectory = "plugins/HeroSpawn";
- File file = new File(mainDirectory + File.separator + "spawnlocations.yml");
- //Set up Listener Classes
- private final HeroSpawnPlayerListener playerListener = new HeroSpawnPlayerListener(this);
-
- public static final Logger log = Logger.getLogger("Minecraft");
- //Permissions Vairiables
- public static PermissionHandler Permissions;
- public boolean UsePermissions;
+ File file = new File( mainDirectory + File.separator + "spawnlocations.yml" );
+ // Set up Listener Classes
+ private final HeroSpawnPlayerListener playerListener = new HeroSpawnPlayerListener(
+ this );
+ public static final Logger log = Logger.getLogger( "Minecraft" );
+ // Permissions Vairiables
+ public Permission permission = null;
+ private String group;
+ public boolean UsePermissions;
@Override
- public void onDisable() {
- log.info("[HeroSpawn] Version 0.2 Disabled");
+ public void onDisable () {
+ log.info( "[HeroSpawn] Version 0.2 Disabled" );
}
@Override
- public void onEnable() {
+ public void onEnable () {
setupPermissions();
- new File(mainDirectory).mkdir();
- if(!file.exists()){
- try {
- file.createNewFile();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- } else {
- PluginManager pm = getServer().getPluginManager();
- pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Event.Priority.Highest, this);
- pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Event.Priority.Highest, this);
- log.info("[HeroSpawn] Version 0.2 Enabled"); }
+ new File( mainDirectory ).mkdir();
+ if ( !file.exists() ) {
+ try {
+ file.createNewFile();
+ } catch ( Exception ex ) {
+ ex.printStackTrace();
+ }
+ } else {
+ group = read ("group");
+ PluginManager pm = getServer().getPluginManager();
+ pm.registerEvent( Event.Type.PLAYER_LOGIN, playerListener,
+ Event.Priority.Highest, this );
+ pm.registerEvent( Event.Type.PLAYER_JOIN, playerListener,
+ Event.Priority.Highest, this );
+ pm.registerEvent( Event.Type.PLAYER_RESPAWN, playerListener,
+ Event.Priority.Highest, this );
+ log.info( "[HeroSpawn] Version 0.2 Enabled" );
}
- public void write(String root, Object x){
+ }
+
+ public void write ( String root, Object x ) {
+ Configuration config = load();
+ config.setProperty( root, x );
+ config.save();
+ }
+
+ public String read ( String root ) {
Configuration config = load();
- config.setProperty(root, x);
- config.save();
- }
-
- public String read(String root){
- Configuration config = load();
- return config.getString(root);
- }
- public Configuration load(){
-
- try {
- Configuration config = new Configuration(file);
- config.load();
- return config;
-
- } catch (Exception e) {
- e.printStackTrace();
+ return config.getString( root );
+ }
+
+ public Configuration load () {
+
+ try {
+ Configuration config = new Configuration( file );
+ config.load();
+ return config;
+
+ } catch ( Exception e ) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private void setupPermissions () {
+ RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
+ if (permissionProvider != null) {
+ permission = permissionProvider.getProvider();
+ UsePermissions = true;
+ System.out.println( "[HeroSpawn] Permissions system detected!" );
+ } else {
+ UsePermissions = false;
+ log.info( "Permission system not detected, defaulting to OP" );
}
- return null;
- }
-
- private void setupPermissions() {
- Plugin test = this.getServer().getPluginManager().getPlugin("Permissions");
- if (HeroSpawn.Permissions == null) {
- if (test != null) {
- UsePermissions = true;
- HeroSpawn.Permissions = ((Permissions) test).getHandler();
- System.out.println("[HeroSpawn] Permissions system detected!");
- } else {
- log.info("Permission system not detected, defaulting to OP");
- UsePermissions = false;
- }
- }
}
-
- public boolean canSetSpawn(Player p) {
- if (UsePermissions) {
- return HeroSpawn.Permissions.has(p, "herospawn.set");
- }
- return p.isOp();
- }
- public boolean canTP(Player p) {
- if (UsePermissions) {
- return HeroSpawn.Permissions.has(p, "herospawn.tp");
- }
- return p.isOp();
- }
-
- public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
-
- if (!(sender instanceof Player)) {
- sender.sendMessage(ChatColor.RED + "This command has to be called by a player!");
- return true;
- }
- Player player = (Player)sender;
- if (command.getName().equalsIgnoreCase("herospawn")) {
- if(args.length==0){
- if (!canTP(player)) {
- player.sendMessage(ChatColor.RED + "You don't have permission to do that!");
- return true;
- }
- double z = Double.parseDouble(read(player.getWorld().getName() + ".Z"));
- double x = Double.parseDouble(read(player.getWorld().getName() + ".X"));
- double y = Double.parseDouble(read(player.getWorld().getName() + ".Y"));
- Location loc = new Location(player.getWorld(), x, y , z);
- player.teleport(loc);
- player.sendMessage("¤f[¤9HeroSpawn¤f]¤e Welcome to First Spawn");
- return true;
-
- }
- if(args[0].equalsIgnoreCase("set")){
- if (!canSet(player)) {
- player.sendMessage(ChatColor.RED + "You don't have permission to do that!");
- return true;
- }
- String x1 = Double.toString(player.getLocation().getX());
- String y1 = Double.toString(player.getLocation().getY());
- String z1 = Double.toString(player.getLocation().getZ());
- write(player.getWorld().getName() + ".X", x1);
- write(player.getWorld().getName() + ".Y", y1);
- write(player.getWorld().getName() + ".Z", z1);
- player.sendMessage(ChatColor.BLUE + "¤f[¤9HeroSpawn¤f] " + ChatColor.YELLOW + "Players will now spawn here on their first login");
-
- } else{
- return false;
- }
- return true;
+
+ public boolean canSetSpawn ( Player p ) {
+ if ( UsePermissions ) {
+ return permission.has( p, PERM_SET );
+ }
+ return p.isOp();
+ }
+
+ public boolean canTP ( Player p ) {
+ if ( UsePermissions ) {
+ return permission.has( p, PERM_TP );
+ }
+ return p.isOp();
}
- return false;
-}
-}
+ public boolean onCommand ( CommandSender sender, Command command,
+ String commandLabel, String[] args ) {
+ if ( !( sender instanceof Player ) ) {
+ sender.sendMessage( ChatColor.RED
+ + "This command has to be called by a player!" );
+ return true;
+ }
+ Player player = (Player) sender;
+ if ( command.getName().equalsIgnoreCase( "herospawn" ) ) {
+ if ( args.length == 0 ) {
+ if ( !canTP( player ) ) {
+ player.sendMessage( ChatColor.RED
+ + "You don't have permission to do that!" );
+ return true;
+ }
+ double z = Double.parseDouble( read( player.getWorld()
+ .getName() + ".Z" ) );
+ double x = Double.parseDouble( read( player.getWorld()
+ .getName() + ".X" ) );
+ double y = Double.parseDouble( read( player.getWorld()
+ .getName() + ".Y" ) );
+ Location loc = new Location( player.getWorld(), x, y, z );
+ player.teleport( loc );
+ player.sendMessage( "¤f[¤9HeroSpawn¤f]¤e Welcome to First Spawn" );
+ return true;
+
+ }
+ if ( args[ 0 ].equalsIgnoreCase( "set" ) ) {
+ if ( !canSetSpawn( player ) ) {
+ player.sendMessage( ChatColor.RED
+ + "You don't have permission to do that!" );
+ return true;
+ }
+ String x1 = Double.toString( player.getLocation().getX() );
+ String y1 = Double.toString( player.getLocation().getY() );
+ String z1 = Double.toString( player.getLocation().getZ() );
+ write( player.getWorld().getName() + ".X", x1 );
+ write( player.getWorld().getName() + ".Y", y1 );
+ write( player.getWorld().getName() + ".Z", z1 );
+ player.sendMessage( ChatColor.BLUE + "¤f[¤9HeroSpawn¤f] "
+ + ChatColor.YELLOW
+ + "Players will now spawn here on their first login" );
+
+ } else {
+ return false;
+ }
+ return true;
+ }
+ return false;
+ }
+ public String getGroup () {
+ return group;
+ }
+}
Oops, something went wrong.

0 comments on commit 90e7f4c

Please sign in to comment.