mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-29 16:46:45 +01:00
Merge branch 'master' of https://github.com/IntellectualSites/PlotSquared
This commit is contained in:
commit
882394987b
@ -1,15 +1,31 @@
|
|||||||
package com.plotsquared.sponge.listener;
|
package com.plotsquared.sponge.listener;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import com.flowpowered.math.vector.Vector3d;
|
||||||
import java.util.HashSet;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import java.util.List;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import java.util.Map.Entry;
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
import java.util.Objects;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import java.util.Optional;
|
import com.intellectualcrafters.plot.flag.Flag;
|
||||||
import java.util.UUID;
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import java.util.function.Predicate;
|
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.BlockSnapshot;
|
||||||
import org.spongepowered.api.block.BlockState;
|
import org.spongepowered.api.block.BlockState;
|
||||||
import org.spongepowered.api.data.Transaction;
|
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.World;
|
||||||
import org.spongepowered.api.world.extent.Extent;
|
import org.spongepowered.api.world.extent.Extent;
|
||||||
|
|
||||||
import com.flowpowered.math.vector.Vector3d;
|
import java.util.ArrayList;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import java.util.HashSet;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import java.util.List;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import java.util.Map.Entry;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import java.util.Objects;
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
import java.util.Optional;
|
||||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
import java.util.UUID;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import java.util.function.Predicate;
|
||||||
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;
|
|
||||||
|
|
||||||
public class MainListener {
|
public class MainListener {
|
||||||
|
|
||||||
@ -107,7 +106,7 @@ public class MainListener {
|
|||||||
if (Settings.USE_PLOTME_ALIAS) {
|
if (Settings.USE_PLOTME_ALIAS) {
|
||||||
SpongeMain.THIS.getGame().getCommandManager().process(source, ("plots " + event.getArguments()).trim());
|
SpongeMain.THIS.getGame().getCommandManager().process(source, ("plots " + event.getArguments()).trim());
|
||||||
} else {
|
} else {
|
||||||
source.sendMessage(SpongeUtil.text(C.NOT_USING_PLOTME.s()));
|
source.sendMessage(Text.of(C.NOT_USING_PLOTME.s()));
|
||||||
}
|
}
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -655,9 +654,6 @@ public class MainListener {
|
|||||||
@Listener
|
@Listener
|
||||||
public void onConnect(final ClientConnectionEvent.Login event) {
|
public void onConnect(final ClientConnectionEvent.Login event) {
|
||||||
GameProfile profile = event.getProfile();
|
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))) {
|
if (profile.getName().equals("PlotSquared") || profile.getUniqueId().equals(DBFunc.everyone) || DBFunc.everyone.equals(UUIDHandler.getUUID(profile.getName(), null))) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package com.plotsquared.sponge.util;
|
package com.plotsquared.sponge.util;
|
||||||
|
|
||||||
import java.util.Optional;
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||||
import java.util.Set;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import java.util.function.Predicate;
|
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.Entity;
|
||||||
import org.spongepowered.api.entity.living.Living;
|
import org.spongepowered.api.entity.living.Living;
|
||||||
import org.spongepowered.api.entity.living.animal.Animal;
|
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.Chunk;
|
||||||
import org.spongepowered.api.world.World;
|
import org.spongepowered.api.world.World;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
import java.util.Optional;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import java.util.Set;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import java.util.function.Predicate;
|
||||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
|
||||||
|
|
||||||
public class SpongeChunkManager extends ChunkManager {
|
public class SpongeChunkManager extends ChunkManager {
|
||||||
|
|
||||||
@ -31,29 +30,26 @@ public class SpongeChunkManager extends ChunkManager {
|
|||||||
final int tx = pos2.getX();
|
final int tx = pos2.getX();
|
||||||
final int tz = pos2.getZ();
|
final int tz = pos2.getZ();
|
||||||
final int[] count = new int[6];
|
final int[] count = new int[6];
|
||||||
world.getEntities(new Predicate<Entity>() {
|
world.getEntities(entity -> {
|
||||||
@Override
|
final org.spongepowered.api.world.Location loc = entity.getLocation();
|
||||||
public boolean test(final Entity entity) {
|
final int x = loc.getBlockX();
|
||||||
final org.spongepowered.api.world.Location loc = entity.getLocation();
|
if ((x >= bx) && (x <= tx)) {
|
||||||
final int x = loc.getBlockX();
|
final int z = loc.getBlockZ();
|
||||||
if ((x >= bx) && (x <= tx)) {
|
if ((z >= bz) && (z <= tz)) {
|
||||||
final int z = loc.getBlockZ();
|
count[0]++;
|
||||||
if ((z >= bz) && (z <= tz)) {
|
if (entity instanceof Living) {
|
||||||
count[0]++;
|
count[3]++;
|
||||||
if (entity instanceof Living) {
|
if (entity instanceof Animal) {
|
||||||
count[3]++;
|
count[1]++;
|
||||||
if (entity instanceof Animal) {
|
} else if (entity instanceof Monster) {
|
||||||
count[1]++;
|
count[2]++;
|
||||||
} else if (entity instanceof Monster) {
|
|
||||||
count[2]++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
count[4]++;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
count[4]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
|
@ -1,32 +1,5 @@
|
|||||||
package com.plotsquared.sponge.util;
|
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.Vector3d;
|
||||||
import com.flowpowered.math.vector.Vector3i;
|
import com.flowpowered.math.vector.Vector3i;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
@ -43,6 +16,36 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
|||||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
import com.intellectualcrafters.plot.util.WorldUtil;
|
||||||
import com.plotsquared.sponge.SpongeMain;
|
import com.plotsquared.sponge.SpongeMain;
|
||||||
import com.plotsquared.sponge.object.SpongePlayer;
|
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 {
|
public class SpongeUtil extends WorldUtil {
|
||||||
|
|
||||||
@ -99,14 +102,7 @@ public class SpongeUtil extends WorldUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static BiomeType getBiome(int index) {
|
public static BiomeType getBiome(int index) {
|
||||||
if (biomes == null) {
|
return (BiomeType) BiomeGenBase.getBiome(index);
|
||||||
initBiomeCache();
|
|
||||||
}
|
|
||||||
return biomes[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Text text(String m) {
|
|
||||||
return Text.of(m);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Translation getTranslation(final String m) {
|
public static Translation getTranslation(final String m) {
|
||||||
@ -161,10 +157,7 @@ public class SpongeUtil extends WorldUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static BlockState getBlockState(int id, int data) {
|
public static BlockState getBlockState(int id, int data) {
|
||||||
if (stateArray == null) {
|
return (BlockState) Block.getBlockById(id).getStateFromMeta(data);
|
||||||
initBlockCache();
|
|
||||||
}
|
|
||||||
return stateArray[id + (data << 12)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlotBlock getPlotBlock(BlockState state) {
|
public static PlotBlock getPlotBlock(BlockState state) {
|
||||||
@ -213,10 +206,9 @@ 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 == last) {
|
if (world.equals(lastWorld.getName())) {
|
||||||
return lastWorld;
|
return lastWorld;
|
||||||
}
|
}
|
||||||
final Optional<World> optional = Sponge.getServer().getWorld(world);
|
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) {
|
public static String getWorldName(final org.spongepowered.api.world.Location origin) {
|
||||||
final Extent extent = origin.getExtent();
|
final Extent extent = origin.getExtent();
|
||||||
if (extent == lastWorld) {
|
if (extent == lastWorld) {
|
||||||
return last;
|
return lastWorld.getName();
|
||||||
}
|
}
|
||||||
if (extent instanceof World) {
|
if (extent instanceof World) {
|
||||||
lastWorld = (World) extent;
|
lastWorld = (World) extent;
|
||||||
last = ((World) extent).getName();
|
return lastWorld.getName();
|
||||||
return last;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -267,9 +258,12 @@ public class SpongeUtil extends WorldUtil {
|
|||||||
@Override
|
@Override
|
||||||
public boolean isBlockSolid(final PlotBlock block) {
|
public boolean isBlockSolid(final PlotBlock block) {
|
||||||
final BlockState state = SpongeUtil.getBlockState(block.id, block.data);
|
final BlockState state = SpongeUtil.getBlockState(block.id, block.data);
|
||||||
final BlockType type = state.getType();
|
Optional<SolidCubeProperty> property = state.getType().getProperty(SolidCubeProperty.class);
|
||||||
// TODO check if solid;
|
if (property.isPresent()) {
|
||||||
return true;
|
return property.get().getValue();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -290,13 +284,14 @@ public class SpongeUtil extends WorldUtil {
|
|||||||
id = Short.parseShort(split[0]);
|
id = Short.parseShort(split[0]);
|
||||||
match = 0;
|
match = 0;
|
||||||
} else {
|
} else {
|
||||||
List<BlockType> types = ReflectionUtils.<BlockType> getStaticFields(BlockTypes.class);
|
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 =
|
||||||
@Override
|
new StringComparison<BlockType>(name, types.toArray(new BlockType[types.size()])) {
|
||||||
public String getString(final BlockType type) {
|
@Override
|
||||||
return type.getId();
|
public String getString(final BlockType type) {
|
||||||
};
|
return type.getId();
|
||||||
}.getBestMatchAdvanced();
|
}
|
||||||
|
}.getBestMatchAdvanced();
|
||||||
match = comparison.match;
|
match = comparison.match;
|
||||||
id = SpongeUtil.getPlotBlock(comparison.best.getDefaultState()).id;
|
id = SpongeUtil.getPlotBlock(comparison.best.getDefaultState()).id;
|
||||||
}
|
}
|
||||||
@ -304,7 +299,8 @@ public class SpongeUtil extends WorldUtil {
|
|||||||
final StringComparison<PlotBlock> outer = new StringComparison<PlotBlock>();
|
final StringComparison<PlotBlock> outer = new StringComparison<PlotBlock>();
|
||||||
return outer.new ComparisonResult(match, block);
|
return outer.new ComparisonResult(match, block);
|
||||||
|
|
||||||
} catch (final Exception e) {}
|
} catch (NumberFormatException e) {
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,7 +364,7 @@ public class SpongeUtil extends WorldUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Sign sign = (Sign) tile;
|
final Sign sign = (Sign) tile;
|
||||||
final Optional<SignData> optional = sign.getOrCreate(SignData.class);
|
final Optional<SignData> optional = sign.get(SignData.class);
|
||||||
if (!optional.isPresent()) {
|
if (!optional.isPresent()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -398,7 +394,7 @@ public class SpongeUtil extends WorldUtil {
|
|||||||
}
|
}
|
||||||
for (int y = 255; y > 0; y--) {
|
for (int y = 255; y > 0; y--) {
|
||||||
final BlockState block = world.getBlock(x, y, z);
|
final BlockState block = world.getBlock(x, y, z);
|
||||||
if ((block != null) && (block.getType() != BlockTypes.AIR)) {
|
if (block.getType() != BlockTypes.AIR) {
|
||||||
return y + 1;
|
return y + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -422,19 +418,7 @@ public class SpongeUtil extends WorldUtil {
|
|||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
text.add(Text.of(lines[i]));
|
text.add(Text.of(lines[i]));
|
||||||
}
|
}
|
||||||
try {
|
sign.offer(Keys.SIGN_LINES, text);
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user