Skip to content

Commit

Permalink
Add customizable messages
Browse files Browse the repository at this point in the history
  • Loading branch information
LXGaming committed Sep 14, 2018
1 parent 9860438 commit b433cef
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand All @@ -45,6 +49,10 @@ public IntegrationCategory getIntegrationCategory() {
return integrationCategory;
}

public MessageCategory getMessageCategory() {
return messageCategory;
}

public MixinCategory getMixinCategory() {
return mixinCategory;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}.
*
Expand Down

0 comments on commit b433cef

Please sign in to comment.