mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Update sponge port
This commit is contained in:
parent
056f77a3ba
commit
46d3dc609e
@ -21,8 +21,7 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final CommandSender commandSender, org.bukkit.command.Command command, final String commandLabel,
|
public boolean onCommand(final CommandSender commandSender, org.bukkit.command.Command command, final String commandLabel, String[] args) {
|
||||||
String[] args) {
|
|
||||||
if (commandSender instanceof Player) {
|
if (commandSender instanceof Player) {
|
||||||
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), args);
|
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), args);
|
||||||
}
|
}
|
||||||
|
@ -1465,13 +1465,16 @@ public class PS {
|
|||||||
}
|
}
|
||||||
for (String areaId : areasSection.getKeys(false)) {
|
for (String areaId : areasSection.getKeys(false)) {
|
||||||
log(C.PREFIX + "&3 - " + areaId);
|
log(C.PREFIX + "&3 - " + areaId);
|
||||||
String[] split = areaId.split("([^\\-]+)(?:-{1})(-{0,1}\\d+\\;-{0,1}\\d+)(?:-{1})(-{0,1}\\d+\\;-{0,1}\\d+)");
|
int i1 = areaId.indexOf("-");
|
||||||
if (split.length != 3) {
|
int i2 = areaId.indexOf(";");
|
||||||
|
if (i1 == -1 || i2 == -1) {
|
||||||
throw new IllegalArgumentException("Invalid Area identifier: " + areaId + ". Expected form `<name>-<pos1>-<pos2>`");
|
throw new IllegalArgumentException("Invalid Area identifier: " + areaId + ". Expected form `<name>-<pos1>-<pos2>`");
|
||||||
}
|
}
|
||||||
String name = split[0];
|
String name = areaId.substring(0, i1);
|
||||||
PlotId pos1 = PlotId.fromString(split[1]);
|
String rest = areaId.substring(i1 + 1);
|
||||||
PlotId pos2 = PlotId.fromString(split[2]);
|
int i3 = rest.indexOf("-", i2);
|
||||||
|
PlotId pos1 = PlotId.fromString(rest.substring(0, i3));
|
||||||
|
PlotId pos2 = PlotId.fromString(rest.substring(i3 + 1));
|
||||||
if (pos1 == null || pos2 == null || name.isEmpty()) {
|
if (pos1 == null || pos2 == null || name.isEmpty()) {
|
||||||
throw new IllegalArgumentException("Invalid Area identifier: " + areaId + ". Expected form `<name>-<x1;z1>-<x2;z2>`");
|
throw new IllegalArgumentException("Invalid Area identifier: " + areaId + ". Expected form `<name>-<x1;z1>-<x2;z2>`");
|
||||||
}
|
}
|
||||||
|
@ -174,6 +174,9 @@ public class Trim extends SubCommand {
|
|||||||
public void run(Set<ChunkLoc> viable, final Set<ChunkLoc> nonViable) {
|
public void run(Set<ChunkLoc> viable, final Set<ChunkLoc> nonViable) {
|
||||||
Runnable regenTask;
|
Runnable regenTask;
|
||||||
if (regen) {
|
if (regen) {
|
||||||
|
PS.log("Starting regen task:");
|
||||||
|
PS.log(" - This is a VERY slow command");
|
||||||
|
PS.log(" - It will say `Trim done!` when complete");
|
||||||
regenTask = new Runnable() {
|
regenTask = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -80,9 +80,10 @@ import java.util.UUID;
|
|||||||
* Created by robin on 01/11/2014
|
* Created by robin on 01/11/2014
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Plugin(id = "com.plotsquared", name = "PlotSquared", description = "Easy, yet powerful Plot World generation and management.", url = "https://github.com/IntellectualSites/PlotSquared", version = "3.3.1")
|
@Plugin(id = "com.plotsquared", name = "PlotSquared", description = "Easy, yet powerful Plot World generation and management.", url = "https://github.com/IntellectualSites/PlotSquared", version = "3.3.2")
|
||||||
public class SpongeMain implements IPlotMain {
|
public class SpongeMain implements IPlotMain {
|
||||||
public static SpongeMain THIS;
|
public static SpongeMain THIS;
|
||||||
|
public PluginContainer plugin;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
@ -130,6 +131,7 @@ public class SpongeMain implements IPlotMain {
|
|||||||
public void onServerAboutToStart(GameAboutToStartServerEvent event) {
|
public void onServerAboutToStart(GameAboutToStartServerEvent event) {
|
||||||
log("PlotSquared: Server init");
|
log("PlotSquared: Server init");
|
||||||
THIS = this;
|
THIS = this;
|
||||||
|
THIS.plugin = this.game.getPluginManager().fromInstance(this).get();
|
||||||
new PS(this, "Sponge");
|
new PS(this, "Sponge");
|
||||||
this.server = this.game.getServer();
|
this.server = this.game.getServer();
|
||||||
this.game.getRegistry().register(WorldGeneratorModifier.class, (WorldGeneratorModifier) new HybridGen().specify());
|
this.game.getRegistry().register(WorldGeneratorModifier.class, (WorldGeneratorModifier) new HybridGen().specify());
|
||||||
@ -304,7 +306,7 @@ public class SpongeMain implements IPlotMain {
|
|||||||
@Override
|
@Override
|
||||||
public void startMetrics() {
|
public void startMetrics() {
|
||||||
try {
|
try {
|
||||||
Metrics metrics = new Metrics(this.game, (PluginContainer) this);
|
Metrics metrics = new Metrics(this.game, plugin);
|
||||||
metrics.start();
|
metrics.start();
|
||||||
log(C.PREFIX.s() + "&6Metrics enabled.");
|
log(C.PREFIX.s() + "&6Metrics enabled.");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -3,11 +3,14 @@ package com.plotsquared.sponge.util;
|
|||||||
import com.intellectualcrafters.plot.commands.MainCommand;
|
import com.intellectualcrafters.plot.commands.MainCommand;
|
||||||
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.Permissions;
|
|
||||||
import com.intellectualcrafters.plot.util.StringComparison;
|
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.plotsquared.general.commands.Command;
|
|
||||||
import com.plotsquared.sponge.SpongeMain;
|
import com.plotsquared.sponge.SpongeMain;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
import org.spongepowered.api.command.CommandCallable;
|
import org.spongepowered.api.command.CommandCallable;
|
||||||
import org.spongepowered.api.command.CommandException;
|
import org.spongepowered.api.command.CommandException;
|
||||||
import org.spongepowered.api.command.CommandResult;
|
import org.spongepowered.api.command.CommandResult;
|
||||||
@ -15,67 +18,44 @@ import org.spongepowered.api.command.CommandSource;
|
|||||||
import org.spongepowered.api.entity.living.player.Player;
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
import org.spongepowered.api.text.Text;
|
import org.spongepowered.api.text.Text;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class SpongeCommand implements CommandCallable {
|
public class SpongeCommand implements CommandCallable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult process(final CommandSource cmd, final String string) throws CommandException {
|
public CommandResult process(final CommandSource cmd, final String string) throws CommandException {
|
||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(() -> {
|
||||||
@Override
|
final String id = cmd.getIdentifier();
|
||||||
public void run() {
|
PlotPlayer pp;
|
||||||
final String id = cmd.getIdentifier();
|
try {
|
||||||
PlotPlayer pp;
|
final UUID uuid = UUID.fromString(id);
|
||||||
try {
|
final Player player = SpongeMain.THIS.getServer().getPlayer(uuid).get();
|
||||||
final UUID uuid = UUID.fromString(id);
|
pp = SpongeUtil.getPlayer(player);
|
||||||
final Player player = SpongeMain.THIS.getServer().getPlayer(uuid).get();
|
} catch (final Exception e) {
|
||||||
pp = SpongeUtil.getPlayer(player);
|
pp = ConsolePlayer.getConsole();
|
||||||
} catch (final Exception e) {
|
|
||||||
pp = ConsolePlayer.getConsole();
|
|
||||||
}
|
|
||||||
MainCommand.onCommand(pp, cmd.getName(), string.isEmpty() ? new String[]{} : string.split(" "));
|
|
||||||
}
|
}
|
||||||
|
MainCommand.onCommand(pp, string.isEmpty() ? new String[]{} : string.split(" "));
|
||||||
});
|
});
|
||||||
return CommandResult.success();
|
return CommandResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getSuggestions(final CommandSource source, final String string) throws CommandException {
|
public List<String> getSuggestions(final CommandSource source, final String s) throws CommandException {
|
||||||
if (!(source instanceof Player)) {
|
if (!(source instanceof Player)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final PlotPlayer player = SpongeUtil.getPlayer((Player) source);
|
final PlotPlayer player = SpongeUtil.getPlayer((Player) source);
|
||||||
String[] split = string.split(" ");
|
String[] args = s.split(" ");
|
||||||
if (split.length < 1) {
|
if (args.length == 0) {
|
||||||
return Collections.singletonList("plots");
|
return Collections.singletonList(MainCommand.getInstance().toString());
|
||||||
}
|
}
|
||||||
if (split.length > 1) {
|
Collection objects = MainCommand.getInstance().tab(player, args, s.endsWith(" "));
|
||||||
return Collections.emptyList();
|
if (objects == null) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
final Set<String> tabOptions = new HashSet<>();
|
List<String> result = new ArrayList<>();
|
||||||
final String arg = split[0].toLowerCase();
|
for (Object o : objects) {
|
||||||
ArrayList<String> labels = new ArrayList<>();
|
result.add(o.toString());
|
||||||
for (final Command cmd : MainCommand.getInstance().getCommands()) {
|
|
||||||
final String label = cmd.toS();
|
|
||||||
HashSet<String> aliases = new HashSet<>(cmd.getAliases());
|
|
||||||
aliases.add(label);
|
|
||||||
for (String alias : aliases) {
|
|
||||||
labels.add(alias);
|
|
||||||
if (alias.startsWith(arg)) {
|
|
||||||
if (Permissions.hasPermission(player, cmd.getPermission())) {
|
|
||||||
tabOptions.add(label);
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
String best = new StringComparison<>(arg, labels).getBestMatch();
|
return result;
|
||||||
tabOptions.add(best);
|
|
||||||
if (!tabOptions.isEmpty()) {
|
|
||||||
return new ArrayList<>(tabOptions);
|
|
||||||
}
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -90,7 +70,7 @@ public class SpongeCommand implements CommandCallable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<? extends Text> getHelp(final CommandSource cmd) {
|
public Optional<? extends Text> getHelp(final CommandSource cmd) {
|
||||||
return Optional.of(Text.of("/plot help"));
|
return Optional.of(Text.of("/plot"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,12 +64,6 @@ public class SpongeEconHandler extends EconHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPermission(String world, String player, String perm, boolean value) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
throw new UnsupportedOperationException("TODO/WIP/NOT IMPLEMENTED!");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(String world, String player, String perm) {
|
public boolean hasPermission(String world, String player, String perm) {
|
||||||
SpongePlayer obj = (SpongePlayer) UUIDHandler.getPlayer(player);
|
SpongePlayer obj = (SpongePlayer) UUIDHandler.getPlayer(player);
|
||||||
|
Loading…
Reference in New Issue
Block a user