Block Break from current edit text/ modified code
This commit is contained in:
1 parent
2c1af6de22
commit
d9a1c9e497
6 files changed
+30
-31
No files matched your search
@@ -2,6 +2,7 @@ package de.philw.textgenerator;
|
||||
|
||||
import de.philw.textgenerator.command.TextGeneratorCommand;
|
||||
import de.philw.textgenerator.letters.CurrentEditedText;
|
||||
import de.philw.textgenerator.listener.BlockDestroyListener;
|
||||
import de.philw.textgenerator.listener.LeaveListener;
|
||||
import de.philw.textgenerator.listener.NoMoveWhileGenerateListener;
|
||||
import de.philw.textgenerator.manager.ConfigManager;
|
||||
@@ -49,6 +50,7 @@ public final class TextGenerator extends JavaPlugin {
|
||||
Bukkit.getPluginManager().registerEvents(new LeaveListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new SettingsUIListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new NoMoveWhileGenerateListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new BlockDestroyListener(), this);
|
||||
}
|
||||
|
||||
public static TextGenerator getInstance() {
|
||||
|
||||
@@ -130,9 +130,10 @@ public class TextGeneratorCommand extends Command {
|
||||
player.sendMessage(MessagesManager.getMessage("edit.this.success",
|
||||
currentEditedText.getTextInstance().getText()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkCancel(Player player, String[] args) {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package de.philw.textgenerator.listener;
|
||||
|
||||
import de.philw.textgenerator.manager.MessagesManager;
|
||||
import de.philw.textgenerator.utils.FastBlockUpdate;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
||||
public class BlockDestroyListener implements Listener {
|
||||
@EventHandler
|
||||
public void onBlockDestroy(BlockBreakEvent e) {
|
||||
if (e.getBlock().hasMetadata(FastBlockUpdate.metaDataKey)) {
|
||||
e.setCancelled(true);
|
||||
e.getPlayer().sendMessage(MessagesManager.getMessage("blockBreakFromCurrentEditedTextDisabled"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public class NoMoveWhileGenerateListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void noMove(PlayerMoveEvent e) {
|
||||
public void onPlayerMove(PlayerMoveEvent e) {
|
||||
if (disallowedToMove.contains(e.getPlayer().getUniqueId())) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@@ -94,6 +94,10 @@ public class GenerateUtil {
|
||||
}
|
||||
lines.add(tempLine);
|
||||
}
|
||||
return combineLines(lines, textInstance, width, biggest);
|
||||
}
|
||||
|
||||
private static String[][] combineLines(ArrayList<String[][]> lines, TextInstance textInstance, int width, String[][] biggest) {
|
||||
// make all 2D-String arrays the same width
|
||||
for (int arrayIndex = 0; arrayIndex < lines.size(); arrayIndex++) {
|
||||
String[][] oldLine = lines.get(arrayIndex);
|
||||
@@ -290,34 +294,7 @@ public class GenerateUtil {
|
||||
biggest = line;
|
||||
}
|
||||
}
|
||||
// make all 2D-String arrays the same width
|
||||
for (int arrayIndex = 0; arrayIndex < lines.size(); arrayIndex++) {
|
||||
String[][] oldLine = lines.get(arrayIndex);
|
||||
if (oldLine == biggest) continue;
|
||||
String[][] doneLine = new String[oldLine.length][width];
|
||||
for (int column = 0; column < oldLine.length; column++) {
|
||||
System.arraycopy(oldLine[column], 0, doneLine[column], 0, oldLine[0].length);
|
||||
}
|
||||
lines.set(arrayIndex, doneLine);
|
||||
}
|
||||
// merge the 2D-Boolean arrays to a big 2D-String considering the in the textInstance given
|
||||
// spaceBetweenEachLine
|
||||
int height = 0;
|
||||
int spaceBetweenEachLine = textInstance.getLineSpacing();
|
||||
for (String[][] doneLine : lines) {
|
||||
height += doneLine.length + spaceBetweenEachLine;
|
||||
}
|
||||
height -= spaceBetweenEachLine;
|
||||
String[][] blocks = new String[height][width];
|
||||
int currentLineIndexCount = 0;
|
||||
for (String[][] doneLine : lines) {
|
||||
for (String[] booleans : doneLine) {
|
||||
blocks[currentLineIndexCount] = booleans;
|
||||
currentLineIndexCount++;
|
||||
}
|
||||
currentLineIndexCount += spaceBetweenEachLine;
|
||||
}
|
||||
return blocks;
|
||||
return combineLines(lines, textInstance, width, biggest);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -37,4 +37,5 @@ refresh:
|
||||
success: "♦success♦&rYou refreshed \"{0}\"!"
|
||||
deniedBecauseNotEditingSomething: "♦denied♦&rYou are not editing something to refresh!"
|
||||
deniedBecauseDragToMoveActivated: "♦denied♦&rYou have enabled the feature \"Drag to move\" and it would not make sense to refresh it now!"
|
||||
needPermissionForCommand: "♦denied♦&rYou need the \"{1}\" permission to use this command!"
|
||||
needPermissionForCommand: "♦denied♦&rYou need the \"{1}\" permission to use this command!"
|
||||
blockBreakFromCurrentEditedTextDisabled: "♦denied♦&rYou cannot destroy a block from a text that is currently edited!"
|
||||
Reference in new issue
Block a user