-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
Marquee.java
108 lines (92 loc) · 4.19 KB
/
Marquee.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
/*
* CraftBook Copyright (C) 2010-2018 sk89q <http://www.sk89q.com>
* CraftBook Copyright (C) 2011-2018 me4502 <http://www.me4502.com>
* CraftBook Copyright (C) Contributors
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not,
* see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.craftbook.sponge.mechanics;
import static com.sk89q.craftbook.sponge.util.locale.TranslationsManager.USE_PERMISSIONS;
import com.google.inject.Inject;
import com.me4502.modularframework.module.Module;
import com.me4502.modularframework.module.guice.ModuleConfiguration;
import com.sk89q.craftbook.core.util.CraftBookException;
import com.sk89q.craftbook.core.util.PermissionNode;
import com.sk89q.craftbook.core.util.documentation.DocumentationProvider;
import com.sk89q.craftbook.sponge.mechanics.types.SpongeSignMechanic;
import com.sk89q.craftbook.sponge.mechanics.variable.Variables;
import com.sk89q.craftbook.sponge.util.SignUtil;
import com.sk89q.craftbook.sponge.util.SpongePermissionNode;
import ninja.leaping.configurate.ConfigurationNode;
import org.spongepowered.api.block.tileentity.Sign;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.block.InteractBlockEvent;
import org.spongepowered.api.event.filter.cause.First;
import org.spongepowered.api.service.permission.PermissionDescription;
import org.spongepowered.api.text.Text;
@Module(id = "marquee", name = "Marquee", onEnable="onInitialize", onDisable="onDisable")
public class Marquee extends SpongeSignMechanic implements DocumentationProvider {
private SpongePermissionNode createPermission = new SpongePermissionNode("craftbook.marquee", "Allows for creation of the marquee.",
PermissionDescription.ROLE_STAFF);
private SpongePermissionNode usePermission = new SpongePermissionNode("craftbook.marquee.use", "Allows for usage of the marquee.",
PermissionDescription.ROLE_USER);
@Inject
@ModuleConfiguration
public ConfigurationNode config;
@Override
public void onInitialize() throws CraftBookException {
super.onInitialize();
createPermission.register();
usePermission.register();
}
@Listener
public void onInteract(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
event.getTargetBlock().getLocation().ifPresent((location) -> {
if (SignUtil.isSign(location)) {
Sign sign = (Sign) location.getTileEntity().get();
if (isMechanicSign(sign)) {
if (!player.hasPermission(usePermission.getNode())) {
player.sendMessage(USE_PERMISSIONS);
return;
}
String variable = SignUtil.getTextRaw(sign, 2);
String line3 = SignUtil.getTextRaw(sign, 3);
String var = Variables.instance.getVariable(line3.isEmpty() ? Variables.GLOBAL_NAMESPACE : line3, variable);
if(var == null || var.isEmpty()) var = "variable.missing";
player.sendMessage(Text.of(var));
event.setCancelled(true);
}
}
});
}
public String getPath() {
return "mechanics/marquee";
}
@Override
public String[] getValidSigns() {
return new String[] {
"[Marquee]"
};
}
@Override
public SpongePermissionNode getCreatePermission() {
return createPermission;
}
@Override
public PermissionNode[] getPermissionNodes() {
return new PermissionNode[] {
createPermission,
usePermission
};
}
}