Add utils for future plugins
This commit is contained in:
12 files changed
+233
-77
No files matched your search
@@ -1,71 +0,0 @@
|
|||||||
package xyz.lncvrt.speedlimitplugin;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
public final class SpeedLimitPlugin extends JavaPlugin implements Listener {
|
|
||||||
private final Map<UUID, Location> lastPos = new ConcurrentHashMap<>();
|
|
||||||
private final Map<UUID, Long> lastTime = new ConcurrentHashMap<>();
|
|
||||||
private static final double MAX_SPEED = 75.0;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
|
||||||
getServer().getPluginManager().registerEvents(this, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
|
||||||
public void onPlayerTeleport(PlayerTeleportEvent e) {
|
|
||||||
UUID id = e.getPlayer().getUniqueId();
|
|
||||||
Location to = e.getTo();
|
|
||||||
lastPos.put(id, to);
|
|
||||||
lastTime.put(id, System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
|
||||||
public void onPlayerMove(PlayerMoveEvent e) {
|
|
||||||
Location to = e.getTo();
|
|
||||||
Location from = e.getFrom();
|
|
||||||
|
|
||||||
UUID id = e.getPlayer().getUniqueId();
|
|
||||||
long now = System.currentTimeMillis();
|
|
||||||
|
|
||||||
if (!to.getWorld().equals(from.getWorld())) {
|
|
||||||
lastPos.put(id, to);
|
|
||||||
lastTime.put(id, now);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Location lastLocation = lastPos.get(id);
|
|
||||||
Long lastTimestamp = lastTime.get(id);
|
|
||||||
if (lastLocation == null || lastTimestamp == null || !lastLocation.getWorld().equals(to.getWorld())) {
|
|
||||||
lastPos.put(id, to);
|
|
||||||
lastTime.put(id, now);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
double dist = lastLocation.distance(to);
|
|
||||||
double elapsed = (now - lastTimestamp) / 1000.0;
|
|
||||||
if (elapsed <= 0.05) elapsed = 0.05;
|
|
||||||
|
|
||||||
double speed = dist / elapsed;
|
|
||||||
|
|
||||||
if (speed > MAX_SPEED) {
|
|
||||||
e.setCancelled(true);
|
|
||||||
e.getPlayer().teleport(lastLocation);
|
|
||||||
e.getPlayer().sendMessage(ChatColor.RED + "You are going " + (int) speed + "BPS! Please slow down and go below " + (int) MAX_SPEED + " BPS.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
lastPos.put(id, to);
|
|
||||||
lastTime.put(id, now);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
name: SpeedLimitPlugin
|
|
||||||
version: '${version}'
|
|
||||||
main: xyz.lncvrt.speedlimitplugin.SpeedLimitPlugin
|
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
|
id("com.gradleup.shadow") version "9.0.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'xyz.lncvrt'
|
group = 'xyz.lncvrt.legacycraftplugins.onepointsixplugin'
|
||||||
version = '1.0.0'
|
version = '1.0.0'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
@@ -10,7 +11,8 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly(files('libs/craftbukkit-1.6.4-R2.0.jar'))
|
implementation project(":utils")
|
||||||
|
compileOnly(files('../libs/craftbukkit-1.6.4-R2.0.jar'))
|
||||||
}
|
}
|
||||||
|
|
||||||
def targetJavaVersion = 8
|
def targetJavaVersion = 8
|
||||||
@@ -31,6 +33,15 @@ tasks.withType(JavaCompile).configureEach {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
shadowJar {
|
||||||
|
archiveClassifier.set("")
|
||||||
|
}
|
||||||
|
build {
|
||||||
|
dependsOn(shadowJar)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
def props = [version: version]
|
def props = [version: version]
|
||||||
inputs.properties props
|
inputs.properties props
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
include(":utils")
|
||||||
+117
@@ -0,0 +1,117 @@
|
|||||||
|
package xyz.lncvrt.legacycraftplugins.onepointsixplugin;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_6_R3.EntityPlayer;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scoreboard.*;
|
||||||
|
import xyz.lncvrt.legacycraftplugins.onepointsixplugin.commands.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public final class LegacyCraftPlugin extends JavaPlugin implements Listener {
|
||||||
|
private final Map<UUID, Location> lastPos = new ConcurrentHashMap<>();
|
||||||
|
private final Map<UUID, Long> lastTime = new ConcurrentHashMap<>();
|
||||||
|
private static final double MAX_SPEED = 75.0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
getCommand("spawn").setExecutor(new SpawnCommand(this));
|
||||||
|
getCommand("rules").setExecutor(new RulesCommand());
|
||||||
|
getCommand("discord").setExecutor(new DiscordCommand());
|
||||||
|
getServer().getPluginManager().registerEvents(this, this);
|
||||||
|
getServer().getScheduler().runTaskTimer(this, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (Player player : getServer().getOnlinePlayers()) {
|
||||||
|
int players = Arrays.stream(getServer().getOnlinePlayers()).toArray().length;
|
||||||
|
int ping = ((CraftPlayer) player).getHandle().ping;
|
||||||
|
String playersString = ChatColor.GOLD + "Players: " + players;
|
||||||
|
String pingString = ChatColor.GOLD + "Ping: " + ping + "ms";
|
||||||
|
if (playersString.length() > 16) {
|
||||||
|
playersString = playersString.substring(0, 16);
|
||||||
|
}
|
||||||
|
if (pingString.length() > 16) {
|
||||||
|
pingString = pingString.substring(0, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScoreboardManager manager = getServer().getScoreboardManager();
|
||||||
|
Scoreboard board = manager.getNewScoreboard();
|
||||||
|
|
||||||
|
Objective objective = board.registerNewObjective(ChatColor.GOLD + "LegacyCraft", "customsb");
|
||||||
|
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||||
|
|
||||||
|
Score score1 = objective.getScore(getServer().getOfflinePlayer(playersString));
|
||||||
|
score1.setScore(1);
|
||||||
|
Score score2 = objective.getScore(getServer().getOfflinePlayer(pingString));
|
||||||
|
score2.setScore(0);
|
||||||
|
|
||||||
|
player.setScoreboard(board);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0L, 20L);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onDisable() {
|
||||||
|
for (Player player : getServer().getOnlinePlayers()) {
|
||||||
|
player.setScoreboard(getServer().getScoreboardManager().getNewScoreboard());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onPlayerTeleport(PlayerTeleportEvent e) {
|
||||||
|
UUID id = e.getPlayer().getUniqueId();
|
||||||
|
Location to = e.getTo();
|
||||||
|
lastPos.put(id, to);
|
||||||
|
lastTime.put(id, System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onPlayerMove(PlayerMoveEvent e) {
|
||||||
|
Location to = e.getTo();
|
||||||
|
Location from = e.getFrom();
|
||||||
|
|
||||||
|
UUID id = e.getPlayer().getUniqueId();
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
|
||||||
|
if (!to.getWorld().equals(from.getWorld())) {
|
||||||
|
lastPos.put(id, to);
|
||||||
|
lastTime.put(id, now);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location lastLocation = lastPos.get(id);
|
||||||
|
Long lastTimestamp = lastTime.get(id);
|
||||||
|
if (lastLocation == null || lastTimestamp == null || !lastLocation.getWorld().equals(to.getWorld())) {
|
||||||
|
lastPos.put(id, to);
|
||||||
|
lastTime.put(id, now);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double dist = lastLocation.distance(to);
|
||||||
|
double elapsed = (now - lastTimestamp) / 1000.0;
|
||||||
|
if (elapsed <= 0.05) elapsed = 0.05;
|
||||||
|
|
||||||
|
double speed = dist / elapsed;
|
||||||
|
|
||||||
|
if (speed > MAX_SPEED) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
e.getPlayer().teleport(lastLocation);
|
||||||
|
e.getPlayer().sendMessage(ChatColor.RED + "You are going " + (int) speed + "BPS! Please slow down and go below " + (int) MAX_SPEED + " BPS.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastPos.put(id, to);
|
||||||
|
lastTime.put(id, now);
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package xyz.lncvrt.legacycraftplugins.onepointsixplugin.commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import xyz.lncvrt.legacycraftplugins.utils.Messages;
|
||||||
|
|
||||||
|
public class DiscordCommand implements CommandExecutor {
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||||
|
commandSender.sendMessage(Messages.discord);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package xyz.lncvrt.legacycraftplugins.onepointsixplugin.commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import xyz.lncvrt.legacycraftplugins.utils.Messages;
|
||||||
|
|
||||||
|
public class RulesCommand implements CommandExecutor {
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||||
|
commandSender.sendMessage(Messages.rules);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
package xyz.lncvrt.legacycraftplugins.onepointsixplugin.commands;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_6_R3.ChatMessage;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import xyz.lncvrt.legacycraftplugins.onepointsixplugin.LegacyCraftPlugin;
|
||||||
|
|
||||||
|
public class SpawnCommand implements CommandExecutor {
|
||||||
|
private final LegacyCraftPlugin plugin;
|
||||||
|
|
||||||
|
public SpawnCommand(LegacyCraftPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||||
|
if (commandSender instanceof Player) {
|
||||||
|
Player player = (Player) commandSender;
|
||||||
|
World world = plugin.getServer().getWorld("world");
|
||||||
|
player.teleport(new Location(world, -78, 63, 262));
|
||||||
|
player.sendMessage(ChatColor.GOLD + "Teleporting to spawn...");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
name: 'LegacyCraftPlugin'
|
||||||
|
version: '${version}'
|
||||||
|
main: xyz.lncvrt.legacycraftplugins.onepointsixplugin.LegacyCraftPlugin
|
||||||
|
commands:
|
||||||
|
spawn:
|
||||||
|
usage: /spawn
|
||||||
|
rules:
|
||||||
|
usage: /rules
|
||||||
|
discord:
|
||||||
|
usage: /discord
|
||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
rootProject.name = 'LegacyCraft-Plugins'
|
rootProject.name = 'LegacyCraft-Plugins'
|
||||||
include("164plugin")
|
include(":onepointsixplugin", ":utils")
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly(files('../libs/craftbukkit-1.6.4-R2.0.jar'))
|
||||||
|
}
|
||||||
|
|
||||||
|
def targetJavaVersion = 8
|
||||||
|
java {
|
||||||
|
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
||||||
|
sourceCompatibility = javaVersion
|
||||||
|
targetCompatibility = javaVersion
|
||||||
|
if (JavaVersion.current() < javaVersion) {
|
||||||
|
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
options.encoding = 'UTF-8'
|
||||||
|
|
||||||
|
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
|
||||||
|
options.release.set(targetJavaVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package xyz.lncvrt.legacycraftplugins.utils;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
public final class Messages {
|
||||||
|
public static String rules = ChatColor.GOLD + "Server Rules\n1. No Griefing\n2. No Stealing\n3. No random killing\n4. Be kind in chat\n5. No saying slurs in chat\n6. No Exploiting\n7. No Duping\n8. No Hacking";
|
||||||
|
public static String discord = ChatColor.GOLD + "Discord Invite: https://discord.gg/mVj6Rem5fM";
|
||||||
|
}
|
||||||
Reference in new issue
Block a user