Skip to content

Commit

Permalink
API 1.0.6
Browse files Browse the repository at this point in the history
Add OfflinePlayer support and changed command processing
  • Loading branch information
Vladg24YT committed Jul 15, 2022
1 parent 6f5f192 commit 625e26d
Show file tree
Hide file tree
Showing 45 changed files with 1,050 additions and 3,166 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ru.vladthemountain</groupId>
<artifactId>lilybukkit</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
<name>LilyBukkit</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/org/bukkit/OfflinePlayer.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.bukkit;

import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.entity.Player;
import org.bukkit.permissions.ServerOperator;

public interface OfflinePlayer extends ServerOperator, ConfigurationSerializable {
public interface OfflinePlayer extends ServerOperator {
/**
* Checks if this player is currently online
*
Expand Down Expand Up @@ -46,13 +45,20 @@ public interface OfflinePlayer extends ServerOperator, ConfigurationSerializable
* @param value true if whitelisted
*/
public void setWhitelisted(boolean value);


/**
* Sets if this player's IP is whitelisted or not
*
* @param value true if whitelisted
*/
public void setIPWhitelisted(boolean value);

/**
* Gets a {@link Player} object that this represents, if there is one
* <p>
* If the player is online, this will return that player. Otherwise,
* it will return null.
*
*
* @return Online player
*/
public Player getPlayer();
Expand Down
19 changes: 0 additions & 19 deletions src/main/java/org/bukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,25 +367,6 @@ public interface Server {
*/
public void reloadWhitelist();

/**
* Gets the player with the exact given name, case insensitive
*
* @param name Exact name of the player to retrieve
* @return Player object or null if not found
*/
public Player getPlayerExact(String name);

/**
* Creates or loads a world with the given name using the specified options.
* <p>
* If the world is already loaded, it will just return the equivalent of
* getWorld(creator.name()).
*
* @param creator Options to use when creating the world
* @return Newly created or loaded world
*/
public World createWorld(WorldCreator creator);

/**
* Shutdowns the server, stopping everything.
*/
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/bukkit/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,17 @@ public interface World {
*/
public boolean isWinter();

/**
* Returns whether the world should be saved.
* @return if the world should be saved
*/
public boolean getAutoSave();

/**
* Sets whether the world should be saved.
*/
public void setAutoSave(boolean save);

/**
* Represents various map environment types that a world may be
*/
Expand Down
174 changes: 30 additions & 144 deletions src/main/java/org/bukkit/command/SimpleCommandMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.bukkit.ChatColor;
import org.bukkit.Server;

import org.bukkit.command.defaults.*;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import static org.bukkit.util.Java15Compat.Arrays_copyOfRange;
Expand All @@ -23,13 +24,14 @@ public final class SimpleCommandMap implements CommandMap {

public SimpleCommandMap(final Server server) {
this.server = server;
setDefaultCommands(server);
setVanillaCommands();
setDefaultCommands();
}

private void setDefaultCommands(final Server server) {
register("bukkit", new VersionCommand("version", server));
register("bukkit", new ReloadCommand("reload", server));
register("bukkit", new PluginsCommand("plugins", server));
private void setDefaultCommands() {
register("bukkit", new VersionCommand("version"));
register("bukkit", new ReloadCommand("reload"));
register("bukkit", new PluginsCommand("plugins"));
}

/**
Expand Down Expand Up @@ -143,7 +145,8 @@ public synchronized void clearCommands() {
}
knownCommands.clear();
aliases.clear();
setDefaultCommands(server);
setDefaultCommands();
setVanillaCommands(); //LilyBukkit
}

public Command getCommand(String name) {
Expand Down Expand Up @@ -183,143 +186,26 @@ public void registerServerAliases() {
}
}

private static class VersionCommand extends Command {
private final Server server;

public VersionCommand(String name, Server server) {
super(name);
this.server = server;
this.description = "Gets the version of this server including any plugins in use";
this.usageMessage = "/version [plugin name]";
this.setAliases(Arrays.asList("ver", "about"));
}

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (args.length == 0) {
sender.sendMessage("This server is running " + ChatColor.GREEN + server.getName() + ChatColor.WHITE + " version " + ChatColor.GREEN + server.getVersion());
sender.sendMessage("This server is also sporting some funky dev build of Bukkit!");
} else {
StringBuilder name = new StringBuilder();

for (String arg : args) {
if (name.length() > 0) {
name.append(' ');
}
name.append(arg);
}

Plugin plugin = server.getPluginManager().getPlugin(name.toString());

if (plugin != null) {
PluginDescriptionFile desc = plugin.getDescription();

sender.sendMessage(ChatColor.GREEN + desc.getName() + ChatColor.WHITE + " version " + ChatColor.GREEN + desc.getVersion());

if (desc.getDescription() != null) {
sender.sendMessage(desc.getDescription());
}

if (desc.getWebsite() != null) {
sender.sendMessage("Website: " + ChatColor.GREEN + desc.getWebsite());
}

if (!desc.getAuthors().isEmpty()) {
if (desc.getAuthors().size() == 1) {
sender.sendMessage("Author: " + getAuthors(desc));
} else {
sender.sendMessage("Authors: " + getAuthors(desc));
}
}
} else {
sender.sendMessage("This server is not running any plugin by that name.");
sender.sendMessage("Use /plugins to get a list of plugins.");
}
}

return true;
}

private String getAuthors(final PluginDescriptionFile desc) {
StringBuilder result = new StringBuilder();
ArrayList<String> authors = desc.getAuthors();

for (int i = 0; i < authors.size(); i++) {
if (result.length() > 0) {
result.append(ChatColor.WHITE);

if (i < authors.size() - 1) {
result.append(", ");
} else {
result.append(" and ");
}
}

result.append(ChatColor.GREEN);
result.append(authors.get(i));
}

return result.toString();
}
}

private static class ReloadCommand extends Command {

private final Server server;

public ReloadCommand(String name, Server server) {
super(name);
this.server = server;
this.description = "Reloads the server configuration and plugins";
this.usageMessage = "/reload";
this.setAliases(Arrays.asList("rl"));
}

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (sender.isOp()) {
server.reload();
sender.sendMessage(ChatColor.GREEN + "Reload complete.");
} else {
sender.sendMessage(ChatColor.RED + "You do not have sufficient access to reload this server.");
}
return true;
}
}

private static class PluginsCommand extends Command {

private final Server server;

public PluginsCommand(String name, Server server) {
super(name);
this.server = server;
this.description = "Gets a list of plugins running on the server";
this.usageMessage = "/plugins";
this.setAliases(Arrays.asList("pl"));
}

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
sender.sendMessage("Plugins: " + getPluginList());
return true;
}

private String getPluginList() {
StringBuilder pluginList = new StringBuilder();
Plugin[] plugins = server.getPluginManager().getPlugins();

for (Plugin plugin : plugins) {
if (pluginList.length() > 0) {
pluginList.append(ChatColor.WHITE);
pluginList.append(", ");
}

pluginList.append(plugin.isEnabled() ? ChatColor.GREEN : ChatColor.RED);
pluginList.append(plugin.getDescription().getName());
}

return pluginList.toString();
}
//LilyBukkit
private void setVanillaCommands(){
register("minecraft", new HelpCommand());
register("minecraft", new KickCommand());
register("minecraft", new BanCommand());
register("minecraft", new BanIpCommand());
register("minecraft", new PardonCommand());
register("minecraft", new PardonIpCommand());
register("minecraft", new OpCommand());
register("minecraft", new DeopCommand());
register("minecraft", new TeleportCommand());
register("minecraft", new GiveCommand());
register("minecraft", new TellCommand());
register("minecraft", new StopCommand());
register("minecraft", new SaveCommand());
register("minecraft", new SaveOffCommand());
register("minecraft", new SaveOnCommand());
register("minecraft", new ListCommand());
register("minecraft", new SayCommand());
register("minecraft", new MeCommand());
register("minecraft", new WhitelistCommand());
}
}
34 changes: 34 additions & 0 deletions src/main/java/org/bukkit/command/defaults/BanIpCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.bukkit.command.defaults;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

public class BanIpCommand extends VanillaCommand {
public BanIpCommand() {
super("ban-ip");
this.description = "Prevents the specified IP address from using this server";
this.usageMessage = "/ban-ip <address>";
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) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}

Bukkit.getServer().banIP(args[0]);
Command.broadcastCommandMessage(sender, "Banning ip " + args[0]);

return true;
}

@Override
public boolean matches(String input) {
return input.startsWith("ban-ip ") || input.equalsIgnoreCase("ban-ip");
}
}
42 changes: 42 additions & 0 deletions src/main/java/org/bukkit/command/defaults/DeopCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.bukkit.command.defaults;

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;

public class DeopCommand extends VanillaCommand {
public DeopCommand() {
super("deop");
this.description = "Takes the specified player's operator status";
this.usageMessage = "/deop <player>";
this.setPermission("bukkit.command.op.take");
}

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

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

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

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

return true;
}

@Override
public boolean matches(String input) {
return input.startsWith("deop ") || input.equalsIgnoreCase("deop");
}
}
Loading

0 comments on commit 625e26d

Please sign in to comment.