From dc37465c8afb4117ef85c50733e709dfed1c7ff6 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Wed, 26 Aug 2015 08:35:32 +1000 Subject: [PATCH] Forgot to push this --- .gitignore | 144 +----------------- .../plot/object/PlotMessage.java | 54 +++++++ .../plot/util/ChatManager.java | 22 +++ .../listeners/worldedit/ExtentWrapper.java | 12 ++ .../bukkit/util/BukkitChatManager.java | 62 ++++++++ .../bukkit/util/BukkitPlainChatManager.java | 52 +++++++ .../bukkit/util/SetBlockFast_1_8.java | 7 +- .../sponge/util/SpongeChatManager.java | 66 ++++++++ 8 files changed, 280 insertions(+), 139 deletions(-) create mode 100644 src/main/java/com/intellectualcrafters/plot/object/PlotMessage.java create mode 100644 src/main/java/com/intellectualcrafters/plot/util/ChatManager.java create mode 100644 src/main/java/com/plotsquared/bukkit/listeners/worldedit/ExtentWrapper.java create mode 100644 src/main/java/com/plotsquared/bukkit/util/BukkitChatManager.java create mode 100644 src/main/java/com/plotsquared/bukkit/util/BukkitPlainChatManager.java create mode 100644 src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java diff --git a/.gitignore b/.gitignore index 4690eedc0..90dc65d43 100644 --- a/.gitignore +++ b/.gitignore @@ -1,139 +1,9 @@ -### Ignore script files -*.sh *.bat - -### Maven template -target/classes -target/maven-archiver -pom.xml.tag -pom.xml.releaseBackup -pom.xml.versionsBackup -pom.xml.next -release.properties -dependency-reduced-pom.xml -buildNumber.properties -.mvn/timing.properties - - -### JetBrains template -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion - -*.iml - -## Directory-based project format: -.idea/ -# if you remove the above rule, at least ignore the following: - -# User-specific stuff: -# .idea/workspace.xml -# .idea/tasks.xml -# .idea/dictionaries - -# Sensitive or high-churn files: -# .idea/dataSources.ids -# .idea/dataSources.xml -# .idea/sqlDataSources.xml -# .idea/dynamic.xml -# .idea/uiDesigner.xml - -# Gradle: -# .idea/gradle.xml -# .idea/libraries - -# Mongo Explorer plugin: -# .idea/mongoSettings.xml - -## File-based project format: -*.ipr -*.iws - -## Plugin-specific files: - -# IntelliJ -/out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties - - -### NetBeans template -nbproject/private/ -build/ -nbbuild/ -dist/ -nbdist/ -nbactions.xml -nb-configuration.xml -.nb-gradle/ - - -### Eclipse template -*.pydevproject -.metadata -.gradle -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath - -# Eclipse Core -.project - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT-specific -.cproject - -# JDT-specific (Eclipse Java Development Tools) -.classpath - -# Java annotation processor (APT) -.factorypath - -# PDT-specific -.buildpath - -# sbteclipse plugin -.target - -# TeXlipse plugin -.texlipse - - -### Java template +*.prefs *.class - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # - -*.war -*.ear -*.zip - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - - -*.java -target/PlotSquared-Null.jar -target/PlotSquared-Uber.jar -/target/ +/target/classes +/target/PlotSquared-Null.jar +/target/PlotSquared-Uber.jar +/target/maven-archiver +*.project +*.classpath \ No newline at end of file diff --git a/src/main/java/com/intellectualcrafters/plot/object/PlotMessage.java b/src/main/java/com/intellectualcrafters/plot/object/PlotMessage.java new file mode 100644 index 000000000..418f2ff08 --- /dev/null +++ b/src/main/java/com/intellectualcrafters/plot/object/PlotMessage.java @@ -0,0 +1,54 @@ +package com.intellectualcrafters.plot.object; + +import com.intellectualcrafters.plot.util.ChatManager; + +public class PlotMessage { + + private Object builder; + + public PlotMessage() { + this.builder = ChatManager.manager.builder(); + } + + public T $(ChatManager manager) { + return (T) builder; + } + + public PlotMessage(String text) { + this(); + text(text); + } + + public PlotMessage text(String text) { + ChatManager.manager.text(this, text); + return this; + } + + public PlotMessage tooltip(PlotMessage... tooltip) { + ChatManager.manager.tooltip(this, tooltip); + return this; + } + + public PlotMessage tooltip(String tooltip) { + return tooltip(new PlotMessage(tooltip)); + } + + public PlotMessage command(String command) { + ChatManager.manager.command(this, command); + return this; + } + + public PlotMessage suggest(String command) { + ChatManager.manager.suggest(this, command); + return this; + } + + public PlotMessage color(String color) { + ChatManager.manager.color(this, color); + return this; + } + + public void send(PlotPlayer player) { + ChatManager.manager.send(this, player); + } +} diff --git a/src/main/java/com/intellectualcrafters/plot/util/ChatManager.java b/src/main/java/com/intellectualcrafters/plot/util/ChatManager.java new file mode 100644 index 000000000..1a37332f3 --- /dev/null +++ b/src/main/java/com/intellectualcrafters/plot/util/ChatManager.java @@ -0,0 +1,22 @@ +package com.intellectualcrafters.plot.util; + +import com.intellectualcrafters.plot.object.PlotMessage; +import com.intellectualcrafters.plot.object.PlotPlayer; + +public abstract class ChatManager { + public static ChatManager manager; + + public abstract T builder(); + + public abstract void color(PlotMessage message, String color); + + public abstract void tooltip(PlotMessage message, PlotMessage... tooltip); + + public abstract void command(PlotMessage message, String command); + + public abstract void text(PlotMessage message, String text); + + public abstract void send(PlotMessage plotMessage, PlotPlayer player); + + public abstract void suggest(PlotMessage plotMessage, String command); +} diff --git a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/ExtentWrapper.java b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/ExtentWrapper.java new file mode 100644 index 000000000..1e64bac30 --- /dev/null +++ b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/ExtentWrapper.java @@ -0,0 +1,12 @@ +package com.plotsquared.bukkit.listeners.worldedit; + +import com.sk89q.worldedit.extent.AbstractDelegateExtent; +import com.sk89q.worldedit.extent.Extent; + +public class ExtentWrapper extends AbstractDelegateExtent { + + protected ExtentWrapper(Extent extent) { + super(extent); + } + +} diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitChatManager.java b/src/main/java/com/plotsquared/bukkit/util/BukkitChatManager.java new file mode 100644 index 000000000..f117423aa --- /dev/null +++ b/src/main/java/com/plotsquared/bukkit/util/BukkitChatManager.java @@ -0,0 +1,62 @@ +package com.plotsquared.bukkit.util; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.ChatColor; + +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.object.ConsolePlayer; +import com.intellectualcrafters.plot.object.PlotMessage; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.ChatManager; +import com.plotsquared.bukkit.chat.FancyMessage; +import com.plotsquared.bukkit.object.BukkitPlayer; + +public class BukkitChatManager extends ChatManager { + + @Override + public FancyMessage builder() { + return new FancyMessage(""); + } + + @Override + public void color(PlotMessage m, String color) { + m.$(this).color(ChatColor.getByChar(C.color(color).substring(1))); + } + + @Override + public void tooltip(PlotMessage m, PlotMessage... tooltips) { + List lines = new ArrayList<>(); + for (PlotMessage tooltip : tooltips) { + lines.add(tooltip.$(this)); + } + m.$(this).formattedTooltip(lines); + } + + @Override + public void command(PlotMessage m, String command) { + m.$(this).command(command); + } + + @Override + public void text(PlotMessage m, String text) { + m.$(this).then(ChatColor.stripColor(text)); + } + + @Override + public void send(PlotMessage m, PlotPlayer player) { + if (ConsolePlayer.isConsole(player)) { + player.sendMessage(m.$(this).toOldMessageFormat()); + } + else { + m.$(this).send(((BukkitPlayer) player).player); + } + } + + @Override + public void suggest(PlotMessage m, String command) { + m.$(this).suggest(command); + } + +} diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitPlainChatManager.java b/src/main/java/com/plotsquared/bukkit/util/BukkitPlainChatManager.java new file mode 100644 index 000000000..0a57a6622 --- /dev/null +++ b/src/main/java/com/plotsquared/bukkit/util/BukkitPlainChatManager.java @@ -0,0 +1,52 @@ +package com.plotsquared.bukkit.util; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.ChatColor; + +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.object.ConsolePlayer; +import com.intellectualcrafters.plot.object.PlotMessage; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.ChatManager; +import com.plotsquared.bukkit.chat.FancyMessage; +import com.plotsquared.bukkit.object.BukkitPlayer; + +public class BukkitPlainChatManager extends ChatManager> { + + @Override + public List builder() { + return new ArrayList(); + } + + @Override + public void color(PlotMessage m, String color) { + List parts = m.$(this); + parts.get(parts.size() - 1).insert(0, color); + } + + @Override + public void tooltip(PlotMessage m, PlotMessage... tooltips) {} + + @Override + public void command(PlotMessage m, String command) {} + + @Override + public void text(PlotMessage m, String text) { + m.$(this).add(new StringBuilder(ChatColor.stripColor(text))); + } + + @Override + public void send(PlotMessage m, PlotPlayer player) { + StringBuilder built = new StringBuilder(); + for (StringBuilder sb : m.$(this)) { + built.append(sb); + } + player.sendMessage(built.toString()); + } + + @Override + public void suggest(PlotMessage m, String command) {} + +} diff --git a/src/main/java/com/plotsquared/bukkit/util/SetBlockFast_1_8.java b/src/main/java/com/plotsquared/bukkit/util/SetBlockFast_1_8.java index 7abe9e53f..ad747ca0e 100644 --- a/src/main/java/com/plotsquared/bukkit/util/SetBlockFast_1_8.java +++ b/src/main/java/com/plotsquared/bukkit/util/SetBlockFast_1_8.java @@ -75,10 +75,13 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager { @Override public void run() { + if (toUpdate.size() == 0) { + return; + } int count = 0; ArrayList chunks = new ArrayList(); Iterator> i = toUpdate.entrySet().iterator(); - while (i.hasNext() && count < 1024) { + while (i.hasNext() && count < 128) { chunks.add(i.next().getValue()); i.remove(); count++; @@ -88,7 +91,7 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager { } update(chunks); } - }, 20); + }, 1); this.chunksender = new SendChunk(); } diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java b/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java new file mode 100644 index 000000000..dd98ee736 --- /dev/null +++ b/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java @@ -0,0 +1,66 @@ +package com.plotsquared.sponge.util; + + +import org.spongepowered.api.text.TextBuilder; +import org.spongepowered.api.text.Texts; +import org.spongepowered.api.text.action.TextActions; + +import com.intellectualcrafters.plot.object.ConsolePlayer; +import com.intellectualcrafters.plot.object.PlotMessage; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.ChatManager; +import com.plotsquared.sponge.object.SpongePlayer; + +public class SpongeChatManager extends ChatManager { + + @Override + public TextBuilder builder() { + return Texts.builder(); + } + + @Override + public void color(PlotMessage m, String color) { + m.$(this).color(Texts.of(color).getColor()); + } + + @Override + public void tooltip(PlotMessage m, PlotMessage... tooltips) { + TextBuilder builder = Texts.builder(); + boolean lb = false; + for (PlotMessage tooltip : tooltips) { + if (lb) { + builder.append(Texts.of("\n")); + } + builder.append(tooltip.$(this).build()); + lb = true; + } +// AchievementBuilder builder = SpongeMain.THIS.getGame().getRegistry().createAchievementBuilder(); + m.$(this).onHover(TextActions.showText(builder.toText())); + } + + @Override + public void command(PlotMessage m, String command) { + m.$(this).onClick(TextActions.runCommand(command)); + } + + @Override + public void text(PlotMessage m, String text) { + m.$(this).append(Texts.of(text)); + } + + @Override + public void send(PlotMessage m, PlotPlayer player) { + if (ConsolePlayer.isConsole(player)) { + player.sendMessage(Texts.legacy().to(m.$(this).build())); + } + else { + ((SpongePlayer) player).player.sendMessage(m.$(this).build()); + } + } + + @Override + public void suggest(PlotMessage m, String command) { + m.$(this).onClick(TextActions.suggestCommand(command)); + } + +}