From b433cef7f71ed0a3a5747655107926d9749c243b Mon Sep 17 00:00:00 2001 From: Alex Thomson Date: Fri, 14 Sep 2018 18:14:30 +1200 Subject: [PATCH] Add customizable messages --- build.gradle | 2 +- .../sledgehammer/configuration/Config.java | 8 +++++ .../category/MessageCategory.java | 31 +++++++++++++++++++ .../SpongeIntegration_Border.java | 10 +++++- .../lxgaming/sledgehammer/util/Reference.java | 2 +- .../lxgaming/sledgehammer/util/Toolbox.java | 5 +++ 6 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 src/main/java/io/github/lxgaming/sledgehammer/configuration/category/MessageCategory.java diff --git a/build.gradle b/build.gradle index ed4ca37..1beae20 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ targetCompatibility = 1.8 group = "io.github.lxgaming" archivesBaseName = "Sledgehammer" -version = "1.12.2-1.2.8" +version = "1.12.2-1.2.9" minecraft { version = "1.12.2-14.23.4.2705" diff --git a/src/main/java/io/github/lxgaming/sledgehammer/configuration/Config.java b/src/main/java/io/github/lxgaming/sledgehammer/configuration/Config.java index a51a95c..4aaf95b 100644 --- a/src/main/java/io/github/lxgaming/sledgehammer/configuration/Config.java +++ b/src/main/java/io/github/lxgaming/sledgehammer/configuration/Config.java @@ -17,6 +17,7 @@ package io.github.lxgaming.sledgehammer.configuration; import io.github.lxgaming.sledgehammer.configuration.category.IntegrationCategory; +import io.github.lxgaming.sledgehammer.configuration.category.MessageCategory; import io.github.lxgaming.sledgehammer.configuration.category.MixinCategory; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -30,6 +31,9 @@ public class Config { @Setting(value = "integration") private IntegrationCategory integrationCategory = new IntegrationCategory(); + @Setting(value = "message") + private MessageCategory messageCategory = new MessageCategory(); + @Setting(value = "mixin") private MixinCategory mixinCategory = new MixinCategory(); @@ -45,6 +49,10 @@ public IntegrationCategory getIntegrationCategory() { return integrationCategory; } + public MessageCategory getMessageCategory() { + return messageCategory; + } + public MixinCategory getMixinCategory() { return mixinCategory; } diff --git a/src/main/java/io/github/lxgaming/sledgehammer/configuration/category/MessageCategory.java b/src/main/java/io/github/lxgaming/sledgehammer/configuration/category/MessageCategory.java new file mode 100644 index 0000000..c1e85b3 --- /dev/null +++ b/src/main/java/io/github/lxgaming/sledgehammer/configuration/category/MessageCategory.java @@ -0,0 +1,31 @@ +/* + * Copyright 2018 Alex Thomson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.github.lxgaming.sledgehammer.configuration.category; + +import ninja.leaping.configurate.objectmapping.Setting; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; + +@ConfigSerializable +public class MessageCategory { + + @Setting(value = "move-outside-border", comment = "Sent to the player when attempting to move outside the world border") + private String moveOutsideBorder = "&cCannot move outside of the world border"; + + public String getMoveOutsideBorder() { + return moveOutsideBorder; + } +} \ No newline at end of file diff --git a/src/main/java/io/github/lxgaming/sledgehammer/integrations/SpongeIntegration_Border.java b/src/main/java/io/github/lxgaming/sledgehammer/integrations/SpongeIntegration_Border.java index 915d058..406258f 100644 --- a/src/main/java/io/github/lxgaming/sledgehammer/integrations/SpongeIntegration_Border.java +++ b/src/main/java/io/github/lxgaming/sledgehammer/integrations/SpongeIntegration_Border.java @@ -18,12 +18,17 @@ import com.flowpowered.math.vector.Vector3d; import io.github.lxgaming.sledgehammer.Sledgehammer; +import io.github.lxgaming.sledgehammer.configuration.Config; +import io.github.lxgaming.sledgehammer.configuration.category.MessageCategory; +import io.github.lxgaming.sledgehammer.util.Toolbox; +import org.codehaus.plexus.util.StringUtils; import org.spongepowered.api.Sponge; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.Order; import org.spongepowered.api.event.entity.MoveEntityEvent; import org.spongepowered.api.event.filter.cause.Root; +import org.spongepowered.api.text.Text; import org.spongepowered.api.world.Location; import org.spongepowered.api.world.World; @@ -48,7 +53,10 @@ public void onMoveEntity(MoveEntityEvent event, @Root Player player) { Vector3d displacement = location.getPosition().sub(world.getWorldBorder().getCenter()).abs(); if (displacement.getX() > radius || displacement.getZ() > radius) { event.setCancelled(true); - Sledgehammer.getInstance().debugMessage("Move denied for {} ({})", player.getName(), player.getUniqueId()); + Sledgehammer.getInstance().debugMessage("Movement denied for {} ({})", player.getName(), player.getUniqueId()); + Sledgehammer.getInstance().getConfig().map(Config::getMessageCategory).map(MessageCategory::getMoveOutsideBorder).filter(StringUtils::isNotBlank).ifPresent(message -> { + player.sendMessage(Text.of(Toolbox.getTextPrefix(), Toolbox.convertColor(message))); + }); } } } \ No newline at end of file diff --git a/src/main/java/io/github/lxgaming/sledgehammer/util/Reference.java b/src/main/java/io/github/lxgaming/sledgehammer/util/Reference.java index 430a9fb..1eb162d 100644 --- a/src/main/java/io/github/lxgaming/sledgehammer/util/Reference.java +++ b/src/main/java/io/github/lxgaming/sledgehammer/util/Reference.java @@ -20,7 +20,7 @@ public class Reference { public static final String PLUGIN_ID = "sledgehammer"; public static final String PLUGIN_NAME = "Sledgehammer"; - public static final String PLUGIN_VERSION = "1.12.2-1.2.8"; + public static final String PLUGIN_VERSION = "1.12.2-1.2.9"; public static final String DESCRIPTION = "Smashes the stupid out of the server."; public static final String AUTHORS = "LX_Gaming"; public static final String SOURCE = "https://github.com/LXGaming/Sledgehammer/"; diff --git a/src/main/java/io/github/lxgaming/sledgehammer/util/Toolbox.java b/src/main/java/io/github/lxgaming/sledgehammer/util/Toolbox.java index 9624192..edbdba7 100644 --- a/src/main/java/io/github/lxgaming/sledgehammer/util/Toolbox.java +++ b/src/main/java/io/github/lxgaming/sledgehammer/util/Toolbox.java @@ -23,6 +23,7 @@ import org.spongepowered.api.text.action.TextActions; import org.spongepowered.api.text.format.TextColors; import org.spongepowered.api.text.format.TextStyles; +import org.spongepowered.api.text.serializer.TextSerializers; import java.net.MalformedURLException; import java.net.URL; @@ -61,6 +62,10 @@ public static TextAction getURLTextAction(String url) { } } + public static Text convertColor(String string) { + return TextSerializers.FORMATTING_CODE.deserialize(string); + } + /** * Removes non-printable characters (excluding new line and carriage return) in the provided {@link java.lang.String String}. *