Permalink
Browse files

Update the Bukkit adapter to the Spigot API Preview

  • Loading branch information...
me4502 committed Jul 12, 2018
1 parent c3b4dcf commit 350d81d1113dfdcea8df254bed2474ef394b91a0
Showing with 139 additions and 650 deletions.
  1. +2 −2 worldedit-bukkit/build.gradle
  2. +1 −1 worldedit-bukkit/src/main/java/com/sk89q/bukkit/util/CommandRegistration.java
  3. +2 −2 worldedit-bukkit/src/main/java/com/sk89q/bukkit/util/CommandsManagerRegistration.java
  4. +7 −7 worldedit-bukkit/src/main/java/com/sk89q/wepif/ConfigurationPermissionsResolver.java
  5. +2 −2 worldedit-bukkit/src/main/java/com/sk89q/wepif/DinnerPermsResolver.java
  6. +7 −7 worldedit-bukkit/src/main/java/com/sk89q/wepif/FlatFilePermissionsResolver.java
  7. +1 −1 worldedit-bukkit/src/main/java/com/sk89q/wepif/NijiPermissionsResolver.java
  8. +8 −8 worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsProvider.java
  9. +2 −2 worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsResolver.java
  10. +3 −3 worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java
  11. +1 −1 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityType.java
  12. +3 −3 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java
  13. +7 −5 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java
  14. +3 −3 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java
  15. +24 −11 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java
  16. +9 −13 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
  17. +45 −48 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java
  18. +1 −70 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java
  19. +1 −1 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java
  20. +0 −70 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java
  21. +0 −79 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/CylinderSelection.java
  22. +0 −62 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java
  23. +0 −118 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/RegionSelection.java
  24. +0 −113 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/selections/Selection.java
  25. +2 −7 worldedit-bukkit/src/test/java/com/sk89q/wepif/TestOfflinePermissible.java
  26. +3 −4 worldedit-bukkit/src/test/java/com/sk89q/worldedit/bukkit/BukkitWorldTest.java
  27. +3 −5 worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java
  28. +1 −1 worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java
  29. +1 −1 worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/CUIChannelHandler.java
@@ -10,8 +10,8 @@ repositories {
dependencies {
compile project(':worldedit-core')
compile 'com.sk89q:dummypermscompat:1.8'
// compile 'org.bukkit:bukkit:18w15a-R0.1-SNAPSHOT' // zzz
compile 'org.bukkit:bukkit:1.9.4-R0.1-SNAPSHOT' // zzz
compile 'org.bukkit:bukkit:1.13-pre5-R0.1-SNAPSHOT' // zzz
// compile 'org.bukkit:bukkit:1.9.4-R0.1-SNAPSHOT' // zzz
testCompile 'org.mockito:mockito-core:1.9.0-rc1'
}
@@ -82,7 +82,7 @@ public CommandMap getCommandMap() {
public boolean unregisterCommands() {
CommandMap commandMap = getCommandMap();
List<String> toRemove = new ArrayList<String>();
List<String> toRemove = new ArrayList<>();
Map<String, org.bukkit.command.Command> knownCommands = ReflectionUtil.getField(commandMap, "knownCommands");
Set<String> aliases = ReflectionUtil.getField(commandMap, "aliases");
if (knownCommands == null || aliases == null) {
@@ -50,7 +50,7 @@ public boolean register(Class<?> clazz) {
}
public boolean registerAll(List<Command> registered) {
List<CommandInfo> toRegister = new ArrayList<CommandInfo>();
List<CommandInfo> toRegister = new ArrayList<>();
for (Command command : registered) {
List<String> permissions = null;
Method cmdMethod = commands.getMethods().get(null).get(command.aliases()[0]);
@@ -59,7 +59,7 @@ public boolean registerAll(List<Command> registered) {
if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) {
permissions = Arrays.asList(cmdMethod.getAnnotation(CommandPermissions.class).value());
} else if (cmdMethod != null && childMethods != null && !childMethods.isEmpty()) {
permissions = new ArrayList<String>();
permissions = new ArrayList<>();
for (Method m : childMethods.values()) {
if (m.isAnnotationPresent(CommandPermissions.class)) {
permissions.addAll(Arrays.asList(m.getAnnotation(CommandPermissions.class).value()));
@@ -52,11 +52,11 @@ public static YAMLNode generateDefaultPerms(YAMLNode section) {
@Override
public void load() {
userGroups = new HashMap<String, Set<String>>();
userPermissionsCache = new HashMap<String, Set<String>>();
defaultPermissionsCache = new HashSet<String>();
userGroups = new HashMap<>();
userPermissionsCache = new HashMap<>();
defaultPermissionsCache = new HashSet<>();
Map<String, Set<String>> userGroupPermissions = new HashMap<String, Set<String>>();
Map<String, Set<String>> userGroupPermissions = new HashMap<>();
List<String> groupKeys = config.getStringList("permissions.groups", null);
@@ -66,7 +66,7 @@ public void load() {
config.getStringList("permissions.groups." + key + ".permissions", null);
if (!permissions.isEmpty()) {
Set<String> groupPerms = new HashSet<String>(permissions);
Set<String> groupPerms = new HashSet<>(permissions);
userGroupPermissions.put(key, groupPerms);
if (key.equals("default")) {
@@ -80,7 +80,7 @@ public void load() {
if (userKeys != null) {
for (String key : userKeys) {
Set<String> permsCache = new HashSet<String>();
Set<String> permsCache = new HashSet<>();
List<String> permissions =
config.getStringList("permissions.users." + key + ".permissions", null);
@@ -103,7 +103,7 @@ public void load() {
}
userPermissionsCache.put(key.toLowerCase(), permsCache);
userGroups.put(key.toLowerCase(), new HashSet<String>(groups));
userGroups.put(key.toLowerCase(), new HashSet<>(groups));
}
}
}
@@ -114,13 +114,13 @@ public boolean inGroup(OfflinePlayer player, String group) {
if (perms == null) {
return new String[0];
}
List<String> groupNames = new ArrayList<String>();
List<String> groupNames = new ArrayList<>();
for (PermissionAttachmentInfo permAttach : perms.getEffectivePermissions()) {
String perm = permAttach.getPermission();
if (!(perm.startsWith(GROUP_PREFIX) && permAttach.getValue())) {
continue;
}
groupNames.add(perm.substring(GROUP_PREFIX.length(), perm.length()));
groupNames.add(perm.substring(GROUP_PREFIX.length()));
}
return groupNames.toArray(new String[groupNames.size()]);
}
@@ -67,7 +67,7 @@ public FlatFilePermissionsResolver(File groupFile, File userFile) {
}
public Map<String, Set<String>> loadGroupPermissions() {
Map<String, Set<String>> userGroupPermissions = new HashMap<String, Set<String>>();
Map<String, Set<String>> userGroupPermissions = new HashMap<>();
BufferedReader buff = null;
@@ -93,7 +93,7 @@ public FlatFilePermissionsResolver(File groupFile, File userFile) {
if (parts.length > 1) {
String[] perms = parts[1].split(",");
Set<String> groupPerms = new HashSet<String>(Arrays.asList(perms));
Set<String> groupPerms = new HashSet<>(Arrays.asList(perms));
userGroupPermissions.put(key, groupPerms);
}
}
@@ -113,9 +113,9 @@ public FlatFilePermissionsResolver(File groupFile, File userFile) {
@Override
public void load() {
userGroups = new HashMap<String, Set<String>>();
userPermissionsCache = new HashMap<String, Set<String>>();
defaultPermissionsCache = new HashSet<String>();
userGroups = new HashMap<>();
userPermissionsCache = new HashMap<>();
defaultPermissionsCache = new HashSet<>();
Map<String, Set<String>> userGroupPermissions = loadGroupPermissions();
@@ -131,7 +131,7 @@ public void load() {
String line;
while ((line = buff.readLine()) != null) {
Set<String> permsCache = new HashSet<String>();
Set<String> permsCache = new HashSet<>();
line = line.trim();
@@ -160,7 +160,7 @@ public void load() {
}
userPermissionsCache.put(key.toLowerCase(), permsCache);
userGroups.put(key.toLowerCase(), new HashSet<String>(Arrays.asList(groups)));
userGroups.put(key.toLowerCase(), new HashSet<>(Arrays.asList(groups)));
}
}
} catch (IOException e) {
@@ -50,7 +50,7 @@ public static PermissionsResolver factory(Server server, YAMLProcessor config) {
Plugin plugin = pluginManager.getPlugin("Permissions");
// Check if plugin is loaded and has Permissions interface
if (plugin == null || !(plugin instanceof Permissions)) {
if (!(plugin instanceof Permissions)) {
return null;
}
@@ -22,19 +22,19 @@
import org.bukkit.OfflinePlayer;
public interface PermissionsProvider {
public boolean hasPermission(String name, String permission);
boolean hasPermission(String name, String permission);
public boolean hasPermission(String worldName, String name, String permission);
boolean hasPermission(String worldName, String name, String permission);
public boolean inGroup(String player, String group);
boolean inGroup(String player, String group);
public String[] getGroups(String player);
String[] getGroups(String player);
public boolean hasPermission(OfflinePlayer player, String permission);
boolean hasPermission(OfflinePlayer player, String permission);
public boolean hasPermission(String worldName, OfflinePlayer player, String permission);
boolean hasPermission(String worldName, OfflinePlayer player, String permission);
public boolean inGroup(OfflinePlayer player, String group);
boolean inGroup(OfflinePlayer player, String group);
public String[] getGroups(OfflinePlayer player);
String[] getGroups(OfflinePlayer player);
}
@@ -20,7 +20,7 @@
package com.sk89q.wepif;
public interface PermissionsResolver extends PermissionsProvider {
public void load();
void load();
public String getDetectionMessage();
String getDetectionMessage();
}
@@ -86,7 +86,7 @@ public static PermissionsResolverManager getInstance() {
private PermissionsResolver permissionResolver;
private YAMLProcessor config;
private Logger logger = Logger.getLogger(getClass().getCanonicalName());
private List<Class<? extends PermissionsResolver>> enabledResolvers = new ArrayList<Class<? extends PermissionsResolver>>();
private List<Class<? extends PermissionsResolver>> enabledResolvers = new ArrayList<>();
@SuppressWarnings("unchecked")
protected Class<? extends PermissionsResolver>[] availableResolvers = new Class[] {
@@ -213,15 +213,15 @@ private boolean loadConfig(File file) {
if (!keys.contains("resolvers")) {
//List<String> resolverKeys = config.getKeys("resolvers");
List<String> resolvers = new ArrayList<String>();
List<String> resolvers = new ArrayList<>();
for (Class<?> clazz : availableResolvers) {
resolvers.add(clazz.getSimpleName());
}
enabledResolvers.addAll(Arrays.asList(availableResolvers));
config.setProperty("resolvers.enabled", resolvers);
isUpdated = true;
} else {
List<String> disabledResolvers = config.getStringList("resolvers.disabled", new ArrayList<String>());
List<String> disabledResolvers = config.getStringList("resolvers.disabled", new ArrayList<>());
List<String> stagedEnabled = config.getStringList("resolvers.enabled", null);
for (Iterator<String> i = stagedEnabled.iterator(); i.hasNext();) {
String nextName = i.next();
@@ -138,7 +138,7 @@ public boolean isTamed() {
@Override
public boolean isTagged() {
return entity instanceof LivingEntity && ((LivingEntity) entity).getCustomName() != null;
return entity instanceof LivingEntity && entity.getCustomName() != null;
}
@Override
@@ -69,7 +69,7 @@ public BaseBlock getBlockInHand(HandSide handSide) throws WorldEditException {
ItemStack itemStack = handSide == HandSide.MAIN_HAND
? player.getInventory().getItemInMainHand()
: player.getInventory().getItemInOffHand();
return BukkitUtil.toBlock(itemStack);
return new BaseBlock(BukkitUtil.toBlock(itemStack));
}
@Override
@@ -79,7 +79,7 @@ public String getName() {
@Override
public void giveItem(BaseItemStack itemStack) {
player.getInventory().addItem(new ItemStack(itemStack.getLegacyId(), itemStack.getAmount()));
player.getInventory().addItem(BukkitUtil.toItemStack(itemStack));
}
@Override
@@ -223,7 +223,7 @@ public boolean isActive() {
// CopyOnWrite list for the list of players, but the Bukkit
// specification doesn't require thread safety (though the
// spec is extremely incomplete)
return Bukkit.getServer().getPlayerExact(name) != null;
return Bukkit.getServer().getPlayer(uuid) != null;
}
@Override
@@ -19,6 +19,7 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.extent.inventory.BlockBag;
@@ -78,8 +79,7 @@ public void fetchBlock(BlockState blockState) throws BlockBagException {
continue;
}
if (bukkitItem.getTypeId() != blockState.getBlockType().getLegacyId()) {
// TODO Fix when bukkit gets not awful
if (!bukkitItem.getType().getKey().toString().equals(blockState.getBlockType().getId())) {
// Type id doesn't fit
continue;
}
@@ -111,6 +111,9 @@ public void storeBlock(BlockState blockState, int amount) throws BlockBagExcepti
if (blockState.getBlockType() == BlockTypes.AIR) {
throw new IllegalArgumentException("Can't store air block");
}
if (!blockState.getBlockType().hasItemType()) {
throw new IllegalArgumentException("This block cannot be stored");
}
loadInventory();
@@ -129,8 +132,7 @@ public void storeBlock(BlockState blockState, int amount) throws BlockBagExcepti
continue;
}
if (bukkitItem.getTypeId() != blockState.getBlockType().getLegacyId()) {
// TODO Fix when bukkit gets not terrible
if (!bukkitItem.getType().getKey().toString().equals(blockState.getBlockType().getId())) {
// Type id doesn't fit
continue;
}
@@ -156,7 +158,7 @@ public void storeBlock(BlockState blockState, int amount) throws BlockBagExcepti
}
if (freeSlot > -1) {
items[freeSlot] = new ItemStack(blockState.getBlockType().getLegacyId(), amount); // TODO Ditto
items[freeSlot] = new ItemStack(BukkitUtil.toItemStack(new BaseItemStack(blockState.getBlockType().getItemType(), amount)));
return;
}
@@ -117,7 +117,7 @@ public BukkitWorld matchWorld(com.sk89q.worldedit.world.World world) {
@Override
public void registerCommands(Dispatcher dispatcher) {
List<CommandInfo> toRegister = new ArrayList<CommandInfo>();
List<CommandInfo> toRegister = new ArrayList<>();
BukkitCommandInspector inspector = new BukkitCommandInspector(plugin, dispatcher);
for (CommandMapping command : dispatcher.getCommands()) {
@@ -159,7 +159,7 @@ public String getPlatformVersion() {
@Override
public Map<Capability, Preference> getCapabilities() {
Map<Capability, Preference> capabilities = new EnumMap<Capability, Preference>(Capability.class);
Map<Capability, Preference> capabilities = new EnumMap<>(Capability.class);
capabilities.put(Capability.CONFIGURATION, Preference.NORMAL);
capabilities.put(Capability.WORLDEDIT_CUI, Preference.NORMAL);
capabilities.put(Capability.GAME_HOOKS, Preference.PREFERRED);
@@ -175,7 +175,7 @@ public void unregisterCommands() {
@Override
public Collection<Actor> getConnectedUsers() {
List<Actor> users = new ArrayList<Actor>();
List<Actor> users = new ArrayList<>();
for (org.bukkit.entity.Player player : Bukkit.getServer().getOnlinePlayers()) {
users.add(new BukkitPlayer(plugin, player));
}
@@ -22,17 +22,19 @@
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemTypes;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -121,17 +123,28 @@ public static World toWorld(final Extent world) {
return ((BukkitWorld) world).getWorld();
}
public static BaseBlock toBlock(ItemStack itemStack) throws WorldEditException {
ItemType itemType = LegacyMapper.getInstance().getItemFromLegacy(itemStack.getTypeId(), itemStack.getData().getData());
if (itemType.hasBlockType()) {
return new BaseBlock(itemType.getBlockType().getDefaultState());
public static BlockState toBlock(BlockData blockData) {
return null; // TODO BLOCKING
}
public static BlockData toBlock(BlockStateHolder block) {
return Bukkit.createBlockData(block.toString()); // TODO BLOCKING
}
public static BlockState toBlock(ItemStack itemStack) throws WorldEditException {
if (itemStack.getType().isBlock()) {
return toBlock(itemStack.getType().createBlockData());
} else {
return new BaseBlock(BlockTypes.AIR.getDefaultState());
return BlockTypes.AIR.getDefaultState();
}
}
public static BaseItemStack toBaseItemStack(ItemStack itemStack) {
ItemType itemType = LegacyMapper.getInstance().getItemFromLegacy(itemStack.getTypeId(), itemStack.getData().getData());
return new BaseItemStack(itemType, itemStack.getAmount());
return new BaseItemStack(ItemTypes.get(itemStack.getType().getKey().toString()), itemStack.getAmount());
}
public static ItemStack toItemStack(BaseItemStack item) {
BlockData blockData = Bukkit.createBlockData(item.getType().getId());
return new ItemStack(blockData.getMaterial(), item.getAmount());
}
}
Oops, something went wrong.

0 comments on commit 350d81d

Please sign in to comment.