mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Warning message in configurable radius
This commit is contained in:
parent
510535fdd4
commit
73ffcbcb41
@ -20,15 +20,22 @@ package com.volmit.iris.core.service;
|
|||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||||
|
import com.volmit.iris.engine.object.IrisDimension;
|
||||||
import com.volmit.iris.engine.object.IrisVillagerOverride;
|
import com.volmit.iris.engine.object.IrisVillagerOverride;
|
||||||
import com.volmit.iris.engine.object.IrisVillagerTrade;
|
import com.volmit.iris.engine.object.IrisVillagerTrade;
|
||||||
|
import com.volmit.iris.util.format.C;
|
||||||
import com.volmit.iris.util.plugin.IrisService;
|
import com.volmit.iris.util.plugin.IrisService;
|
||||||
|
import com.volmit.iris.util.plugin.VolmitSender;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Villager;
|
import org.bukkit.entity.Villager;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.entity.VillagerAcquireTradeEvent;
|
import org.bukkit.event.entity.VillagerAcquireTradeEvent;
|
||||||
import org.bukkit.event.entity.VillagerCareerChangeEvent;
|
import org.bukkit.event.entity.VillagerCareerChangeEvent;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class VillageSVC implements IrisService {
|
public class VillageSVC implements IrisService {
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@ -42,18 +49,45 @@ public class VillageSVC implements IrisService {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void on(VillagerCareerChangeEvent event) {
|
public void on(VillagerCareerChangeEvent event) {
|
||||||
|
|
||||||
if (!IrisToolbelt.isIrisWorld(event.getEntity().getWorld())) {
|
if (!IrisToolbelt.isIrisWorld(event.getEntity().getWorld())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IrisToolbelt.access(event.getEntity().getWorld())
|
IrisDimension dim = IrisToolbelt.access(event.getEntity().getWorld())
|
||||||
.getEngine().getDimension().isRemoveCartographersDueToCrash()) {
|
.getEngine().getDimension();
|
||||||
|
|
||||||
|
if (!dim.isRemoveCartographersDueToCrash()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getProfession().equals(Villager.Profession.CARTOGRAPHER)) {
|
if (event.getProfession().equals(Villager.Profession.CARTOGRAPHER)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
Iris.info("Cancelled Cartographer Villager to prevent server crash!");
|
|
||||||
|
Location eventLocation = event.getEntity().getLocation();
|
||||||
|
|
||||||
|
int radius = dim.getNotifyPlayersOfCartographerCancelledRadius();
|
||||||
|
|
||||||
|
if (radius == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Player> playersInWorld = event.getEntity().getWorld().getPlayers();
|
||||||
|
|
||||||
|
String message = C.GOLD + "Iris does not allow cartographers in its world due to crashes.";
|
||||||
|
|
||||||
|
Iris.info("Cancelled Cartographer Villager to prevent server crash at " + eventLocation + "!");
|
||||||
|
|
||||||
|
if (radius == -2) {
|
||||||
|
playersInWorld.stream().map(VolmitSender::new).forEach(v -> v.sendMessage(message));
|
||||||
|
} else {
|
||||||
|
playersInWorld.forEach(p -> {
|
||||||
|
if (p.getLocation().distance(eventLocation) < radius) {
|
||||||
|
new VolmitSender(p).sendMessage(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,6 +227,8 @@ public class IrisDimension extends IrisRegistrant {
|
|||||||
// private IrisVillagerOverride patchCartographers = new IrisVillagerOverride().setDisableTrade(false);
|
// private IrisVillagerOverride patchCartographers = new IrisVillagerOverride().setDisableTrade(false);
|
||||||
@Desc("Remove cartographers so they do not crash the server (Iris worlds only)")
|
@Desc("Remove cartographers so they do not crash the server (Iris worlds only)")
|
||||||
private boolean removeCartographersDueToCrash = true;
|
private boolean removeCartographersDueToCrash = true;
|
||||||
|
@Desc("Notify players of cancelled cartographer villager in this radius in blocks (set to -1 to disable, -2 for everyone)")
|
||||||
|
private int notifyPlayersOfCartographerCancelledRadius = 30;
|
||||||
@Desc("Collection of ores to be generated")
|
@Desc("Collection of ores to be generated")
|
||||||
@ArrayType(type = IrisOreGenerator.class, min = 1)
|
@ArrayType(type = IrisOreGenerator.class, min = 1)
|
||||||
private KList<IrisOreGenerator> ores = new KList<>();
|
private KList<IrisOreGenerator> ores = new KList<>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user