mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-11-04 11:13:45 +01:00 
			
		
		
		
	Updates to docs, code style tweaks, and some code optimizations
This commit is contained in:
		@@ -51,13 +51,6 @@ import com.plotsquared.sponge.util.block.SpongeLocalQueue;
 | 
			
		||||
import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper;
 | 
			
		||||
import com.plotsquared.sponge.uuid.SpongeOnlineUUIDWrapper;
 | 
			
		||||
import com.plotsquared.sponge.uuid.SpongeUUIDHandler;
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.nio.file.Path;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
import org.slf4j.Logger;
 | 
			
		||||
import org.spongepowered.api.Game;
 | 
			
		||||
import org.spongepowered.api.Server;
 | 
			
		||||
@@ -74,6 +67,14 @@ import org.spongepowered.api.world.gen.GenerationPopulator;
 | 
			
		||||
import org.spongepowered.api.world.gen.WorldGenerator;
 | 
			
		||||
import org.spongepowered.api.world.gen.WorldGeneratorModifier;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.nio.file.Path;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
@Plugin(id = "plotsquared", name = "PlotSquared", description = "Easy, yet powerful Plot World generation and management.",
 | 
			
		||||
        url = "https://github.com/IntellectualSites/PlotSquared", version = "3.3.3")
 | 
			
		||||
public class SpongeMain implements IPlotMain {
 | 
			
		||||
@@ -165,6 +166,10 @@ public class SpongeMain implements IPlotMain {
 | 
			
		||||
        return new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), split.length == 3 ? Integer.parseInt(split[2]) : 0};
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override public String getPluginVersionString() {
 | 
			
		||||
        return this.plugin.getVersion().orElse("");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int[] getServerVersion() {
 | 
			
		||||
        PS.log("Checking minecraft version: Sponge: ");
 | 
			
		||||
 
 | 
			
		||||
@@ -443,7 +443,7 @@ public class MainListener {
 | 
			
		||||
    public void onBlockBreak(ChangeBlockEvent.Break event) {
 | 
			
		||||
        Player player = SpongeUtil.getCause(event.getCause(), Player.class);
 | 
			
		||||
        if (player == null) {
 | 
			
		||||
//            SpongeUtil.printCause("break", event.getCause());
 | 
			
		||||
            //SpongeUtil.printCause("break", event.getCause());
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        PlotPlayer pp = SpongeUtil.getPlayer(player);
 | 
			
		||||
@@ -486,36 +486,29 @@ public class MainListener {
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        event.filter(new Predicate<org.spongepowered.api.world.Location<World>>() {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public boolean test(org.spongepowered.api.world.Location<World> l) {
 | 
			
		||||
                Location loc = SpongeUtil.getLocation(worldName, l);
 | 
			
		||||
                Plot plot = loc.getPlot();
 | 
			
		||||
                if (plot == null) {
 | 
			
		||||
                    if (loc.getPlotAbs() == null) {
 | 
			
		||||
                        return true;
 | 
			
		||||
                    }
 | 
			
		||||
                    return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD);
 | 
			
		||||
                }
 | 
			
		||||
                if (!plot.hasOwner()) {
 | 
			
		||||
                    if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
 | 
			
		||||
                        return true;
 | 
			
		||||
                    }
 | 
			
		||||
                    MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_UNOWNED);
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
                if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
 | 
			
		||||
        event.filter(l -> {
 | 
			
		||||
            Location loc1 = SpongeUtil.getLocation(worldName, l);
 | 
			
		||||
            Plot plot1 = loc1.getPlot();
 | 
			
		||||
            if (plot1 == null) {
 | 
			
		||||
                return loc1.getPlotAbs() == null || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD);
 | 
			
		||||
            }
 | 
			
		||||
            if (!plot1.hasOwner()) {
 | 
			
		||||
                if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
 | 
			
		||||
                    return true;
 | 
			
		||||
                } else {
 | 
			
		||||
                    com.google.common.base.Optional<HashSet<PlotBlock>> destroy = plot.getFlag(Flags.BREAK);
 | 
			
		||||
                    BlockState state = l.getBlock();
 | 
			
		||||
                    if (destroy.isPresent() && destroy.get().contains(SpongeUtil.getPlotBlock(state))) {
 | 
			
		||||
                        return true;
 | 
			
		||||
                    }
 | 
			
		||||
                    MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
                MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_UNOWNED);
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            if (plot1.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) {
 | 
			
		||||
                return true;
 | 
			
		||||
            } else {
 | 
			
		||||
                com.google.common.base.Optional<HashSet<PlotBlock>> destroy = plot1.getFlag(Flags.BREAK);
 | 
			
		||||
                BlockState state = l.getBlock();
 | 
			
		||||
                if (destroy.isPresent() && destroy.get().contains(SpongeUtil.getPlotBlock(state))) {
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
                MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
@@ -524,7 +517,7 @@ public class MainListener {
 | 
			
		||||
    public void onBlockPlace(ChangeBlockEvent.Place event) {
 | 
			
		||||
        Player player = SpongeUtil.getCause(event.getCause(), Player.class);
 | 
			
		||||
        if (player == null) {
 | 
			
		||||
//            SpongeUtil.printCause("place", event.getCause());
 | 
			
		||||
            //SpongeUtil.printCause("place", event.getCause());
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        PlotPlayer pp = SpongeUtil.getPlayer(player);
 | 
			
		||||
@@ -552,9 +545,9 @@ public class MainListener {
 | 
			
		||||
                    return;
 | 
			
		||||
                } else {
 | 
			
		||||
                    MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
 | 
			
		||||
                    com.google.common.base.Optional<HashSet<PlotBlock>> BUILD = plot.getFlag(Flags.PLACE);
 | 
			
		||||
                    com.google.common.base.Optional<HashSet<PlotBlock>> place = plot.getFlag(Flags.PLACE);
 | 
			
		||||
                    BlockState state = pos.getState();
 | 
			
		||||
                    if (!BUILD.isPresent() || !BUILD.get().contains(SpongeUtil.getPlotBlock(state))) {
 | 
			
		||||
                    if (!place.isPresent() || !place.get().contains(SpongeUtil.getPlotBlock(state))) {
 | 
			
		||||
                        event.setCancelled(true);
 | 
			
		||||
                        return;
 | 
			
		||||
                    }
 | 
			
		||||
@@ -575,10 +568,7 @@ public class MainListener {
 | 
			
		||||
                Location loc = SpongeUtil.getLocation(worldName, l);
 | 
			
		||||
                Plot plot = loc.getPlot();
 | 
			
		||||
                if (plot == null) {
 | 
			
		||||
                    if (loc.getPlotAbs() == null) {
 | 
			
		||||
                        return true;
 | 
			
		||||
                    }
 | 
			
		||||
                    return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD);
 | 
			
		||||
                    return loc.getPlotAbs() == null || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD);
 | 
			
		||||
                }
 | 
			
		||||
                if (!plot.hasOwner()) {
 | 
			
		||||
                    if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
 | 
			
		||||
@@ -590,9 +580,9 @@ public class MainListener {
 | 
			
		||||
                if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
 | 
			
		||||
                    return true;
 | 
			
		||||
                } else {
 | 
			
		||||
                    com.google.common.base.Optional<HashSet<PlotBlock>> build = plot.getFlag(Flags.PLACE);
 | 
			
		||||
                    com.google.common.base.Optional<HashSet<PlotBlock>> place = plot.getFlag(Flags.PLACE);
 | 
			
		||||
                    BlockState state = l.getBlock();
 | 
			
		||||
                    if (build.isPresent() && build.get().contains(SpongeUtil.getPlotBlock(state))) {
 | 
			
		||||
                    if (place.isPresent() && place.get().contains(SpongeUtil.getPlotBlock(state))) {
 | 
			
		||||
                        return true;
 | 
			
		||||
                    }
 | 
			
		||||
                    MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
 | 
			
		||||
@@ -627,12 +617,7 @@ public class MainListener {
 | 
			
		||||
        // Delayed
 | 
			
		||||
 | 
			
		||||
        // Async
 | 
			
		||||
        TaskManager.runTaskLaterAsync(new Runnable() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void run() {
 | 
			
		||||
                EventUtil.manager.doJoinTask(pp);
 | 
			
		||||
            }
 | 
			
		||||
        }, 20);
 | 
			
		||||
        TaskManager.runTaskLaterAsync(() -> EventUtil.manager.doJoinTask(pp), 20);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    @Listener
 | 
			
		||||
 
 | 
			
		||||
@@ -74,7 +74,7 @@ public class SpongePlayer extends PlotPlayer {
 | 
			
		||||
    
 | 
			
		||||
    @Override
 | 
			
		||||
    public void sendMessage(String message) {
 | 
			
		||||
        if (!StringMan.isEqual(this.<String>getMeta("lastMessage"), message) || (System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) {
 | 
			
		||||
        if (!StringMan.isEqual(this.getMeta("lastMessage"), message) || (System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) {
 | 
			
		||||
            setMeta("lastMessage", message);
 | 
			
		||||
            setMeta("lastMessageTime", System.currentTimeMillis());
 | 
			
		||||
            this.player.sendMessage(ChatTypes.CHAT, TextSerializers.LEGACY_FORMATTING_CODE.deserialize(message));
 | 
			
		||||
@@ -162,23 +162,21 @@ public class SpongePlayer extends PlotPlayer {
 | 
			
		||||
    
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setTime(long time) {
 | 
			
		||||
        // TODO Auto-generated method stub
 | 
			
		||||
        if (time != Long.MAX_VALUE) {} else {}
 | 
			
		||||
        throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setFlight(boolean fly) {
 | 
			
		||||
        this.player.offer(Keys.IS_FLYING, fly);
 | 
			
		||||
        this.player.offer(Keys.CAN_FLY, fly);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean getFlight() {
 | 
			
		||||
        Optional<Boolean> flying = player.get(Keys.CAN_FLY);
 | 
			
		||||
        return flying.isPresent() && flying.get();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setFlight(boolean fly) {
 | 
			
		||||
        this.player.offer(Keys.IS_FLYING, fly);
 | 
			
		||||
        this.player.offer(Keys.CAN_FLY, fly);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void playMusic(Location location, int id) {
 | 
			
		||||
        switch (id) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user