• 欢迎来到Minecraft插件百科!
  • 对百科编辑一脸懵逼?帮助:快速入门带您快速熟悉百科编辑!
  • 因近日遭受攻击,百科现已限制编辑,有意编辑请加入插件百科企鹅群:223812289

PlotSquared/Dev

来自Minecraft插件百科
C7w讨论 | 贡献2016年10月28日 (五) 19:10的版本 如何在PlotSquared上工作
跳转至: 导航搜索

这里是PlotSquared的开发文档界面~

[原文地址]

有用的类

教程

使用Java语言编码

总览

  • 脚本放到 PlotSquared/scripts 目录下
  • 语言请使用Java语言

指令

  • /plot debugexec run <script> [args...]
  • /plot debugexec runasync <script> [args...]
  • /plot debugexec

示例脚本

其他脚本

写了你自己的脚本?想发到这里?[欢迎!]

一个PlotSquared的附属插件实例

import com.intellectualcrafters.plot.api.PlotAPI;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.PluginManager;

public class Main extends JavaPlugin {
    public PlotAPI api;

    @Override
    public void onEnable() {
        PluginManager manager = Bukkit.getServer().getPluginManager();
        final Plugin plotsquared = manager.getPlugin("PlotSquared");

        // 如果插件没有安装的话就关闭这个插件

        // If you move any PlotSquared related tasks to en external class you 
        // wouldn't have to disable the plugin if PlotSquared wasn't installed

        if(plotsquared != null && !plotsquared.isEnabled()) {
            PS.log(null, "&c[ExamplePlugin] Could not find PlotSquared! Disabling plugin...");
            manager.disablePlugin(this);
            return;
        }

        // Do PlotSquared related stuff
        api = new PlotAPI();

        // 现在你就可以使用这个API了
    }
}

增加一个子命令

当玩家输入 /plot help <category> 时会展示你增加的子命令。 CATEGORY 为你添加子命令时选择的类型

增加命令

下面是一个例子

@CommandDeclaration(
    // 你所添加命令的名字
    command = "test",
    
    // 若要运行你所添加的命令,你需要的权限
    permission = "plots.music",
    
    // 你所添加的命令的描述
    description = "Player music in a plot",
    
    // 你所添加的命令的使用方法
    usage = "/plot music",
    
    // 你所添加的命令的类型
    category = CommandCategory.ACTIONS,
    
    // 需要的命令执行者 (NONE 允许控制台执行)
    requiredType = RequiredType.NONE
)
public class TestCommand extends SubCommand {
        public TestCommand() {
            // 你可以在这儿或者其他地方自定义命令
            MainCommand.getInstance().addCommand(this);
            
            // Then just call:
            // new TestCommand();
            // 在游戏中使用 :  /plot test
        }

        // 下面是这个指令是干嘛的
    @Override
    public boolean onCommand(final PlotPlayer player, final String[] args) {
        Location loc = player.getLocation();
        Plot plot = Plot plot1 = MainUtil.getPlot(loc);
        if (plot1 == null) {
            sendMessage(player, C.NOT_IN_PLOT);
            return false;
        }
        Plot plot = MainUtil.getCurrentPlot(plr);
        MainUtil.sendMessage(player, "You are in plot " + plot.getId());
        return true;
    }
}

动态命令添加

Command<PlotPlayer> cmd = new Command<PlotPlayer>(String command, String usage, String description, String permission, String[] aliases, RequiredType requiredType) {

    @Override
    public boolean onCommand(PlotPlayer plr, String[] arguments) {
        Location loc = player.getLocation();
        Plot plot = Plot plot1 = MainUtil.getPlot(loc);
        if (plot1 == null) {
            sendMessage(player, C.NOT_IN_PLOT);
            return false;
        }
        Plot plot = MainUtil.getCurrentPlot(plr);
        MainUtil.sendMessage(player, "You are in plot " + plot.getId());
        return true;
    }
};

MainCommand.getInstance().addCommand(cmd);

增加自定义标志

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

import com.intellectualcrafters.plot.AbstractFlag;
import com.intellectualcrafters.plot.Flag;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.api.PlotAPI;
import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent;

public class Main extends JavaPlugin implements Listener {
    PlotAPI plotAPI = null;
    @Override
    public void onEnable() {

        // 获取插件
        Plugin plotSquaredPlugin = getServer().getPluginManager().getPlugin("PlotSquared");

        //检查PS插件是否被启动
        if (plotSquaredPlugin!=null && plotSquaredPlugin.isEnabled()) {

            // 这儿我们来获取一些带有有趣事情的API
            plotAPI = new PlotAPI((JavaPlugin) plotSquaredPlugin);
        }
        else {

            // 当PS没有启用时 给控制台发送一条消息然后关闭这个插件吧!
            // 当然你也可以把PS的代码移到另一个类中,这样你就不要单独写停止PS的部分了。
            getServer().getConsoleSender().sendMessage("Plugin 'PlotSquared' not found. Disabling MyPlugin");
            Bukkit.getPluginManager().disablePlugin(this);
        }

        //增加一个 AbstractFlag (标志的关键)
        AbstractFlag abFlag = new AbstractFlag("greeting") {

            // 下面的东西是可选的 并允许你限制哪些玩家可以设置这个标志:

            @Override
            public String parseValue(String value) {

                // Only accept woof, dog, cat, meow for the greeting flag

                switch (value.toLowerCase()) {
                    case "woof":
                    case "dog":
                        return "dog"; 
                    case "cat":
                    case "meow":
                        return "cat";
                    default:
                        return null; // Return null the value is invalid
                }

                // 你也可以使用一些简单的IF语句 例子如下:

                /*
                if (value.equals("hello")) {
                    return value;
                }
                return null;
                */
            }


            @Override
            public String getValueDesc() {
                return "You are currently only allowed to set the greeting to: woof, dog, cat, meow"; 
            }
        };
        // 现在我们要注册标志了
        plotAPI.addFlag(abFlag);

        // 别忘记注册一个消息然后我们才可以给控制台发消息
        getServer().getPluginManager().registerEvents(this, this);
    }

    // 这儿是 PlayerEnterPlotEvent, 同时也有其他你可以接入的事件。这些会在网页中列举出来。
    @EventHandler
    public void onPlayerEnterPlot(PlayerEnterPlotEvent event) {
        Plot plot = event.getPlot();
        Player player = event.getPlayer();

        // checking if the plot has that flag
        if (plot.settings.getFlag("greeting")!=null) {

            // Get the message
            String message = plot.settings.getFlag("greeting").getValue();

            // Only send a message if it's not blank.
            if (!message.equals("")) {

                // Send the player the message set for that plot
                player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
            }
        }
    }
}

使用 PlotAPI 类

PlotAPI API = new PlotAPI(null);

Plot plot = API.getPlot(final Location l);

输入:


com.intellectualcrafters.plot.api.PlotAPI

com.intellectualcrafters.plot.object.Plot

使用PlotPlayer类

总览:

[PlotPlayer.java] 是用于表现服务器上的玩家的一个语言。

获取 PlotPlayer 从 org.bukkit.entity.Player 处:

BukkitUtil.getPlayer(Player player)

PlotPlayer.wrap(Player player)

获取 PlotPlayer 从 org.bukkit.OfflinePlayer:

BukkitUtil.getPlayer(OfflinePlayer offline)

PlotPlayer.wrap(OfflinePlayer player) 你可能会把这个链接到 BukkitPlayer 如果你需要它的帮助的话。

注意:一些功能作为一个离线玩家可能不会正常工作,尤其是他们从没加入过游戏的情况。

使用 PlotPlayer 你可以做什么:

  • 将他们在各种各样的PlotSquared功能中使用
  • 设置持久属性: Plotplayer.setAttribute(String attribute)
  • Set session only metadata: plotplayer.setMeta(String key, Object value)
  • 获取UUID: plotplayer.getUUID()

增加一个自定义的世界生成器

如果你不熟悉如何快速自定义世界生成器的话,请看这里的快速教程链接——

如何在PlotSquared上工作

每个世界都有它自己的配置文件。这为你定向到了 PlotWorld 类。 PlotWorld 类也有一些硬性设定,但是不多。

PlotSquared 默认为一个 HybridPlotWorld 类,没有包括任何我们需要的基础设置。你可以随意使用它【通过API】,或者只是复制它来做一些简要的修改。

每个生成器也会有它自己的 PlotManager 类,这些类决定着一些类似于地皮清理等基础的事情,可以在每个 PlotWorld 类中找到。

PlotSquared 使用 HybridPlotManager , 当然你也可以使用它,用它来制作一些你需要的 PlotSquared 附属插件。

这儿当然也有一些其他几个 PlotWorld 和 PlotManager 类来供你需要的地皮生成器的依赖选择。

对于方形的地皮,你就不需要提供你自己的清除算法,因为 PlotSquared 可以为你做那的所有事情。详情请看 SquarePlotManager 类。

记得让你的 PlotManager 类和 PlotWorld 类对应起来,如,如果你选择了我们的 SquarePlotManager 类, 你最好搭配一个 SquarePlotWorld 或更好的类。

PlotSquared 区块生成器

With PlotSquared, instead of extending ChunkGenerator you will want to extend PlotGenerator. This can be seen being done in our HybridGen class.

You will register this PlotGenerator as you would a normal ChunkGenerator in your main class:

@Override public ChunkGenerator getWorldGenerator(String worldName, String id) {

   return new YourPlotGenerator(worldName);

} Example PlotGenerator classes

(free to use/modify for a P^2 addon)

PlotSquared: The standard generator

HybridGen This generator combines normal plot generation with some features of AdvPlots for convenient, performant and highly configurable plot generation It's very messy, as there are a bunch of optimizations made depending on configuration and what P^2 is doing, which you don't neccessarily need to do yourself BasicPlots: Has one plot per chunk

BasicGen It's fast as it generates the array for the chunk when it initializes and returns that same array for every chunk The downside is that plots need to be the size of a chunk so it's not very customizable PlotSquaredMG: Uses region files for generation

MegaGen It takes ages to load up, but allows large areas of custom terrain Since it's using region files, it can easily pre-generate the map on startup, and since the plot size is a multiple of 16, it calculates all the chunk arrays during startup The obvious downside is the long startup time, and that plots must be huge (multiples of 512) AdvPlots generator: Schematic generation

SchemGen This shows that with PlotSquared you aren't limited to just squares for plots It demonstrates schematic generation that works with plot merging In fact if you can code it, you could provide any coordinates you want for plot locations, it doesn't have to be a grid Non PlotGenerator generators that may be useful to have a look at:

ClassicGen: One of the earliest generators used by PlotSquared:

ClassicGen It's not simple, but the benefit is that there was no logic or checks inside the loops making it fairly efficient Kind of the opposite of PlotMe which appears to put as much logic inside loops as it can The downside to this is that it's incredibly difficult to have anything apart from simple cuboids making up the plot, so schematics in generation are out of the question Here's a generator that I wrote which has the basics of what you would expect in a plot generator:

Source It doesn't inherit PlotGenerator, but it is documented and shows some basic optimizations and functionality

开发的东西

[源代码]

特有词汇