mirror of
https://github.com/taoneill/war.git
synced 2025-01-03 06:17:33 +01:00
Updated API version to Sponge:2.1-SNAPSHOT
This commit is contained in:
parent
06f7fe9655
commit
b133f03543
@ -94,12 +94,15 @@
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>war-repo</id>
|
||||
<url>http://ci.tommytony.com/plugin/repository/everything/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sponge-repo</id>
|
||||
<url>http://repo.spongepowered.org/Sponge/maven/</url>
|
||||
<id>sponge-maven-repo</id>
|
||||
<name>Sponge maven repo</name>
|
||||
<url>http://repo.spongepowered.org/maven</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
@ -113,7 +116,8 @@
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>spongeapi</artifactId>
|
||||
<version>1.0</version>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
|
@ -105,7 +105,7 @@ public class WarConfig implements Closeable {
|
||||
UUID playerId = UUID.fromString(result.getString(1));
|
||||
if (playerId == null)
|
||||
continue;
|
||||
Optional<Player> player = plugin.getGame().getPlayer(playerId);
|
||||
Optional<Player> player = plugin.getGame().getServer().getPlayer(playerId);
|
||||
if (player.isPresent())
|
||||
makers.add(player.get());
|
||||
}
|
||||
@ -137,7 +137,7 @@ public class WarConfig implements Closeable {
|
||||
private final Class<?> dataType;
|
||||
private final Object defaultValue;
|
||||
|
||||
private WarSetting(Class<?> dataType, Object defaultValue) {
|
||||
WarSetting(Class<?> dataType, Object defaultValue) {
|
||||
this.dataType = dataType;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
@ -1,39 +1,48 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.inject.Inject;
|
||||
import com.tommytony.war.command.WarConfigCommand;
|
||||
import com.tommytony.war.command.WarzoneCommand;
|
||||
import com.tommytony.war.zone.Warzone;
|
||||
import org.slf4j.Logger;
|
||||
import org.spongepowered.api.Game;
|
||||
import org.spongepowered.api.event.Subscribe;
|
||||
import org.spongepowered.api.event.state.PreInitializationEvent;
|
||||
import org.spongepowered.api.event.state.ServerStartedEvent;
|
||||
import org.spongepowered.api.event.state.ServerStartingEvent;
|
||||
import org.spongepowered.api.plugin.Plugin;
|
||||
import org.spongepowered.api.util.event.Subscribe;
|
||||
import org.spongepowered.api.service.config.DefaultConfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Plugin(id = "war", name = "War", version = "2.0-SNAPSHOT")
|
||||
public class WarPlugin {
|
||||
private Game game;
|
||||
|
||||
@Inject
|
||||
private Logger logger;
|
||||
|
||||
@Inject
|
||||
@DefaultConfig(sharedRoot = false)
|
||||
private File dataDir;
|
||||
|
||||
private WarConfig config;
|
||||
private Map<String, Warzone> zones;
|
||||
|
||||
@Subscribe
|
||||
public void onConstruction(PreInitializationEvent event) throws InstantiationException {
|
||||
game = event.getGame();
|
||||
logger = event.getPluginLog();
|
||||
dataDir = event.getConfigurationDirectory();
|
||||
try {
|
||||
Class.forName("com.tommytony.war.sqlite.JDBC").newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
|
||||
throw new InstantiationException("Failed to load SQLite database");
|
||||
}
|
||||
zones = new HashMap<>();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@ -51,6 +60,7 @@ public class WarPlugin {
|
||||
public void onStart(ServerStartedEvent event) {
|
||||
// register commands
|
||||
game.getCommandDispatcher().register(this, new WarzoneCommand(this), "warzone", "zone");
|
||||
game.getCommandDispatcher().register(this, new WarConfigCommand(this), "warcfg", "warconfig");
|
||||
}
|
||||
|
||||
public Game getGame() {
|
||||
|
@ -1,133 +1,74 @@
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.tommytony.war.WarConfig;
|
||||
import com.tommytony.war.WarPlugin;
|
||||
import org.spongepowered.api.entity.player.Player;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
import org.spongepowered.api.text.Text;
|
||||
import org.spongepowered.api.text.Texts;
|
||||
import org.spongepowered.api.util.command.CommandCallable;
|
||||
import org.spongepowered.api.util.command.CommandException;
|
||||
import org.spongepowered.api.util.command.CommandResult;
|
||||
import org.spongepowered.api.util.command.CommandSource;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WarConfigCommand implements CommandCallable {
|
||||
|
||||
private final Optional<Text> desc = Optional.of((Text) Texts.of("View/modify War config"));
|
||||
private final Optional<Text> help = Optional.of((Text) Texts.of("Allows viewing of the server config or changing various settings."));
|
||||
private final Text usage = (Text) Texts.of("[-p] setting value");
|
||||
|
||||
private final WarPlugin plugin;
|
||||
|
||||
public WarConfigCommand(WarPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the command based on input arguments.
|
||||
* <p/>
|
||||
* <p>The implementing class must perform the necessary permission
|
||||
* checks.</p>
|
||||
*
|
||||
* @param source The caller of the command
|
||||
* @param arguments The raw arguments for this command
|
||||
* @param parents A stack of parent commands, where the first entry is
|
||||
* the root command
|
||||
* @return Whether a command was processed
|
||||
* @throws org.spongepowered.api.util.command.CommandException Thrown on a command error
|
||||
*/
|
||||
@Override
|
||||
public boolean call(CommandSource source, String arguments, List<String> parents) throws CommandException {
|
||||
if (!testPermission(source)) {
|
||||
source.sendMessage("You do not have permission for this command.");
|
||||
return true;
|
||||
}
|
||||
source.sendMessage("you do have permission");
|
||||
return false;
|
||||
public CommandResult process(CommandSource source, String arguments) throws CommandException {
|
||||
throw new UnsupportedOperationException("Not implemented yet");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether this command can probably be executed by the given source.
|
||||
* <p/>
|
||||
* <p>If implementations are unsure if the command can be executed by
|
||||
* the source, {@code true} should be returned. Return values of this method
|
||||
* may be used to determine whether this command is listed in command
|
||||
* listings.</p>
|
||||
*
|
||||
* @param source The caller of the command
|
||||
* @return Whether permission is (probably) granted
|
||||
*/
|
||||
@Override
|
||||
public boolean testPermission(CommandSource source) {
|
||||
if (source instanceof Player) {
|
||||
try {
|
||||
if (plugin.getConfig().getZoneMakers().contains(source)) {
|
||||
source.sendMessage("You are a zone maker.");
|
||||
return true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().error("Loading zone makers for testing permission", e);
|
||||
}
|
||||
}
|
||||
if (source instanceof Subject && ((Subject) source).isPermitted("war.admin.config")) {
|
||||
source.sendMessage("You are a war admin.");
|
||||
return true;
|
||||
}
|
||||
if (!(source instanceof Player) && !(source instanceof Subject)) {
|
||||
source.sendMessage("You are console or something.");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a short one-line description of this command.
|
||||
*
|
||||
* @return A description, if available
|
||||
*/
|
||||
@Override
|
||||
public Optional<String> getShortDescription() {
|
||||
return Optional.of("View/modify war config");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a longer help text about this command.
|
||||
*
|
||||
* @return A help text, if available
|
||||
*/
|
||||
@Override
|
||||
public Optional<String> getHelp() {
|
||||
return Optional.of("Allows viewing of the war server config or changing various settings.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the usage string of this command.
|
||||
* <p/>
|
||||
* <p>A usage string may look like
|
||||
* {@code [-w <world>] <var1> <var2>}.</p>
|
||||
*
|
||||
* @return A usage string
|
||||
*/
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "[-p] setting:value...";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of suggestions based on input.
|
||||
* <p/>
|
||||
* <p>If a suggestion is chosen by the user, it will replace the last
|
||||
* word.</p>
|
||||
*
|
||||
* @param source The command source
|
||||
* @param arguments The arguments entered up to this point
|
||||
* @return A list of suggestions
|
||||
* @throws org.spongepowered.api.util.command.CommandException Thrown if there was a parsing error
|
||||
*/
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandSource source, String arguments) throws CommandException {
|
||||
ArrayList<String> suggestions = new ArrayList<>();
|
||||
ImmutableList.Builder<String> list = ImmutableList.builder();
|
||||
for (WarConfig.WarSetting setting : WarConfig.WarSetting.values()) {
|
||||
if (setting.name().toLowerCase().startsWith(arguments.toLowerCase()))
|
||||
suggestions.add(setting.name().toLowerCase() + ":");
|
||||
list.add(setting.name().toLowerCase() + ":");
|
||||
}
|
||||
return suggestions;
|
||||
return list.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandSource source) {
|
||||
try {
|
||||
if (source instanceof Player && plugin.getConfig().getZoneMakers().contains(source)) {
|
||||
return true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().error("Loading zone makers for testing permission", e);
|
||||
}
|
||||
if (source.hasPermission("war.config")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<? extends Text> getShortDescription(CommandSource source) {
|
||||
return desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<? extends Text> getHelp(CommandSource source) {
|
||||
return help;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getUsage(CommandSource source) {
|
||||
return usage;
|
||||
}
|
||||
}
|
||||
|
@ -1,126 +1,82 @@
|
||||
package com.tommytony.war.command;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.tommytony.war.WarPlugin;
|
||||
import com.tommytony.war.zone.Warzone;
|
||||
import org.spongepowered.api.entity.player.Player;
|
||||
import org.spongepowered.api.text.Text;
|
||||
import org.spongepowered.api.text.Texts;
|
||||
import org.spongepowered.api.util.command.CommandCallable;
|
||||
import org.spongepowered.api.util.command.CommandException;
|
||||
import org.spongepowered.api.util.command.CommandResult;
|
||||
import org.spongepowered.api.util.command.CommandSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Teleport to warzone.
|
||||
*/
|
||||
public class WarzoneCommand implements CommandCallable {
|
||||
|
||||
private final Optional<Text> desc = Optional.of((Text) Texts.of("Teleport to a zone"));
|
||||
private final Optional<Text> help = Optional.of((Text) Texts.of("Teleport to a warzone, or join automatically."));
|
||||
private final Text usage = (Text) Texts.of("<zone>");
|
||||
|
||||
private WarPlugin plugin;
|
||||
|
||||
public WarzoneCommand(WarPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the command based on input arguments.
|
||||
* <p/>
|
||||
* <p>The implementing class must perform the necessary permission
|
||||
* checks.</p>
|
||||
*
|
||||
* @param source The caller of the command
|
||||
* @param arguments The raw arguments for this command
|
||||
* @param parents A stack of parent commands, where the first entry is
|
||||
* the root command
|
||||
* @return Whether a command was processed
|
||||
* @throws org.spongepowered.api.util.command.CommandException Thrown on a command error
|
||||
*/
|
||||
@Override
|
||||
public boolean call(CommandSource source, String arguments, List<String> parents) throws CommandException {
|
||||
if (!(source instanceof Player)) {
|
||||
return false;
|
||||
public CommandResult process(CommandSource commandSource, String s) throws CommandException {
|
||||
if (!(commandSource instanceof Player)) {
|
||||
return CommandResult.empty();
|
||||
}
|
||||
String[] argv = arguments.split(" ");
|
||||
String[] argv = s.split(" ");
|
||||
if (argv.length < 1) {
|
||||
return false;
|
||||
return CommandResult.empty();
|
||||
}
|
||||
String zoneName = argv[0];
|
||||
Optional<Warzone> zone = plugin.getZone(zoneName);
|
||||
if (!zone.isPresent()) {
|
||||
return false;
|
||||
return CommandResult.empty();
|
||||
}
|
||||
Player player = (Player) source;
|
||||
player.teleport(zone.get().getTeleport());
|
||||
Player player = (Player) commandSource;
|
||||
player.setLocation(zone.get().getTeleport());
|
||||
|
||||
return true;
|
||||
return CommandResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether this command can probably be executed by the given source.
|
||||
* <p/>
|
||||
* <p>If implementations are unsure if the command can be executed by
|
||||
* the source, {@code true} should be returned. Return values of this method
|
||||
* may be used to determine whether this command is listed in command
|
||||
* listings.</p>
|
||||
*
|
||||
* @param source The caller of the command
|
||||
* @return Whether permission is (probably) granted
|
||||
*/
|
||||
@Override
|
||||
public boolean testPermission(CommandSource source) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a short one-line description of this command.
|
||||
*
|
||||
* @return A description, if available
|
||||
*/
|
||||
@Override
|
||||
public Optional<String> getShortDescription() {
|
||||
return Optional.of("Teleport to a zone");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a longer help text about this command.
|
||||
*
|
||||
* @return A help text, if available
|
||||
*/
|
||||
@Override
|
||||
public Optional<String> getHelp() {
|
||||
return Optional.of("Use this command to teleport to a zone lobby");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the usage string of this command.
|
||||
* <p/>
|
||||
* <p>A usage string may look like
|
||||
* {@code [-w <world>] <var1> <var2>}.</p>
|
||||
*
|
||||
* @return A usage string
|
||||
*/
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "<zone>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of suggestions based on input.
|
||||
* <p/>
|
||||
* <p>If a suggestion is chosen by the user, it will replace the last
|
||||
* word.</p>
|
||||
*
|
||||
* @param source The command source
|
||||
* @param arguments The arguments entered up to this point
|
||||
* @return A list of suggestions
|
||||
* @throws org.spongepowered.api.util.command.CommandException Thrown if there was a parsing error
|
||||
*/
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandSource source, String arguments) throws CommandException {
|
||||
ArrayList<String> suggestions = new ArrayList<>();
|
||||
for (String zone : plugin.getZones().keySet()) {
|
||||
if (zone.toLowerCase().startsWith(arguments.toLowerCase()))
|
||||
suggestions.add(zone);
|
||||
public List<String> getSuggestions(CommandSource commandSource, String s) throws CommandException {
|
||||
ImmutableList.Builder<String> list = ImmutableList.builder();
|
||||
for (Warzone zone : plugin.getZones().values()) {
|
||||
if (zone.getName().toLowerCase().startsWith(s.toLowerCase())) {
|
||||
list.add(zone.getName());
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
return list.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandSource commandSource) {
|
||||
return commandSource.hasPermission("war.teleport");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<? extends Text> getShortDescription(CommandSource commandSource) {
|
||||
return desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<? extends Text> getHelp(CommandSource commandSource) {
|
||||
return help;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getUsage(CommandSource commandSource) {
|
||||
return usage;
|
||||
}
|
||||
}
|
||||
|
@ -1,103 +0,0 @@
|
||||
package com.tommytony.war.struct;
|
||||
|
||||
import org.spongepowered.api.block.BlockLoc;
|
||||
import org.spongepowered.api.math.Vector3d;
|
||||
import org.spongepowered.api.world.Location;
|
||||
import org.spongepowered.api.world.extent.BlockVolume;
|
||||
|
||||
/**
|
||||
* A selection of blocks in the world. Identified by two corners.
|
||||
*/
|
||||
public class Region implements BlockVolume {
|
||||
/**
|
||||
* One corner of the selection.
|
||||
*/
|
||||
private Location first;
|
||||
/**
|
||||
* The second corner of the selection.
|
||||
*/
|
||||
private Location second;
|
||||
|
||||
public Region(Location first, Location second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the minimum value of the selection.
|
||||
*
|
||||
* @return the minimum value.
|
||||
*/
|
||||
public Location getMin() {
|
||||
return new Location(first.getExtent(), first.getPosition().min(second.getPosition()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the maximum value of the selection.
|
||||
*
|
||||
* @return the maximum value.
|
||||
*/
|
||||
public Location getMax() {
|
||||
return new Location(first.getExtent(), first.getPosition().max(second.getPosition()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the region in the X dimension.
|
||||
*
|
||||
* @return X dimension length.
|
||||
*/
|
||||
public int getSizeX() {
|
||||
return getMax().getBlock().getX() - getMin().getBlock().getX();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the region in the Y dimension.
|
||||
*
|
||||
* @return Y dimension length.
|
||||
*/
|
||||
public int getSizeY() {
|
||||
return getMax().getBlock().getY() - getMin().getBlock().getY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the region in the Z dimension.
|
||||
*
|
||||
* @return Z dimension length.
|
||||
*/
|
||||
public int getSizeZ() {
|
||||
return getMax().getBlock().getZ() - getMin().getBlock().getZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total area of the region.
|
||||
*
|
||||
* @return region total area.
|
||||
*/
|
||||
public int getSize() {
|
||||
return getSizeX() * getSizeY() * getSizeZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a representation of the block at the given position.
|
||||
*
|
||||
* @param position The position
|
||||
* @return The block
|
||||
*/
|
||||
@Override
|
||||
public BlockLoc getBlock(Vector3d position) {
|
||||
return first.getExtent().getBlock(position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a representation of the block at the given position.
|
||||
*
|
||||
* @param x The X position
|
||||
* @param y The Y position
|
||||
* @param z The Z position
|
||||
* @return The block
|
||||
*/
|
||||
@Override
|
||||
public BlockLoc getBlock(int x, int y, int z) {
|
||||
return first.getExtent().getBlock(x, y, z);
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ public class Warzone {
|
||||
private final String name;
|
||||
private final ZoneStorage db;
|
||||
private final ZoneConfig config;
|
||||
private Location teleport;
|
||||
private Location<World> teleport;
|
||||
|
||||
/**
|
||||
* Load or create a war zone from the war settings store.
|
||||
@ -56,11 +56,11 @@ public class Warzone {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Location getTeleport() {
|
||||
public Location<World> getTeleport() {
|
||||
try {
|
||||
Optional<Location> lobby = db.getPosition("lobby", Optional.<World>absent());
|
||||
if (lobby.isPresent())
|
||||
return lobby.get();
|
||||
return lobby.<World>get();
|
||||
else throw new RuntimeException("No teleport location found for zone " + name);
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().error("Retrieving teleport", e);
|
||||
|
@ -2,7 +2,6 @@ package com.tommytony.war.zone;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.tommytony.war.WarPlugin;
|
||||
import org.spongepowered.api.math.Vectors;
|
||||
import org.spongepowered.api.world.Location;
|
||||
import org.spongepowered.api.world.World;
|
||||
|
||||
@ -86,10 +85,18 @@ public class ZoneStorage implements AutoCloseable {
|
||||
try (ResultSet resultSet = stmt.executeQuery()) {
|
||||
if (resultSet.next()) {
|
||||
World resultWorld;
|
||||
if (world.isPresent()) resultWorld = world.get();
|
||||
else resultWorld = plugin.getGame().getWorld(resultSet.getString("world"));
|
||||
return Optional.of(new Location(resultWorld, Vectors.create3d(
|
||||
resultSet.getDouble("x"), resultSet.getDouble("y"), resultSet.getDouble("z"))));
|
||||
if (world.isPresent()) {
|
||||
resultWorld = world.get();
|
||||
} else {
|
||||
Optional<World> optwld = plugin.getGame().getServer().getWorld(resultSet.getString("world"));
|
||||
if (optwld.isPresent()) {
|
||||
resultWorld = optwld.get();
|
||||
} else {
|
||||
return Optional.absent();
|
||||
}
|
||||
}
|
||||
return Optional.of(new Location(resultWorld,
|
||||
resultSet.getDouble("x"), resultSet.getDouble("y"), resultSet.getDouble("z")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user