Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit 8bdd5b307b663e74ed7069806081f3528c407c25 @Dinnerbone Dinnerbone committed
17 .gitignore
@@ -0,0 +1,17 @@
+# Eclipse stuff
+/.classpath
+/.project
+/.settings
+
+# netbeans
+/nbproject
+
+# maven
+/target
+
+# ant
+/bin
+/dist
+
+# vim
+.*.sw[a-p]
30 pom.xml
@@ -0,0 +1,30 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.bukkit</groupId>
+ <artifactId>bukkit-home</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <name>HomeBukkit</name>
+ <url>http://www.bukkit.org</url>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.bukkit</groupId>
+ <artifactId>bukkit</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+</project>
139 src/main/java/com/dinnerbone/bukkit/home/Home.java
@@ -0,0 +1,139 @@
+
+package com.dinnerbone.bukkit.home;
+
+import com.avaje.ebean.validation.Length;
+import com.avaje.ebean.validation.NotEmpty;
+import com.avaje.ebean.validation.NotNull;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+
+@Entity()
+@Table(name="hb_home")
+public class Home {
+ @Id
+ private int id;
+
+ @NotNull
+ private String playerName;
+
+ @Length(max=30)
+ @NotEmpty
+ private String name;
+
+ @NotNull
+ private double x;
+
+ @NotNull
+ private double y;
+
+ @NotNull
+ private double z;
+
+ @NotNull
+ private float pitch;
+
+ @NotNull
+ private float yaw;
+
+ @NotEmpty
+ private String worldName;
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getPlayerName() {
+ return playerName;
+ }
+
+ public void setPlayerName(String playerName) {
+ this.playerName = playerName;
+ }
+
+ public Player getPlayer() {
+ return Bukkit.getServer().getPlayer(playerName);
+ }
+
+ public void setPlayer(Player player) {
+ this.playerName = player.getName();
+ }
+
+ public String getWorldName() {
+ return worldName;
+ }
+
+ public void setWorldName(String worldName) {
+ this.worldName = worldName;
+ }
+
+ public double getX() {
+ return x;
+ }
+
+ public void setX(double x) {
+ this.x = x;
+ }
+
+ public double getY() {
+ return y;
+ }
+
+ public void setY(double y) {
+ this.y = y;
+ }
+
+ public double getZ() {
+ return z;
+ }
+
+ public void setZ(double z) {
+ this.z = z;
+ }
+
+ public float getPitch() {
+ return pitch;
+ }
+
+ public void setPitch(float pitch) {
+ this.pitch = pitch;
+ }
+
+ public float getYaw() {
+ return yaw;
+ }
+
+ public void setYaw(float yaw) {
+ this.yaw = yaw;
+ }
+
+ public void setLocation(Location location) {
+ this.worldName = location.getWorld().getName();
+ this.x = location.getX();
+ this.y = location.getY();
+ this.z = location.getZ();
+ this.pitch = location.getPitch();
+ this.yaw = location.getYaw();
+ }
+
+ public Location getLocation() {
+ World world = Bukkit.getServer().getWorld(worldName);
+ return new Location(world, x, y, z, yaw, pitch);
+ }
+}
74 src/main/java/com/dinnerbone/bukkit/home/HomeBukkit.java
@@ -0,0 +1,74 @@
+
+package com.dinnerbone.bukkit.home;
+
+import com.dinnerbone.bukkit.home.commands.GoHomeCommand;
+import com.dinnerbone.bukkit.home.commands.ListHomesCommand;
+import com.dinnerbone.bukkit.home.commands.SetHomeCommand;
+import java.util.ArrayList;
+import java.util.List;
+import javax.persistence.PersistenceException;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.PluginDescriptionFile;
+import org.bukkit.plugin.java.JavaPlugin;
+
+public class HomeBukkit extends JavaPlugin {
+ public void onDisable() {
+ }
+
+ public void onEnable() {
+ PluginDescriptionFile desc = getDescription();
+
+ System.out.println(desc.getFullName() + " has been enabled");
+
+ getCommand("listhomes").setExecutor(new ListHomesCommand(this));
+ getCommand("sethome").setExecutor(new SetHomeCommand(this));
+ getCommand("gohome").setExecutor(new GoHomeCommand(this));
+
+ setupDatabase();
+ }
+
+ private void setupDatabase() {
+ try {
+ getDatabase().find(Home.class).findRowCount();
+ } catch (PersistenceException ex) {
+ System.out.println("Installing database for " + getDescription().getName() + " due to first time usage");
+ installDDL();
+ }
+ }
+
+ @Override
+ public List<Class<?>> getDatabaseClasses() {
+ List<Class<?>> list = new ArrayList<Class<?>>();
+ list.add(Home.class);
+ return list;
+ }
+
+ public static boolean anonymousCheck(CommandSender sender) {
+ if (!(sender instanceof Player)) {
+ sender.sendMessage("Cannot execute that command, I don't know who you are!");
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public static Player getPlayer(CommandSender sender, String[] args, int index) {
+ if (args.length > index) {
+ List<Player> players = sender.getServer().matchPlayer(args[index]);
+
+ if (players.isEmpty()) {
+ sender.sendMessage("I don't know who '" + args[index] + "' is!");
+ return null;
+ } else {
+ return players.get(0);
+ }
+ } else {
+ if (anonymousCheck(sender)) {
+ return null;
+ } else {
+ return (Player)sender;
+ }
+ }
+ }
+}
46 src/main/java/com/dinnerbone/bukkit/home/commands/GoHomeCommand.java
@@ -0,0 +1,46 @@
+
+package com.dinnerbone.bukkit.home.commands;
+
+import com.dinnerbone.bukkit.home.Home;
+import com.dinnerbone.bukkit.home.HomeBukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class GoHomeCommand implements CommandExecutor {
+ private final HomeBukkit plugin;
+
+ public GoHomeCommand(HomeBukkit plugin) {
+ this.plugin = plugin;
+ }
+
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ Player player = HomeBukkit.getPlayer(sender, args, 1);
+
+ if (player == null) {
+ return true;
+ } else if ((player != sender) && (!sender.isOp())) {
+ sender.sendMessage(ChatColor.RED + "You don't have permission to go to other players homes");
+ return true;
+ } else if (!(sender instanceof Player)) {
+ sender.sendMessage(ChatColor.RED + "I don't know how to move you!");
+ return true;
+ } else if (args.length < 1) {
+ return false;
+ }
+
+ String name = args[0];
+
+ Home home = plugin.getDatabase().find(Home.class).where().ieq("name", name).ieq("playerName", player.getName()).findUnique();
+
+ if (home == null) {
+ sender.sendMessage(ChatColor.RED + "I don't know where that is!");
+ } else {
+ ((Player)sender).teleport(home.getLocation());
+ }
+
+ return true;
+ }
+}
50 src/main/java/com/dinnerbone/bukkit/home/commands/ListHomesCommand.java
@@ -0,0 +1,50 @@
+
+package com.dinnerbone.bukkit.home.commands;
+
+import com.dinnerbone.bukkit.home.Home;
+import com.dinnerbone.bukkit.home.HomeBukkit;
+import java.util.List;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class ListHomesCommand implements CommandExecutor {
+ private final HomeBukkit plugin;
+
+ public ListHomesCommand(HomeBukkit plugin) {
+ this.plugin = plugin;
+ }
+
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ Player player = HomeBukkit.getPlayer(sender, args, 0);
+
+ if (player == null) {
+ return true;
+ }
+
+ List<Home> homes = plugin.getDatabase().find(Home.class).where().ieq("playerName", player.getName()).findList();
+
+ if (homes.isEmpty()) {
+ if (sender == player) {
+ sender.sendMessage("You have no homes!");
+ } else {
+ sender.sendMessage("That player has no homes!");
+ }
+ } else {
+ String result = "";
+
+ for (Home home : homes) {
+ if (result.length() > 0) {
+ result += ", ";
+ }
+
+ result += home.getName();
+ }
+
+ sender.sendMessage("All home(s): " + result);
+ }
+
+ return true;
+ }
+}
50 src/main/java/com/dinnerbone/bukkit/home/commands/SetHomeCommand.java
@@ -0,0 +1,50 @@
+
+package com.dinnerbone.bukkit.home.commands;
+
+import com.dinnerbone.bukkit.home.Home;
+import com.dinnerbone.bukkit.home.HomeBukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class SetHomeCommand implements CommandExecutor {
+ private final HomeBukkit plugin;
+
+ public SetHomeCommand(HomeBukkit plugin) {
+ this.plugin = plugin;
+ }
+
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ Player player = HomeBukkit.getPlayer(sender, args, 1);
+
+ if (player == null) {
+ return true;
+ } else if ((player != sender) && (!sender.isOp())) {
+ sender.sendMessage(ChatColor.RED + "You don't have permission to set other players homes");
+ return true;
+ } else if (!(sender instanceof Player)) {
+ sender.sendMessage(ChatColor.RED + "I don't know where you are!");
+ return true;
+ } else if (args.length < 1) {
+ return false;
+ }
+
+ String name = args[0];
+
+ Home home = plugin.getDatabase().find(Home.class).where().ieq("name", name).ieq("playerName", player.getName()).findUnique();
+
+ if (home == null) {
+ home = new Home();
+ home.setPlayer(player);
+ home.setName(name);
+ }
+
+ home.setLocation(((Player)sender).getLocation());
+
+ plugin.getDatabase().save(home);
+
+ return true;
+ }
+}
24 src/main/resources/plugin.yml
@@ -0,0 +1,24 @@
+name: HomeBukkit
+main: com.dinnerbone.bukkit.home.HomeBukkit
+version: 0.0.1
+website: http://www.bukkit.org
+author: The Bukkit Team
+database: true
+description: >
+ Basic home functionality.
+ This plugin is one of the default plugins shipped with Bukkit.
+commands:
+ sethome:
+ aliases: [addhome]
+ description: Sets your current position to a home of the given name
+ usage: |
+ /<command> <name> [player]
+ Example: /<command> BeachHouse
+ listhomes:
+ aliases: [homes]
+ description: Lists all homes that you own
+ usage: /<command> [player]
+ gohome:
+ aliases: [home]
+ description: Goes to a home
+ usage: /<command> <name> [player]

1 comment on commit 8bdd5b3

@NathanWolf

Well, this will be nice! Thanks, Dinnerbone.

Please sign in to comment.
Something went wrong with that request. Please try again.