This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
PlayerPlacesBlockScriptEvent.java
111 lines (93 loc) · 3.77 KB
/
PlayerPlacesBlockScriptEvent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package com.denizenscript.denizen2sponge.events.player;
import com.denizenscript.denizen2core.events.ScriptEvent;
import com.denizenscript.denizen2core.tags.AbstractTagObject;
import com.denizenscript.denizen2sponge.Denizen2Sponge;
import com.denizenscript.denizen2sponge.events.D2SpongeEventHelper;
import com.denizenscript.denizen2sponge.tags.objects.BlockTypeTag;
import com.denizenscript.denizen2sponge.tags.objects.LocationTag;
import com.denizenscript.denizen2sponge.tags.objects.PlayerTag;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.data.Transaction;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.block.ChangeBlockEvent;
import org.spongepowered.api.event.filter.cause.Root;
import java.util.HashMap;
public class PlayerPlacesBlockScriptEvent extends ScriptEvent {
// <--[event]
// @Events
// player places block
//
// @Updated 2016/09/22
//
// @Cancellable true
//
// @Group Player
//
// @Triggers when a player places a block.
//
// @Context
// player (PlayerTag) returns the player that broke the block.
// material (BlockTypeTag) returns the placed material.
// old_material (BlockTypeTag) returns the material that the block was placed onto.
// location (LocationTag) returns the location of the broken block.
//
// @Determinations
// None.
// -->
@Override
public String getName() {
return "PlayerPlacesBlock";
}
@Override
public boolean couldMatch(ScriptEvent.ScriptEventData data) {
return data.eventPath.startsWith("player places block");
}
@Override
public boolean matches(ScriptEvent.ScriptEventData data) {
return D2SpongeEventHelper.checkBlockType(material.getInternal(), data, this::error);
}
public PlayerTag player;
public BlockTypeTag material;
public BlockTypeTag old_material;
public LocationTag location;
public ChangeBlockEvent.Place internal;
public Transaction<BlockSnapshot> block;
@Override
public HashMap<String, AbstractTagObject> getDefinitions(ScriptEvent.ScriptEventData data) {
HashMap<String, AbstractTagObject> defs = super.getDefinitions(data);
defs.put("player", player);
defs.put("material", material);
defs.put("old_material", old_material);
defs.put("location", location);
return defs;
}
@Override
public void enable() {
Sponge.getEventManager().registerListeners(Denizen2Sponge.instance, this);
}
@Override
public void disable() {
Sponge.getEventManager().unregisterListeners(this);
}
@Listener
public void onBlockPlaced(ChangeBlockEvent.Place evt, @Root Player player) {
for (Transaction<BlockSnapshot> block : evt.getTransactions()) {
PlayerPlacesBlockScriptEvent event = (PlayerPlacesBlockScriptEvent) clone();
event.internal = evt;
event.block = block;
event.player = new PlayerTag(player);
event.material = new BlockTypeTag(block.getFinal().getState().getType());
event.old_material = new BlockTypeTag(block.getOriginal().getState().getType());
event.location = new LocationTag(block.getOriginal().getLocation().get());
event.cancelled = evt.isCancelled();
event.run();
evt.setCancelled(event.cancelled);
}
}
@Override
public void applyDetermination(boolean errors, String determination, AbstractTagObject value) {
super.applyDetermination(errors, determination, value);
}
}