Fixed message formatting

This commit is contained in:
stijnb1234 2020-02-28 16:38:47 +01:00
parent f6bf85c654
commit f5f8ba67e9
4 changed files with 178 additions and 161 deletions

View file

@ -3,13 +3,14 @@ package nl.SBDeveloper.V10Lift.Managers;
import nl.SBDeveloper.V10Lift.Utils.XMaterial; import nl.SBDeveloper.V10Lift.Utils.XMaterial;
import org.bukkit.Material; import org.bukkit.Material;
import java.util.ArrayList; import java.util.HashSet;
public class AntiCopyBlockManager { public class AntiCopyBlockManager {
private ArrayList<XMaterial> antiCopy = new ArrayList<>(); private HashSet<XMaterial> antiCopy = new HashSet<>();
public AntiCopyBlockManager() { public AntiCopyBlockManager() {
//TODO Add more anti copy materials //TODO Add more anti copy materials
//TODO Add to config
antiCopy.add(XMaterial.REDSTONE_TORCH); antiCopy.add(XMaterial.REDSTONE_TORCH);
antiCopy.add(XMaterial.REDSTONE_WALL_TORCH); antiCopy.add(XMaterial.REDSTONE_WALL_TORCH);
antiCopy.add(XMaterial.REPEATER); antiCopy.add(XMaterial.REPEATER);
@ -56,6 +57,26 @@ public class AntiCopyBlockManager {
antiCopy.add(XMaterial.DETECTOR_RAIL); antiCopy.add(XMaterial.DETECTOR_RAIL);
antiCopy.add(XMaterial.ACTIVATOR_RAIL); antiCopy.add(XMaterial.ACTIVATOR_RAIL);
antiCopy.add(XMaterial.LADDER); antiCopy.add(XMaterial.LADDER);
/* Because of datatypes */
antiCopy.add(XMaterial.BEEHIVE);
antiCopy.add(XMaterial.BELL);
antiCopy.add(XMaterial.BREWING_STAND);
antiCopy.add(XMaterial.BUBBLE_COLUMN);
antiCopy.add(XMaterial.CAKE);
antiCopy.add(XMaterial.CAMPFIRE);
antiCopy.add(XMaterial.COCOA);
antiCopy.add(XMaterial.COMMAND_BLOCK);
antiCopy.add(XMaterial.CHAIN_COMMAND_BLOCK);
antiCopy.add(XMaterial.REPEATING_COMMAND_BLOCK);
antiCopy.add(XMaterial.DAYLIGHT_DETECTOR);
antiCopy.add(XMaterial.DISPENSER);
antiCopy.add(XMaterial.END_PORTAL_FRAME);
antiCopy.add(XMaterial.FARMLAND);
antiCopy.add(XMaterial.FIRE);
antiCopy.add(XMaterial.FURNACE);
antiCopy.add(XMaterial.HOPPER);
antiCopy.add(XMaterial.JUKEBOX);
} }
public boolean isAntiCopy(Material mat) { public boolean isAntiCopy(Material mat) {

View file

@ -3,20 +3,14 @@ package nl.SBDeveloper.V10Lift.Managers;
import nl.SBDeveloper.V10Lift.Utils.XMaterial; import nl.SBDeveloper.V10Lift.Utils.XMaterial;
import org.bukkit.Material; import org.bukkit.Material;
import java.util.ArrayList; import java.util.HashSet;
public class ForbiddenBlockManager { public class ForbiddenBlockManager {
private ArrayList<XMaterial> forbidden = new ArrayList<>(); private HashSet<XMaterial> forbidden = new HashSet<>();
public ForbiddenBlockManager() { public ForbiddenBlockManager() {
//TODO Add more forbidden materials //TODO Add more forbidden materials
/*forbidden.add(XMaterial.ACACIA_DOOR); //TODO Add to config
forbidden.add(XMaterial.BIRCH_DOOR);
forbidden.add(XMaterial.DARK_OAK_DOOR);
forbidden.add(XMaterial.IRON_DOOR);
forbidden.add(XMaterial.JUNGLE_DOOR);
forbidden.add(XMaterial.OAK_DOOR);
forbidden.add(XMaterial.SPRUCE_DOOR);*/
forbidden.add(XMaterial.BLACK_BED); forbidden.add(XMaterial.BLACK_BED);
forbidden.add(XMaterial.BLUE_BED); forbidden.add(XMaterial.BLUE_BED);
forbidden.add(XMaterial.BROWN_BED); forbidden.add(XMaterial.BROWN_BED);

View file

@ -32,15 +32,19 @@ public class ConfigUtil {
* @param path The path to look for * @param path The path to look for
*/ */
public static void sendMessage(CommandSender p, @Nonnull String path) { public static void sendMessage(CommandSender p, @Nonnull String path) {
String fileMessage = V10LiftPlugin.getMessages().getFile().getString(path); if (V10LiftPlugin.getMessages().getFile().get(path) == null) {
if (fileMessage == null) {
throw new NullPointerException("Message " + path + " not found in messages.yml!"); throw new NullPointerException("Message " + path + " not found in messages.yml!");
} }
String[] messages = fileMessage.split("\n"); if (V10LiftPlugin.getMessages().getFile().isList(path)) {
for (String message : messages) { //Multi line message
for (String message : V10LiftPlugin.getMessages().getFile().getStringList(path)) {
p.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); p.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
} }
} else {
//Single line message
p.sendMessage(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(V10LiftPlugin.getMessages().getFile().getString(path))));
}
} }
/** /**
@ -51,20 +55,31 @@ public class ConfigUtil {
* @param replacement The replacements -> key: %Name% = value: TheName * @param replacement The replacements -> key: %Name% = value: TheName
*/ */
public static void sendMessage(CommandSender p, @Nonnull String path, Map<String, String> replacement) { public static void sendMessage(CommandSender p, @Nonnull String path, Map<String, String> replacement) {
String fileMessage = V10LiftPlugin.getMessages().getFile().getString(path); if (V10LiftPlugin.getMessages().getFile().get(path) == null) {
if (fileMessage == null) {
throw new NullPointerException("Message " + path + " not found in messages.yml!"); throw new NullPointerException("Message " + path + " not found in messages.yml!");
} }
if (V10LiftPlugin.getMessages().getFile().isList(path)) {
//Multi line message
for (String message : V10LiftPlugin.getMessages().getFile().getStringList(path)) {
p.sendMessage(formatMessage(message, replacement));
}
} else {
//Single line message
String message = V10LiftPlugin.getMessages().getFile().getString(path);
p.sendMessage(formatMessage(message, replacement));
}
}
@Nonnull
private static String formatMessage(String message, @Nonnull Map<String, String> replacement) {
Map<String, String> fixedMap = new HashMap<>(); Map<String, String> fixedMap = new HashMap<>();
for (Map.Entry<String, String> ent : replacement.entrySet()) { for (Map.Entry<String, String> ent : replacement.entrySet()) {
fixedMap.put(ent.getKey().replaceAll("%", ""), ent.getValue()); fixedMap.put(ent.getKey().replaceAll("%", ""), ent.getValue());
} }
String[] messages = fileMessage.split("\n");
for (String message : messages) {
Pattern pattern = Pattern.compile("%(.*?)%"); Pattern pattern = Pattern.compile("%(.*?)%");
Matcher matcher = pattern.matcher(message); Matcher matcher = pattern.matcher(Objects.requireNonNull(message));
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
int i = 0; int i = 0;
while (matcher.find()) { while (matcher.find()) {
@ -77,7 +92,6 @@ public class ConfigUtil {
i = matcher.end(); i = matcher.end();
} }
builder.append(message.substring(i)); builder.append(message.substring(i));
p.sendMessage(ChatColor.translateAlternateColorCodes('&', builder.toString())); return ChatColor.translateAlternateColorCodes('&', builder.toString());
}
} }
} }

View file

@ -1,155 +1,143 @@
General: General:
#General #General
NoPermission: "&cYou don't have the permission to do this." NoPermission: '&cYou don''t have the permission to do this.'
PlayerOnly: "&cYou have to be a player to do this." PlayerOnly: '&cOnly players can do this.'
IncorrectUsage: "&cPlease use %Command%" IncorrectUsage: '&cPlease use %Command% instead'
InternalError: "&cInternal error!" InternalError: '&cSomething went wrong internally.'
#General lift #Lift general
DoesntExists: "&cA lift with that name doesn't exists." DoesntExists: '&cThere are no lifts with that name.'
AlreadyExists: "&cA lift with that name already exists." AlreadyExists: '&cA lift with that name already exists.'
SwitchOnEdit: "&cFirst switch on the editor mode!" SwitchOnEdit: '&cEnable editor mode before doing this.'
DetectionFailed: "&cAutomatic floor detection failed!" DetectionFailed: '&cAutomatic floor detection failed!'
FloorDoesntExists: "&cThe floor %Name% doesn't exists!" FloorDoesntExists: '&cThe floor %Name% doesn''t exists!'
#Control lift #Lift control
NoWhitelistPermission: "&cYou can't go to that floor!" NoWhitelistPermission: '&cYou can''t go to that floor!'
NoFloors: "&cThis elevator has no floors!" NoFloors: '&cThis elevator has no floors!'
#Anti break
RemoveLiftFirst: "&cYou can't do this! Remove the lift first."
RemoveRopeFirst: "&cYou can't do this! Remove the rope first."
RemoveDoorFirst: "&cYou can't do this! Remove the door first."
#Protection
RemoveLiftFirst: '&cYou can''t do this! Remove the lift first.'
RemoveRopeFirst: '&cYou can''t do this! Remove the rope first.'
RemoveDoorFirst: '&cYou can''t do this! Remove the door first.'
Create: Create:
AddBlocks: "&aOkay, now add all the blocks from the cab by right-clicking on the blocks.\n&aThen type: /v10lift create <Name>" AddBlocks: |-
NoBlocks: "&cAdd blocks first." &aOkay, now add all the blocks from the cab by right-clicking them.
Created: "&aThe lift %Name% is successfully created." &awhen finished, type: /v10lift create <Name>
NoBlocks: '&cYou must add blocks first.'
Created: '&aSuccessfully created lift %Name%.'
Delete: Delete:
NotRemoved: "&cThe lift %Name% couldn't be removed." NotRemoved: '&cThe lift %Name% couldn''t be removed.'
Removed: "&aThe lift %Name% is successfully removed." Removed: '&aSuccessfully removed lift %Name%.'
Rename: Rename:
Renamed: "&aLift successfully renamed!" Renamed: '&aLift successfully renamed!'
Edit: Edit:
StillInEditMode: "&cYou are still in editor mode." StillInEditMode: '&cYou are still in editor mode.'
TurnedOn: "&aEditor turned on." TurnedOn: '&aEnabled editor.'
TurnedOff: "&aEditor turned off." TurnedOff: '&aDisabled editor.'
Floor: Floor:
ToHigh: "&cThat floor is too high!" ToHigh: '&cThat floor is too high!'
AlreadyExists: "&cThat floor already exists!" AlreadyExists: '&cThat floor already exists!'
DoesntExists: "&cThat floor doesn't exists!" DoesntExists: '&cThat floor doesn''t exists!'
Added: "&aFloor successfully added!" Added: '&aFloor successfully added!'
Removed: "&aFloor successfully removed!" Removed: '&aFloor successfully removed!'
Renamed: "&aFloor successfully renamed!" Renamed: '&aFloor successfully renamed!'
Input: Input:
StillAdjusting: "&cYou are still adjusting an input!" StillAdjusting: '&cYou are still adjusting an input!'
NothingToRemove: "&cThere is no input to remove!" NothingToRemove: '&cThere is no input to remove!'
AlreadyAdded: "&cThis block has already been chosen as an input. Choose another block!" AlreadyAdded: '&cThis block has already been chosen as an input. Choose another
NoInput: "&cThis block is not an input. Choose another block!" block!'
RightClick: "&aNow right click on the input block!" NoInput: '&cThis block is not an input. Choose another block!'
Created: "&aInput created!" RightClick: '&aNow right click on the input block!'
Removed: "&aInput removed!" Created: '&aInput created!'
Removed: '&aInput removed!'
OfflineInput: OfflineInput:
StillAdjusting: "&cYou are still adjusting an offline input!" StillAdjusting: '&cYou are still adjusting an offline input!'
NothingToRemove: "&cThere is no offline input to remove!" NothingToRemove: '&cThere is no offline input to remove!'
AlreadyAdded: "&cThis block has already been chosen as an offline input. Choose another block!" AlreadyAdded: '&cThis block has already been chosen as an offline input. Choose
NoInput: "&cThis block is not an offline input. Choose another block!" another block!'
RightClick: "&aNow right click on the offline input block!" NoInput: '&cThis block is not an offline input. Choose another block!'
Created: "&aOffline input created!" RightClick: '&aNow right click on the offline input block!'
Removed: "&aOffline input removed!" Created: '&aOffline input created!'
Removed: '&aOffline input removed!'
Build: Build:
Disabled: "&aConstruction mode disabled!" Disabled: '&aConstruction mode disabled!'
Enabled: "&aNow right-click on the elevator blocks!\n&aThen do /v10lift build to save it!" Enabled: |-
BlockAdded: "&aBlock added to the elevator." &aNow right-click on the elevator blocks!
BlockRemoved: "&6Block removed from the elevator." &aThen do /v10lift build to save it!
BlacklistedMaterial: "&cThe material %Name% cannot be used!" BlockAdded: '&aBlock added to the elevator.'
BlockRemoved: '&6Block removed from the elevator.'
BlacklistedMaterial: '&cThe material %Name% cannot be used!'
Rope: Rope:
StillAdjusting: "&cYou are still adjusting a rope." StillAdjusting: '&cYou are still adjusting a rope.'
OnlyUp: "&cA rope can only go up!" OnlyUp: '&cA rope can only go up!'
OnlyOneMaterial: "&cThe rope must be of the same material!" OnlyOneMaterial: '&cThe rope must be of the same material!'
AlreadyARope: "&cPart of the rope is already part of another rope!" AlreadyARope: '&cPart of the rope is already part of another rope!'
NotARope: "&cThis block is not part of the rope." NotARope: '&cThis block is not part of the rope.'
BlacklistedMaterial: "&cThe rope is build of blacklisted blocks!" BlacklistedMaterial: '&cThe rope is build of blacklisted blocks!'
Add: "&aNow right-click on the beginning and the end of the rope." Add: '&aNow right-click on the beginning and the end of the rope.'
Delete: "&aNow right-click on the rope." Delete: '&aNow right-click on the rope.'
ClickOnEnd: "&6Now right-click on the end of the rope!" ClickOnEnd: '&6Now right-click on the end of the rope!'
PartRemoved: "&6Start removed!\n&6Now right-click on the end of the rope!" PartRemoved: |-
Created: "&aRope created." &6Start removed!
Removed: "&aRope removed." &6Now right-click on the end of the rope!
Created: '&aRope created.'
Removed: '&aRope removed.'
Door: Door:
BlacklistedMaterial: "&cThe material %Name% is currently not supported!" BlacklistedMaterial: '&cThe material %Name% is currently not supported!'
Disabled: "&aDoor editor mode disabled!" Disabled: '&aDoor editor mode disabled!'
Enabled: "&aNow right-click on the door blocks! (If it are real doors, click on the bottom block)\n&aThen do /v10lift door to save it." Enabled: |-
Created: "&aDoor created." &aNow right-click on the door blocks! (If it are real doors, click on the bottom block)
Removed: "&6Door removed." &aThen do /v10lift door to save it.
Created: '&aDoor created.'
Removed: '&6Door removed.'
Whitelist: Whitelist:
Group: Group:
VaultNotFound: "&cYou can't add a group when Vault is not found." VaultNotFound: '&cYou can''t add a group when Vault is not found.'
NotFound: "&cThe group %Name% is not found." NotFound: '&cThe group %Name% is not found.'
AlreadyContains: "&cWhitelist already contains this group!" AlreadyContains: '&cThe whitelist already contains this group!'
DoesntContains: "&cWhitelist doesn't contain this group!" DoesntContains: '&cThe whitelist doesn''t contain this group!'
Added: "&aGroup added to whitelist!" Added: '&aGroup added to whitelist!'
Removed: "&aGroup removed from whitelist!" Removed: '&aGroup removed from whitelist!'
Player: Player:
NotFound: "&cThe player %Name% is not found." NotFound: '&cThe player %Name% could not be found.'
AlreadyContains: "Whitelist already contains this user!" AlreadyContains: '&cThis user is already on the whitelist'
DoesntContains: "&cWhitelist doesn't contain this user!" DoesntContains: '&cThis user isn''t on the whitelist'
Added: "&aUser added to whitelist!" Added: '&aUser added to whitelist!'
Removed: "&aUser removed from whitelist!" Removed: '&aUser removed from whitelist!'
Whois: Whois:
UseWithoutName: "&cYou need to be a player to use this command without name." UseWithoutName: '&cYou need to be a player to use this command without name.'
NotALift: "&cThis block is not part of a lift." NotALift: '&cThis block is not part of a lift.'
WithoutName: "&aNow right-click on the block you want to check." WithoutName: '&aNow right-click on the block you want to check.'
Speed: Speed:
WrongSpeed: "&cThe speed %Speed% is incorrect." WrongSpeed: '&cThe speed %Speed% is incorrect.'
Changed: "&aLift speed changed!" Changed: '&aUpdated lift speed!'
Sound: Sound:
TurnedOn: "&aSound mode turned on!" TurnedOn: '&aSounds are now turned on!'
TurnedOff: "&aSound mode turned off!" TurnedOff: '&aSounds are now turned off!'
Realistic: Realistic:
TurnedOn: "&aRealistic mode turned on!" TurnedOn: '&aRealistic mode turned on!'
TurnedOff: "&aRealistic mode turned off!" TurnedOff: '&aRealistic mode turned off!'
Disable: Disable:
AlreadyDefective: "&cThis lift is already defective!" AlreadyDefective: '&cThis lift is already defective!'
Disabled: "&aLift disabled!" Disabled: '&aLift disabled!'
Repair: Repair:
NotDefective: "&cThis lift isn't defective!" NotDefective: '&cThis lift isn''t defective!'
ItemsNeeded: "&cYou need %Amount%x %ItemName%!" ItemsNeeded: '&cYou need %Amount%x %ItemName%!'
Repaired: "&aLift repaired!" Repaired: '&aYou successfully repaired the lift!'
Abort: Abort:
NothingToCancel: "&cOops! You can't cancel anything." NothingToCancel: '&cOops! You can''t cancel anything.'
Cancelled: "&6Cancelled." Cancelled: '&6Cancelled.'
Reload: Reload:
Reloaded: "&6Plugin reloaded successfully!" Reloaded: '&6Plugin reloaded successfully!'
Start: Start:
NonPlayer: "&cPlease give a name as non-player!" NonPlayer: '&cPlease give a name as non-player!'
Started: "&aLift %Name% started." Started: '&aLift %Name% started.'
Stop: Stop:
NonPlayer: "&cPlease give a name as non-player!" NonPlayer: '&cPlease give a name as non-player!'
NoMovingTasks: "&cLift %Name% doesn't contain any movingtasks!" NoMovingTasks: '&cLift %Name% doesn''t contain any movingtasks!'
Started: "&aLift %Name% stopped." Started: '&aLift %Name% stopped.'
LiftSign: LiftSign:
NoName: "&cNo lift name given!" NoName: '&cNo lift name given!'
Created: "&aLift sign created!" Created: '&aLift sign created!'
Removed: "&6Lift sign removed!" Removed: '&6Lift sign removed!'