Added World View Distance Override (#26)

master
Joey Hines 2019-02-27 18:00:56 +01:00 committed by Gitea
parent cd8182b67c
commit 7bc3ba3783
8 changed files with 96 additions and 26 deletions

View File

@ -11,4 +11,5 @@ Changelogs
v1.3 <v1.3>
v1.4 <v1.4>
v1.5 <v1.5>
v1.6 <v1.6>
v1.6 <v1.6>
v1.7 <v1.7>

View File

@ -0,0 +1,15 @@
.. include:: ../common.rst
.. _qol_v1.7:
QoL v1.7
========
Additions
---------
* `World View Distance Overrides`_ - Allows each world to have its own view distance, set in the config
.. _World View Distance Overrides: https://git.etztech.xyz/Etzelia/Etzelia/QoL/commit/81a2fb3fa0e16ebbd4363074b17447be1d5b950e
Bug Fixes
---------

View File

@ -52,4 +52,9 @@ If Dynmap is detected on the server, QoL will hide a user on the dynmap when the
Grief Alert
-----------
If a player places TnT, starts a fire, or dumps lava, everyone with the ``qol.griefalert`` permission is notified as well as an optional Discord ping.
If a player places TnT, starts a fire, or dumps lava, everyone with the ``qol.griefalert`` permission is notified as well as an optional Discord ping.
World View Distance Override
----------------------------
Each world can have its own view distance. View distances of each world can be set in the config file. If no view distance is set, the view distance defaults to the one in server.properties.

12
pom.xml
View File

@ -3,7 +3,7 @@
<groupId>xyz.etztech</groupId>
<artifactId>QoL</artifactId>
<!-- Version is used in plugin.yml -->
<version>1.6</version>
<version>1.7</version>
<packaging>jar</packaging>
<!-- Plugin Information -->
@ -29,9 +29,9 @@
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13.1-R0.1-SNAPSHOT</version>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -59,8 +59,8 @@
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>etztech-repo</id>

View File

@ -1,8 +1,10 @@
package xyz.etztech.qol;
import net.ess3.api.Economy;
import net.ess3.api.IEssentials;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
@ -13,9 +15,7 @@ import xyz.etztech.qol.other.GriefAlert;
import xyz.etztech.qol.other.LinkCommand;
import xyz.etztech.qol.other.TPSRunnable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.logging.Logger;
public class QoL extends JavaPlugin {
@ -33,6 +33,8 @@ public class QoL extends JavaPlugin {
private static boolean timeout = false;
private static List<String> audits = new ArrayList<>();
private static List<LinkCommand> links = new ArrayList<>();
private static Map<String, Integer> viewDistances = new HashMap<>();
private GriefAlert griefAlert;
public void onEnable() {
@ -74,6 +76,8 @@ public class QoL extends JavaPlugin {
getServer().getPluginManager().registerEvents(playerBucketEmptyListener, this);
BlockPlaceListener blockPlaceListener = new BlockPlaceListener(this);
getServer().getPluginManager().registerEvents(blockPlaceListener, this);
PlayerChangedWorldListener playerChangedWorldListener = new PlayerChangedWorldListener(this);
getServer().getPluginManager().registerEvents(playerChangedWorldListener, this);
// Add commands
MainCommand mainCommand = new MainCommand(this);
@ -175,6 +179,17 @@ public class QoL extends JavaPlugin {
for (String raw : config.getStringList("links")) {
links.add(LinkCommand.fromString(raw));
}
viewDistances = new HashMap<>();
ConfigurationSection view_distances = config.getConfigurationSection("view-distances");
for (String worldName : view_distances.getKeys(false)) {
int viewDistance = view_distances.getInt(worldName);
viewDistances.put(worldName, viewDistance);
}
}
@ -279,16 +294,16 @@ public class QoL extends JavaPlugin {
return griefAlert;
}
public static Map<String, Integer> getViewDistances() {
return viewDistances;
}
public void runTask(final String command) {
Bukkit.getScheduler().runTask(QoL.instance, () -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command));
}
public void updatePlayerViewDistance(Player player) {
player.setViewDistance(viewDistances.getOrDefault(player.getWorld().getName().toLowerCase(), getServer().getViewDistance()));
}
}

View File

@ -42,18 +42,24 @@ public class JoinListener implements Listener {
// Queue commands
List<?> queues = plugin.getConfig().getList("queue");
for (int i = 0; i < queues.size(); i++) {
try {
LinkedHashMap queue = (LinkedHashMap) queues.get(i);
String permission = (String) queue.get("permission");
if (player.hasPermission(permission)) {
for (String command : (List<String>) queue.get("commands")) {
plugin.runTask(command.replace("<player>", player.getName()));
if (queues != null) {
for (int i = 0; i < queues.size(); i++) {
try {
LinkedHashMap queue = (LinkedHashMap) queues.get(i);
String permission = (String) queue.get("permission");
if (player.hasPermission(permission)) {
for (String command : (List<String>) queue.get("commands")) {
plugin.runTask(command.replace("<player>", player.getName()));
}
}
} catch (Exception ignored) {
}
} catch (Exception ignored) {}
}
}
plugin.updatePlayerViewDistance(player);
}
}

View File

@ -0,0 +1,24 @@
package xyz.etztech.qol.listeners;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import xyz.etztech.qol.QoL;
import java.util.Map;
public class PlayerChangedWorldListener implements Listener {
QoL plugin;
public PlayerChangedWorldListener(QoL plugin) {
this.plugin = plugin;
}
@EventHandler
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
Player player = event.getPlayer();
plugin.updatePlayerViewDistance(player);
}
}

View File

@ -88,4 +88,8 @@ disable-fire:
lightning: false
fireball: false
ender_crystal: false
explosion: false
explosion: false
# Overrides view distance per world, format is [World Name]: [View Distance]
view-distances:
# world: 2