jued_huangjim
本帖最后由 jued_huangjim 于 2020-5-4 20:59 编辑

怎么做到和res那种保护区域,而且支持上万区域都不掉tps
我只需要阻止玩家破坏和放置,做感觉都不太理想,都是掉tps


尺素情深
https://www.mcbbs.net/thread-812491-1-1.html

南柯郡守
很早之前看过这个帖子了https://www.mcbbs.net/thread-812491-1-1.html

当时刚看到我是有点懵了
啥叫新建一个类来储存领地

后来大概明白了

就是想声明一个变量一样 先去新建一个类 在初始化部分传入参数
然后通过内部方法进行判定

效率更高
比如说我现在要新一个领地

  1. public class Ground{
  2.     private Location loc1,loc2;
  3.     private String groundname;
  4.     public ground(Location location1,Location location2,String name){
  5.         this.loc1=location1;
  6.         this.loc2=location2;
  7.         this.groundname=name;
  8.     }
  9.     public boolean isPlayerInGround(Player player){
  10.         //判定玩家坐标是否在loc1和loc2之间
  11.         return false;
  12.     }
  13. }
复制代码


使用的时候就像这样

  1. //可以写在监听BlockBreakEvent中
  2.     Ground g = new Ground();//这一步应该在插件加载的时候初始化 或者在创建新领地的时候加入到插件初始化的list之类中
  3.     if(g.isPlayerInGround(player)){
  4.         e.setCancelled(true);
  5.     }
复制代码

William_Shi
boolean        isInAABB(Vector min, Vector max)
判断本向量是否在一个AABB包围盒中.
boolean        isInSphere(Vector origin, double radius)
判断本向量是否在一个球形空间中.

上面二位说的很详细
我给一个提高效率的建议
使用向量的是否处于某区域方法
我看似乎类似于WorldEdit这类插件是使用vector做了遍历的
说明vector效率应该相对高些