Skip to content

Commit

Permalink
Update Bukkit for 1.3.1 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
feildmaster authored and amaranth committed Aug 2, 2012
1 parent 6a53010 commit 110ad8c
Show file tree
Hide file tree
Showing 31 changed files with 410 additions and 143 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.2.5-R5.1-SNAPSHOT</version>
<version>1.3.1-R0.1-SNAPSHOT</version>
<name>Bukkit</name>
<url>http://www.bukkit.org</url>

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/org/bukkit/GameMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@
*/
public enum GameMode {
/**
* Creative mode may fly, build instantly, become invulnerable and create free items
* Creative mode may fly, build instantly, become invulnerable and create free items.
*/
CREATIVE(1),

/**
* Survival mode is the "normal" gameplay type, with no special features.
*/
SURVIVAL(0);
SURVIVAL(0),

/**
* Adventure mode cannot break blocks, use chat, use buckets, etc.
*/
ADVENTURE(2);

private final int value;
private final static Map<Integer, GameMode> BY_ID = Maps.newHashMap();
Expand Down
22 changes: 19 additions & 3 deletions src/main/java/org/bukkit/Material.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ public enum Material {
GRILLED_PORK(320),
PAINTING(321),
GOLDEN_APPLE(322),
SIGN(323, 1),
SIGN(323, 16),
WOOD_DOOR(324, 1),
BUCKET(325, 1),
BUCKET(325, 16),
WATER_BUCKET(326, 1),
LAVA_BUCKET(327, 1),
MINECART(328, 1),
Expand Down Expand Up @@ -290,7 +290,23 @@ public enum Material {
RECORD_8(2263, 1),
RECORD_9(2264, 1),
RECORD_10(2265, 1),
RECORD_11(2266, 1);
RECORD_11(2266, 1),
WOOD_DOUBLE_STEP(125, Step.class),
WOOD_STEP(126, Step.class),
COCOA(127),
SANDSTONE_STAIRS(128, Stairs.class),
EMERALD_ORE(129),
ENDER_CHEST(130),
TRIPWIRE_HOOK(131, Button.class),
TRIPWIRE(132),
EMERALD_BLOCK(133),
SPRUCE_WOOD_STAIRS(134),
BIRCH_WOOD_STAIRS(135),
JUNGLE_WOOD_STAIRS(136),
BOOK_AND_QUILL(386, 1),
WRITTEN_BOOK(387, 1),
EMERALD(388, 64);


private final int id;
private final Class<? extends MaterialData> data;
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/org/bukkit/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ protected Command(String name, String description, String usageMessage, List<Str
*/
public abstract boolean execute(CommandSender sender, String commandLabel, String[] args);

/**
* Executed on tab completion for this command, returning a list of options
* the player can tab through.
* <p />
* By returning null, you tell Bukkit to generate a list of players to send
* to the sender.
* By returning an empty list, no options will be sent.
*
* @param sender Source object which is executing this command
* @param args All arguments passed to the command, split via ' '
* @return null to generate a Player list, otherwise a list of options
*/
public List<String> tabComplete(CommandSender sender, String[] args) {
return null;
}

/**
* Returns the name of this command
*
Expand Down Expand Up @@ -110,7 +126,7 @@ public boolean testPermissionSilent(CommandSender target) {
if ((permission == null) || (permission.length() == 0)) {
return true;
}

for (String p : permission.split(";")) {
if (target.hasPermission(p)) {
return true;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/bukkit/command/SimpleCommandMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class SimpleCommandMap implements CommandMap {
fallbackCommands.add(new ExpCommand());
fallbackCommands.add(new ToggleDownfallCommand());
fallbackCommands.add(new BanListCommand());
fallbackCommands.add(new DefaultGameModeCommand());
fallbackCommands.add(new SeedCommand());
}

public SimpleCommandMap(final Server server) {
Expand Down Expand Up @@ -139,7 +141,7 @@ protected Command getFallback(String label) {

return null;
}

public Set<VanillaCommand> getFallbackCommands() {
return Collections.unmodifiableSet(fallbackCommands);
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/bukkit/command/TabCommandExecutor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.bukkit.command;

import java.util.List;

/**
* Represents a class which can handle command tab completion and commands
*/
public interface TabCommandExecutor extends CommandExecutor {
public List<String> onTabComplete();
}
21 changes: 16 additions & 5 deletions src/main/java/org/bukkit/command/defaults/BanCommand.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
package org.bukkit.command.defaults;

import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class BanCommand extends VanillaCommand {
public BanCommand() {
super("ban");
this.description = "Prevents the specified player from using this server";
this.usageMessage = "/ban <player>";
this.usageMessage = "/ban <player> [reason ...]";
this.setPermission("bukkit.command.ban.player");
}

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length != 1) {
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}

// TODO: Ban Reason support
Bukkit.getOfflinePlayer(args[0]).setBanned(true);
if (Bukkit.getPlayer(args[0]) != null) Bukkit.getPlayer(args[0]).kickPlayer("Banned by admin.");
Command.broadcastCommandMessage(sender, "Banning " + args[0]);

Player player = Bukkit.getPlayer(args[0]);
if (player != null) {
player.kickPlayer("Banned by admin.");
}

sender.sendMessage("Banned player " + args[0]);
return true;
}

@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
return args.length >= 1 ? null : EMPTY_LIST;
}

@Override
public boolean matches(String input) {
return input.equalsIgnoreCase("ban");
Expand Down
36 changes: 31 additions & 5 deletions src/main/java/org/bukkit/command/defaults/BanIpCommand.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,58 @@
package org.bukkit.command.defaults;

import java.util.List;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class BanIpCommand extends VanillaCommand {
public static final Pattern ipValidity = Pattern.compile("^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");

public BanIpCommand() {
super("ban-ip");
this.description = "Prevents the specified IP address from using this server";
this.usageMessage = "/ban-ip <address>";
this.usageMessage = "/ban-ip <address|player> [reason ...]";
this.setPermission("bukkit.command.ban.ip");
}

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length != 1) {
if (args.length < 1) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}

Bukkit.banIP(args[0]);
Command.broadcastCommandMessage(sender, "Banning ip " + args[0]);
// TODO: Ban Reason support
if (ipValidity.matcher(args[0]).matches()) {
processIPBan(args[0], sender);
} else {
Player player = Bukkit.getPlayer(args[0]);

if (player == null) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
processIPBan(player.getAddress().getAddress().getHostAddress(), sender);
}

return true;
}

@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
return args.length >= 1 ? null : EMPTY_LIST;
}

private void processIPBan(String ip, CommandSender sender) {
// TODO: Kick on ban
Bukkit.banIP(ip);

sender.sendMessage("Banned IP Address " + ip);
}

@Override
public boolean matches(String input) {
return input.equalsIgnoreCase("ban-ip");
Expand Down
28 changes: 20 additions & 8 deletions src/main/java/org/bukkit/command/defaults/BanListCommand.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
package org.bukkit.command.defaults;

import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;

public class BanListCommand extends VanillaCommand {
public BanListCommand() {
super("banlist");
this.description = "View all players banned from this server";
this.usageMessage = "/banlist";
this.usageMessage = "/banlist [ips|players]";
this.setPermission("bukkit.command.ban.list");
}

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;

StringBuilder message = new StringBuilder().append(ChatColor.GRAY).append("Ban list: ");
// TODO: ips support
StringBuilder message = new StringBuilder();
OfflinePlayer[] banlist = Bukkit.getServer().getBannedPlayers().toArray(new OfflinePlayer[0]);

int count = 0;
for (OfflinePlayer p : Bukkit.getServer().getBannedPlayers()) {
if (count++ > 0) {
message.append(", ");
for (int x = 0; x < banlist.length; x++) {
if (x != 0) {
if (x == banlist.length - 1) {
message.append(" and ");
} else {
message.append(", ");
}
}
message.append(p.getName());
message.append(banlist[x].getName());
}

sender.sendMessage("There are " + banlist.length + " total banned players:");
sender.sendMessage(message.toString());
return true;
}

@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
return args.length >= 1 ? null : EMPTY_LIST;
}

@Override
public boolean matches(String input) {
return input.equalsIgnoreCase("banlist");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.bukkit.command.defaults;

import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.command.CommandSender;

public class DefaultGameModeCommand extends VanillaCommand {
public DefaultGameModeCommand() {
super("defaultgamemode");
this.description = "Set the default gamemode";
this.usageMessage = "/defaultgamemode <mode>";
this.setPermission("bukkit.command.defaultgamemode");
}

@Override
public boolean matches(String input) {
return input.equalsIgnoreCase(this.getName());
}

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (args.length == 0) {
sender.sendMessage("Useage: " + usageMessage);
return false;
}

String modeArg = args[0];
int value = -1;

try {
value = Integer.parseInt(modeArg);
} catch (NumberFormatException ex) {}

GameMode mode = GameMode.getByValue(value);

if (mode == null) {
if (modeArg.equalsIgnoreCase("creative") || modeArg.equalsIgnoreCase("c")) {
mode = GameMode.CREATIVE;
} else if (modeArg.equalsIgnoreCase("adventure") || modeArg.equalsIgnoreCase("a")) {
mode = GameMode.ADVENTURE;
} else {
mode = GameMode.SURVIVAL;
}
}

Bukkit.getServer().setDefaultGameMode(mode);
sender.sendMessage("Default game mode set to " + mode.toString().toLowerCase());

return true;
}

}
12 changes: 8 additions & 4 deletions src/main/java/org/bukkit/command/defaults/DeopCommand.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.bukkit.command.defaults;

import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

Expand All @@ -18,23 +18,27 @@ public DeopCommand() {
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length != 1) {
if (args.length != 1 || args[0].length() == 0) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}

Command.broadcastCommandMessage(sender, "De-opping " + args[0]);

OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
player.setOp(false);

if (player instanceof Player) {
((Player) player).sendMessage(ChatColor.YELLOW + "You are no longer op!");
}

sender.sendMessage("De-opped " + args[0]);
return true;
}

@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
return args.length >= 1 ? null : EMPTY_LIST;
}

@Override
public boolean matches(String input) {
return input.equalsIgnoreCase("deop");
Expand Down
Loading

0 comments on commit 110ad8c

Please sign in to comment.