Skip to content

Commit 83546ab

Browse files
committed
Implement World Border support + Example plugin
1 parent ca32b26 commit 83546ab

File tree

6 files changed

+209
-0
lines changed

6 files changed

+209
-0
lines changed

Examples/cWorldBorder/pom.xml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>net.cheatbreaker</groupId>
8+
<artifactId>cWorldBorder</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<name>cWorldBorder</name>
13+
14+
<properties>
15+
<java.version>1.8</java.version>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
</properties>
18+
19+
<build>
20+
<defaultGoal>clean package</defaultGoal>
21+
<plugins>
22+
<plugin>
23+
<groupId>org.apache.maven.plugins</groupId>
24+
<artifactId>maven-compiler-plugin</artifactId>
25+
<version>3.14.0</version>
26+
<configuration>
27+
<source>${java.version}</source>
28+
<target>${java.version}</target>
29+
</configuration>
30+
</plugin>
31+
<plugin>
32+
<groupId>org.apache.maven.plugins</groupId>
33+
<artifactId>maven-shade-plugin</artifactId>
34+
<version>3.6.0</version>
35+
<executions>
36+
<execution>
37+
<phase>package</phase>
38+
<goals>
39+
<goal>shade</goal>
40+
</goals>
41+
<configuration>
42+
<createDependencyReducedPom>false</createDependencyReducedPom>
43+
</configuration>
44+
</execution>
45+
</executions>
46+
</plugin>
47+
</plugins>
48+
<resources>
49+
<resource>
50+
<directory>src/main/resources</directory>
51+
<filtering>true</filtering>
52+
</resource>
53+
</resources>
54+
</build>
55+
56+
<repositories>
57+
<repository>
58+
<id>spigotmc-repo</id>
59+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
60+
</repository>
61+
</repositories>
62+
63+
<dependencies>
64+
<dependency>
65+
<groupId>org.bukkit</groupId>
66+
<artifactId>bukkit</artifactId>
67+
<version>1.15.2-R0.1-SNAPSHOT</version>
68+
<scope>provided</scope>
69+
</dependency>
70+
<dependency>
71+
<groupId>com.cheatbreaker</groupId>
72+
<artifactId>CheatBreakerAPI</artifactId>
73+
<version>1.0-SNAPSHOT</version>
74+
<systemPath>${project.basedir}/lib/CheatBreakerAPI.jar</systemPath>
75+
<scope>system</scope>
76+
</dependency>
77+
</dependencies>
78+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package net.cheatbreaker.cworldborder;
2+
3+
import com.cheatbreaker.api.CheatBreakerAPI;
4+
import com.cheatbreaker.api.object.CBWorldBorder;
5+
import org.bukkit.Bukkit;
6+
import org.bukkit.Location;
7+
import org.bukkit.configuration.file.FileConfiguration;
8+
import org.bukkit.event.EventHandler;
9+
import org.bukkit.event.Listener;
10+
import org.bukkit.event.player.PlayerJoinEvent;
11+
import org.bukkit.plugin.java.JavaPlugin;
12+
import org.bukkit.util.Vector;
13+
14+
public final class cWorldBorder extends JavaPlugin implements Listener {
15+
16+
@Override
17+
public void onEnable() {
18+
this.saveDefaultConfig();
19+
Bukkit.getPluginManager().registerEvents(this, this);
20+
}
21+
22+
@EventHandler
23+
public void onJoin(PlayerJoinEvent event) {
24+
for (String s : getConfig().getConfigurationSection("worldborders").getKeys(false)) {
25+
FileConfiguration config = getConfig();
26+
27+
String path = "worldborders." + s;
28+
29+
CheatBreakerAPI.getInstance().sendWorldBorder(event.getPlayer(), new CBWorldBorder(s, new Location(Bukkit.getWorld(config.getString(path + ".world")), config.getDouble(path + ".min_x"), 0, config.getDouble(path + ".min_z")), new Location(Bukkit.getWorld(config.getString(path + ".world")), config.getDouble(path + ".max_x"), 0, config.getDouble(path + ".max_z")), config.getInt(path + ".color"), config.getBoolean(path + ".prohibit_exiting"), config.getBoolean(path + ".allow_shrink_expand")));
30+
}
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# When making a world border, it needs a color which is an integer that you can get from: http://www.shodor.org/stella2java/rgbint.html
2+
# by putting in your color like (255, 146, 92) to get the RGB int.
3+
4+
worldborders:
5+
Spawn:
6+
world: world
7+
min_x: 0
8+
min_z: 0
9+
max_x: 100
10+
max_z: 100
11+
prohibit_exiting: false
12+
allow_shrink_expand: false
13+
color: 16777215
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: cWorldBorder
2+
version: ${project.version}
3+
main: net.cheatbreaker.cworldborder.cWorldBorder
4+
api-version: 1.13
5+
depend: [ CheatBreakerAPI ]

src/main/java/com/cheatbreaker/api/CheatBreakerAPI.java

+29
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,35 @@ public void clearCooldown(Player player, CBCooldown cooldown) {
337337
sendPacket(player, new CBPacketCooldown(cooldown.getMessage(), 0L, cooldown.getIcon().getId()));
338338
}
339339

340+
public void sendWorldBorder(Player player, CBWorldBorder border) {
341+
sendPacket(player, new CBPacketWorldBorder(
342+
border.getId(),
343+
border.getWorld(),
344+
border.isCancelsExit(),
345+
border.isCanShrinkExpand(),
346+
border.getColor(),
347+
border.getMin_x(),
348+
border.getMin_z(),
349+
border.getMax_x(),
350+
border.getMax_z()
351+
));
352+
}
353+
354+
public void sendWorldBorderUpdate(Player player, CBPacketWorldBorderUpdate border) {
355+
sendPacket(player, new CBPacketWorldBorderUpdate(
356+
border.getId(),
357+
border.getMinX(),
358+
border.getMinZ(),
359+
border.getMaxX(),
360+
border.getMaxZ(),
361+
border.getDurationTicks()
362+
));
363+
}
364+
365+
public void sendWorldBorderRemove(Player player, CBWorldBorder border) {
366+
sendPacket(player, new CBPacketWorldBorderRemove(border.getId()));
367+
}
368+
340369
public void voiceEnabled(boolean enabled) {
341370
voiceEnabled = enabled;
342371
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* This program is free software: you can redistribute it and/or modify
3+
* it under the terms of the GNU General Public License as published by
4+
* the Free Software Foundation, either version 3 of the License, or
5+
* (at your option) any later version.
6+
*
7+
* This program is distributed in the hope that it will be useful,
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
* GNU General Public License for more details.
11+
*
12+
* You should have received a copy of the GNU General Public License
13+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
14+
*/
15+
16+
package com.cheatbreaker.api.object;
17+
18+
import com.cheatbreaker.api.CheatBreakerAPI;
19+
import lombok.AllArgsConstructor;
20+
import lombok.EqualsAndHashCode;
21+
import lombok.Getter;
22+
import org.bukkit.Location;
23+
24+
@EqualsAndHashCode
25+
@AllArgsConstructor
26+
public final class CBWorldBorder {
27+
28+
@Getter private final String id;
29+
@Getter private final String world;
30+
@Getter private final boolean cancelsExit;
31+
@Getter private final boolean canShrinkExpand;
32+
@Getter private final int color;
33+
@Getter private final double min_x;
34+
@Getter private final double min_z;
35+
@Getter private final double max_x;
36+
@Getter private final double max_z;
37+
38+
public CBWorldBorder(String id, Location locationmin, Location locationmax, int color, boolean cancelsExit, boolean canShrinkExpand) {
39+
this(
40+
id,
41+
CheatBreakerAPI.getInstance().getWorldIdentifier(locationmin.getWorld()),
42+
cancelsExit,
43+
canShrinkExpand,
44+
color,
45+
locationmin.getBlockX(),
46+
locationmin.getBlockZ(),
47+
locationmax.getBlockX(),
48+
locationmax.getBlockZ()
49+
);
50+
}
51+
52+
}

0 commit comments

Comments
 (0)