added plugin
This commit is contained in:
parent
6492267929
commit
5b31273665
12 changed files with 501 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target/
|
31
Chunksfall.iml
Normal file
31
Chunksfall.iml
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>SPIGOT</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.15.2-R0.1-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:21.0" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.15-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.25" level="project" />
|
||||
</component>
|
||||
</module>
|
75
pom.xml
Normal file
75
pom.xml
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>defelo.mc</groupId>
|
||||
<artifactId>chunksfall</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Chunksfall</name>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.7.0</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
187
src/main/java/defelo/mc/chunksfall/Chunksfall.java
Normal file
187
src/main/java/defelo/mc/chunksfall/Chunksfall.java
Normal file
|
@ -0,0 +1,187 @@
|
|||
package defelo.mc.chunksfall;
|
||||
|
||||
import defelo.mc.chunksfall.animations.*;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.AreaEffectCloud;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class Chunksfall extends JavaPlugin implements Listener {
|
||||
|
||||
private static Random random = new Random();
|
||||
|
||||
private boolean running = false;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "Chunksfall enabled");
|
||||
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "Chunksfall disabled");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
if (command.getName().equals("chunksfall")) {
|
||||
if (args.length == 1) {
|
||||
return Stream.of("info", "start", "stop", "reset").filter(s -> s.startsWith(args[0])).collect(Collectors.toList());
|
||||
} else if (args.length == 2) {
|
||||
if (args[0].equals("reset")) {
|
||||
return Stream.of("chunk", "world").filter(s -> s.startsWith(args[1])).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return super.onTabComplete(sender, command, alias, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (command.getName().equals("chunksfall")) {
|
||||
if (args.length < 1) return false;
|
||||
|
||||
String cmd = args[0];
|
||||
switch (cmd) {
|
||||
case "info":
|
||||
if (running) {
|
||||
getServer().broadcastMessage(ChatColor.GREEN + "Chunksfall is currently running!");
|
||||
} else {
|
||||
getServer().broadcastMessage(ChatColor.RED + "Chunksfall has not been started.");
|
||||
}
|
||||
long count = getServer().getWorlds().stream().map(world ->
|
||||
world.getEntities().stream().filter(entity -> entity.getScoreboardTags().contains("chunk_deleted")).count()
|
||||
).reduce(0L, Long::sum);
|
||||
getServer().broadcastMessage(count + " Chunk(s) have been marked as deleted.");
|
||||
break;
|
||||
case "start":
|
||||
if (running) {
|
||||
getServer().broadcastMessage(ChatColor.RED + "Chunksfall has already been started!");
|
||||
} else {
|
||||
getServer().broadcastMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Chunksfall started!");
|
||||
running = true;
|
||||
}
|
||||
break;
|
||||
case "stop":
|
||||
if (running) {
|
||||
getServer().broadcastMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "Chunksfall stopped!");
|
||||
running = false;
|
||||
} else {
|
||||
getServer().broadcastMessage(ChatColor.RED + "Chunksfall has not been started!");
|
||||
}
|
||||
break;
|
||||
case "reset":
|
||||
if (args.length < 2) return false;
|
||||
|
||||
if (args[1].equals("world")) {
|
||||
getServer().getWorlds().forEach(world -> world.getEntities().forEach(entity -> {
|
||||
if (entity.getScoreboardTags().contains("chunk_deleted"))
|
||||
entity.remove();
|
||||
}));
|
||||
getServer().broadcastMessage(ChatColor.DARK_GREEN + "" + ChatColor.BOLD + "Chunksfall has been reset!");
|
||||
} else if (args[1].equals("chunk") && sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
Arrays.stream(player.getLocation().getChunk().getEntities()).forEach(entity -> {
|
||||
if (entity.getScoreboardTags().contains("chunk_deleted"))
|
||||
entity.remove();
|
||||
});
|
||||
getServer().broadcastMessage(ChatColor.DARK_GREEN + "" + ChatColor.BOLD + "Chunk has been reset!");
|
||||
} else return false;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void delete_column(Chunk chunk, int x, int z) {
|
||||
for (int y = 255; y >= 1; y--) {
|
||||
chunk.getBlock(x, y, z).setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerMove(PlayerMoveEvent event) {
|
||||
if (!running) return;
|
||||
Player player = event.getPlayer();
|
||||
Chunk chunk = player.getLocation().getChunk();
|
||||
Chunk spawnChunk = chunk.getWorld().getSpawnLocation().getChunk();
|
||||
if (Math.abs(chunk.getX() - spawnChunk.getX()) <= 1 && Math.abs(chunk.getZ() - spawnChunk.getZ()) <= 1)
|
||||
return;
|
||||
if (Arrays.stream(chunk.getEntities()).noneMatch(entity -> entity.getScoreboardTags().contains("chunk_deleted"))) {
|
||||
AreaEffectCloud aec = (AreaEffectCloud) chunk.getWorld().spawnEntity(chunk.getBlock(0, 0, 0).getLocation().add(0, -20, 0), EntityType.AREA_EFFECT_CLOUD);
|
||||
aec.setDuration(Integer.MAX_VALUE - 20);
|
||||
aec.setRadius(0);
|
||||
aec.addScoreboardTag("chunk_deleted");
|
||||
|
||||
// getServer().broadcastMessage(ChatColor.RED + "" + ChatColor.BOLD + "" + ChatColor.MAGIC + "XXX"
|
||||
// + ChatColor.RESET + "" + ChatColor.RED + "" + ChatColor.BOLD + "" + " DELETING CHUNK " + chunk.getX() + " " + chunk.getZ() + " " + ChatColor.MAGIC + "XXX");
|
||||
|
||||
int rotation = random.nextInt(4);
|
||||
IAnimation animation;
|
||||
switch (random.nextInt(6)) {
|
||||
case 0:
|
||||
animation = new LineByLineAnimation();
|
||||
break;
|
||||
case 1:
|
||||
animation = new LineByLine2Animation();
|
||||
break;
|
||||
case 2:
|
||||
animation = new LineByLine4Animation();
|
||||
break;
|
||||
case 3:
|
||||
animation = new SpiralAnimation();
|
||||
break;
|
||||
case 4:
|
||||
animation = new SpiralReverseAnimation();
|
||||
break;
|
||||
case 5:
|
||||
default:
|
||||
animation = new RandomAnimation();
|
||||
break;
|
||||
}
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!running) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
int[] coords = animation.get_column();
|
||||
switch (rotation) {
|
||||
case 0:
|
||||
delete_column(chunk, coords[0], coords[1]);
|
||||
break;
|
||||
case 1:
|
||||
delete_column(chunk, 15 - coords[1], coords[0]);
|
||||
break;
|
||||
case 2:
|
||||
delete_column(chunk, 15 - coords[0], 15 - coords[1]);
|
||||
break;
|
||||
case 3:
|
||||
delete_column(chunk, coords[1], 15 - coords[0]);
|
||||
break;
|
||||
}
|
||||
if (!animation.next()) cancel();
|
||||
}
|
||||
}.runTaskTimer(this, 0, 1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package defelo.mc.chunksfall.animations;
|
||||
|
||||
|
||||
public interface IAnimation {
|
||||
int[] get_column();
|
||||
boolean next();
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package defelo.mc.chunksfall.animations;
|
||||
|
||||
public class LineByLine2Animation implements IAnimation {
|
||||
|
||||
private int x = 0;
|
||||
private int z = 0;
|
||||
private int inc = 1;
|
||||
private boolean toggle = true;
|
||||
|
||||
@Override
|
||||
public int[] get_column() {
|
||||
if (toggle)
|
||||
return new int[]{x, z};
|
||||
else
|
||||
return new int[]{15 - x, 15 - z};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean next() {
|
||||
if (toggle) toggle = false;
|
||||
else {
|
||||
toggle = true;
|
||||
x += inc;
|
||||
if (x == 16 || x == -1) {
|
||||
if (++z == 8) return false;
|
||||
inc *= -1;
|
||||
x += inc;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package defelo.mc.chunksfall.animations;
|
||||
|
||||
public class LineByLine4Animation implements IAnimation {
|
||||
|
||||
private int x = 0;
|
||||
private int z = 0;
|
||||
private int inc = 1;
|
||||
private int toggle = 0;
|
||||
|
||||
@Override
|
||||
public int[] get_column() {
|
||||
switch (toggle) {
|
||||
case 0:
|
||||
return new int[]{x, z};
|
||||
case 1:
|
||||
return new int[]{15 - z, x};
|
||||
case 2:
|
||||
return new int[]{15 - x, 15 - z};
|
||||
case 3:
|
||||
default:
|
||||
return new int[]{z, 15 - x};
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean next() {
|
||||
if (++toggle == 4) {
|
||||
toggle = 0;
|
||||
x += inc;
|
||||
if (x == 8 || x == -1) {
|
||||
if (++z == 8) return false;
|
||||
inc *= -1;
|
||||
x += inc;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package defelo.mc.chunksfall.animations;
|
||||
|
||||
public class LineByLineAnimation implements IAnimation {
|
||||
|
||||
private int x = 0;
|
||||
private int z = 0;
|
||||
private int inc = 1;
|
||||
|
||||
@Override
|
||||
public int[] get_column() {
|
||||
return new int[]{x, z};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean next() {
|
||||
x += inc;
|
||||
if (x == 16 || x == -1) {
|
||||
if (++z == 16) return false;
|
||||
inc *= -1;
|
||||
x += inc;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package defelo.mc.chunksfall.animations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
public class RandomAnimation implements IAnimation {
|
||||
|
||||
private ArrayList<int[]> coords;
|
||||
|
||||
public RandomAnimation() {
|
||||
coords = new ArrayList<>();
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
coords.add(new int[]{i, j});
|
||||
}
|
||||
}
|
||||
Collections.shuffle(coords);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] get_column() {
|
||||
return coords.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean next() {
|
||||
coords.remove(0);
|
||||
return !coords.isEmpty();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package defelo.mc.chunksfall.animations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SpiralAnimation implements IAnimation {
|
||||
private ArrayList<int[]> coords;
|
||||
|
||||
public SpiralAnimation() {
|
||||
coords = new ArrayList<>();
|
||||
for (int k = 0; k < 8; k++) {
|
||||
for (int i = k; i <= 15 - k; i++) coords.add(new int[]{i, k});
|
||||
for (int i = k + 1; i <= 15 - k; i++) coords.add(new int[]{15 - k, i});
|
||||
for (int i = 15 - k - 1; i >= k; i--) coords.add(new int[]{i, 15 - k});
|
||||
for (int i = 15 - k - 1; i >= k + 1; i--) coords.add(new int[]{k, i});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] get_column() {
|
||||
return coords.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean next() {
|
||||
coords.remove(0);
|
||||
return !coords.isEmpty();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package defelo.mc.chunksfall.animations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SpiralReverseAnimation implements IAnimation {
|
||||
private ArrayList<int[]> coords;
|
||||
|
||||
public SpiralReverseAnimation() {
|
||||
coords = new ArrayList<>();
|
||||
for (int k = 0; k < 8; k++) {
|
||||
for (int i = k; i <= 15 - k; i++) coords.add(new int[]{i, k});
|
||||
for (int i = k + 1; i <= 15 - k; i++) coords.add(new int[]{15 - k, i});
|
||||
for (int i = 15 - k - 1; i >= k; i--) coords.add(new int[]{i, 15 - k});
|
||||
for (int i = 15 - k - 1; i >= k + 1; i--) coords.add(new int[]{k, i});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] get_column() {
|
||||
return coords.get(coords.size() - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean next() {
|
||||
coords.remove(coords.size() - 1);
|
||||
return !coords.isEmpty();
|
||||
}
|
||||
|
||||
}
|
15
src/main/resources/plugin.yml
Normal file
15
src/main/resources/plugin.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
name: Chunksfall
|
||||
version: ${project.version}
|
||||
main: defelo.mc.chunksfall.Chunksfall
|
||||
api-version: "1.13"
|
||||
authors: [Defelo]
|
||||
|
||||
commands:
|
||||
chunksfall:
|
||||
description: Chunksfall
|
||||
permission: chunksfall.admin
|
||||
usage: "usage: /chunksfall <info|start|stop|reset>"
|
||||
|
||||
permissions:
|
||||
chunksfall.admin:
|
||||
default: op
|
Reference in a new issue