added LocatorBar preferences
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.locatorBar;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.Settings;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class LocatorBar extends Appliance {
|
||||
private enum Distance {
|
||||
MAX(6.0e7),
|
||||
ZERO(0.0);
|
||||
|
||||
final double distance;
|
||||
Distance(double distance) {
|
||||
this.distance = distance;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Settings.instance().declareSetting(LocatorBarSettings.class);
|
||||
Settings.instance().addChangeListener(LocatorBarSettings.class, this::updateLocatorBar);
|
||||
}
|
||||
|
||||
public void updateLocatorBar(Player player) {
|
||||
boolean enabled = Settings.instance().getSetting(player, Settings.Key.LocatorBarConfig, Boolean.class);
|
||||
|
||||
AttributeInstance receive = player.getAttribute(Attribute.WAYPOINT_RECEIVE_RANGE);
|
||||
AttributeInstance transmit = player.getAttribute(Attribute.WAYPOINT_TRANSMIT_RANGE);
|
||||
|
||||
Objects.requireNonNull(receive);
|
||||
Objects.requireNonNull(transmit);
|
||||
|
||||
receive.setBaseValue(enabled ? Distance.MAX.distance : Distance.ZERO.distance);
|
||||
transmit.setBaseValue(enabled ? Distance.MAX.distance : Distance.ZERO.distance);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new LocatorBarUpdateListener()
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.locatorBar;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.CategorizedSetting;
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.SettingCategory;
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.Settings;
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.datatypes.BoolSetting;
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class LocatorBarSettings extends BoolSetting implements CategorizedSetting {
|
||||
@Override
|
||||
public SettingCategory category() {
|
||||
return SettingCategory.Gameplay;
|
||||
}
|
||||
|
||||
public LocatorBarSettings() {
|
||||
super(Settings.Key.LocatorBarConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String title() {
|
||||
return "Ortungsleiste / Locator Bar";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String description() {
|
||||
return "Konfiguriere, ob andere Spieler deine Position und du die Position anderer sehen möchtest";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Material icon() {
|
||||
return Material.COMPASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean defaultValue() {
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.locatorBar;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
class LocatorBarUpdateListener extends ApplianceListener<LocatorBar> {
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
this.getAppliance().updateLocatorBar(event.getPlayer());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user