Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added SignChangeEvent

Signed-off-by: dredhorse <dredhorse@breiden.net>
  • Loading branch information...
commit 6b443717e6199b730302931398d02155a72b2b92 1 parent 6312ba0
@dredhorse dredhorse authored
View
27 src/main/java/org/spout/vanilla/controller/block/Sign.java
@@ -28,11 +28,15 @@
import java.util.HashSet;
+import org.spout.api.Source;
+import org.spout.api.Spout;
+import org.spout.api.event.EventManager;
import org.spout.api.geo.cuboid.Block;
import org.spout.api.player.Player;
import org.spout.vanilla.controller.VanillaBlockController;
import org.spout.vanilla.controller.VanillaControllerTypes;
+import org.spout.vanilla.event.block.SignChangeEvent;
import org.spout.vanilla.material.VanillaMaterials;
import org.spout.vanilla.protocol.msg.UpdateSignMessage;
import org.spout.vanilla.util.VanillaNetworkUtil;
@@ -41,6 +45,7 @@
private String[] text = new String[4];
private HashSet<Player> dirty = new HashSet<Player>();
private int range = 20;
+ EventManager eventManager = Spout.getEngine().getEventManager();
public Sign() {
super(VanillaControllerTypes.SIGN, VanillaMaterials.SIGN.getPlacedMaterial());
@@ -92,14 +97,18 @@ public void setRange(int range) {
/**
* Sets the current lines of this Sign
+ * @param source which is setting the text lines
* @param text to set to
*/
- public void setText(String[] text) throws IllegalArgumentException {
+ public void setText(Source source, String[] text) throws IllegalArgumentException {
if (text.length != 4) {
throw new IllegalArgumentException("The amount of lines have to equal 4");
}
- this.text = text;
- update();
+ SignChangeEvent signChangeEvent = eventManager.callEvent(new SignChangeEvent(this, source, text));
+ if (!signChangeEvent.isCancelled()) {
+ this.text = text;
+ update();
+ }
}
/**
@@ -113,12 +122,18 @@ public String getLine(int line) {
/**
* Sets the line text at a certain line row
+ * @param source which sets the line
* @param line row index
* @param text to set the line to
*/
- public void setLine(int line, String text) {
- this.text[line] = text;
- update();
+ public void setLine(Source source, int line, String text) {
+ String[] temp = this.text;
+ temp[line] = text;
+ SignChangeEvent signChangeEvent = eventManager.callEvent(new SignChangeEvent(this, source, temp));
+ if (!signChangeEvent.isCancelled()) {
+ this.text[line] = text;
+ update();
+ }
}
private void update() {
View
90 src/main/java/org/spout/vanilla/event/block/SignChangeEvent.java
@@ -0,0 +1,90 @@
+/*
+ * This file is part of Vanilla.
+ *
+ * Copyright (c) 2011-2012, VanillaDev <http://www.spout.org/>
+ * Vanilla is licensed under the SpoutDev License Version 1.
+ *
+ * Vanilla is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * In addition, 180 days after any changes are published, you can use the
+ * software, incorporating those changes, under the terms of the MIT license,
+ * as described in the SpoutDev License Version 1.
+ *
+ * Vanilla is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License,
+ * the MIT license and the SpoutDev License Version 1 along with this program.
+ * If not, see <http://www.gnu.org/licenses/> for the GNU Lesser General Public
+ * License and see <http://www.spout.org/SpoutDevLicenseV1.txt> for the full license,
+ * including the MIT license.
+ */
+package org.spout.vanilla.event.block;
+
+import org.spout.api.Source;
+import org.spout.api.event.Cancellable;
+import org.spout.api.event.Event;
+import org.spout.api.event.HandlerList;
+
+import org.spout.vanilla.controller.block.Sign;
+
+/**
+ * Event which is called when the text on a sign changes
+ */
+public class SignChangeEvent extends Event implements Cancellable {
+ private static HandlerList handlers = new HandlerList();
+ private String[] text;
+ private Sign sign;
+ private Source source;
+
+ public SignChangeEvent(Sign sign, Source source, String[] text) {
+ super();
+ this.sign = sign;
+ this.source = source;
+ this.text = text;
+ }
+
+ /**
+ * Get the source which changes the text on a sign
+ * @return source which changes the text on a sign
+ */
+ public Source getSource() {
+ return source;
+ }
+
+ /**
+ * Get the sign which text is being changed
+ * @return sign which is being changed
+ */
+ public Sign getSign() {
+ return sign;
+ }
+
+ /**
+ * Get the text which should be placed on the sign. The text being returned isn't
+ * necessary the text entered by the Source if the source only changed one line.
+ * @return text which is placed on the sign 1 - 4 lines
+ */
+ public String[] getText() {
+ return text;
+ }
+
+ @Override
+ public void setCancelled(boolean cancelled) {
+ super.setCancelled(cancelled);
+ }
+
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+}
View
2  src/main/java/org/spout/vanilla/protocol/handler/UpdateSignHandler.java
@@ -52,6 +52,6 @@ public void handleServer(Session session, Player player, UpdateSignMessage messa
}
Sign sign = (Sign) controller;
- sign.setText(text);
+ sign.setText(player, text);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.