Skip to content

Commit

Permalink
Added new message structure.
Browse files Browse the repository at this point in the history
Added title message capabilities.
Re-organized command files
Added updateChatSettings command to configure message structure.
Removed SetSpawn command.
Added system for per mine spawns.
Added AddSpawn command.
Added RemoveSpawn command.
Added UpdateSpawn command.
Added ChangeSpawn command.
Improved command filling of mines to include error message returns.
Improved details / info command.
  • Loading branch information
JamieS1211 committed Jul 7, 2016
1 parent 2fe8a24 commit 1a451aa
Show file tree
Hide file tree
Showing 36 changed files with 931 additions and 308 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
defaultTasks 'build', 'shadowJar'

group = 'io.github.jamies1211.minereset'
version = '1.0.3'
version = '1.0.4'
description = 'MineReset'
sourceCompatibility = 1.8

Expand Down
322 changes: 187 additions & 135 deletions src/main/java/com/github/jamies1211/minereset/Actions/FillMineAction.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.github.jamies1211.minereset.Actions;

import com.github.jamies1211.minereset.Messages;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.chat.ChatTypes;
import org.spongepowered.api.text.serializer.TextSerializers;
import org.spongepowered.api.text.title.Title;

/**
* Created by Jamie on 07-Jul-16.
*/
public class SendMessages {
public static boolean messageToPlayer (Player player, int messageType, String message) {

/** Title */
if (messageType >= 4) {
messageType -= 4;
// Send title message;
if (message != null) {
String titleMessage = Messages.MinePrefix;
String subtitleMessage = message.replace(Messages.MinePrefix, "&e");
sendTitleMessage(player, titleMessage, subtitleMessage);
}
}


/** Action Bar */
if (messageType >= 2) {
messageType -= 2;
if (message != null) {
// Send actionBar message;
player.sendMessage(ChatTypes.ACTION_BAR, TextSerializers.FORMATTING_CODE.deserialize(message));
}
}


/** Chat */
if (messageType >= 1) {
messageType -= 1;
if (message != null) {
// Send chat message;
player.sendMessage(ChatTypes.CHAT, TextSerializers.FORMATTING_CODE.deserialize(message));
}
}

return (messageType == 0);
}

public static boolean messageToAllPlayers (int messageType, String message) {

/** Title */
if (messageType >= 4) {
messageType -= 4;
// Send title message;
for (Player player : Sponge.getServer().getOnlinePlayers()) {
if (message != null) {
String titleMessage = Messages.MinePrefix;
String subtitleMessage = message.replace(Messages.MinePrefix, "&e");
sendTitleMessage(player, titleMessage, subtitleMessage);
}
}
}


/** Action Bar */
if (messageType >= 2) {
messageType -= 2;
for (Player player : Sponge.getServer().getOnlinePlayers()) {
if (message != null) {
// Send actionBar message;
player.sendMessage(ChatTypes.ACTION_BAR, TextSerializers.FORMATTING_CODE.deserialize(message));
}
}
}


/** Chat */
if (messageType >= 1) {
messageType -= 1;
for (Player player : Sponge.getServer().getOnlinePlayers()) {
if (message != null) {
// Send chat message;
player.sendMessage(ChatTypes.CHAT, TextSerializers.FORMATTING_CODE.deserialize(message));
}
}
}

return (messageType == 0);
}

public static void sendTitleMessage (Player player, String titleString, String subTitleString) {

if (titleString == null) {
titleString = "";
}

if (subTitleString == null) {
subTitleString = "";
}

Text title = TextSerializers.FORMATTING_CODE.deserialize(titleString);
Text subTitle = TextSerializers.FORMATTING_CODE.deserialize(subTitleString);

player.sendTitle(Title.of(title, subTitle));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.github.jamies1211.minereset.Actions;

import com.github.jamies1211.minereset.MineReset;
import ninja.leaping.configurate.ConfigurationNode;
import org.spongepowered.api.Sponge;

/**
* Created by Jamie on 06-Jul-16.
*/
public class UpdateConfig {

public static void update1to2 () {

ConfigurationNode config = MineReset.plugin.getConfig();

if (config.getNode("1 - ConfigMode").getInt() == 1) {
config.getNode("1 - ConfigMode").setValue("2");

if (config.getNode("3 - Spawn", "SpawnX").getValue() == null) {
config.getNode("3 - Spawn", "SpawnDefault", "SpawnX").setValue(0.5);
config.getNode("3 - Spawn", "SpawnDefault", "SpawnY").setValue(85.0);
config.getNode("3 - Spawn", "SpawnDefault", "SpawnZ").setValue(0.5);
config.getNode("3 - Spawn", "SpawnDefault", "SpawnDirection").setValue("West");
config.getNode("3 - Spawn", "SpawnDefault", "SpawnWorld").setValue(Sponge.getServer().getDefaultWorld().get().getUniqueId().toString());
} else {
config.getNode("3 - Spawn", "SpawnDefault", "SpawnX").setValue(config.getNode("3 - Spawn", "SpawnX").getDouble());
config.getNode("3 - Spawn", "SpawnDefault", "SpawnY").setValue(config.getNode("3 - Spawn", "SpawnY").getDouble());
config.getNode("3 - Spawn", "SpawnDefault", "SpawnZ").setValue(config.getNode("3 - Spawn", "SpawnS").getDouble());
config.getNode("3 - Spawn", "SpawnDefault", "SpawnDirection").setValue(config.getNode("3 - Spawn", "SpawnX").getDouble());
config.getNode("3 - Spawn", "SpawnDefault", "SpawnWorld").setValue(config.getNode("3 - Spawn", "SpawnWorld").getString());


config.getNode("3 - Spawn").removeChild("SpawnX");
config.getNode("3 - Spawn").removeChild("SpawnY");
config.getNode("3 - Spawn").removeChild("SpawnZ");
config.getNode("3 - Spawn").removeChild("SpawnDirection");
config.getNode("3 - Spawn").removeChild("SpawnWorld");
}

for (Object groupObject : config.getNode("4 - MineGroups").getChildrenMap().keySet()) {
String group = groupObject.toString();
for (Object objects : config.getNode("4 - MineGroups", group).getChildrenMap().keySet()) {
if (!objects.toString().equalsIgnoreCase("InitialDelay") && !objects.toString().equalsIgnoreCase("ResetTime")) {
String mine = objects.toString();
if (config.getNode("4 - MineGroups", group, mine, "SpawnPoint").getValue() == null) {
config.getNode("4 - MineGroups", group, mine, "SpawnPoint").setValue("Default");
}
}
}
}

config.getNode("5 - Lists", "AirBlocks").setValue(
"\"minecraft:torch\", \"minecraft:redstone_torch\", \"minecraft:redstone_wire\", \"minecraft:powered_repeater\", \"minecraft:unpowered_repeater\", \"minecraft:powered_comparator\",\n" +
"\"minecraft:unpowered_comparator\", \"minecraft:wooden_button\", \"minecraft:stone_button\", \"minecraft:lever\", \"minecraft:tripwire_hook\", \"minecraft:stone_pressure_plate\",\n" +
"\"minecraft:wooden_pressure_plate\", \"minecraft:light_weighted_pressure_plate\", \"minecraft:heavy_weighted_pressure_plate\", \"minecraft:trapdoor\", \"minecraft:iron_trapdoor\",\n" +
"\"minecraft:fence_gate\", \"minecraft:spruce_fence_gate\", \"minecraft:birch_fence_gate\", \"minecraft:jungle_fence_gate\", \"minecraft:dark_oak_fence_gate\", \"minecraft:acacia_fence_gate\",\n" +
"\"minecraft:wooden_door\", \"minecraft:iron_door\", \"minecraft:spruce_door\", \"minecraft:birch_door\", \"minecraft:jungle_door\", \"minecraft:acacia_door\", \"minecraft:dark_oak_door\", \n" +
"\"minecraft:rail\", \"minecraft:golden_rail\", \"minecraft:detector_rail\", \"minecraft:activator_rail\", \"minecraft:tallgrass\", \"minecraft:sapling\", \"minecraft:deadbush\",\n" +
"\"minecraft:yellow_flower\", \"minecraft:red_flower\", \"minecraft:brown_mushroom\", \"minecraft:red_mushroom\", \"minecraft:ladder\", \"minecraft:snow_layer\", \"minecraft:fence\",\n" +
"\"minecraft:nether_brick_fence\", \"minecraft:iron_bars\", \"minecraft:glass_pane\", \"minecraft:vine\", \"minecraft:waterlily\", \"minecraft:cobblestone_wall\", \"minecraft:anvil\",\n" +
"\"minecraft:stained_glass_pane\", \"minecraft:carpet\", \"minecraft:double_plant\", \"minecraft:wall_sign\", \"minecraft:standing_sign\", \"minecraft:skull\", \"minecraft:brewing_stand\",\n" +
"\"minecraft:skull\", \"minecraft:standing_banner\"");

config.getNode("6 - ChatSettings", "FillingText").setValue("1");
config.getNode("6 - ChatSettings", "ReminderText").setValue("2");
MineReset.plugin.save();
}
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jamies1211.minereset.Commands;
package com.github.jamies1211.minereset.Commands.ConfigCommands;

import com.github.jamies1211.minereset.Actions.BlockBelowPlayer;
import com.github.jamies1211.minereset.Messages;
Expand Down Expand Up @@ -33,7 +33,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm

if (!airBlocks.contains(blockString)) {

String blockListString = config.getNode("2 - RemindSecondList").getString();
String blockListString = config.getNode("5 - Lists", "AirBlocks").getString();

if (!airBlocks.isEmpty()) { // Add comma if other values there.
blockListString = blockListString + ", ";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jamies1211.minereset.Commands;
package com.github.jamies1211.minereset.Commands.ConfigCommands;

import com.github.jamies1211.minereset.Messages;
import com.github.jamies1211.minereset.MineReset;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jamies1211.minereset.Commands;
package com.github.jamies1211.minereset.Commands.ConfigCommands;

import com.github.jamies1211.minereset.Messages;
import com.github.jamies1211.minereset.MineReset;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jamies1211.minereset.Commands;
package com.github.jamies1211.minereset.Commands.ConfigCommands;

import com.github.jamies1211.minereset.Messages;
import com.github.jamies1211.minereset.MineReset;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jamies1211.minereset.Commands;
package com.github.jamies1211.minereset.Commands.ConfigCommands;

import com.github.jamies1211.minereset.Actions.BlockBelowPlayer;
import com.github.jamies1211.minereset.Messages;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jamies1211.minereset.Commands;
package com.github.jamies1211.minereset.Commands.ConfigCommands;

import com.github.jamies1211.minereset.Messages;
import com.github.jamies1211.minereset.MineReset;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.github.jamies1211.minereset.Commands.ConfigCommands;

import com.github.jamies1211.minereset.Actions.SendMessages;
import com.github.jamies1211.minereset.Messages;
import com.github.jamies1211.minereset.MineReset;
import ninja.leaping.configurate.ConfigurationNode;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.text.serializer.TextSerializers;

/**
* Created by Jamie on 07-Jul-16.
*/
public class UpdateChatSettings implements CommandExecutor {

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {

ConfigurationNode config = MineReset.plugin.getConfig();

String type = args.<String>getOne("type").get();
int option = args.<Integer>getOne("option").get();

if (type.equalsIgnoreCase("FillingText")) {
type = "FillingText";
} else if (type.equalsIgnoreCase("ReminderText")) {
type = "ReminderText";
} else {
type = null;
}

int oldOption = config.getNode("6 - ChatSettings", type).getInt();

if (type != null) {
if (option != oldOption) {
if (SendMessages.messageToAllPlayers(option, null)) {
config.getNode("6 - ChatSettings", type).setValue(option); // Wright changes to file.
MineReset.plugin.save();
src.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(Messages.MinePrefix + Messages.ChatSettingChanged +
" " + type + " " + "to" + " " + option));
} else {
src.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(Messages.MinePrefix + Messages.InvalidChatSetting));
}
} else {
src.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(Messages.MinePrefix + Messages.ChatSettingAlreadySet1 +
" " + type + " " + Messages.ChatSettingAlreadySet2 + " " + option));
}
} else {
src.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(Messages.MinePrefix + Messages.InvalidChatType));
}


return CommandResult.success();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jamies1211.minereset.Commands;
package com.github.jamies1211.minereset.Commands.FillingCommands;

import com.github.jamies1211.minereset.Actions.FillMineAction;
import com.github.jamies1211.minereset.Messages;
Expand Down Expand Up @@ -34,7 +34,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm
if (group == null) {
src.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(Messages.MinePrefix + mine + " " + Messages.MineDoesNotExist));
} else {
FillMineAction.fill(group, mine, "minecraft:air");
FillMineAction.fill(group, mine, "minecraft:air", src);
src.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(Messages.MinePrefix + mine + " " + Messages.MineCleared));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jamies1211.minereset.Commands;
package com.github.jamies1211.minereset.Commands.FillingCommands;

import com.github.jamies1211.minereset.Actions.BlockBelowPlayer;
import com.github.jamies1211.minereset.Actions.FillMineAction;
Expand Down Expand Up @@ -41,7 +41,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm
src.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(Messages.MinePrefix + mine + " " + Messages.MineDoesNotExist));
} else {
String block = BlockBelowPlayer.getBlockStringBelowPlayer(player);
FillMineAction.fill(group, mine, block);
FillMineAction.fill(group, mine, block, src);
src.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(Messages.MinePrefix + mine + " " + Messages.MineFilledBlock + " " + block));
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.github.jamies1211.minereset.Commands;
package com.github.jamies1211.minereset.Commands.FillingCommands;

import com.github.jamies1211.minereset.Actions.FillMineAction;
import com.github.jamies1211.minereset.Messages;
import com.github.jamies1211.minereset.MineReset;
import ninja.leaping.configurate.ConfigurationNode;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
Expand Down Expand Up @@ -35,8 +36,7 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm
if (group == null) {
src.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(Messages.MinePrefix + mine + " " + Messages.MineDoesNotExist));
} else {
FillMineAction.fill(group, mine, null);
src.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(Messages.MinePrefix + mine + " " + Messages.MineFilled));
FillMineAction.fill(group, mine, null, src);
}

return CommandResult.success();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jamies1211.minereset.Commands;
package com.github.jamies1211.minereset.Commands.GroupCommands;

import com.github.jamies1211.minereset.Messages;
import com.github.jamies1211.minereset.MineReset;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jamies1211.minereset.Commands;
package com.github.jamies1211.minereset.Commands.GroupCommands;

import com.github.jamies1211.minereset.Messages;
import com.github.jamies1211.minereset.MineReset;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jamies1211.minereset.Commands;
package com.github.jamies1211.minereset.Commands.GroupCommands;

import com.github.jamies1211.minereset.Messages;
import com.github.jamies1211.minereset.MineReset;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jamies1211.minereset.Commands;
package com.github.jamies1211.minereset.Commands.InfoCommands;

import com.github.jamies1211.minereset.Actions.TimeUntillFill;
import com.github.jamies1211.minereset.Messages;
Expand Down
Loading

0 comments on commit 1a451aa

Please sign in to comment.