Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LWCMagnetPullEvent #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/main/java/com/griefcraft/modules/flag/MagnetModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.griefcraft.model.Flag;
import com.griefcraft.model.Protection;
import com.griefcraft.scripting.JavaModule;
import com.griefcraft.scripting.event.LWCMagnetPullEvent;
import com.griefcraft.util.config.Configuration;
import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand Down Expand Up @@ -119,6 +120,14 @@ public void run() {
if (item.getPickupDelay() > item.getTicksLived()) {
continue; // a player wouldn't have had a chance to pick it up yet
}

LWCMagnetPullEvent event = new LWCMagnetPullEvent(item);
lwc.getModuleLoader().dispatchEvent(event);

// has the event been cancelled?
if (event.isCancelled()) {
continue;
}

Location location = item.getLocation();
int x = location.getBlockX();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/griefcraft/scripting/JavaModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.griefcraft.scripting.event.LWCCommandEvent;
import com.griefcraft.scripting.event.LWCDropItemEvent;
import com.griefcraft.scripting.event.LWCEntityInteractEvent;
import com.griefcraft.scripting.event.LWCMagnetPullEvent;
import com.griefcraft.scripting.event.LWCProtectionDestroyEvent;
import com.griefcraft.scripting.event.LWCProtectionInteractEntityEvent;
import com.griefcraft.scripting.event.LWCProtectionInteractEvent;
Expand Down Expand Up @@ -127,4 +128,8 @@ public void onEntityInteract(LWCEntityInteractEvent event) {
public void onProtectionInteractEntity(
LWCProtectionInteractEntityEvent event) {
}

public void onMagnetPull(LWCMagnetPullEvent event) {

}
}
8 changes: 8 additions & 0 deletions src/main/java/com/griefcraft/scripting/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.griefcraft.scripting.event.LWCCommandEvent;
import com.griefcraft.scripting.event.LWCDropItemEvent;
import com.griefcraft.scripting.event.LWCEntityInteractEvent;
import com.griefcraft.scripting.event.LWCMagnetPullEvent;
import com.griefcraft.scripting.event.LWCProtectionDestroyEvent;
import com.griefcraft.scripting.event.LWCProtectionInteractEntityEvent;
import com.griefcraft.scripting.event.LWCProtectionInteractEvent;
Expand Down Expand Up @@ -150,5 +151,12 @@ public enum Result {
* @param event
*/
public void onSendLocale(LWCSendLocaleEvent event);

/**
* Called when the Magnet (flag) pulls an item
*
* @param event
*/
public void onMagnetPull(LWCMagnetPullEvent event);

}
14 changes: 12 additions & 2 deletions src/main/java/com/griefcraft/scripting/ModuleLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.griefcraft.scripting.event.LWCDropItemEvent;
import com.griefcraft.scripting.event.LWCEntityInteractEvent;
import com.griefcraft.scripting.event.LWCEvent;
import com.griefcraft.scripting.event.LWCMagnetPullEvent;
import com.griefcraft.scripting.event.LWCProtectionDestroyEvent;
import com.griefcraft.scripting.event.LWCProtectionInteractEntityEvent;
import com.griefcraft.scripting.event.LWCProtectionInteractEvent;
Expand Down Expand Up @@ -145,7 +146,12 @@ public enum Event {
/**
* Called when LWC's config is reloaded
*/
RELOAD_EVENT;
RELOAD_EVENT,

/**
* Called when the Magnet (flag) pulls an item
*/
MAGNET_PULL(1);

Event() {
}
Expand Down Expand Up @@ -278,7 +284,9 @@ private void registerFastCache(Module module) {
event = Event.REDSTONE;
} else if (parameter == LWCReloadEvent.class) {
event = Event.RELOAD_EVENT;
}
} else if (parameter == LWCMagnetPullEvent.class) {
event = Event.MAGNET_PULL;
}

// ok!
if (event != null) {
Expand Down Expand Up @@ -372,6 +380,8 @@ public void dispatchEvent(LWCEvent event) {
module.onRedstone((LWCRedstoneEvent) event);
} else if (type == Event.RELOAD_EVENT) {
module.onReload((LWCReloadEvent) event);
} else if (type == Event.MAGNET_PULL) {
module.onMagnetPull((LWCMagnetPullEvent) event);
}
}
} catch (Throwable throwable) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2011 Tyler Blair. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and contributors and should not be interpreted as representing official policies,
* either expressed or implied, of anybody else.
*/

package com.griefcraft.scripting.event;

import org.bukkit.entity.Item;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

import com.griefcraft.scripting.ModuleLoader;

public class LWCMagnetPullEvent extends LWCEvent implements Cancellable {

private static final HandlerList handlers = new HandlerList();
private Item item;
private boolean cancelled;

public LWCMagnetPullEvent(Item item) {
super(ModuleLoader.Event.MAGNET_PULL);

this.item = item;
}

public Item getItem() {
return item;
}

public boolean isCancelled() {
return cancelled;
}

public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}

}