This commit is contained in:
Jesse Boyd 2016-02-24 03:08:12 +11:00
commit 882394987b
3 changed files with 119 additions and 143 deletions

View File

@ -1,15 +1,31 @@
package com.plotsquared.sponge.listener;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Predicate;
import com.flowpowered.math.vector.Vector3d;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.listener.PlotListener;
import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.object.SpongePlayer;
import com.plotsquared.sponge.util.SpongeUtil;
import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.data.Transaction;
@ -42,32 +58,15 @@ import org.spongepowered.api.text.Text;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.extent.Extent;
import com.flowpowered.math.vector.Vector3d;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.listener.PlotListener;
import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.object.SpongePlayer;
import com.plotsquared.sponge.util.SpongeUtil;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Predicate;
public class MainListener {
@ -107,7 +106,7 @@ public class MainListener {
if (Settings.USE_PLOTME_ALIAS) {
SpongeMain.THIS.getGame().getCommandManager().process(source, ("plots " + event.getArguments()).trim());
} else {
source.sendMessage(SpongeUtil.text(C.NOT_USING_PLOTME.s()));
source.sendMessage(Text.of(C.NOT_USING_PLOTME.s()));
}
event.setCancelled(true);
}
@ -655,9 +654,6 @@ public class MainListener {
@Listener
public void onConnect(final ClientConnectionEvent.Login event) {
GameProfile profile = event.getProfile();
if (profile == null) {
return;
}
if (profile.getName().equals("PlotSquared") || profile.getUniqueId().equals(DBFunc.everyone) || DBFunc.everyone.equals(UUIDHandler.getUUID(profile.getName(), null))) {
event.setCancelled(true);
}

View File

@ -1,9 +1,10 @@
package com.plotsquared.sponge.util;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.TaskManager;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.living.Living;
import org.spongepowered.api.entity.living.animal.Animal;
@ -11,11 +12,9 @@ import org.spongepowered.api.entity.living.monster.Monster;
import org.spongepowered.api.world.Chunk;
import org.spongepowered.api.world.World;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.TaskManager;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
public class SpongeChunkManager extends ChunkManager {
@ -31,9 +30,7 @@ public class SpongeChunkManager extends ChunkManager {
final int tx = pos2.getX();
final int tz = pos2.getZ();
final int[] count = new int[6];
world.getEntities(new Predicate<Entity>() {
@Override
public boolean test(final Entity entity) {
world.getEntities(entity -> {
final org.spongepowered.api.world.Location loc = entity.getLocation();
final int x = loc.getBlockX();
if ((x >= bx) && (x <= tx)) {
@ -53,7 +50,6 @@ public class SpongeChunkManager extends ChunkManager {
}
}
return false;
}
});
return count;

View File

@ -1,32 +1,5 @@
package com.plotsquared.sponge.util;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.block.BlockType;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.block.tileentity.Sign;
import org.spongepowered.api.block.tileentity.TileEntity;
import org.spongepowered.api.data.manipulator.mutable.tileentity.SignData;
import org.spongepowered.api.data.value.mutable.ListValue;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.translation.Translatable;
import org.spongepowered.api.text.translation.Translation;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.biome.BiomeType;
import org.spongepowered.api.world.biome.BiomeTypes;
import org.spongepowered.api.world.extent.Extent;
import com.flowpowered.math.vector.Vector3d;
import com.flowpowered.math.vector.Vector3i;
import com.intellectualcrafters.plot.PS;
@ -43,6 +16,36 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.object.SpongePlayer;
import net.minecraft.block.Block;
import net.minecraft.world.biome.BiomeGenBase;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.block.BlockType;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.block.tileentity.Sign;
import org.spongepowered.api.block.tileentity.TileEntity;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.manipulator.mutable.tileentity.SignData;
import org.spongepowered.api.data.property.block.SolidCubeProperty;
import org.spongepowered.api.data.value.mutable.ListValue;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.translation.Translatable;
import org.spongepowered.api.text.translation.Translation;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.biome.BiomeType;
import org.spongepowered.api.world.biome.BiomeTypes;
import org.spongepowered.api.world.extent.Extent;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
public class SpongeUtil extends WorldUtil {
@ -99,14 +102,7 @@ public class SpongeUtil extends WorldUtil {
}
public static BiomeType getBiome(int index) {
if (biomes == null) {
initBiomeCache();
}
return biomes[index];
}
public static Text text(String m) {
return Text.of(m);
return (BiomeType) BiomeGenBase.getBiome(index);
}
public static Translation getTranslation(final String m) {
@ -161,10 +157,7 @@ public class SpongeUtil extends WorldUtil {
}
public static BlockState getBlockState(int id, int data) {
if (stateArray == null) {
initBlockCache();
}
return stateArray[id + (data << 12)];
return (BlockState) Block.getBlockById(id).getStateFromMeta(data);
}
public static PlotBlock getPlotBlock(BlockState state) {
@ -213,10 +206,9 @@ public class SpongeUtil extends WorldUtil {
}
private static World lastWorld;
private static String last;
public static World getWorld(final String world) {
if (world == last) {
if (world.equals(lastWorld.getName())) {
return lastWorld;
}
final Optional<World> optional = Sponge.getServer().getWorld(world);
@ -238,12 +230,11 @@ public class SpongeUtil extends WorldUtil {
public static String getWorldName(final org.spongepowered.api.world.Location origin) {
final Extent extent = origin.getExtent();
if (extent == lastWorld) {
return last;
return lastWorld.getName();
}
if (extent instanceof World) {
lastWorld = (World) extent;
last = ((World) extent).getName();
return last;
return lastWorld.getName();
}
return null;
}
@ -267,9 +258,12 @@ public class SpongeUtil extends WorldUtil {
@Override
public boolean isBlockSolid(final PlotBlock block) {
final BlockState state = SpongeUtil.getBlockState(block.id, block.data);
final BlockType type = state.getType();
// TODO check if solid;
return true;
Optional<SolidCubeProperty> property = state.getType().getProperty(SolidCubeProperty.class);
if (property.isPresent()) {
return property.get().getValue();
} else {
return false;
}
}
@Override
@ -291,11 +285,12 @@ public class SpongeUtil extends WorldUtil {
match = 0;
} else {
List<BlockType> types = ReflectionUtils.<BlockType>getStaticFields(BlockTypes.class);
final StringComparison<BlockType>.ComparisonResult comparison = new StringComparison<BlockType>(name, types.toArray(new BlockType[types.size()])) {
final StringComparison<BlockType>.ComparisonResult comparison =
new StringComparison<BlockType>(name, types.toArray(new BlockType[types.size()])) {
@Override
public String getString(final BlockType type) {
return type.getId();
};
}
}.getBestMatchAdvanced();
match = comparison.match;
id = SpongeUtil.getPlotBlock(comparison.best.getDefaultState()).id;
@ -304,7 +299,8 @@ public class SpongeUtil extends WorldUtil {
final StringComparison<PlotBlock> outer = new StringComparison<PlotBlock>();
return outer.new ComparisonResult(match, block);
} catch (final Exception e) {}
} catch (NumberFormatException e) {
}
return null;
}
@ -368,7 +364,7 @@ public class SpongeUtil extends WorldUtil {
return null;
}
final Sign sign = (Sign) tile;
final Optional<SignData> optional = sign.getOrCreate(SignData.class);
final Optional<SignData> optional = sign.get(SignData.class);
if (!optional.isPresent()) {
return null;
}
@ -398,7 +394,7 @@ public class SpongeUtil extends WorldUtil {
}
for (int y = 255; y > 0; y--) {
final BlockState block = world.getBlock(x, y, z);
if ((block != null) && (block.getType() != BlockTypes.AIR)) {
if (block.getType() != BlockTypes.AIR) {
return y + 1;
}
}
@ -422,19 +418,7 @@ public class SpongeUtil extends WorldUtil {
for (int i = 0; i < 4; i++) {
text.add(Text.of(lines[i]));
}
try {
final Optional<SignData> optional = sign.getOrCreate(SignData.class);
if (optional.isPresent()) {
final SignData offering = optional.get();
offering.lines().set(0, Text.of(lines[0]));
offering.lines().set(1, Text.of(lines[1]));
offering.lines().set(2, Text.of(lines[2]));
offering.lines().set(3, Text.of(lines[3]));
sign.offer(offering);
}
} catch (final NullPointerException e) {
e.printStackTrace();
}
sign.offer(Keys.SIGN_LINES, text);
}
@Override