Skip to content

Commit

Permalink
[1.1.0] 版本更新
Browse files Browse the repository at this point in the history
- `[A]` 添加 checkInterval(ticks) 配置,便。
- `[U]` 采用 DataXZLocation ,限制全部y轴高度。
  • Loading branch information
CarmJos committed Feb 19, 2022
1 parent 2d56830 commit 2d8e1f2
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 61 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.idea/
/target/
./*.iml
*.iml
asset/
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>cc.carm.plugin</groupId>
<artifactId>regionprotection</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<packaging>jar</packaging>

<name>RegionProtection</name>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cc/carm/plugin/regionprotection/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import cc.carm.plugin.regionprotection.manager.ConfigManager;
import cc.carm.plugin.regionprotection.manager.PlayerManager;
import cc.carm.plugin.regionprotection.manager.RegionManager;
import cc.carm.plugin.regionprotection.model.DataBlockLocation;
import cc.carm.plugin.regionprotection.model.DataXZLocation;
import cc.carm.plugin.regionprotection.model.ProtectedRegion;
import org.bukkit.configuration.serialization.ConfigurationSerialization;

Expand Down Expand Up @@ -48,7 +48,7 @@ protected void load() {
@Override
public boolean initialize() {
log("加载插件配置文件...");
ConfigurationSerialization.registerClass(DataBlockLocation.class);
ConfigurationSerialization.registerClass(DataXZLocation.class);
ConfigurationSerialization.registerClass(ProtectedRegion.class);
Main.configManager = new ConfigManager();
if (!Main.configManager.initConfig()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public class PluginConfig {
"play-time", Integer.class, 1440
);

public static final ConfigValue<Integer> CHECK_INTERVAL = new ConfigValue<>(
"check-interval", Integer.class, 5
);


public static class Sounds {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import cc.carm.plugin.regionprotection.RegionProtection;
import cc.carm.plugin.regionprotection.configuration.PluginMessages;
import cc.carm.plugin.regionprotection.manager.PlayerManager;
import cc.carm.plugin.regionprotection.model.DataBlockLocation;
import cc.carm.plugin.regionprotection.model.DataXZLocation;
import cc.carm.plugin.regionprotection.model.SelectingRegion;
import org.bukkit.Material;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -43,7 +43,7 @@ public void onClicking(PlayerInteractEvent event) {
return;
}
}
DataBlockLocation location = new DataBlockLocation(block.getLocation());
DataXZLocation location = new DataXZLocation(block.getLocation());
if (isPos1) {
if (region.getPos1() != null && region.getPos1().equals(location)) return;
region.setPos1(location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ public void resetTriedTimes(UUID uuid) {
}

public boolean isTriedTimesExceeded(UUID uuid) {
return triedTimes.containsKey(uuid) && triedTimes.get(uuid) >= 5;
return triedTimes.containsKey(uuid) && triedTimes.get(uuid) > 1;
}

public boolean shouldCheck(UUID uuid) {
return !checkInterval.containsKey(uuid) || System.currentTimeMillis() - checkInterval.get(uuid) >= 500; // 0.5s
int checkTicks = PluginConfig.CHECK_INTERVAL.get();
if (checkTicks <= 0) return true;
else {
return !checkInterval.containsKey(uuid) || System.currentTimeMillis() - checkInterval.get(uuid) >= (50L * checkTicks); // 0.25s | 5ticks
}
}

public void updateCheckTime(UUID uuid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.apache.commons.lang.StringUtils;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
import org.bukkit.util.NumberConversions;
Expand All @@ -12,38 +11,36 @@
import java.util.Map;
import java.util.Objects;

@SerializableAs("cc.carm.config.DataBlockLocation")
public class DataBlockLocation implements ConfigurationSerializable {
@SerializableAs("cc.carm.config.DataXZLocation")
public class DataXZLocation implements ConfigurationSerializable {

private int x;
private int y;
private int z;

public DataBlockLocation(Location location) {
this(location.getBlockX(), location.getBlockY(), location.getBlockZ());
public DataXZLocation(Location location) {
this(location.getBlockX(), location.getBlockZ());
}

public DataBlockLocation(final int x, final int y, final int z) {
public DataXZLocation(final int x, final int z) {
this.x = x;
this.y = y;
this.z = z;
}

public static DataBlockLocation deserialize(Map<String, Object> args) {
return new DataBlockLocation(NumberConversions.toInt(args.get("x")),
NumberConversions.toInt(args.get("y")),
NumberConversions.toInt(args.get("z")));
public static DataXZLocation deserialize(Map<String, Object> args) {
return new DataXZLocation(
NumberConversions.toInt(args.get("x")),
NumberConversions.toInt(args.get("z"))
);
}

public static DataBlockLocation deserializeText(String s) {
public static DataXZLocation deserializeText(String s) {
if (s == null || !s.contains(";")) return null;
String[] args = StringUtils.split(s, ";");
if (args.length != 3) return null;
if (args.length != 2) return null;
try {
int x = NumberConversions.toInt(args[0]);
int y = NumberConversions.toInt(args[1]);
int z = NumberConversions.toInt(args[2]);
return new DataBlockLocation(x, y, z);
return new DataXZLocation(x, z);
} catch (Exception ex) {
return null;
}
Expand All @@ -57,14 +54,6 @@ public void setX(int x) {
this.x = x;
}

public int getY() {
return y;
}

public void setY(int y) {
this.y = y;
}

public int getZ() {
return z;
}
Expand All @@ -73,40 +62,33 @@ public void setZ(int z) {
this.z = z;
}

public Location getBukkitLocation(World world) {
return new Location(world, getX(), getY(), getZ());
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DataBlockLocation location = (DataBlockLocation) o;
return x == location.x && y == location.y && z == location.z;
DataXZLocation location = (DataXZLocation) o;
return x == location.x && z == location.z;
}

@Override
public int hashCode() {
return Objects.hash(x, y, z);
return Objects.hash(x, z);
}

@Override
public @NotNull Map<String, Object> serialize() {
Map<String, Object> data = new HashMap<>();

data.put("x", this.x);
data.put("y", this.y);
data.put("z", this.z);

return data;
}

@Override
public String toString() {
return x + " " + y + " " + z;
return x + ", " + z;
}

public String serializeToText() {
return getX() + ";" + getY() + ";" + getZ();
return getX() + ";" + getZ();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cc.carm.plugin.regionprotection.model;

import org.apache.commons.lang.StringUtils;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
Expand All @@ -16,23 +15,23 @@
public class ProtectedRegion implements ConfigurationSerializable {

@Nullable String world;
@NotNull DataBlockLocation pos1;
@NotNull DataBlockLocation pos2;
@NotNull DataXZLocation pos1;
@NotNull DataXZLocation pos2;

public ProtectedRegion(@Nullable String world, @NotNull DataBlockLocation pos1, @NotNull DataBlockLocation pos2) {
public ProtectedRegion(@Nullable String world, @NotNull DataXZLocation pos1, @NotNull DataXZLocation pos2) {
this.world = world;
this.pos1 = pos1;
this.pos2 = pos2;
}

public ProtectedRegion(@NotNull DataBlockLocation pos1, @NotNull DataBlockLocation pos2) {
public ProtectedRegion(@NotNull DataXZLocation pos1, @NotNull DataXZLocation pos2) {
this(null, pos1, pos2);
}

public static ProtectedRegion deserialize(Map<String, Object> args) {
String world = args.containsKey("world") ? (String) args.get("world") : null;
if (args.containsKey("pos1") && args.containsKey("pos2")) {
return new ProtectedRegion(world, (DataBlockLocation) args.get("pos1"), (DataBlockLocation) args.get("pos2"));
return new ProtectedRegion(world, (DataXZLocation) args.get("pos1"), (DataXZLocation) args.get("pos2"));
}
return null;
}
Expand All @@ -53,19 +52,19 @@ public void setWorld(@Nullable World world) {
setWorld(world == null ? null : world.getName());
}

public @NotNull DataBlockLocation getPos1() {
public @NotNull DataXZLocation getPos1() {
return pos1;
}

public void setPos1(@NotNull DataBlockLocation pos1) {
public void setPos1(@NotNull DataXZLocation pos1) {
this.pos1 = pos1;
}

public @NotNull DataBlockLocation getPos2() {
public @NotNull DataXZLocation getPos2() {
return pos2;
}

public void setPos2(@NotNull DataBlockLocation pos2) {
public void setPos2(@NotNull DataXZLocation pos2) {
this.pos2 = pos2;
}

Expand All @@ -80,7 +79,6 @@ public double getCenterZ() {
public boolean isInArea(Location location) {
return (getWorld() == null || (location.getWorld() != null && location.getWorld().getName().equalsIgnoreCase(getWorld())))
&& isNumberInRange((int) location.getX(), getPos1().getX(), getPos2().getX())
&& isNumberInRange((int) location.getY(), getPos1().getY(), getPos2().getY())
&& isNumberInRange((int) location.getZ(), getPos1().getZ(), getPos2().getZ());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
public class SelectingRegion {

@NotNull String world;
@Nullable DataBlockLocation pos1;
@Nullable DataBlockLocation pos2;
@Nullable DataXZLocation pos1;
@Nullable DataXZLocation pos2;

public SelectingRegion(@NotNull String world, @Nullable DataBlockLocation pos1, @Nullable DataBlockLocation pos2) {
public SelectingRegion(@NotNull String world, @Nullable DataXZLocation pos1, @Nullable DataXZLocation pos2) {
this.world = world;
this.pos1 = pos1;
this.pos2 = pos2;
Expand All @@ -32,19 +32,19 @@ public void setWorld(@NotNull World world) {
setWorld(world.getName());
}

public @Nullable DataBlockLocation getPos1() {
public @Nullable DataXZLocation getPos1() {
return pos1;
}

public void setPos1(@NotNull DataBlockLocation pos1) {
public void setPos1(@NotNull DataXZLocation pos1) {
this.pos1 = pos1;
}

public @Nullable DataBlockLocation getPos2() {
public @Nullable DataXZLocation getPos2() {
return pos2;
}

public void setPos2(@NotNull DataBlockLocation pos2) {
public void setPos2(@NotNull DataXZLocation pos2) {
this.pos2 = pos2;
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ permission: "RegionProtection.override"
# 游玩时间,超过该时间的玩家将可以进入区域,单位:分钟
play-time: 1440 # 24 hours

check-interval: 5 # 5 ticks

sounds:
not-permitted: ENTITY_VILLAGER_NO # 进入未经允许的区域时播放的声音

0 comments on commit 2d8e1f2

Please sign in to comment.