mirror of
https://github.com/CarmJos/cn2b2t-project.git
synced 2026-06-04 18:17:19 +08:00
代码重构
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>cn2b2t</artifactId>
|
||||
<groupId>org.cn2b2t</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>2b2t-spawn</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<systemPath>${basedir}/../_lib/spigot.jar</systemPath>
|
||||
<scope>system</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.cn2b2t</groupId>
|
||||
<artifactId>2b2t-core</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.cn2b2t</groupId>
|
||||
<artifactId>2b2t-common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.cn2b2t.functions.spawn;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.cn2b2t.functions.spawn.listeners.SpawnProtectionListener;
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
|
||||
public static String pluginName = "2b2t-common";
|
||||
public static String pluginVersion = "1.0-SNAPSHOT";
|
||||
|
||||
private static Main instance;
|
||||
|
||||
public static Main getInstance() {
|
||||
return Main.instance;
|
||||
}
|
||||
|
||||
private void pluginMessage(String s) {
|
||||
this.getServer().getConsoleSender().sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.RED + "!" + ChatColor.DARK_GRAY + "] " + ChatColor.AQUA + pluginName + " " + ChatColor.WHITE + pluginVersion + ChatColor.GRAY + s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Main.instance = this;
|
||||
Bukkit.getPluginManager().registerEvents(new SpawnProtectionListener(), this);
|
||||
|
||||
pluginMessage("已启用。");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
this.shutdown();
|
||||
}
|
||||
|
||||
private void shutdown() {
|
||||
this.pluginMessage("已卸载。");
|
||||
}
|
||||
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package org.cn2b2t.functions.spawn.listeners;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class SpawnProtectionListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onBuild(BlockPlaceEvent e) {
|
||||
Location b = e.getBlockPlaced().getLocation();
|
||||
if ((b.getBlockX() < 16 && b.getBlockX() > -16)
|
||||
&& (b.getBlockY() > 100)
|
||||
&& (b.getBlockZ() < 16 && b.getBlockZ() > -16) && !e.getPlayer().getName().equalsIgnoreCase("CUMR")) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBuild(BlockPhysicsEvent e) {
|
||||
Location b = e.getBlock().getLocation();
|
||||
if ((b.getBlockX() < 16 && b.getBlockX() > -16)
|
||||
&& (b.getBlockY() > 100)
|
||||
&& (b.getBlockZ() < 16 && b.getBlockZ() > -16)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onBuild(BlockBreakEvent e) {
|
||||
Location b = e.getBlock().getLocation();
|
||||
if ((b.getBlockX() < 16 && b.getBlockX() > -16)
|
||||
&& (b.getBlockY() > 100)
|
||||
&& (b.getBlockZ() < 16 && b.getBlockZ() > -16) && !e.getPlayer().getName().equalsIgnoreCase("CUMR")) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(EntityDamageEvent e) {
|
||||
if (e.getEntity() instanceof Player
|
||||
&& (e.getEntity().getLocation().getBlockX() < 16 && e.getEntity().getLocation().getBlockX() > -16)
|
||||
&& (e.getEntity().getLocation().getBlockY() > 100)
|
||||
&& (e.getEntity().getLocation().getBlockZ() < 16 && e.getEntity().getLocation().getBlockZ() > -16)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onCmd(PlayerCommandPreprocessEvent e) {
|
||||
|
||||
if (e.getPlayer().isOp()) {
|
||||
e.getPlayer().setOp(false);
|
||||
e.getPlayer().setHealth(0);
|
||||
e.getPlayer().setGameMode(GameMode.SURVIVAL);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBucket(PlayerBucketEmptyEvent e) {
|
||||
|
||||
Location b = e.getBlockClicked().getLocation();
|
||||
if ((b.getBlockX() < 16 && b.getBlockX() > -16)
|
||||
&& (b.getBlockY() > 100)
|
||||
&& (b.getBlockZ() < 16 && b.getBlockZ() > -16) && !e.getPlayer().getName().equalsIgnoreCase("CUMR")) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
if (b.getBlock().getType() == Material.ENDER_PORTAL
|
||||
|| b.getBlock().getType() == Material.ENDER_PORTAL_FRAME) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBucket(PlayerBucketFillEvent e) {
|
||||
Location b = e.getBlockClicked().getLocation();
|
||||
if ((b.getBlockX() < 16 && b.getBlockX() > -16)
|
||||
&& (b.getBlockY() > 100)
|
||||
&& (b.getBlockZ() < 16 && b.getBlockZ() > -16) && !e.getPlayer().getName().equalsIgnoreCase("CUMR")) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
if (b.getBlock().getType() == Material.ENDER_PORTAL
|
||||
|| b.getBlock().getType() == Material.ENDER_PORTAL_FRAME) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
name: 2b2t-spawn
|
||||
main: org.cn2b2t.functions.spawn.Main
|
||||
version: 1.0.0 - SNAPSHOT
|
||||
authors:
|
||||
- Moci
|
||||
- cn2b2t
|
||||
depend:
|
||||
- 2b2t-core
|
||||
- 2b2t-common
|
||||
Reference in New Issue
Block a user