Skip to content

Commit 8bdd5b3

Browse files
committed
Initial commit
0 parents  commit 8bdd5b3

File tree

8 files changed

+430
-0
lines changed

8 files changed

+430
-0
lines changed

.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Eclipse stuff
2+
/.classpath
3+
/.project
4+
/.settings
5+
6+
# netbeans
7+
/nbproject
8+
9+
# maven
10+
/target
11+
12+
# ant
13+
/bin
14+
/dist
15+
16+
# vim
17+
.*.sw[a-p]

pom.xml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<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">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>org.bukkit</groupId>
4+
<artifactId>bukkit-home</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<name>HomeBukkit</name>
7+
<url>http://www.bukkit.org</url>
8+
<build>
9+
<plugins>
10+
<plugin>
11+
<groupId>org.apache.maven.plugins</groupId>
12+
<artifactId>maven-compiler-plugin</artifactId>
13+
<version>2.0.2</version>
14+
<configuration>
15+
<source>1.5</source>
16+
<target>1.5</target>
17+
</configuration>
18+
</plugin>
19+
</plugins>
20+
</build>
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.bukkit</groupId>
24+
<artifactId>bukkit</artifactId>
25+
<version>0.0.1-SNAPSHOT</version>
26+
<type>jar</type>
27+
<scope>compile</scope>
28+
</dependency>
29+
</dependencies>
30+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
2+
package com.dinnerbone.bukkit.home;
3+
4+
import com.avaje.ebean.validation.Length;
5+
import com.avaje.ebean.validation.NotEmpty;
6+
import com.avaje.ebean.validation.NotNull;
7+
import javax.persistence.Entity;
8+
import javax.persistence.Id;
9+
import javax.persistence.Table;
10+
import org.bukkit.Bukkit;
11+
import org.bukkit.Location;
12+
import org.bukkit.World;
13+
import org.bukkit.entity.Player;
14+
15+
@Entity()
16+
@Table(name="hb_home")
17+
public class Home {
18+
@Id
19+
private int id;
20+
21+
@NotNull
22+
private String playerName;
23+
24+
@Length(max=30)
25+
@NotEmpty
26+
private String name;
27+
28+
@NotNull
29+
private double x;
30+
31+
@NotNull
32+
private double y;
33+
34+
@NotNull
35+
private double z;
36+
37+
@NotNull
38+
private float pitch;
39+
40+
@NotNull
41+
private float yaw;
42+
43+
@NotEmpty
44+
private String worldName;
45+
46+
public void setId(int id) {
47+
this.id = id;
48+
}
49+
50+
public int getId() {
51+
return id;
52+
}
53+
54+
public String getName() {
55+
return name;
56+
}
57+
58+
public void setName(String name) {
59+
this.name = name;
60+
}
61+
62+
public String getPlayerName() {
63+
return playerName;
64+
}
65+
66+
public void setPlayerName(String playerName) {
67+
this.playerName = playerName;
68+
}
69+
70+
public Player getPlayer() {
71+
return Bukkit.getServer().getPlayer(playerName);
72+
}
73+
74+
public void setPlayer(Player player) {
75+
this.playerName = player.getName();
76+
}
77+
78+
public String getWorldName() {
79+
return worldName;
80+
}
81+
82+
public void setWorldName(String worldName) {
83+
this.worldName = worldName;
84+
}
85+
86+
public double getX() {
87+
return x;
88+
}
89+
90+
public void setX(double x) {
91+
this.x = x;
92+
}
93+
94+
public double getY() {
95+
return y;
96+
}
97+
98+
public void setY(double y) {
99+
this.y = y;
100+
}
101+
102+
public double getZ() {
103+
return z;
104+
}
105+
106+
public void setZ(double z) {
107+
this.z = z;
108+
}
109+
110+
public float getPitch() {
111+
return pitch;
112+
}
113+
114+
public void setPitch(float pitch) {
115+
this.pitch = pitch;
116+
}
117+
118+
public float getYaw() {
119+
return yaw;
120+
}
121+
122+
public void setYaw(float yaw) {
123+
this.yaw = yaw;
124+
}
125+
126+
public void setLocation(Location location) {
127+
this.worldName = location.getWorld().getName();
128+
this.x = location.getX();
129+
this.y = location.getY();
130+
this.z = location.getZ();
131+
this.pitch = location.getPitch();
132+
this.yaw = location.getYaw();
133+
}
134+
135+
public Location getLocation() {
136+
World world = Bukkit.getServer().getWorld(worldName);
137+
return new Location(world, x, y, z, yaw, pitch);
138+
}
139+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
2+
package com.dinnerbone.bukkit.home;
3+
4+
import com.dinnerbone.bukkit.home.commands.GoHomeCommand;
5+
import com.dinnerbone.bukkit.home.commands.ListHomesCommand;
6+
import com.dinnerbone.bukkit.home.commands.SetHomeCommand;
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
import javax.persistence.PersistenceException;
10+
import org.bukkit.command.CommandSender;
11+
import org.bukkit.entity.Player;
12+
import org.bukkit.plugin.PluginDescriptionFile;
13+
import org.bukkit.plugin.java.JavaPlugin;
14+
15+
public class HomeBukkit extends JavaPlugin {
16+
public void onDisable() {
17+
}
18+
19+
public void onEnable() {
20+
PluginDescriptionFile desc = getDescription();
21+
22+
System.out.println(desc.getFullName() + " has been enabled");
23+
24+
getCommand("listhomes").setExecutor(new ListHomesCommand(this));
25+
getCommand("sethome").setExecutor(new SetHomeCommand(this));
26+
getCommand("gohome").setExecutor(new GoHomeCommand(this));
27+
28+
setupDatabase();
29+
}
30+
31+
private void setupDatabase() {
32+
try {
33+
getDatabase().find(Home.class).findRowCount();
34+
} catch (PersistenceException ex) {
35+
System.out.println("Installing database for " + getDescription().getName() + " due to first time usage");
36+
installDDL();
37+
}
38+
}
39+
40+
@Override
41+
public List<Class<?>> getDatabaseClasses() {
42+
List<Class<?>> list = new ArrayList<Class<?>>();
43+
list.add(Home.class);
44+
return list;
45+
}
46+
47+
public static boolean anonymousCheck(CommandSender sender) {
48+
if (!(sender instanceof Player)) {
49+
sender.sendMessage("Cannot execute that command, I don't know who you are!");
50+
return true;
51+
} else {
52+
return false;
53+
}
54+
}
55+
56+
public static Player getPlayer(CommandSender sender, String[] args, int index) {
57+
if (args.length > index) {
58+
List<Player> players = sender.getServer().matchPlayer(args[index]);
59+
60+
if (players.isEmpty()) {
61+
sender.sendMessage("I don't know who '" + args[index] + "' is!");
62+
return null;
63+
} else {
64+
return players.get(0);
65+
}
66+
} else {
67+
if (anonymousCheck(sender)) {
68+
return null;
69+
} else {
70+
return (Player)sender;
71+
}
72+
}
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
package com.dinnerbone.bukkit.home.commands;
3+
4+
import com.dinnerbone.bukkit.home.Home;
5+
import com.dinnerbone.bukkit.home.HomeBukkit;
6+
import org.bukkit.ChatColor;
7+
import org.bukkit.command.Command;
8+
import org.bukkit.command.CommandExecutor;
9+
import org.bukkit.command.CommandSender;
10+
import org.bukkit.entity.Player;
11+
12+
public class GoHomeCommand implements CommandExecutor {
13+
private final HomeBukkit plugin;
14+
15+
public GoHomeCommand(HomeBukkit plugin) {
16+
this.plugin = plugin;
17+
}
18+
19+
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
20+
Player player = HomeBukkit.getPlayer(sender, args, 1);
21+
22+
if (player == null) {
23+
return true;
24+
} else if ((player != sender) && (!sender.isOp())) {
25+
sender.sendMessage(ChatColor.RED + "You don't have permission to go to other players homes");
26+
return true;
27+
} else if (!(sender instanceof Player)) {
28+
sender.sendMessage(ChatColor.RED + "I don't know how to move you!");
29+
return true;
30+
} else if (args.length < 1) {
31+
return false;
32+
}
33+
34+
String name = args[0];
35+
36+
Home home = plugin.getDatabase().find(Home.class).where().ieq("name", name).ieq("playerName", player.getName()).findUnique();
37+
38+
if (home == null) {
39+
sender.sendMessage(ChatColor.RED + "I don't know where that is!");
40+
} else {
41+
((Player)sender).teleport(home.getLocation());
42+
}
43+
44+
return true;
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
package com.dinnerbone.bukkit.home.commands;
3+
4+
import com.dinnerbone.bukkit.home.Home;
5+
import com.dinnerbone.bukkit.home.HomeBukkit;
6+
import java.util.List;
7+
import org.bukkit.command.Command;
8+
import org.bukkit.command.CommandExecutor;
9+
import org.bukkit.command.CommandSender;
10+
import org.bukkit.entity.Player;
11+
12+
public class ListHomesCommand implements CommandExecutor {
13+
private final HomeBukkit plugin;
14+
15+
public ListHomesCommand(HomeBukkit plugin) {
16+
this.plugin = plugin;
17+
}
18+
19+
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
20+
Player player = HomeBukkit.getPlayer(sender, args, 0);
21+
22+
if (player == null) {
23+
return true;
24+
}
25+
26+
List<Home> homes = plugin.getDatabase().find(Home.class).where().ieq("playerName", player.getName()).findList();
27+
28+
if (homes.isEmpty()) {
29+
if (sender == player) {
30+
sender.sendMessage("You have no homes!");
31+
} else {
32+
sender.sendMessage("That player has no homes!");
33+
}
34+
} else {
35+
String result = "";
36+
37+
for (Home home : homes) {
38+
if (result.length() > 0) {
39+
result += ", ";
40+
}
41+
42+
result += home.getName();
43+
}
44+
45+
sender.sendMessage("All home(s): " + result);
46+
}
47+
48+
return true;
49+
}
50+
}

0 commit comments

Comments
 (0)