mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Tab completion, fix SpongeUtil.getWorld
This commit is contained in:
parent
bf85ba5833
commit
f73a542b04
@ -74,7 +74,7 @@ public class ReflectionUtils {
|
|||||||
|
|
||||||
public static Field findField(Class<?> clazz, Class<?> fieldClass) {
|
public static Field findField(Class<?> clazz, Class<?> fieldClass) {
|
||||||
for (Field field : clazz.getFields()) {
|
for (Field field : clazz.getFields()) {
|
||||||
if (field.getClass() == fieldClass) {
|
if (fieldClass == field.getType() || fieldClass.isAssignableFrom(field.getType())) {
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
return field;
|
return field;
|
||||||
}
|
}
|
||||||
|
@ -83,22 +83,31 @@ public class SpongeChunkManager extends ChunkManager {
|
|||||||
PS.debug("Not valid world generator for: " + world);
|
PS.debug("Not valid world generator for: " + world);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ChunkProviderServer chunkProvider = (ChunkProviderServer) provider;
|
|
||||||
long pos = loc.x & 4294967295L | (loc.z & 4294967295L) << 32;
|
ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
|
||||||
|
IChunkProvider chunkProvider = chunkServer.serverChunkGenerator;
|
||||||
|
|
||||||
|
long pos = ChunkCoordIntPair.chunkXZ2Int(loc.x, loc.z);
|
||||||
|
System.out.println((loc.x & 4294967295L | (loc.z & 4294967295L) << 32) + ":" + pos);
|
||||||
net.minecraft.world.chunk.Chunk mcChunk = (net.minecraft.world.chunk.Chunk) spongeChunk;
|
net.minecraft.world.chunk.Chunk mcChunk = (net.minecraft.world.chunk.Chunk) spongeChunk;
|
||||||
if (provider.chunkExists(loc.x, loc.z)) {
|
if (chunkServer.chunkExists(loc.x, loc.z)) {
|
||||||
mcChunk = chunkProvider.loadChunk(loc.x, loc.z);
|
mcChunk = chunkServer.loadChunk(loc.x, loc.z);
|
||||||
mcChunk.onChunkUnload();
|
mcChunk.onChunkUnload();
|
||||||
}
|
}
|
||||||
Set<Long> set = (Set<Long>) chunkProvider.getClass().getDeclaredField("droppedChunksSet").get(chunkProvider);
|
// Set<Long> set = (Set<Long>) chunkProvider.getClass().getDeclaredField("droppedChunksSet").get(chunkProvider);
|
||||||
|
Set<Long> set = (Set<Long>) ReflectionUtils.findField(chunkServer.getClass(), Set.class).get(chunkServer);
|
||||||
set.remove(pos);
|
set.remove(pos);
|
||||||
chunkProvider.id2ChunkMap.remove(pos);
|
chunkServer.id2ChunkMap.remove(pos);
|
||||||
mcChunk = provider.provideChunk(loc.x, loc.z);
|
mcChunk = chunkProvider.provideChunk(loc.x, loc.z);
|
||||||
chunkProvider.id2ChunkMap.add(pos, mcChunk);
|
chunkServer.id2ChunkMap.add(pos, mcChunk);
|
||||||
chunkProvider.loadedChunks.add(mcChunk);
|
chunkServer.loadedChunks.add(mcChunk);
|
||||||
if (mcChunk != null) {
|
if (mcChunk != null) {
|
||||||
mcChunk.onChunkLoad();
|
mcChunk.onChunkLoad();
|
||||||
mcChunk.populateChunk(chunkProvider, chunkProvider, loc.x, loc.z);
|
mcChunk.populateChunk(chunkProvider, chunkProvider, loc.x, loc.z);
|
||||||
|
System.out.println("WORKED?");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PS.debug("CHUNK IS NULL!?");
|
||||||
}
|
}
|
||||||
} catch (Throwable e){
|
} catch (Throwable e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -3,6 +3,9 @@ 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.plotsquared.general.commands.Command;
|
||||||
import com.plotsquared.sponge.SpongeMain;
|
import com.plotsquared.sponge.SpongeMain;
|
||||||
import org.spongepowered.api.command.CommandCallable;
|
import org.spongepowered.api.command.CommandCallable;
|
||||||
import org.spongepowered.api.command.CommandException;
|
import org.spongepowered.api.command.CommandException;
|
||||||
@ -11,11 +14,7 @@ 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.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class SpongeCommand implements CommandCallable {
|
public class SpongeCommand implements CommandCallable {
|
||||||
|
|
||||||
@ -38,9 +37,42 @@ public class SpongeCommand implements CommandCallable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getSuggestions(final CommandSource cmd, final String string) throws CommandException {
|
public List<String> getSuggestions(final CommandSource source, final String string) throws CommandException {
|
||||||
// TODO Auto-generated method stub
|
if (!(source instanceof Player)) {
|
||||||
return new ArrayList<>(Collections.singletonList("TEST"));
|
return null;
|
||||||
|
}
|
||||||
|
final PlotPlayer player = SpongeUtil.getPlayer((Player) source);
|
||||||
|
String[] split = string.split(" ");
|
||||||
|
if (split.length < 2) {
|
||||||
|
return Collections.singletonList("plots");
|
||||||
|
}
|
||||||
|
if (split.length > 2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final Set<String> tabOptions = new HashSet<>();
|
||||||
|
final String arg = split[1].toLowerCase();
|
||||||
|
ArrayList<String> labels = new ArrayList<>();
|
||||||
|
for (final Command<PlotPlayer> cmd : MainCommand.getInstance().getCommands()) {
|
||||||
|
final String label = cmd.getCommand();
|
||||||
|
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();
|
||||||
|
tabOptions.add(best);
|
||||||
|
if (!tabOptions.isEmpty()) {
|
||||||
|
return new ArrayList<>(tabOptions);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -206,16 +206,19 @@ public class SpongeUtil extends WorldUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static World lastWorld;
|
private static World lastWorld;
|
||||||
|
private static String last;
|
||||||
|
|
||||||
public static World getWorld(final String world) {
|
public static World getWorld(final String world) {
|
||||||
if (world.equals(lastWorld.getName())) {
|
if (StringMan.isEqual(world, last)) {
|
||||||
return lastWorld;
|
return lastWorld;
|
||||||
}
|
}
|
||||||
final Optional<World> optional = Sponge.getServer().getWorld(world);
|
final Optional<World> optional = Sponge.getServer().getWorld(world);
|
||||||
if (!optional.isPresent()) {
|
if (!optional.isPresent()) {
|
||||||
return null;
|
last = null;
|
||||||
|
return lastWorld = null;
|
||||||
}
|
}
|
||||||
return optional.get();
|
last = world;
|
||||||
|
return lastWorld = optional.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removePlayer(final String player) {
|
public static void removePlayer(final String player) {
|
||||||
|
Loading…
Reference in New Issue
Block a user