├── .gitattributes
├── .gitignore
├── LICENSE
├── README.md
├── pom.xml
└── src
└── main
├── java
└── ce
│ └── ajneb97
│ ├── ConditionalEvents.java
│ ├── MainCommand.java
│ ├── api
│ ├── ConditionalEventsAPI.java
│ ├── ConditionalEventsAction.java
│ ├── ConditionalEventsCallEvent.java
│ ├── ConditionalEventsEvent.java
│ └── ExpansionCE.java
│ ├── configs
│ ├── CEConfig.java
│ ├── ConfigsManager.java
│ ├── DataFolderConfigManager.java
│ ├── MainConfigManager.java
│ ├── PlayerConfig.java
│ ├── PlayerConfigsManager.java
│ └── SavedItemsConfigManager.java
│ ├── libs
│ ├── actionbar
│ │ └── ActionBarAPI.java
│ ├── armorequipevent
│ │ ├── ArmorEquipEvent.java
│ │ ├── ArmorListener.java
│ │ └── ArmorType.java
│ ├── centeredmessages
│ │ └── DefaultFontInfo.java
│ ├── itemselectevent
│ │ ├── DropType.java
│ │ ├── ItemSelectEvent.java
│ │ ├── ItemSelectListener.java
│ │ ├── ItemSelectListenerNew.java
│ │ ├── PlayerCustomDropEvent.java
│ │ └── SelectType.java
│ └── titles
│ │ └── TitleAPI.java
│ ├── listeners
│ ├── CustomEventListener.java
│ ├── ItemEventsListener.java
│ ├── OtherEventsListener.java
│ ├── PlayerEventsListener.java
│ ├── PlayerEventsListenerNew1_16.java
│ ├── PlayerEventsListenerNew1_9.java
│ └── dependencies
│ │ ├── CitizensListener.java
│ │ └── WGRegionEventsListener.java
│ ├── managers
│ ├── APIManager.java
│ ├── BungeeMessagingManager.java
│ ├── DebugManager.java
│ ├── DependencyManager.java
│ ├── EventsManager.java
│ ├── InterruptEventManager.java
│ ├── MessagesManager.java
│ ├── PlayerManager.java
│ ├── RepetitiveManager.java
│ ├── SavedItemsManager.java
│ ├── UpdateCheckerManager.java
│ ├── VerifyManager.java
│ ├── commandregister
│ │ ├── CECommand.java
│ │ └── CommandRegisterManager.java
│ └── dependencies
│ │ ├── DiscordSRVManager.java
│ │ ├── Metrics.java
│ │ ├── ProtocolLibManager.java
│ │ └── ProtocolLibReceiveMessageEvent.java
│ ├── model
│ ├── CEEvent.java
│ ├── ConditionalType.java
│ ├── CustomEventProperties.java
│ ├── EventType.java
│ ├── StoredVariable.java
│ ├── ToConditionGroup.java
│ ├── actions
│ │ ├── ActionGroup.java
│ │ ├── ActionTargeter.java
│ │ ├── ActionTargeterType.java
│ │ ├── ActionType.java
│ │ └── CEAction.java
│ ├── internal
│ │ ├── CheckConditionsResult.java
│ │ ├── ConditionEvent.java
│ │ ├── DebugSender.java
│ │ ├── ExecutedEvent.java
│ │ ├── PostEventVariableResult.java
│ │ ├── SeparatorType.java
│ │ ├── UpdateCheckerResult.java
│ │ ├── VariablesProperties.java
│ │ └── WaitActionTask.java
│ ├── player
│ │ ├── EventData.java
│ │ └── PlayerData.java
│ └── verify
│ │ ├── CEError.java
│ │ ├── CEErrorAction.java
│ │ ├── CEErrorCondition.java
│ │ ├── CEErrorEventType.java
│ │ └── CEErrorRandomVariable.java
│ ├── tasks
│ └── PlayerDataSaveTask.java
│ └── utils
│ ├── ActionUtils.java
│ ├── BlockUtils.java
│ ├── GlobalVariablesUtils.java
│ ├── InventoryUtils.java
│ ├── ItemUtils.java
│ ├── JSONMessage.java
│ ├── MathUtils.java
│ ├── OtherUtils.java
│ ├── PlayerUtils.java
│ ├── ServerVersion.java
│ ├── TimeUtils.java
│ ├── VariablesUtils.java
│ └── VariablesUtilsExperimental.java
└── resources
├── config.yml
├── events
└── more_events.yml
├── plugin.yml
└── saved_items.yml
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | *.class
3 |
4 |
5 | *.log
6 |
7 |
8 | *.ctxt
9 |
10 |
11 | .mtj.tmp/
12 |
13 |
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 | *.iml
22 |
23 |
24 | hs_err_pid*
25 |
26 |
27 | .metadata
28 | bin/
29 | tmp/
30 | *.tmp
31 | *.bak
32 | *.swp
33 | *~.nib
34 | *.classpath
35 | *.project
36 | local.properties
37 | .settings/
38 | .loadpath
39 | dependency-reduced-pom.xml
40 | .recommenders
41 | .idea/
42 | target/
43 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Ajneb97
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ConditionalEvents
2 | https://www.spigotmc.org/resources/conditionalevents-custom-actions-for-certain-events-1-8-1-18.82271/
3 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | ce.ajneb97
8 | ConditionalEvents
9 | 1.0-SNAPSHOT
10 |
11 |
12 | 21
13 | 21
14 | 21
15 |
16 |
17 |
18 |
19 | papermc
20 | https://repo.papermc.io/repository/maven-public/
21 |
22 |
23 | spigot-repo
24 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/
25 |
26 |
27 | placeholderapi
28 | https://repo.extendedclip.com/content/repositories/placeholderapi/
29 |
30 |
31 | minecraft-repo
32 | https://libraries.minecraft.net/
33 |
34 |
35 | everything
36 | https://repo.citizensnpcs.co/
37 |
38 |
39 | jitpack.io
40 | https://jitpack.io
41 |
42 |
43 | sk89q-repo
44 | https://maven.enginehub.org/repo/
45 |
46 |
47 | dv8tion
48 | m2-dv8tion
49 | https://m2.dv8tion.net/releases
50 |
51 |
52 | Scarsz-Nexus
53 | https://nexus.scarsz.me/content/groups/public/
54 |
55 |
56 | dmulloy2-repo
57 | https://repo.dmulloy2.net/repository/public/
58 |
59 |
60 |
61 |
62 |
63 | io.papermc.paper
64 | paper-api
65 | 1.21.4-R0.1-SNAPSHOT
66 | provided
67 |
68 |
69 | org.spigotmc
70 | spigot
71 | 1.21.5-R0.1-SNAPSHOT
72 | provided
73 |
74 |
75 | me.clip
76 | placeholderapi
77 | 2.11.1
78 | provided
79 |
80 |
81 | net.objecthunter
82 | exp4j
83 | 0.4.8
84 |
85 |
86 | com.mojang
87 | authlib
88 | 1.5.25
89 | provided
90 |
91 |
92 | net.citizensnpcs
93 | citizens-main
94 | 2.0.30-SNAPSHOT
95 | provided
96 |
97 |
98 | net.raidstone
99 | WorldGuardEvents
100 | 1.18.1
101 | provided
102 |
103 |
104 | com.sk89q.worldguard
105 | worldguard-bukkit
106 | 7.0.7
107 | provided
108 |
109 |
110 | com.comphenix.protocol
111 | ProtocolLib
112 | 5.0.0-SNAPSHOT
113 | provided
114 |
115 |
116 | com.discordsrv
117 | discordsrv
118 | 1.26.0
119 | provided
120 |
121 |
122 |
123 |
124 |
125 |
126 | maven-compiler-plugin
127 | 3.8.1
128 |
129 | 1.8
130 | 1.8
131 | 8
132 |
133 |
134 |
135 | org.apache.maven.plugins
136 | maven-shade-plugin
137 | 3.2.4
138 |
139 |
140 |
141 |
142 | package
143 |
144 | shade
145 |
146 |
147 |
148 |
149 | net.objecthunter.exp4j
150 | ce.ajneb97.libs.exp4j
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/ConditionalEvents.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97;
2 |
3 |
4 | import ce.ajneb97.api.ConditionalEventsAPI;
5 | import ce.ajneb97.api.ExpansionCE;
6 | import ce.ajneb97.configs.ConfigsManager;
7 | import ce.ajneb97.libs.armorequipevent.ArmorListener;
8 | import ce.ajneb97.libs.itemselectevent.ItemSelectListener;
9 | import ce.ajneb97.libs.itemselectevent.ItemSelectListenerNew;
10 | import ce.ajneb97.listeners.*;
11 | import ce.ajneb97.listeners.dependencies.CitizensListener;
12 | import ce.ajneb97.managers.dependencies.Metrics;
13 | import ce.ajneb97.listeners.dependencies.WGRegionEventsListener;
14 | import ce.ajneb97.managers.*;
15 | import ce.ajneb97.managers.commandregister.CommandRegisterManager;
16 | import ce.ajneb97.model.EventType;
17 | import ce.ajneb97.model.internal.ConditionEvent;
18 | import ce.ajneb97.model.internal.UpdateCheckerResult;
19 | import ce.ajneb97.tasks.PlayerDataSaveTask;
20 | import ce.ajneb97.utils.ServerVersion;
21 | import org.bukkit.Bukkit;
22 | import org.bukkit.event.HandlerList;
23 | import org.bukkit.plugin.PluginDescriptionFile;
24 | import org.bukkit.plugin.PluginManager;
25 | import org.bukkit.plugin.java.JavaPlugin;
26 | import java.util.ArrayList;
27 |
28 | public class ConditionalEvents extends JavaPlugin {
29 |
30 | PluginDescriptionFile pdfFile = getDescription();
31 | public String version = pdfFile.getVersion();
32 | public static ServerVersion serverVersion;
33 | public static String prefix;
34 |
35 | private EventsManager eventsManager;
36 | private DependencyManager dependencyManager;
37 | private PlayerManager playerManager;
38 | private ConfigsManager configsManager;
39 | private DebugManager debugManager;
40 | private BungeeMessagingManager bungeeMessagingManager;
41 | private MessagesManager messagesManager;
42 | private VerifyManager verifyManager;
43 | private UpdateCheckerManager updateCheckerManager;
44 | private CommandRegisterManager commandRegisterManager;
45 | private SavedItemsManager savedItemsManager;
46 | private APIManager apiManager;
47 | private InterruptEventManager interruptEventManager;
48 |
49 | private PlayerDataSaveTask playerDataSaveTask;
50 |
51 |
52 | public void onEnable(){
53 | setVersion();
54 | setPrefix();
55 |
56 | this.eventsManager = new EventsManager(this);
57 | this.dependencyManager = new DependencyManager(this);
58 | this.bungeeMessagingManager = new BungeeMessagingManager(this);
59 | this.debugManager = new DebugManager(this);
60 | this.playerManager = new PlayerManager(this);
61 | this.savedItemsManager = new SavedItemsManager(this);
62 | this.apiManager = new APIManager(this);
63 | this.interruptEventManager = new InterruptEventManager(this);
64 | this.configsManager = new ConfigsManager(this);
65 | this.configsManager.configure();
66 |
67 | registerEvents();
68 | registerCommands();
69 |
70 | this.verifyManager = new VerifyManager(this);
71 | this.verifyManager.verifyEvents();
72 |
73 | this.commandRegisterManager = new CommandRegisterManager(this);
74 | commandRegisterManager.registerCommands();
75 |
76 |
77 |
78 | reloadPlayerDataSaveTask();
79 |
80 | ConditionalEventsAPI api = new ConditionalEventsAPI(this);
81 | if(getServer().getPluginManager().getPlugin("PlaceholderAPI") != null){
82 | new ExpansionCE(this).register();
83 | }
84 | Metrics metrics = new Metrics(this, 19371);
85 |
86 | Bukkit.getConsoleSender().sendMessage(MessagesManager.getColoredMessage(prefix+" &eHas been enabled! &fVersion: "+version));
87 | Bukkit.getConsoleSender().sendMessage(MessagesManager.getColoredMessage(prefix+" &eThanks for using my plugin! &f~Ajneb97"));
88 |
89 | updateCheckerManager = new UpdateCheckerManager(version);
90 | if(configsManager.getMainConfigManager().isUpdateNotifications()){
91 | updateMessage(updateCheckerManager.check());
92 | }
93 |
94 | new ConditionEvent(this, null, null, EventType.SERVER_START, null)
95 | .checkEvent();
96 | }
97 |
98 | public void onDisable(){
99 | new ConditionEvent(this, null, null, EventType.SERVER_STOP, null)
100 | .checkEvent();
101 | this.configsManager.getPlayerConfigsManager().savePlayerData();
102 | Bukkit.getConsoleSender().sendMessage(MessagesManager.getColoredMessage(prefix+" &eHas been disabled! &fVersion: "+version));
103 | }
104 |
105 | public void registerEvents() {
106 | PluginManager pm = getServer().getPluginManager();
107 | pm.registerEvents(new PlayerEventsListener(this), this);
108 | pm.registerEvents(new ItemEventsListener(this), this);
109 | pm.registerEvents(new ArmorListener(new ArrayList<>()), this);
110 | pm.registerEvents(new ItemSelectListener(this), this);
111 | pm.registerEvents(new OtherEventsListener(this), this);
112 | pm.registerEvents(new CustomEventListener(this), this);
113 |
114 | if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_9_R1)){
115 | pm.registerEvents(new ItemSelectListenerNew(), this);
116 | pm.registerEvents(new PlayerEventsListenerNew1_9(this), this);
117 | }
118 | if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_16_R1)){
119 | pm.registerEvents(new PlayerEventsListenerNew1_16(this), this);
120 | }
121 |
122 | if(dependencyManager.isCitizens()){
123 | pm.registerEvents(new CitizensListener(this), this);
124 | }
125 | if(dependencyManager.isWorldGuardEvents()){
126 | pm.registerEvents(new WGRegionEventsListener(this), this);
127 | }
128 | }
129 |
130 | public void setPrefix(){
131 | prefix = MessagesManager.getColoredMessage("&4[&bConditionalEvents&4]");
132 | }
133 |
134 | public void setVersion(){
135 | String packageName = Bukkit.getServer().getClass().getPackage().getName();
136 | String bukkitVersion = Bukkit.getServer().getBukkitVersion().split("-")[0];
137 | switch(bukkitVersion){
138 | case "1.20.5":
139 | case "1.20.6":
140 | serverVersion = ServerVersion.v1_20_R4;
141 | break;
142 | case "1.21":
143 | case "1.21.1":
144 | serverVersion = ServerVersion.v1_21_R1;
145 | break;
146 | case "1.21.2":
147 | case "1.21.3":
148 | serverVersion = ServerVersion.v1_21_R2;
149 | break;
150 | case "1.21.4":
151 | serverVersion = ServerVersion.v1_21_R3;
152 | break;
153 | case "1.21.5":
154 | serverVersion = ServerVersion.v1_21_R4;
155 | break;
156 | default:
157 | serverVersion = ServerVersion.valueOf(packageName.replace("org.bukkit.craftbukkit.", ""));
158 | }
159 | }
160 |
161 | public void reloadEvents(){
162 | HandlerList.unregisterAll(this);
163 | registerEvents();
164 | }
165 |
166 | public void reloadPlayerDataSaveTask() {
167 | if(playerDataSaveTask != null) {
168 | playerDataSaveTask.end();
169 | }
170 | playerDataSaveTask = new PlayerDataSaveTask(this);
171 | playerDataSaveTask.start(configsManager.getMainConfigManager().getConfig().getInt("Config.data_save_time"));
172 | }
173 |
174 | public void registerCommands(){
175 | this.getCommand("conditionalevents").setExecutor(new MainCommand(this));
176 | }
177 |
178 | public EventsManager getEventsManager() {
179 | return eventsManager;
180 | }
181 |
182 | public DependencyManager getDependencyManager() {
183 | return dependencyManager;
184 | }
185 |
186 | public ConfigsManager getConfigsManager() {
187 | return configsManager;
188 | }
189 |
190 | public DebugManager getDebugManager() {
191 | return debugManager;
192 | }
193 |
194 | public BungeeMessagingManager getBungeeMessagingManager() {
195 | return bungeeMessagingManager;
196 | }
197 |
198 | public PlayerManager getPlayerManager() {
199 | return playerManager;
200 | }
201 |
202 | public MessagesManager getMessagesManager() {
203 | return messagesManager;
204 | }
205 |
206 | public void setMessagesManager(MessagesManager messagesManager) {
207 | this.messagesManager = messagesManager;
208 | }
209 |
210 | public VerifyManager getVerifyManager() {
211 | return verifyManager;
212 | }
213 |
214 | public UpdateCheckerManager getUpdateCheckerManager() {
215 | return updateCheckerManager;
216 | }
217 |
218 | public CommandRegisterManager getCommandRegisterManager() {
219 | return commandRegisterManager;
220 | }
221 |
222 | public APIManager getApiManager() {
223 | return apiManager;
224 | }
225 |
226 | public SavedItemsManager getSavedItemsManager() {
227 | return savedItemsManager;
228 | }
229 |
230 | public InterruptEventManager getInterruptEventManager() {
231 | return interruptEventManager;
232 | }
233 |
234 | public void updateMessage(UpdateCheckerResult result){
235 | if(!result.isError()){
236 | String latestVersion = result.getLatestVersion();
237 | if(latestVersion != null){
238 | Bukkit.getConsoleSender().sendMessage(MessagesManager.getColoredMessage("&cThere is a new version available. &e(&7"+latestVersion+"&e)"));
239 | Bukkit.getConsoleSender().sendMessage(MessagesManager.getColoredMessage("&cYou can download it at: &fhttps://modrinth.com/plugin/conditionalevents"));
240 | }
241 | }else{
242 | Bukkit.getConsoleSender().sendMessage(MessagesManager.getColoredMessage(prefix+" &cError while checking update."));
243 | }
244 |
245 | }
246 |
247 | }
248 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/api/ConditionalEventsAPI.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.api;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import ce.ajneb97.managers.MessagesManager;
5 | import ce.ajneb97.model.CEEvent;
6 | import ce.ajneb97.utils.TimeUtils;
7 | import org.bukkit.entity.Player;
8 | import org.bukkit.plugin.java.JavaPlugin;
9 |
10 | public class ConditionalEventsAPI {
11 |
12 | private static ConditionalEvents plugin;
13 | public ConditionalEventsAPI(ConditionalEvents plugin){
14 | this.plugin = plugin;
15 | }
16 |
17 | public static String getEventCooldown(Player player, String event){
18 | CEEvent ceEvent = plugin.getEventsManager().getEvent(event);
19 | MessagesManager messagesManager = plugin.getMessagesManager();
20 |
21 | if(ceEvent == null){
22 | return messagesManager.getPlaceholderAPICooldownNameError();
23 | }
24 |
25 | long eventCooldownMillis = plugin.getPlayerManager().getEventCooldown(event,player)+(ceEvent.getCooldown()*1000);
26 | long currentTimeMillis = System.currentTimeMillis();
27 |
28 |
29 | if(eventCooldownMillis > currentTimeMillis){
30 | return TimeUtils.getTime((eventCooldownMillis-currentTimeMillis)/1000, messagesManager);
31 | }else{
32 | return messagesManager.getPlaceholderAPICooldownReady();
33 | }
34 | }
35 |
36 | public static String getOneTimeReady(Player player, String event){
37 | CEEvent ceEvent = plugin.getEventsManager().getEvent(event);
38 |
39 | if(ceEvent == null){
40 | return "no";
41 | }
42 |
43 | boolean oneTime = plugin.getPlayerManager().getEventOneTime(event,player);
44 | if(oneTime){
45 | return "yes";
46 | }else{
47 | return "no";
48 | }
49 | }
50 |
51 | public static void registerApiActions(JavaPlugin p, ConditionalEventsAction... actions){
52 | plugin.getApiManager().registerApiActions(p,actions);
53 | }
54 |
55 | public static void unregisterApiActions(JavaPlugin p){
56 | plugin.getApiManager().unregisterApiActions(p);
57 | }
58 |
59 | public static ConditionalEvents getPlugin() {
60 | return plugin;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/api/ConditionalEventsAction.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.api;
2 |
3 | import org.bukkit.entity.Player;
4 | import org.bukkit.event.Event;
5 | import org.bukkit.plugin.java.JavaPlugin;
6 |
7 | public abstract class ConditionalEventsAction {
8 |
9 | protected String name;
10 | protected JavaPlugin plugin;
11 |
12 | public ConditionalEventsAction(String name){
13 | this.name = name;
14 | }
15 | public abstract void execute(Player player, String actionLine, Event minecraftEvent);
16 |
17 | public String getName() {
18 | return name;
19 | }
20 |
21 | public JavaPlugin getPlugin() {
22 | return plugin;
23 | }
24 |
25 | public void setPlugin(JavaPlugin plugin) {
26 | this.plugin = plugin;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/api/ConditionalEventsCallEvent.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.api;
2 |
3 | import ce.ajneb97.model.StoredVariable;
4 | import org.bukkit.entity.Player;
5 | import org.bukkit.event.Event;
6 | import org.bukkit.event.HandlerList;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 |
12 | public class ConditionalEventsCallEvent extends Event{
13 |
14 | private Player player;
15 | private ArrayList variables;
16 | private String event;
17 | private static final HandlerList handlers = new HandlerList();
18 |
19 | public ConditionalEventsCallEvent(Player player, ArrayList variables, String event){
20 | this.player = player;
21 | this.variables = variables;
22 | this.event = event;
23 | }
24 |
25 | public Player getPlayer() {
26 | return player;
27 | }
28 |
29 | public String getEvent() {
30 | return event;
31 | }
32 |
33 | public ArrayList getVariables() {
34 | return variables;
35 | }
36 |
37 | @Override
38 | public HandlerList getHandlers() {
39 | // TODO Auto-generated method stub
40 | return handlers;
41 | }
42 |
43 | public static HandlerList getHandlerList() {
44 | return handlers;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/api/ConditionalEventsEvent.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.api;
2 |
3 | import org.bukkit.entity.Player;
4 | import org.bukkit.event.Event;
5 | import org.bukkit.event.HandlerList;
6 |
7 |
8 | public class ConditionalEventsEvent extends Event{
9 |
10 | private Player player;
11 | private String event;
12 | private String actionGroup;
13 | private static final HandlerList handlers = new HandlerList();
14 |
15 | //Event called when conditions for an event are accomplished
16 | public ConditionalEventsEvent(Player player,String event,String actionGroup){
17 | this.player = player;
18 | this.event = event;
19 | this.actionGroup = actionGroup;
20 | }
21 |
22 | public Player getPlayer() {
23 | return player;
24 | }
25 |
26 | public String getEvent() {
27 | return event;
28 | }
29 |
30 | public String getActionGroup() {
31 | return actionGroup;
32 | }
33 |
34 | @Override
35 | public HandlerList getHandlers() {
36 | // TODO Auto-generated method stub
37 | return handlers;
38 | }
39 |
40 | public static HandlerList getHandlerList() {
41 | return handlers;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/api/ExpansionCE.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.api;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import org.bukkit.entity.Player;
5 |
6 | import me.clip.placeholderapi.expansion.PlaceholderExpansion;
7 |
8 | public class ExpansionCE extends PlaceholderExpansion {
9 |
10 | // We get an instance of the plugin later.
11 | private ConditionalEvents plugin;
12 |
13 | public ExpansionCE(ConditionalEvents plugin) {
14 | this.plugin = plugin;
15 | }
16 |
17 | @Override
18 | public boolean persist(){
19 | return true;
20 | }
21 |
22 | @Override
23 | public boolean canRegister(){
24 | return true;
25 | }
26 |
27 | @Override
28 | public String getAuthor(){
29 | return "Ajneb97";
30 | }
31 |
32 | @Override
33 | public String getIdentifier(){
34 | return "conditionalevents";
35 | }
36 |
37 | @Override
38 | public String getVersion(){
39 | return plugin.getDescription().getVersion();
40 | }
41 |
42 | @Override
43 | public String onPlaceholderRequest(Player player, String identifier){
44 |
45 | if(player == null){
46 | return "";
47 | }
48 |
49 | if(identifier.startsWith("cooldown_")){
50 | // %conditionalevents_cooldown_%
51 | String event = identifier.replace("cooldown_", "");
52 | return ConditionalEventsAPI.getEventCooldown(player,event);
53 | }else if(identifier.startsWith("onetime_ready_")){
54 | // %conditionalevents_onetime_ready_%
55 | String event = identifier.replace("onetime_ready_", "");
56 | return ConditionalEventsAPI.getOneTimeReady(player,event);
57 | }
58 |
59 | return null;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/configs/CEConfig.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.configs;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import org.apache.commons.lang.Validate;
5 | import org.bukkit.Bukkit;
6 | import org.bukkit.configuration.InvalidConfigurationException;
7 | import org.bukkit.configuration.file.FileConfiguration;
8 | import org.bukkit.configuration.file.YamlConfiguration;
9 | import org.jetbrains.annotations.NotNull;
10 |
11 | import java.io.*;
12 | import java.util.logging.Level;
13 |
14 | public class CEConfig {
15 |
16 | private String fileName;
17 | private FileConfiguration fileConfiguration = null;
18 | private File file = null;
19 | private String route;
20 | private ConditionalEvents plugin;
21 | private String folderName;
22 | private boolean firstTime;
23 |
24 | public CEConfig(String fileName,ConditionalEvents plugin, String folderName){
25 | this.fileName = fileName;
26 | this.plugin = plugin;
27 | this.firstTime = false;
28 | this.folderName = folderName;
29 | }
30 |
31 | public String getPath(){
32 | return this.fileName;
33 | }
34 |
35 | public void registerConfig(){
36 | if(folderName != null){
37 | file = new File(plugin.getDataFolder() +File.separator + folderName,fileName);
38 | }else{
39 | file = new File(plugin.getDataFolder(), fileName);
40 | }
41 |
42 | route = file.getPath();
43 | if(!file.exists()){
44 | firstTime = true;
45 | this.getConfig().options().copyDefaults(true);
46 | saveConfig();
47 | firstTime = false;
48 | }
49 |
50 | }
51 | public void saveConfig() {
52 | try {
53 | fileConfiguration.save(file);
54 | } catch (IOException e) {
55 | e.printStackTrace();
56 | }
57 | }
58 |
59 | public FileConfiguration getConfig() {
60 | if (fileConfiguration == null) {
61 | reloadConfig();
62 | }
63 | return fileConfiguration;
64 | }
65 |
66 | public boolean reloadConfig() {
67 | if (fileConfiguration == null) {
68 | if(folderName != null){
69 | file = new File(plugin.getDataFolder() +File.separator + folderName, fileName);
70 | }else{
71 | file = new File(plugin.getDataFolder(), fileName);
72 | }
73 |
74 | }
75 | fileConfiguration = loadConfiguration(file);
76 |
77 | if(firstTime){
78 | Reader defConfigStream;
79 | try {
80 | if(folderName != null){
81 | defConfigStream = new InputStreamReader(plugin.getResource(folderName+"/"+fileName), "UTF8");
82 | }else{
83 | defConfigStream = new InputStreamReader(plugin.getResource(fileName), "UTF8");
84 | }
85 |
86 | if (defConfigStream != null) {
87 | YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
88 | fileConfiguration.setDefaults(defConfig);
89 | }
90 | } catch (UnsupportedEncodingException e) {
91 | e.printStackTrace();
92 | }
93 | }
94 |
95 | if(fileConfiguration == null){
96 | return false;
97 | }
98 |
99 | return true;
100 | }
101 |
102 | public static YamlConfiguration loadConfiguration(@NotNull File file) {
103 | Validate.notNull(file, "File cannot be null");
104 |
105 | YamlConfiguration config = new YamlConfiguration();
106 |
107 | try {
108 | config.load(file);
109 | } catch (FileNotFoundException ex) {
110 |
111 | } catch (IOException ex) {
112 | Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex);
113 | return null;
114 | } catch (InvalidConfigurationException ex) {
115 | Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex);
116 | return null;
117 | }
118 |
119 | return config;
120 | }
121 |
122 | public String getRoute() {
123 | return route;
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/configs/DataFolderConfigManager.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.configs;
2 |
3 |
4 | import ce.ajneb97.ConditionalEvents;
5 | import ce.ajneb97.utils.OtherUtils;
6 | import org.bukkit.configuration.file.FileConfiguration;
7 |
8 | import java.io.File;
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | public class DataFolderConfigManager {
13 |
14 | protected ArrayList configs;
15 | protected ConditionalEvents plugin;
16 | private String folderName;
17 |
18 | public DataFolderConfigManager(ConditionalEvents plugin, String folderName) {
19 | this.plugin = plugin;
20 | this.folderName = folderName;
21 | this.configs = new ArrayList();
22 | }
23 |
24 | public void configure() {
25 | createFolder();
26 | reloadConfigs();
27 | }
28 |
29 | public void reloadConfigs(){
30 | this.configs = new ArrayList();
31 | registerConfigs();
32 | }
33 |
34 | public void createFolder(){
35 | File folder;
36 | try {
37 | folder = new File(plugin.getDataFolder() + File.separator + folderName);
38 | if(!folder.exists()){
39 | folder.mkdirs();
40 | createExample();
41 | }
42 | } catch(SecurityException e) {
43 | folder = null;
44 | }
45 | }
46 |
47 | public void createExample(){
48 | String pathName = "more_events.yml";
49 | CEConfig config = new CEConfig(pathName,plugin,folderName);
50 | config.registerConfig();
51 | }
52 |
53 | public void saveConfigs() {
54 | for(int i=0;i getConfigs(){
78 | return this.configs;
79 | }
80 |
81 | public boolean fileAlreadyRegistered(String pathName) {
82 | for(int i=0;i toConditionGroups;
30 | public MainConfigManager(ConditionalEvents plugin){
31 | this.plugin = plugin;
32 | this.configFile = new CEConfig("config.yml",plugin,null);
33 | configFile.registerConfig();
34 | checkMessagesUpdate();
35 | }
36 |
37 | public void configure(){
38 | FileConfiguration config = configFile.getConfig();
39 |
40 | updateNotifications = config.getBoolean("Config.update_notification");
41 | debugActions = config.getBoolean("Config.debug_actions");
42 | experimentalVariableReplacement = config.getBoolean("Config.experimental.variable_replacement");
43 | toConditionGroups = new ArrayList<>();
44 | String path = "Config.to_condition_groups";
45 | if(config.contains(path)){
46 | for(String key : config.getConfigurationSection(path).getKeys(false)){
47 | ToConditionGroup group = new ToConditionGroup(key,config.getStringList(path+"."+key));
48 | toConditionGroups.add(group);
49 | }
50 | }
51 |
52 | //Configure messages
53 | MessagesManager msgManager = new MessagesManager();
54 | msgManager.setTimeSeconds(config.getString("Messages.seconds"));
55 | msgManager.setTimeMinutes(config.getString("Messages.minutes"));
56 | msgManager.setTimeHours(config.getString("Messages.hours"));
57 | msgManager.setTimeDays(config.getString("Messages.days"));
58 | msgManager.setPrefix(config.getString("Messages.prefix"));
59 | msgManager.setPlaceholderAPICooldownNameError(config.getString("Messages.placeholderAPICooldownNameError"));
60 | msgManager.setPlaceholderAPICooldownReady(config.getString("Messages.placeholderAPICooldownReady"));
61 |
62 | this.plugin.setMessagesManager(msgManager);
63 | }
64 |
65 | public boolean reloadConfig(){
66 | if(!configFile.reloadConfig()){
67 | return false;
68 | }
69 | configure();
70 | return true;
71 | }
72 |
73 | public FileConfiguration getConfig(){
74 | return configFile.getConfig();
75 | }
76 |
77 | public CEConfig getConfigFile(){
78 | return this.configFile;
79 | }
80 |
81 | public void saveConfig(){
82 | configFile.saveConfig();
83 | }
84 |
85 | public void checkMessagesUpdate(){
86 | Path pathConfig = Paths.get(configFile.getRoute());
87 | try{
88 | String text = new String(Files.readAllBytes(pathConfig));
89 | if(!text.contains("commandInterruptError:")){
90 | getConfig().set("Messages.commandInterruptError", "&cUse &7/ce interrupt (optional)");
91 | getConfig().set("Messages.commandInterruptCorrect", "&aActions of event &7%event% &ainterrupted.");
92 | getConfig().set("Messages.commandInterruptCorrectPlayer", "&aActions of event &7%event% &ainterrupted for player &7%player%&a.");
93 | saveConfig();
94 | }
95 | if(!text.contains("variable_replacement:")){
96 | getConfig().set("Config.experimental.variable_replacement", false);
97 | saveConfig();
98 | }
99 | if(!text.contains("commandItemError:")){
100 | getConfig().set("Messages.commandItemError", "&cUse &7/ce item ");
101 | getConfig().set("Messages.savedItemDoesNotExists", "&cThat saved item doesn't exists.");
102 | getConfig().set("Messages.savedItemRemoved", "&aItem &7%name% &aremoved.");
103 | getConfig().set("Messages.mustHaveItemInHand", "&cYou must have an item on your hand.");
104 | getConfig().set("Messages.savedItemAlreadyExists", "&cA saved item with that name already exists.");
105 | getConfig().set("Messages.savedItemAdded", "&aItem &7%name% &asaved.");
106 | saveConfig();
107 | }
108 | if(!text.contains("commandCallCorrectPlayer:")){
109 | getConfig().set("Messages.commandCallCorrectPlayer", "&aEvent &7%event% &asuccessfully executed for player &7%player%&a.");
110 | saveConfig();
111 | }
112 | if(!text.contains("playerNotOnline:")){
113 | getConfig().set("Messages.playerNotOnline", "&cThat player is not online.");
114 | saveConfig();
115 | }
116 | if(!text.contains("debugEnabledPlayer:")){
117 | getConfig().set("Messages.debugEnabledPlayer", "&aDebug now enabled for event &7%event% &aand player &7%player%&a!");
118 | getConfig().set("Messages.debugDisabledPlayer", "&aDebug disabled for event &7%event% &aand player &7%player%&a!");
119 | getConfig().set("Config.debug_actions", true);
120 | saveConfig();
121 | }
122 | if(!text.contains("eventDataResetForAllPlayers:")){
123 | getConfig().set("Messages.eventDataResetForAllPlayers", "&aData reset for &eall players &aon event &e%event%&a!");
124 | getConfig().set("Messages.eventDataResetAllForAllPlayers", "&aAll player data reset.");
125 | saveConfig();
126 | }
127 | if(!text.contains("commandCallError:")){
128 | getConfig().set("Messages.commandCallError", "&cUse &7/ce call (optional)%variable1%=;%variableN%=");
129 | getConfig().set("Messages.commandCallInvalidEvent", "&cYou can only execute a CALL event.");
130 | getConfig().set("Messages.commandCallCorrect", "&aEvent &7%event% &asuccessfully executed.");
131 | getConfig().set("Messages.commandCallFailed", "&cEvent &7%event% &ccould not be executed. Maybe a format error?");
132 | saveConfig();
133 | }
134 | if(!text.contains("register_commands:")){
135 | List commands = new ArrayList<>();
136 | getConfig().set("Config.register_commands", commands);
137 | saveConfig();
138 | }
139 | if(!text.contains("placeholderAPICooldownReady:")){
140 | getConfig().set("Messages.placeholderAPICooldownReady", "Ready!");
141 | getConfig().set("Messages.placeholderAPICooldownNameError", "No event with that name!");
142 | saveConfig();
143 | }
144 | if(!text.contains("eventDataResetAll:")){
145 | getConfig().set("Messages.eventDataResetAll", "&aAll data reset for player &e%player%&a!");
146 | saveConfig();
147 | }
148 | if(!text.contains("eventDataReset:")){
149 | getConfig().set("Messages.eventDataReset", "&aData reset for player &e%player% &aon event &e%event%&a!");
150 | saveConfig();
151 | }
152 | if(!text.contains("data_save_time:")){
153 | getConfig().set("Config.data_save_time", 5);
154 | saveConfig();
155 | }
156 | if(!text.contains("commandDebugError:")){
157 | getConfig().set("Messages.commandDebugError", "&cUse &7/ce debug ");
158 | getConfig().set("Messages.debugEnabled", "&aDebug now enabled for event &7%event%&a!");
159 | getConfig().set("Messages.debugDisabled", "&aDebug disabled for event &7%event%&a!");
160 | getConfig().set("Messages.onlyPlayerCommand", "&cThis command can be only used by a player.");
161 | getConfig().set("Messages.playerDoesNotExists", "&cThat player doesn''t have any data.");
162 | saveConfig();
163 | }
164 | }catch(IOException e){
165 | e.printStackTrace();
166 | }
167 | }
168 |
169 | public boolean isUpdateNotifications() {
170 | return updateNotifications;
171 | }
172 |
173 | public boolean isDebugActions() {
174 | return debugActions;
175 | }
176 |
177 | public ToConditionGroup getToConditionGroup(String name){
178 | for(ToConditionGroup group : toConditionGroups){
179 | if(group.getName().equals(name)) {
180 | return group;
181 | }
182 | }
183 | return null;
184 | }
185 |
186 | public boolean isExperimentalVariableReplacement() {
187 | return experimentalVariableReplacement;
188 | }
189 | }
190 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/configs/PlayerConfig.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.configs;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import org.bukkit.configuration.InvalidConfigurationException;
5 | import org.bukkit.configuration.file.FileConfiguration;
6 | import org.bukkit.configuration.file.YamlConfiguration;
7 |
8 | import java.io.File;
9 | import java.io.IOException;
10 |
11 |
12 | public class PlayerConfig {
13 |
14 | private FileConfiguration config;
15 | private File configFile;
16 | private String filePath;
17 | private ConditionalEvents plugin;
18 |
19 | public PlayerConfig(String filePath, ConditionalEvents plugin){
20 | this.config = null;
21 | this.configFile = null;
22 | this.filePath = filePath;
23 | this.plugin = plugin;
24 | }
25 |
26 | public String getPath(){
27 | return this.filePath;
28 | }
29 |
30 | public FileConfiguration getConfig(){
31 | if (config == null) {
32 | reloadPlayerConfig();
33 | }
34 | return this.config;
35 | }
36 |
37 | public void registerPlayerConfig(){
38 | configFile = new File(plugin.getDataFolder() +File.separator + "players",filePath);
39 | if(!configFile.exists()){
40 | try {
41 | configFile.createNewFile();
42 | } catch (IOException e) {
43 | // TODO Auto-generated catch block
44 | e.printStackTrace();
45 | }
46 | }
47 | config = new YamlConfiguration();
48 | try {
49 | config.load(configFile);
50 | } catch (IOException e) {
51 | e.printStackTrace();
52 | } catch (InvalidConfigurationException e) {
53 | // TODO Auto-generated catch block
54 | e.printStackTrace();
55 | }
56 | }
57 |
58 | public void savePlayerConfig() {
59 | try {
60 | config.save(configFile);
61 | } catch (IOException e) {
62 | e.printStackTrace();
63 | }
64 | }
65 |
66 | public void reloadPlayerConfig() {
67 | if (config == null) {
68 | configFile = new File(plugin.getDataFolder() +File.separator + "players", filePath);
69 | }
70 | config = YamlConfiguration.loadConfiguration(configFile);
71 |
72 | if (configFile != null) {
73 | YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(configFile);
74 | config.setDefaults(defConfig);
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/configs/PlayerConfigsManager.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.configs;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import ce.ajneb97.model.player.EventData;
5 | import ce.ajneb97.model.player.PlayerData;
6 | import ce.ajneb97.utils.OtherUtils;
7 | import org.bukkit.Bukkit;
8 | import org.bukkit.configuration.file.FileConfiguration;
9 |
10 | import java.io.File;
11 | import java.util.ArrayList;
12 |
13 | public class PlayerConfigsManager {
14 |
15 | private ConditionalEvents plugin;
16 |
17 | public PlayerConfigsManager(ConditionalEvents plugin) {
18 | this.plugin = plugin;
19 | }
20 |
21 | public void configure() {
22 | createPlayersFolder();
23 | loadPlayerData();
24 | }
25 |
26 | public void createPlayersFolder(){
27 | File folder;
28 | try {
29 | folder = new File(plugin.getDataFolder() + File.separator + "players");
30 | if(!folder.exists()){
31 | folder.mkdirs();
32 | }
33 | } catch(SecurityException e) {
34 | folder = null;
35 | }
36 | }
37 |
38 | private PlayerConfig getPlayerConfig(String pathName) {
39 | PlayerConfig playerConfig = new PlayerConfig(pathName,plugin);
40 | playerConfig.registerPlayerConfig();
41 | return playerConfig;
42 | }
43 |
44 | public void loadPlayerData() {
45 | ArrayList playerData = new ArrayList<>();
46 |
47 | String path = plugin.getDataFolder() + File.separator + "players";
48 | File folder = new File(path);
49 | File[] listOfFiles = folder.listFiles();
50 | for (File file : listOfFiles) {
51 | if (file.isFile()) {
52 | String pathName = file.getName();
53 | String ext = OtherUtils.getFileExtension(pathName);
54 | if (!ext.equals("yml")) {
55 | continue;
56 | }
57 | PlayerConfig config = new PlayerConfig(pathName, plugin);
58 | config.registerPlayerConfig();
59 |
60 | FileConfiguration players = config.getConfig();
61 | String name = players.getString("name");
62 | String uuid = config.getPath().replace(".yml", "");
63 |
64 | PlayerData p = new PlayerData(uuid,name);
65 | ArrayList eventData = new ArrayList<>();
66 |
67 | if(players.contains("events")){
68 | for(String key : players.getConfigurationSection("events").getKeys(false)){
69 | boolean oneTime = players.getBoolean("events."+key+".one_time");
70 | long cooldown = players.getLong("events."+key+".cooldown");
71 | EventData event = new EventData(key,cooldown,oneTime);
72 |
73 | eventData.add(event);
74 | }
75 | }
76 |
77 | p.setEventData(eventData);
78 | playerData.add(p);
79 | }
80 | }
81 |
82 | plugin.getPlayerManager().setPlayerData(playerData);
83 | }
84 |
85 | public void savePlayer(PlayerData player){
86 | String playerName = player.getName();
87 | PlayerConfig playerConfig = getPlayerConfig(player.getUuid()+".yml");
88 | FileConfiguration players = playerConfig.getConfig();
89 |
90 | players.set("name", playerName);
91 | players.set("events", null);
92 |
93 | for(EventData event : player.getEventData()){
94 | String path = "events."+event.getName();
95 | players.set(path+".one_time", event.isOneTime());
96 | players.set(path+".cooldown", event.getCooldown());
97 | }
98 |
99 | playerConfig.savePlayerConfig();
100 | }
101 |
102 | public void savePlayerData() {
103 | for(PlayerData player : plugin.getPlayerManager().getPlayerData()) {
104 | if(player.isModified()){
105 | savePlayer(player);
106 | }
107 | player.setModified(false);
108 | }
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/configs/SavedItemsConfigManager.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.configs;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import ce.ajneb97.managers.MessagesManager;
5 | import ce.ajneb97.model.ToConditionGroup;
6 | import org.bukkit.configuration.file.FileConfiguration;
7 | import org.bukkit.inventory.ItemStack;
8 |
9 | import java.io.IOException;
10 | import java.nio.file.Files;
11 | import java.nio.file.Path;
12 | import java.nio.file.Paths;
13 | import java.util.ArrayList;
14 | import java.util.HashMap;
15 | import java.util.List;
16 | import java.util.Map;
17 |
18 | public class SavedItemsConfigManager {
19 |
20 | private CEConfig configFile;
21 | private ConditionalEvents plugin;
22 |
23 | public SavedItemsConfigManager(ConditionalEvents plugin){
24 | this.plugin = plugin;
25 | this.configFile = new CEConfig("saved_items.yml",plugin,null);
26 | configFile.registerConfig();
27 | }
28 |
29 | public void configure(){
30 | Map savedItems = new HashMap<>();
31 |
32 | FileConfiguration config = configFile.getConfig();
33 | if(config.contains("items")){
34 | for(String key : config.getConfigurationSection("items").getKeys(false)){
35 | ItemStack item = config.getItemStack("items."+key);
36 | savedItems.put(key,item);
37 | }
38 | }
39 |
40 | plugin.getSavedItemsManager().setSavedItems(savedItems);
41 | }
42 |
43 | public void saveItem(String name,ItemStack item){
44 | FileConfiguration config = configFile.getConfig();
45 | config.set("items."+name,item);
46 | saveConfig();
47 | }
48 |
49 | public void removeItem(String name){
50 | FileConfiguration config = configFile.getConfig();
51 | config.set("items."+name,null);
52 | saveConfig();
53 | }
54 |
55 | public boolean reloadConfig(){
56 | if(!configFile.reloadConfig()){
57 | return false;
58 | }
59 | configure();
60 | return true;
61 | }
62 |
63 | public FileConfiguration getConfig(){
64 | return configFile.getConfig();
65 | }
66 |
67 | public CEConfig getConfigFile(){
68 | return this.configFile;
69 | }
70 |
71 | public void saveConfig(){
72 | configFile.saveConfig();
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/libs/actionbar/ActionBarAPI.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.libs.actionbar;
2 |
3 | import java.lang.reflect.Field;
4 | import java.lang.reflect.Method;
5 |
6 | import ce.ajneb97.managers.MessagesManager;
7 | import ce.ajneb97.utils.OtherUtils;
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.entity.Player;
10 | import org.bukkit.scheduler.BukkitRunnable;
11 | import ce.ajneb97.ConditionalEvents;
12 | import net.md_5.bungee.api.ChatMessageType;
13 | import net.md_5.bungee.api.chat.TextComponent;
14 |
15 | public class ActionBarAPI
16 | {
17 |
18 |
19 | public static void sendActionBar(Player player, String message) {
20 | if(OtherUtils.isNew()) {
21 | player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(MessagesManager.getColoredMessage(message)));
22 | return;
23 | }
24 | message = MessagesManager.getColoredMessage(message);
25 | boolean useOldMethods = false;
26 | String nmsver = Bukkit.getServer().getClass().getPackage().getName();
27 | nmsver = nmsver.substring(nmsver.lastIndexOf(".") + 1);
28 | if ((nmsver.equalsIgnoreCase("v1_8_R1")) || (nmsver.startsWith("v1_7_"))) {
29 | useOldMethods = true;
30 | }
31 | if (!player.isOnline()) {
32 | return; // Player may have logged out
33 | }
34 |
35 | try {
36 | Class> craftPlayerClass = Class.forName("org.bukkit.craftbukkit." + nmsver + ".entity.CraftPlayer");
37 | Object craftPlayer = craftPlayerClass.cast(player);
38 | Object packet;
39 | Class> packetPlayOutChatClass = Class.forName("net.minecraft.server." + nmsver + ".PacketPlayOutChat");
40 | Class> packetClass = Class.forName("net.minecraft.server." + nmsver + ".Packet");
41 | if (useOldMethods) {
42 | Class> chatSerializerClass = Class.forName("net.minecraft.server." + nmsver + ".ChatSerializer");
43 | Class> iChatBaseComponentClass = Class.forName("net.minecraft.server." + nmsver + ".IChatBaseComponent");
44 | Method m3 = chatSerializerClass.getDeclaredMethod("a", String.class);
45 | Object cbc = iChatBaseComponentClass.cast(m3.invoke(chatSerializerClass, "{\"text\": \"" + message + "\"}"));
46 | packet = packetPlayOutChatClass.getConstructor(new Class>[]{iChatBaseComponentClass, byte.class}).newInstance(cbc, (byte) 2);
47 | } else {
48 | Class> chatComponentTextClass = Class.forName("net.minecraft.server." + nmsver + ".ChatComponentText");
49 | Class> iChatBaseComponentClass = Class.forName("net.minecraft.server." + nmsver + ".IChatBaseComponent");
50 | try {
51 |
52 | Class> chatMessageTypeClass = Class.forName("net.minecraft.server." + nmsver + ".ChatMessageType");
53 | Object[] chatMessageTypes = chatMessageTypeClass.getEnumConstants();
54 | Object chatMessageType = null;
55 | for (Object obj : chatMessageTypes) {
56 | if (obj.toString().equals("GAME_INFO")) {
57 | chatMessageType = obj;
58 | }
59 | }
60 | Object chatCompontentText = chatComponentTextClass.getConstructor(new Class>[]{String.class}).newInstance(message);
61 | packet = packetPlayOutChatClass.getConstructor(new Class>[]{iChatBaseComponentClass, chatMessageTypeClass}).newInstance(chatCompontentText, chatMessageType);
62 | } catch (ClassNotFoundException cnfe) {
63 | Object chatCompontentText = chatComponentTextClass.getConstructor(new Class>[]{String.class}).newInstance(message);
64 | packet = packetPlayOutChatClass.getConstructor(new Class>[]{iChatBaseComponentClass, byte.class}).newInstance(chatCompontentText, (byte) 2);
65 | }
66 | }
67 | Method craftPlayerHandleMethod = craftPlayerClass.getDeclaredMethod("getHandle");
68 | Object craftPlayerHandle = craftPlayerHandleMethod.invoke(craftPlayer);
69 | Field playerConnectionField = craftPlayerHandle.getClass().getDeclaredField("playerConnection");
70 | Object playerConnection = playerConnectionField.get(craftPlayerHandle);
71 | Method sendPacketMethod = playerConnection.getClass().getDeclaredMethod("sendPacket", packetClass);
72 | sendPacketMethod.invoke(playerConnection, packet);
73 | } catch (Exception e) {
74 | e.printStackTrace();
75 | }
76 | }
77 |
78 | public static void sendActionBar(final Player player, final String message, int duration,ConditionalEvents plugin) {
79 | sendActionBar(player, message);
80 |
81 | if (duration > 0) {
82 | // Sends empty message at the end of the duration. Allows messages shorter than 3 seconds, ensures precision.
83 | new BukkitRunnable() {
84 | @Override
85 | public void run() {
86 | sendActionBar(player, "");
87 | }
88 | }.runTaskLater(plugin, duration + 1);
89 | }
90 |
91 | // Re-sends the messages every 3 seconds so it doesn't go away from the player's screen.
92 | while (duration > 40) {
93 | duration -= 40;
94 | new BukkitRunnable() {
95 | @Override
96 | public void run() {
97 | sendActionBar(player, message);
98 | }
99 | }.runTaskLater(plugin, (long) duration);
100 | }
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/libs/armorequipevent/ArmorEquipEvent.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.libs.armorequipevent;
2 |
3 | import org.bukkit.entity.Player;
4 | import org.bukkit.event.Cancellable;
5 | import org.bukkit.event.HandlerList;
6 | import org.bukkit.event.player.PlayerEvent;
7 | import org.bukkit.inventory.ItemStack;
8 |
9 | /**
10 | * @author Arnah
11 | * @since Jul 30, 2015
12 | */
13 | public final class ArmorEquipEvent extends PlayerEvent implements Cancellable{
14 |
15 | private static final HandlerList handlers = new HandlerList();
16 | private boolean cancel = false;
17 | private final EquipMethod equipType;
18 | private final ArmorType type;
19 | private ItemStack oldArmorPiece, newArmorPiece;
20 |
21 | /**
22 | * @param player The player who put on / removed the armor.
23 | * @param type The ArmorType of the armor added
24 | * @param oldArmorPiece The ItemStack of the armor removed.
25 | * @param newArmorPiece The ItemStack of the armor added.
26 | */
27 | public ArmorEquipEvent(final Player player, final EquipMethod equipType, final ArmorType type, final ItemStack oldArmorPiece, final ItemStack newArmorPiece){
28 | super(player);
29 | this.equipType = equipType;
30 | this.type = type;
31 | this.oldArmorPiece = oldArmorPiece;
32 | this.newArmorPiece = newArmorPiece;
33 | }
34 |
35 | /**
36 | * Gets a list of handlers handling this event.
37 | *
38 | * @return A list of handlers handling this event.
39 | */
40 | public static HandlerList getHandlerList(){
41 | return handlers;
42 | }
43 |
44 | /**
45 | * Gets a list of handlers handling this event.
46 | *
47 | * @return A list of handlers handling this event.
48 | */
49 | @Override
50 | public final HandlerList getHandlers(){
51 | return handlers;
52 | }
53 |
54 | /**
55 | * Sets if this event should be cancelled.
56 | *
57 | * @param cancel If this event should be cancelled.
58 | */
59 | public final void setCancelled(final boolean cancel){
60 | this.cancel = cancel;
61 | }
62 |
63 | /**
64 | * Gets if this event is cancelled.
65 | *
66 | * @return If this event is cancelled
67 | */
68 | public final boolean isCancelled(){
69 | return cancel;
70 | }
71 |
72 | public final ArmorType getType(){
73 | return type;
74 | }
75 |
76 | /**
77 | * Returns the last equipped armor piece, could be a piece of armor, or null
78 | */
79 | public final ItemStack getOldArmorPiece(){
80 | return oldArmorPiece;
81 | }
82 |
83 | public final void setOldArmorPiece(final ItemStack oldArmorPiece){
84 | this.oldArmorPiece = oldArmorPiece;
85 | }
86 |
87 | /**
88 | * Returns the newly equipped armor, could be a piece of armor, or null
89 | */
90 | public final ItemStack getNewArmorPiece(){
91 | return newArmorPiece;
92 | }
93 |
94 | public final void setNewArmorPiece(final ItemStack newArmorPiece){
95 | this.newArmorPiece = newArmorPiece;
96 | }
97 |
98 | /**
99 | * Gets the method used to either equip or unequip an armor piece.
100 | */
101 | public EquipMethod getMethod(){
102 | return equipType;
103 | }
104 |
105 | public enum EquipMethod{// These have got to be the worst documentations ever.
106 | /**
107 | * When you shift click an armor piece to equip or unequip
108 | */
109 | SHIFT_CLICK,
110 | /**
111 | * When you drag and drop the item to equip or unequip
112 | */
113 | DRAG,
114 | /**
115 | * When you manually equip or unequip the item. Use to be DRAG
116 | */
117 | PICK_DROP,
118 | /**
119 | * When you right click an armor piece in the hotbar without the inventory open to equip.
120 | */
121 | HOTBAR,
122 | /**
123 | * When you press the hotbar slot number while hovering over the armor slot to equip or unequip
124 | */
125 | HOTBAR_SWAP,
126 | /**
127 | * When in range of a dispenser that shoots an armor piece to equip.
128 | * Requires the spigot version to have {@link org.bukkit.event.block.BlockDispenseArmorEvent} implemented.
129 | */
130 | DISPENSER,
131 | /**
132 | * When an armor piece is removed due to it losing all durability.
133 | */
134 | BROKE,
135 | /**
136 | * When you die causing all armor to unequip
137 | */
138 | DEATH,
139 | ;
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/libs/armorequipevent/ArmorType.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.libs.armorequipevent;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import ce.ajneb97.utils.ServerVersion;
5 | import org.bukkit.Material;
6 | import org.bukkit.inventory.ItemStack;
7 |
8 | /**
9 | * @author Arnah
10 | * @since Jul 30, 2015
11 | */
12 | public enum ArmorType{
13 | HELMET(5), CHESTPLATE(6), LEGGINGS(7), BOOTS(8);
14 |
15 | private final int slot;
16 |
17 | ArmorType(int slot){
18 | this.slot = slot;
19 | }
20 |
21 | /**
22 | * Attempts to match the ArmorType for the specified ItemStack.
23 | *
24 | * @param itemStack The ItemStack to parse the type of.
25 | * @return The parsed ArmorType, or null if not found.
26 | */
27 | public static ArmorType matchType(final ItemStack itemStack){
28 | if(ArmorListener.isAirOrNull(itemStack)) return null;
29 | String type = itemStack.getType().name();
30 |
31 | ServerVersion serverVersion = ConditionalEvents.serverVersion;
32 | if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_13_R1)){
33 | if(type.equals("CARVED_PUMPKIN")){
34 | return HELMET;
35 | }
36 | }else{
37 | if(type.equals("PUMPKIN")){
38 | return HELMET;
39 | }
40 | }
41 |
42 | if(type.endsWith("_HELMET") || type.startsWith("SKULL_") || type.endsWith("_HEAD") || type.endsWith("_SKULL")) return HELMET;
43 | else if(type.endsWith("_CHESTPLATE") || type.equals("ELYTRA")) return CHESTPLATE;
44 | else if(type.endsWith("_LEGGINGS")) return LEGGINGS;
45 | else if(type.endsWith("_BOOTS")) return BOOTS;
46 | else return null;
47 | }
48 |
49 | public int getSlot(){
50 | return slot;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/libs/centeredmessages/DefaultFontInfo.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.libs.centeredmessages;
2 |
3 | public enum DefaultFontInfo{
4 |
5 | A('A', 5),
6 | a('a', 5),
7 | B('B', 5),
8 | b('b', 5),
9 | C('C', 5),
10 | c('c', 5),
11 | D('D', 5),
12 | d('d', 5),
13 | E('E', 5),
14 | e('e', 5),
15 | F('F', 5),
16 | f('f', 4),
17 | G('G', 5),
18 | g('g', 5),
19 | H('H', 5),
20 | h('h', 5),
21 | I('I', 3),
22 | i('i', 1),
23 | J('J', 5),
24 | j('j', 5),
25 | K('K', 5),
26 | k('k', 4),
27 | L('L', 5),
28 | l('l', 1),
29 | M('M', 5),
30 | m('m', 5),
31 | N('N', 5),
32 | n('n', 5),
33 | O('O', 5),
34 | o('o', 5),
35 | P('P', 5),
36 | p('p', 5),
37 | Q('Q', 5),
38 | q('q', 5),
39 | R('R', 5),
40 | r('r', 5),
41 | S('S', 5),
42 | s('s', 5),
43 | T('T', 5),
44 | t('t', 4),
45 | U('U', 5),
46 | u('u', 5),
47 | V('V', 5),
48 | v('v', 5),
49 | W('W', 5),
50 | w('w', 5),
51 | X('X', 5),
52 | x('x', 5),
53 | Y('Y', 5),
54 | y('y', 5),
55 | Z('Z', 5),
56 | z('z', 5),
57 | NUM_1('1', 5),
58 | NUM_2('2', 5),
59 | NUM_3('3', 5),
60 | NUM_4('4', 5),
61 | NUM_5('5', 5),
62 | NUM_6('6', 5),
63 | NUM_7('7', 5),
64 | NUM_8('8', 5),
65 | NUM_9('9', 5),
66 | NUM_0('0', 5),
67 | EXCLAMATION_POINT('!', 1),
68 | AT_SYMBOL('@', 6),
69 | NUM_SIGN('#', 5),
70 | DOLLAR_SIGN('$', 5),
71 | PERCENT('%', 5),
72 | UP_ARROW('^', 5),
73 | AMPERSAND('&', 5),
74 | ASTERISK('*', 5),
75 | LEFT_PARENTHESIS('(', 4),
76 | RIGHT_PERENTHESIS(')', 4),
77 | MINUS('-', 5),
78 | UNDERSCORE('_', 5),
79 | PLUS_SIGN('+', 5),
80 | EQUALS_SIGN('=', 5),
81 | LEFT_CURL_BRACE('{', 4),
82 | RIGHT_CURL_BRACE('}', 4),
83 | LEFT_BRACKET('[', 3),
84 | RIGHT_BRACKET(']', 3),
85 | COLON(':', 1),
86 | SEMI_COLON(';', 1),
87 | DOUBLE_QUOTE('"', 3),
88 | SINGLE_QUOTE('\'', 1),
89 | LEFT_ARROW('<', 4),
90 | RIGHT_ARROW('>', 4),
91 | QUESTION_MARK('?', 5),
92 | SLASH('/', 5),
93 | BACK_SLASH('\\', 5),
94 | LINE('|', 1),
95 | TILDE('~', 5),
96 | TICK('`', 2),
97 | PERIOD('.', 1),
98 | COMMA(',', 1),
99 | SPACE(' ', 3),
100 | DEFAULT('a', 4);
101 |
102 | private char character;
103 | private int length;
104 |
105 | DefaultFontInfo(char character, int length) {
106 | this.character = character;
107 | this.length = length;
108 | }
109 |
110 | public char getCharacter(){
111 | return this.character;
112 | }
113 |
114 | public int getLength(){
115 | return this.length;
116 | }
117 |
118 | public int getBoldLength(){
119 | if(this == DefaultFontInfo.SPACE) return this.getLength();
120 | return this.length + 1;
121 | }
122 |
123 | public static DefaultFontInfo getDefaultFontInfo(char c){
124 | for(DefaultFontInfo dFI : DefaultFontInfo.values()){
125 | if(dFI.getCharacter() == c) return dFI;
126 | }
127 | return DefaultFontInfo.DEFAULT;
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/libs/itemselectevent/DropType.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.libs.itemselectevent;
2 |
3 | public enum DropType {
4 |
5 | PLAYER,
6 | INVENTORY
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/libs/itemselectevent/ItemSelectEvent.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.libs.itemselectevent;
2 |
3 | import org.bukkit.entity.Player;
4 | import org.bukkit.event.HandlerList;
5 | import org.bukkit.event.player.PlayerEvent;
6 | import org.bukkit.inventory.ItemStack;
7 |
8 | public class ItemSelectEvent extends PlayerEvent{
9 |
10 | private static final HandlerList handlers = new HandlerList();
11 | private SelectType selectType;
12 | private ItemStack item;
13 |
14 | public ItemSelectEvent(Player player,ItemStack item,SelectType selectType) {
15 | super(player);
16 | this.item = item;
17 | this.selectType = selectType;
18 | }
19 |
20 | public SelectType getSelectType() {
21 | return selectType;
22 | }
23 |
24 | public ItemStack getItem() {
25 | return item;
26 | }
27 |
28 | @Override
29 | public HandlerList getHandlers() {
30 | // TODO Auto-generated method stub
31 | return handlers;
32 | }
33 |
34 | public static HandlerList getHandlerList() {
35 | return handlers;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/libs/itemselectevent/ItemSelectListener.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.libs.itemselectevent;
2 |
3 | import java.util.ArrayList;
4 | import org.bukkit.Bukkit;
5 | import org.bukkit.Material;
6 | import org.bukkit.entity.Player;
7 | import org.bukkit.event.EventHandler;
8 | import org.bukkit.event.Listener;
9 | import org.bukkit.event.inventory.ClickType;
10 | import org.bukkit.event.inventory.InventoryAction;
11 | import org.bukkit.event.inventory.InventoryClickEvent;
12 | import org.bukkit.event.player.PlayerDropItemEvent;
13 | import org.bukkit.event.player.PlayerItemBreakEvent;
14 | import org.bukkit.event.player.PlayerItemHeldEvent;
15 | import org.bukkit.event.player.PlayerPickupItemEvent;
16 | import org.bukkit.inventory.ItemStack;
17 | import org.bukkit.scheduler.BukkitRunnable;
18 | import ce.ajneb97.ConditionalEvents;
19 |
20 | public class ItemSelectListener implements Listener{
21 |
22 | private ArrayList players = new ArrayList();
23 | private ConditionalEvents plugin;
24 | public ItemSelectListener(ConditionalEvents plugin) {
25 | this.plugin = plugin;
26 | }
27 |
28 | @EventHandler
29 | public void onItemChanged(PlayerItemHeldEvent event) {
30 | if(event.isCancelled()) {
31 | return;
32 | }
33 |
34 | Player player = event.getPlayer();
35 |
36 | int previousSlot = event.getPreviousSlot();
37 | int newSlot = event.getNewSlot();
38 | ItemStack newItem = player.getInventory().getItem(newSlot);
39 | ItemStack previousItem = player.getInventory().getItem(previousSlot);
40 | ArrayList items = new ArrayList();
41 | items.add(newItem);items.add(previousItem);
42 | for(int i=0;i items = new ArrayList();
141 | if(selectedSlot == slot) {
142 | items.add(current);items.add(cursor);
143 | }else if(selectedSlot == slotHotbar) {
144 | items.add(cursor);items.add(current);
145 | }
146 | for(int i=0;i items = new ArrayList();
25 | items.add(itemMain);items.add(itemOff);
26 | for(int i=0;i getNMSClass(String name) {
26 | String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
27 | try {
28 | return Class.forName("net.minecraft.server." + version + "." + name);
29 | } catch (ClassNotFoundException e) {
30 | e.printStackTrace();
31 | return null;
32 | }
33 | }
34 |
35 | public static void sendTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String title, String subtitle) {
36 | if(OtherUtils.isNew()) {
37 | if(title.isEmpty()) {
38 | title = " ";
39 | }
40 | if(subtitle.isEmpty()) {
41 | subtitle = " ";
42 | }
43 | player.sendTitle(MessagesManager.getColoredMessage(title), MessagesManager.getColoredMessage(subtitle), fadeIn, stay, fadeOut);
44 | return;
45 | }
46 | try {
47 | Object e;
48 | Object chatTitle;
49 | Object chatSubtitle;
50 | Constructor subtitleConstructor;
51 | Object titlePacket;
52 | Object subtitlePacket;
53 |
54 | if (title != null) {
55 | title = ChatColor.translateAlternateColorCodes('&', title);
56 | title = title.replaceAll("%player%", player.getDisplayName());
57 | // Times packets
58 | e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get((Object) null);
59 | chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke((Object) null, new Object[]{"{\"text\":\"" + title + "\"}"});
60 | subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[]{getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE});
61 | titlePacket = subtitleConstructor.newInstance(new Object[]{e, chatTitle, fadeIn, stay, fadeOut});
62 | sendPacket(player, titlePacket);
63 |
64 | e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TITLE").get((Object) null);
65 | chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke((Object) null, new Object[]{"{\"text\":\"" + title + "\"}"});
66 | subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[]{getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent")});
67 | titlePacket = subtitleConstructor.newInstance(new Object[]{e, chatTitle});
68 | sendPacket(player, titlePacket);
69 | }
70 |
71 | if (subtitle != null) {
72 | subtitle = ChatColor.translateAlternateColorCodes('&', subtitle);
73 | subtitle = subtitle.replaceAll("%player%", player.getDisplayName());
74 | // Times packets
75 | e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get((Object) null);
76 | chatSubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke((Object) null, new Object[]{"{\"text\":\"" + title + "\"}"});
77 | subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[]{getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE});
78 | subtitlePacket = subtitleConstructor.newInstance(new Object[]{e, chatSubtitle, fadeIn, stay, fadeOut});
79 | sendPacket(player, subtitlePacket);
80 |
81 | e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("SUBTITLE").get((Object) null);
82 | chatSubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke((Object) null, new Object[]{"{\"text\":\"" + subtitle + "\"}"});
83 | subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[]{getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE});
84 | subtitlePacket = subtitleConstructor.newInstance(new Object[]{e, chatSubtitle, fadeIn, stay, fadeOut});
85 | sendPacket(player, subtitlePacket);
86 | }
87 | } catch (Exception var11) {
88 | var11.printStackTrace();
89 | }
90 | }
91 | }
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/listeners/CustomEventListener.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.listeners;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import ce.ajneb97.managers.MessagesManager;
5 | import ce.ajneb97.model.CEEvent;
6 | import ce.ajneb97.model.CustomEventProperties;
7 | import ce.ajneb97.model.EventType;
8 | import ce.ajneb97.model.StoredVariable;
9 | import ce.ajneb97.model.internal.ConditionEvent;
10 | import org.bukkit.Bukkit;
11 | import org.bukkit.entity.Player;
12 | import org.bukkit.event.Event;
13 | import org.bukkit.event.EventPriority;
14 | import org.bukkit.event.Listener;
15 | import org.bukkit.plugin.EventExecutor;
16 |
17 | import java.lang.reflect.InvocationTargetException;
18 | import java.lang.reflect.Method;
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | public class CustomEventListener implements Listener {
23 |
24 | public ConditionalEvents plugin;
25 | public CustomEventListener(ConditionalEvents plugin) {
26 | this.plugin = plugin;
27 | configure();
28 | }
29 |
30 | public void configure(){
31 | ArrayList validEvents = plugin.getEventsManager().getEventsByType(EventType.CUSTOM);
32 | for(CEEvent ceEvent : validEvents) {
33 | CustomEventProperties properties = ceEvent.getCustomEventProperties();
34 | String eventPackage = properties.getEventPackage();
35 | try {
36 | Class extends Event> eventClass = (Class extends Event>) Class.forName(eventPackage);
37 | EventExecutor eventExecutor = (listener, event) -> executeEvent(event, ceEvent.getName());
38 | plugin.getServer().getPluginManager().registerEvent(eventClass, this, EventPriority.MONITOR, eventExecutor, plugin);
39 | } catch (ClassNotFoundException ex) {
40 | Bukkit.getConsoleSender().sendMessage(ConditionalEvents.prefix
41 | + MessagesManager.getColoredMessage("&cClass "+eventPackage+" &cdoesn't exists for custom event &e"+ceEvent.getName()+"&c."));
42 | }
43 | }
44 | }
45 |
46 | public void executeEvent(Event event,String ceEventName) {
47 | Class> classObject = event.getClass();
48 |
49 | CEEvent ceEvent = plugin.getEventsManager().getEvent(ceEventName);
50 | if(ceEvent == null || !ceEvent.isEnabled()){
51 | return;
52 | }
53 |
54 | CustomEventProperties properties = ceEvent.getCustomEventProperties();
55 | try {
56 | if (!Class.forName(properties.getEventPackage()).isAssignableFrom(classObject)) {
57 | return;
58 | }
59 | } catch (ClassNotFoundException e1) {
60 | e1.printStackTrace();
61 | }
62 |
63 | //Get variables
64 | List variablesToCapture = properties.getVariablesToCapture();
65 | ArrayList storedVariables = new ArrayList();
66 | for(String line : variablesToCapture) {
67 | String[] sepLine = line.split(";");
68 | String variable = sepLine[0];
69 | String methodName = sepLine[1].replace("(", "").replace(")", "");
70 | Object objectFinal = null;
71 | if(methodName.contains(".")) {
72 | objectFinal = getFinalObjectFromMultipleMethods(methodName,event,classObject);
73 | }else {
74 | Method m = obtainMethod(classObject,methodName);
75 | objectFinal = obtainObjectFromEvent(m,event);
76 | }
77 |
78 | if(objectFinal != null){
79 | storedVariables.add(new StoredVariable(variable,objectFinal.toString()));
80 | }
81 | }
82 |
83 | //Get player
84 | Object playerObjectFinal = null;
85 | if(properties.getPlayerVariable() != null) {
86 | String methodName = properties.getPlayerVariable().replace("(", "").replace(")", "");
87 | if(methodName.contains(".")) {
88 | playerObjectFinal = getFinalObjectFromMultipleMethods(methodName,event,classObject);
89 | }else {
90 | Method m = obtainMethod(classObject,methodName);
91 | playerObjectFinal = obtainObjectFromEvent(m,event);
92 | }
93 | }
94 |
95 | try {
96 | Player player = null;
97 | if(playerObjectFinal != null) {
98 | player = (Player) playerObjectFinal;
99 | }
100 |
101 | ConditionEvent conditionEvent = new ConditionEvent(plugin, player, event, EventType.CUSTOM, null)
102 | .addVariables(storedVariables);
103 | plugin.getEventsManager().checkSingularEvent(conditionEvent,ceEvent);
104 | }catch(Exception ex) {
105 |
106 | }
107 | }
108 |
109 | private Object getFinalObjectFromMultipleMethods(String method,Event event,Class> classObject){
110 | Object objectFinal = null;
111 | String[] methods = method.split("\\.");
112 | Class> newClass = classObject;
113 | try{
114 | for(int i=0;i classObject,String methodName) {
132 | try {
133 | return classObject.getMethod(methodName);
134 | } catch (NoSuchMethodException e) {
135 | e.printStackTrace();
136 | } catch (Exception e) {
137 |
138 | }
139 | return null;
140 | }
141 |
142 | private Object obtainObjectFromEvent(Method m,Event event) {
143 | try {
144 | m.setAccessible(true);
145 | return m.invoke(event);
146 | } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
147 |
148 | }
149 | return null;
150 | }
151 |
152 | private Object obtainObjectFromObject(Method m,Object object) {
153 | try {
154 | m.setAccessible(true);
155 | return m.invoke(object);
156 | } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
157 |
158 | }
159 | return null;
160 | }
161 |
162 | }
163 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/listeners/OtherEventsListener.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.listeners;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import ce.ajneb97.api.ConditionalEventsCallEvent;
5 | import ce.ajneb97.libs.itemselectevent.ItemSelectEvent;
6 | import ce.ajneb97.managers.EventsManager;
7 | import ce.ajneb97.model.CEEvent;
8 | import ce.ajneb97.model.EventType;
9 | import ce.ajneb97.model.StoredVariable;
10 | import ce.ajneb97.model.internal.ConditionEvent;
11 | import org.bukkit.Material;
12 | import org.bukkit.entity.Entity;
13 | import org.bukkit.entity.EntityType;
14 | import org.bukkit.entity.Player;
15 | import org.bukkit.entity.Projectile;
16 | import org.bukkit.event.EventHandler;
17 | import org.bukkit.event.EventPriority;
18 | import org.bukkit.event.Listener;
19 | import org.bukkit.event.entity.CreatureSpawnEvent;
20 | import org.bukkit.event.entity.EntityDamageByEntityEvent;
21 | import org.bukkit.event.entity.ProjectileLaunchEvent;
22 | import org.bukkit.event.inventory.ClickType;
23 | import org.bukkit.event.inventory.CraftItemEvent;
24 | import org.bukkit.event.inventory.InventoryClickEvent;
25 | import org.bukkit.event.player.PlayerDropItemEvent;
26 | import org.bukkit.event.player.PlayerInteractEvent;
27 | import org.bukkit.event.player.PlayerItemConsumeEvent;
28 | import org.bukkit.event.player.PlayerPickupItemEvent;
29 | import org.bukkit.event.server.ServerCommandEvent;
30 | import org.bukkit.event.server.TabCompleteEvent;
31 | import org.bukkit.inventory.InventoryView;
32 | import org.bukkit.inventory.ItemStack;
33 | import org.bukkit.metadata.FixedMetadataValue;
34 |
35 | import java.util.ArrayList;
36 |
37 | public class OtherEventsListener implements Listener {
38 |
39 | public ConditionalEvents plugin;
40 | public OtherEventsListener(ConditionalEvents plugin) {
41 | this.plugin = plugin;
42 | }
43 |
44 | @EventHandler(priority = EventPriority.HIGHEST)
45 | public void onEntitySpawn(CreatureSpawnEvent event){
46 | Entity entity = event.getEntity();
47 | new ConditionEvent(plugin, null, event, EventType.ENTITY_SPAWN, null)
48 | .addVariables(
49 | new StoredVariable("%reason%",event.getSpawnReason().name())
50 | )
51 | .setCommonEntityVariables(entity).checkEvent();
52 | }
53 |
54 | @EventHandler(priority = EventPriority.HIGHEST)
55 | public void onConsoleCommand(ServerCommandEvent event) {
56 | String command = event.getCommand();
57 | String[] args = command.split(" ");
58 |
59 | ArrayList eventVariables = new ArrayList();
60 | for(int i=1;i apiActions;
16 | public APIManager(ConditionalEvents plugin){
17 | this.plugin = plugin;
18 | apiActions = new ArrayList<>();
19 | }
20 |
21 | public void registerApiActions(JavaPlugin plugin, ConditionalEventsAction... actions){
22 | for(ConditionalEventsAction a : actions){
23 | a.setPlugin(plugin);
24 | Bukkit.getConsoleSender().sendMessage(ConditionalEvents.prefix+
25 | MessagesManager.getColoredMessage(" &7Custom API Action &a"+a.getName()+" &7registered from plugin &e"+a.getPlugin().getName()));
26 | apiActions.add(a);
27 | }
28 | this.plugin.getConfigsManager().endRepetitiveEvents();
29 | this.plugin.getConfigsManager().configureEvents();
30 | this.plugin.getVerifyManager().verifyEvents();
31 | }
32 |
33 | public void unregisterApiActions(JavaPlugin plugin){
34 | apiActions.removeIf(a -> a.getPlugin() == plugin);
35 | this.plugin.getConfigsManager().endRepetitiveEvents();
36 | this.plugin.getConfigsManager().configureEvents();
37 | this.plugin.getVerifyManager().verifyEvents();
38 | }
39 |
40 | public ConditionalEventsAction getApiAction(String actionName){
41 | for(ConditionalEventsAction action : apiActions){
42 | if(action.getName().equals(actionName)){
43 | return action;
44 | }
45 | }
46 | return null;
47 | }
48 |
49 | public void executeAction(String actionName, Player player, String actionLine, Event minecraftEvent){
50 | ConditionalEventsAction action = getApiAction(actionName);
51 | if(action != null){
52 | action.execute(player,actionLine,minecraftEvent);
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/managers/BungeeMessagingManager.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.managers;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import com.google.common.io.ByteArrayDataOutput;
5 | import com.google.common.io.ByteStreams;
6 | import org.bukkit.Bukkit;
7 | import org.bukkit.entity.Player;
8 | import org.bukkit.plugin.messaging.PluginMessageListener;
9 |
10 | public class BungeeMessagingManager implements PluginMessageListener {
11 |
12 | private ConditionalEvents plugin;
13 | public BungeeMessagingManager(ConditionalEvents plugin){
14 | this.plugin = plugin;
15 | Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord");
16 | Bukkit.getServer().getMessenger().registerIncomingPluginChannel(plugin, "BungeeCord", this);
17 | }
18 |
19 | @Override
20 | public void onPluginMessageReceived(String channel, Player player, byte[] bytes) {
21 | if (!channel.equals("BungeeCord")) {
22 | return;
23 | }
24 | }
25 |
26 | public void sendToServer(Player player,String server){
27 | ByteArrayDataOutput out = ByteStreams.newDataOutput();
28 | out.writeUTF("Connect");
29 | out.writeUTF(server);
30 | player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/managers/DebugManager.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.managers;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import ce.ajneb97.model.actions.ActionTargeter;
5 | import ce.ajneb97.model.actions.ActionTargeterType;
6 | import ce.ajneb97.model.actions.ActionType;
7 | import ce.ajneb97.model.internal.DebugSender;
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.command.CommandSender;
10 | import org.bukkit.entity.Player;
11 |
12 | import java.util.ArrayList;
13 |
14 | public class DebugManager {
15 |
16 | private ConditionalEvents plugin;
17 | private ArrayList debugSenders;
18 | public DebugManager(ConditionalEvents plugin){
19 | this.plugin = plugin;
20 | this.debugSenders = new ArrayList();
21 | }
22 |
23 | public boolean setDebugSender(CommandSender sender,String event,String playerName){
24 | DebugSender debugSender = getDebugSender(sender);
25 | if(debugSender == null){
26 | this.debugSenders.add(new DebugSender(sender,event,playerName));
27 | return true;
28 | }
29 | if(debugSender.getEvent().equals(event)){
30 | //If the same, then remove it
31 | removeDebugSender(sender);
32 | return false;
33 | }
34 | //If not the same, update it
35 | debugSender.setEvent(event);
36 | return true;
37 | }
38 |
39 | public DebugSender getDebugSender(CommandSender sender){
40 | for(DebugSender debugSender : debugSenders){
41 | if(debugSender.getSender().equals(sender)){
42 | return debugSender;
43 | }
44 | }
45 | return null;
46 | }
47 |
48 | public void removeDebugSender(CommandSender sender){
49 | for(int i=0;i tasks;
13 |
14 | public InterruptEventManager(ConditionalEvents plugin){
15 | this.plugin = plugin;
16 | this.tasks = new ArrayList<>();
17 | }
18 |
19 | public void addTask(String playerName, String eventName, BukkitTask bukkitTask){
20 | tasks.add(new WaitActionTask(playerName,eventName,bukkitTask));
21 | }
22 |
23 | public void removeTaskById(int taskId){
24 | tasks.removeIf(task -> task.getTask().getTaskId() == taskId);
25 | }
26 |
27 | // Interrupt actions for a specific event, globally or per player
28 | public void interruptEvent(String eventName, String playerName){
29 | tasks.removeIf(task -> {
30 | if(playerName == null){
31 | if(task.getEventName().equals(eventName)){
32 | task.getTask().cancel();
33 | return true;
34 | }
35 | }else{
36 | if(task.getPlayerName() != null && task.getPlayerName().equals(playerName) && task.getEventName().equals(eventName)){
37 | task.getTask().cancel();
38 | return true;
39 | }
40 | }
41 | return false;
42 | });
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/managers/MessagesManager.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.managers;
2 |
3 | import ce.ajneb97.libs.centeredmessages.DefaultFontInfo;
4 | import ce.ajneb97.utils.OtherUtils;
5 | import net.md_5.bungee.api.ChatColor;
6 | import org.bukkit.command.CommandSender;
7 |
8 | import java.util.regex.Matcher;
9 | import java.util.regex.Pattern;
10 |
11 | public class MessagesManager {
12 |
13 | private String timeSeconds;
14 | private String timeMinutes;
15 | private String timeHours;
16 | private String timeDays;
17 | private String prefix;
18 | private String placeholderAPICooldownReady;
19 | private String placeholderAPICooldownNameError;
20 |
21 |
22 | public String getTimeSeconds() {
23 | return timeSeconds;
24 | }
25 |
26 | public void setTimeSeconds(String timeSeconds) {
27 | this.timeSeconds = timeSeconds;
28 | }
29 |
30 | public String getTimeMinutes() {
31 | return timeMinutes;
32 | }
33 |
34 | public void setTimeMinutes(String timeMinutes) {
35 | this.timeMinutes = timeMinutes;
36 | }
37 |
38 | public String getTimeHours() {
39 | return timeHours;
40 | }
41 |
42 | public void setTimeHours(String timeHours) {
43 | this.timeHours = timeHours;
44 | }
45 |
46 | public String getTimeDays() {
47 | return timeDays;
48 | }
49 |
50 | public void setTimeDays(String timeDays) {
51 | this.timeDays = timeDays;
52 | }
53 |
54 | public String getPrefix() {
55 | return prefix;
56 | }
57 |
58 | public void setPrefix(String prefix) {
59 | this.prefix = prefix;
60 | }
61 |
62 | public String getPlaceholderAPICooldownReady() {
63 | return placeholderAPICooldownReady;
64 | }
65 |
66 | public void setPlaceholderAPICooldownReady(String placeholderAPICooldownReady) {
67 | this.placeholderAPICooldownReady = placeholderAPICooldownReady;
68 | }
69 |
70 | public String getPlaceholderAPICooldownNameError() {
71 | return placeholderAPICooldownNameError;
72 | }
73 |
74 | public void setPlaceholderAPICooldownNameError(String placeholderAPICooldownNameError) {
75 | this.placeholderAPICooldownNameError = placeholderAPICooldownNameError;
76 | }
77 |
78 | public void sendMessage(CommandSender sender, String message, boolean prefix){
79 | if(!message.isEmpty()){
80 | if(prefix){
81 | sender.sendMessage(getColoredMessage(this.prefix+message));
82 | }else{
83 | sender.sendMessage(getColoredMessage(message));
84 | }
85 | }
86 | }
87 |
88 | public static String getColoredMessage(String message) {
89 | if(OtherUtils.isNew()) {
90 | Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}");
91 | Matcher match = pattern.matcher(message);
92 |
93 | while(match.find()) {
94 | String color = message.substring(match.start(),match.end());
95 | message = message.replace(color, ChatColor.of(color)+"");
96 |
97 | match = pattern.matcher(message);
98 | }
99 | }
100 |
101 | message = ChatColor.translateAlternateColorCodes('&', message);
102 | return message;
103 | }
104 |
105 | public static String getCenteredMessage(String message){
106 | int CENTER_PX = 154;
107 | int messagePxSize = 0;
108 | boolean previousCode = false;
109 | boolean isBold = false;
110 |
111 | for(char c : message.toCharArray()){
112 | if(c == '§'){
113 | previousCode = true;
114 | continue;
115 | }else if(previousCode == true){
116 | previousCode = false;
117 | if(c == 'l' || c == 'L'){
118 | isBold = true;
119 | continue;
120 | }else isBold = false;
121 | }else{
122 | DefaultFontInfo dFI = DefaultFontInfo.getDefaultFontInfo(c);
123 | messagePxSize += isBold ? dFI.getBoldLength() : dFI.getLength();
124 | messagePxSize++;
125 | }
126 | }
127 |
128 | int halvedMessageSize = messagePxSize / 2;
129 | int toCompensate = CENTER_PX - halvedMessageSize;
130 | int spaceLength = DefaultFontInfo.SPACE.getLength() + 1;
131 | int compensated = 0;
132 | StringBuilder sb = new StringBuilder();
133 | while(compensated < toCompensate){
134 | sb.append(" ");
135 | compensated += spaceLength;
136 | }
137 | return (sb.toString() + message);
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/managers/PlayerManager.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.managers;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import ce.ajneb97.model.player.PlayerData;
5 | import org.bukkit.entity.Player;
6 |
7 | import java.util.ArrayList;
8 |
9 | public class PlayerManager {
10 |
11 | private ConditionalEvents plugin;
12 | private ArrayList playerData;
13 | public PlayerManager(ConditionalEvents plugin){
14 | this.plugin = plugin;
15 | this.playerData = new ArrayList();
16 | }
17 |
18 | public ArrayList getPlayerData() {
19 | return playerData;
20 | }
21 |
22 | public void setPlayerData(ArrayList playerData) {
23 | this.playerData = playerData;
24 | }
25 |
26 | public PlayerData getPlayerData(Player player){
27 | for(PlayerData p : playerData){
28 | if(p.getUuid().equals(player.getUniqueId().toString())){
29 | return p;
30 | }
31 | }
32 | return null;
33 | }
34 |
35 | public PlayerData getPlayerDataByName(String playerName){
36 | for(PlayerData p : playerData){
37 | if(p.getName().equals(playerName)){
38 | return p;
39 | }
40 | }
41 | return null;
42 | }
43 |
44 | private PlayerData createPlayerData(Player player){
45 | PlayerData p = getPlayerData(player);
46 | if(p == null){
47 | p = new PlayerData(player.getUniqueId().toString(),player.getName());
48 | p.setModified(true);
49 | playerData.add(p);
50 | }
51 | return p;
52 | }
53 |
54 | public void setEventCooldown(String eventName,Player player){
55 | PlayerData p = createPlayerData(player);
56 | p.setCooldown(eventName,System.currentTimeMillis());
57 | p.setModified(true);
58 | }
59 |
60 | public long getEventCooldown(String eventName,Player player){
61 | PlayerData p = getPlayerData(player);
62 | if(p == null){
63 | return 0;
64 | }else{
65 | return p.getCooldown(eventName);
66 | }
67 | }
68 |
69 | public void setEventOneTime(String eventName,Player player){
70 | PlayerData p = createPlayerData(player);
71 | p.setOneTime(eventName,true);
72 | p.setModified(true);
73 | }
74 |
75 | public boolean getEventOneTime(String eventName,Player player){
76 | PlayerData p = getPlayerData(player);
77 | if(p == null){
78 | return false;
79 | }else{
80 | return p.isEventOneTime(eventName);
81 | }
82 | }
83 |
84 | public void resetEventDataForPlayers(String eventName){
85 | for(PlayerData p : playerData){
86 | p.resetCooldown(eventName);
87 | p.setOneTime(eventName,false);
88 | p.setModified(true);
89 | }
90 | }
91 |
92 | public void resetAllDataForPlayers(){
93 | for(PlayerData p : playerData){
94 | p.resetAll();
95 | p.setModified(true);
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/managers/RepetitiveManager.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.managers;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import ce.ajneb97.model.CEEvent;
5 | import ce.ajneb97.model.EventType;
6 | import ce.ajneb97.model.internal.ConditionEvent;
7 | import org.bukkit.Bukkit;
8 | import org.bukkit.entity.Player;
9 | import org.bukkit.scheduler.BukkitRunnable;
10 |
11 | public class RepetitiveManager {
12 |
13 | private ConditionalEvents plugin;
14 | private CEEvent ceEvent;
15 | private long ticks;
16 | private boolean mustEnd;
17 | private boolean started;
18 |
19 | public RepetitiveManager(ConditionalEvents plugin,CEEvent ceEvent,long ticks){
20 | this.plugin = plugin;
21 | this.ceEvent = ceEvent;
22 | this.ticks = ticks;
23 | }
24 |
25 | public boolean isStarted() {
26 | return started;
27 | }
28 |
29 | public void end() {
30 | this.mustEnd = true;
31 | this.started = false;
32 | }
33 |
34 | public void start(){
35 | this.mustEnd = false;
36 | this.started = true;
37 | new BukkitRunnable(){
38 | @Override
39 | public void run() {
40 | if(mustEnd || !execute()){
41 | this.cancel();
42 | }
43 | }
44 | }.runTaskTimerAsynchronously(plugin, 0L, ticks);
45 | }
46 |
47 | public boolean execute(){
48 | if(ceEvent == null){
49 | return false;
50 | }
51 |
52 | EventsManager eventsManager = plugin.getEventsManager();
53 | if(ceEvent.getEventType().equals(EventType.REPETITIVE)){
54 | for(Player player : Bukkit.getOnlinePlayers()){
55 | ConditionEvent conditionEvent = new ConditionEvent(plugin, player, null, EventType.REPETITIVE, null);
56 | conditionEvent.setAsync(true);
57 | eventsManager.checkSingularEvent(conditionEvent,ceEvent);
58 | }
59 | }else{
60 | //Repetitive server
61 | ConditionEvent conditionEvent = new ConditionEvent(plugin, null, null, EventType.REPETITIVE_SERVER, null);
62 | conditionEvent.setAsync(true);
63 | eventsManager.checkSingularEvent(conditionEvent,ceEvent);
64 | }
65 | return true;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/managers/SavedItemsManager.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.managers;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import ce.ajneb97.utils.OtherUtils;
5 | import org.bukkit.entity.Player;
6 | import org.bukkit.inventory.ItemStack;
7 | import org.bukkit.inventory.meta.ItemMeta;
8 |
9 | import java.util.HashMap;
10 | import java.util.List;
11 | import java.util.Map;
12 |
13 | public class SavedItemsManager {
14 | private ConditionalEvents plugin;
15 | private Map savedItems;
16 | public SavedItemsManager(ConditionalEvents plugin){
17 | this.plugin = plugin;
18 | this.savedItems = new HashMap<>();
19 | }
20 |
21 | public Map getSavedItems() {
22 | return savedItems;
23 | }
24 |
25 | public void setSavedItems(Map savedItems) {
26 | this.savedItems = savedItems;
27 | }
28 |
29 | public ItemStack getItem(String name, Player player){
30 | if(!savedItems.containsKey(name)){
31 | return null;
32 | }
33 |
34 | ItemStack item = savedItems.get(name).clone();
35 | if(player == null){
36 | return item;
37 | }
38 |
39 | // Placeholders
40 | ItemMeta meta = item.getItemMeta();
41 | if(meta.hasDisplayName()){
42 | String displayName = OtherUtils.replaceGlobalVariables(meta.getDisplayName(),player,plugin);
43 | meta.setDisplayName(displayName);
44 | }
45 | if(meta.hasLore()){
46 | List lore = meta.getLore();
47 | lore.replaceAll(text -> OtherUtils.replaceGlobalVariables(text, player, plugin));
48 | meta.setLore(lore);
49 | }
50 | item.setItemMeta(meta);
51 |
52 | return item;
53 | }
54 |
55 | public void addItem(String name,ItemStack item){
56 | savedItems.put(name,item);
57 | plugin.getConfigsManager().getSavedItemsConfigManager().saveItem(name,item);
58 | }
59 |
60 | public void removeItem(String name){
61 | savedItems.remove(name);
62 | plugin.getConfigsManager().getSavedItemsConfigManager().removeItem(name);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/managers/UpdateCheckerManager.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.managers;
2 |
3 | import ce.ajneb97.model.internal.UpdateCheckerResult;
4 |
5 | import java.io.BufferedReader;
6 | import java.io.InputStreamReader;
7 | import java.net.HttpURLConnection;
8 | import java.net.URL;
9 |
10 | public class UpdateCheckerManager {
11 |
12 | private String version;
13 | private String latestVersion;
14 |
15 | public UpdateCheckerManager(String version){
16 | this.version = version;
17 | }
18 |
19 | public UpdateCheckerResult check(){
20 | try {
21 | HttpURLConnection con = (HttpURLConnection) new URL(
22 | "https://api.spigotmc.org/legacy/update.php?resource=82271").openConnection();
23 | int timed_out = 1500;
24 | con.setConnectTimeout(timed_out);
25 | con.setReadTimeout(timed_out);
26 | latestVersion = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
27 | if (latestVersion.length() <= 7) {
28 | if(!version.equals(latestVersion)){
29 | return UpdateCheckerResult.noErrors(latestVersion);
30 | }
31 | }
32 | return UpdateCheckerResult.noErrors(null);
33 | } catch (Exception ex) {
34 | return UpdateCheckerResult.error();
35 | }
36 | }
37 |
38 | public String getLatestVersion() {
39 | return latestVersion;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/managers/VerifyManager.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.managers;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import ce.ajneb97.configs.CEConfig;
5 | import ce.ajneb97.model.CEEvent;
6 | import ce.ajneb97.model.ConditionalType;
7 | import ce.ajneb97.model.EventType;
8 | import ce.ajneb97.model.actions.ActionGroup;
9 | import ce.ajneb97.model.actions.ActionTargeter;
10 | import ce.ajneb97.model.actions.ActionType;
11 | import ce.ajneb97.model.actions.CEAction;
12 | import ce.ajneb97.model.internal.SeparatorType;
13 | import ce.ajneb97.model.verify.*;
14 | import org.bukkit.configuration.file.FileConfiguration;
15 | import org.bukkit.entity.Player;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | public class VerifyManager {
21 | private ConditionalEvents plugin;
22 | private ArrayList errors;
23 | public VerifyManager(ConditionalEvents plugin) {
24 | this.plugin = plugin;
25 | this.errors = new ArrayList();
26 | }
27 |
28 | public void sendVerification(Player player) {
29 | player.sendMessage(MessagesManager.getColoredMessage("&f&l- - - - - - - - &b&lEVENTS VERIFY &f&l- - - - - - - -"));
30 | player.sendMessage(MessagesManager.getColoredMessage(""));
31 | if(errors.isEmpty()) {
32 | player.sendMessage(MessagesManager.getColoredMessage("&aThere are no errors in your events ;)"));
33 | }else {
34 | player.sendMessage(MessagesManager.getColoredMessage("&e&oHover on the errors to see more information."));
35 | for(CEError error : errors) {
36 | error.sendMessage(player);
37 | }
38 | }
39 | player.sendMessage(MessagesManager.getColoredMessage(""));
40 | player.sendMessage(MessagesManager.getColoredMessage("&f&l- - - - - - - - &b&lEVENTS VERIFY &f&l- - - - - - - -"));
41 | }
42 |
43 | public void verifyEvents() {
44 | this.errors = new ArrayList();
45 | ArrayList events = plugin.getEventsManager().getEvents();
46 |
47 | //Loaded events
48 | for(CEEvent event : events) {
49 | verifyEvent(event);
50 | }
51 |
52 | //Unloaded events
53 | ArrayList ceConfigs = plugin.getConfigsManager().getEventConfigs();
54 | for(CEConfig ceConfig : ceConfigs){
55 | FileConfiguration config = ceConfig.getConfig();
56 | if(!config.contains("Events")){
57 | return;
58 | }
59 | for (String key : config.getConfigurationSection("Events").getKeys(false)) {
60 | String eventType = config.getString("Events."+key+".type");
61 | try{
62 | EventType.valueOf(eventType.toUpperCase());
63 | }catch(Exception e){
64 | errors.add(new CEErrorEventType(key, eventType));
65 | }
66 |
67 | String pathActions = "Events."+key+".actions";
68 | if(!config.contains(pathActions)) {
69 | continue;
70 | }
71 | for (String groupName : config.getConfigurationSection(pathActions).getKeys(false)) {
72 | String path = pathActions+"."+groupName;
73 | List actionsList = config.getStringList(path);
74 | for(int i=0;i conditions = event.getConditions();
125 | for(int i=0;i actionGroups = event.getActionGroups();
135 | for(ActionGroup actionGroup : actionGroups){
136 | List actions = actionGroup.getActions();
137 | for(CEAction action : actions){
138 | if(!verifyRandomVariable(action.getActionLine())){
139 | errors.add(new CEErrorRandomVariable(event.getName(), action.getActionLine()));
140 | }
141 | }
142 | }
143 |
144 | }
145 |
146 | private boolean verifyRandomVariable(String line){
147 | for(int c=0;c commands = config.getStringList("Config.register_commands");
38 | for(String commandName : commands){
39 | registerCommand(commandName);
40 | }
41 | }
42 | }
43 |
44 | public void registerCommand(String commandName) {
45 | CECommand ceCommand = new CECommand(commandName);
46 | CommandMap commandMap = getCommandMap();
47 | commandMap.register("ConditionalEvents",ceCommand);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/managers/dependencies/DiscordSRVManager.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.managers.dependencies;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import github.scarsz.discordsrv.DiscordSRV;
5 | import github.scarsz.discordsrv.dependencies.jda.api.EmbedBuilder;
6 | import github.scarsz.discordsrv.dependencies.jda.api.entities.MessageChannel;
7 | import org.bukkit.Bukkit;
8 | import java.awt.Color;
9 | import org.bukkit.entity.Player;
10 |
11 | public class DiscordSRVManager {
12 |
13 | private ConditionalEvents plugin;
14 | public DiscordSRVManager(ConditionalEvents plugin){
15 | this.plugin = plugin;
16 | }
17 |
18 | public void sendEmbedMessage(String actionLine){
19 | // discordsrv_embed: channel:;author_name:;title:;player_skin_name:;
20 | //color:,,;image:
21 | EmbedBuilder embed = new EmbedBuilder();
22 |
23 | String channel = null;
24 | String authorName = null;
25 | String authorAvatarURL = DiscordSRV.getPlugin().getJda().getSelfUser().getAvatarUrl();
26 | String title = null;
27 | String footer = null;
28 | String description = null;
29 | String imageUrl = null;
30 | String thumbnailUrl = null;
31 | int colorR = 0;
32 | int colorG = 0;
33 | int colorB = 0;
34 |
35 | String[] sep = actionLine.split(";");
36 | for(String s : sep) {
37 | String key = s.split(":")[0];
38 | String value = s.replace(key+":","");
39 |
40 | switch(key){
41 | case "channel":
42 | channel = value;
43 | break;
44 | case "author_name":
45 | authorName = value;
46 | break;
47 | case "title":
48 | title = value;
49 | break;
50 | case "footer":
51 | footer = value;
52 | break;
53 | case "author_avatar":
54 | if(value.startsWith("http:/") || value.startsWith("https:/")){
55 | authorAvatarURL = value;
56 | }else{
57 | Player player = Bukkit.getPlayer(value);
58 | if(player != null){
59 | authorAvatarURL = DiscordSRV.getAvatarUrl(player);
60 | }
61 | }
62 | break;
63 | case "color":
64 | try{
65 | String[] color = value.split(",");
66 | colorR = Integer.parseInt(color[0]);
67 | colorG = Integer.parseInt(color[1]);
68 | colorB = Integer.parseInt(color[2]);
69 | }catch(Exception e){
70 | colorR = 0;
71 | colorG = 0;
72 | colorB = 0;
73 | }
74 | break;
75 | case "description":
76 | description = value;
77 | break;
78 | case "image":
79 | imageUrl = value;
80 | break;
81 | case "thumbnail":
82 | thumbnailUrl = value;
83 | break;
84 | }
85 | }
86 |
87 | embed.setAuthor(authorName,null,authorAvatarURL);
88 | embed.setTitle(title);
89 | embed.setFooter(footer);
90 | embed.setColor(new Color(colorR, colorG, colorB));
91 | embed.setDescription(description);
92 | embed.setImage(imageUrl);
93 | embed.setThumbnail(thumbnailUrl);
94 |
95 | MessageChannel messageChannel = DiscordSRV.getPlugin().getDestinationTextChannelForGameChannelName(channel);
96 | messageChannel.sendMessageEmbeds(embed.build()).queue();
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/managers/dependencies/ProtocolLibManager.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.managers.dependencies;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import ce.ajneb97.model.CEEvent;
5 | import ce.ajneb97.model.EventType;
6 | import ce.ajneb97.model.StoredVariable;
7 | import ce.ajneb97.model.internal.ConditionEvent;
8 | import ce.ajneb97.utils.OtherUtils;
9 | import com.comphenix.protocol.PacketType;
10 | import com.comphenix.protocol.ProtocolLibrary;
11 | import com.comphenix.protocol.events.ListenerPriority;
12 | import com.comphenix.protocol.events.PacketAdapter;
13 | import com.comphenix.protocol.events.PacketContainer;
14 | import com.comphenix.protocol.events.PacketEvent;
15 | import com.comphenix.protocol.wrappers.*;
16 | import net.kyori.adventure.text.Component;
17 | import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
18 | import net.md_5.bungee.api.chat.BaseComponent;
19 | import net.md_5.bungee.chat.ComponentSerializer;
20 | import org.bukkit.Bukkit;
21 | import org.bukkit.ChatColor;
22 | import org.bukkit.entity.Player;
23 |
24 | import java.util.ArrayList;
25 |
26 | public class ProtocolLibManager {
27 |
28 | private ConditionalEvents plugin;
29 | public ProtocolLibManager(ConditionalEvents plugin){
30 | this.plugin = plugin;
31 | configure();
32 | }
33 |
34 | public void configure(){
35 | ProtocolLibrary.getProtocolManager().addPacketListener(getChatAdapter(PacketType.Play.Server.CHAT));
36 | if(OtherUtils.isChatNew()) {
37 | ProtocolLibrary.getProtocolManager().addPacketListener(getChatAdapter(PacketType.Play.Server.SYSTEM_CHAT));
38 | ProtocolLibrary.getProtocolManager().addPacketListener(getChatAdapter(PacketType.Play.Server.DISGUISED_CHAT));
39 | }
40 | }
41 |
42 | public PacketAdapter getChatAdapter(PacketType type) {
43 | return new PacketAdapter(plugin, ListenerPriority.HIGHEST, type) {
44 | @Override
45 | public void onPacketSending(PacketEvent event) {
46 | ConditionalEvents pluginInstance = (ConditionalEvents) plugin;
47 | boolean isPaper = pluginInstance.getDependencyManager().isPaper();
48 |
49 | //Check if config has a protocollib event
50 | ArrayList validEvents = pluginInstance.getEventsManager().getValidEvents(EventType.PROTOCOLLIB_RECEIVE_MESSAGE);
51 | if(validEvents.size() == 0){
52 | return;
53 | }
54 |
55 | PacketContainer packet = event.getPacket();
56 | Player player = event.getPlayer();
57 | for(EnumWrappers.ChatType type : packet.getChatTypes().getValues()) {
58 | if(type.equals(EnumWrappers.ChatType.GAME_INFO)) {
59 | return;
60 | }
61 | }
62 |
63 | if(isPaper && OtherUtils.isChatNew()){
64 | for(boolean b : packet.getBooleans().getValues()){
65 | if(b){
66 | return;
67 | }
68 | }
69 | }
70 |
71 | for(Object object : packet.getModifier().getValues()) {
72 | if(object == null) {
73 | continue;
74 | }
75 |
76 | String jsonMessage = null;
77 | String normalMessage = null;
78 |
79 | if(object instanceof String) {
80 | jsonMessage = (String) object;
81 | normalMessage = OtherUtils.fromJsonMessageToNormalMessage(jsonMessage);
82 | }else if(object instanceof BaseComponent[]) {
83 | BaseComponent[] baseComponents = (BaseComponent[]) object;
84 | normalMessage = BaseComponent.toLegacyText(baseComponents);
85 | jsonMessage = ComponentSerializer.toString(baseComponents);
86 | }
87 |
88 | if(isPaper && OtherUtils.isChatNew()){
89 | if(object instanceof Component){
90 | WrappedChatComponent wrappedChatComponent = AdventureComponentConverter
91 | .fromComponent((Component)object);
92 | jsonMessage = wrappedChatComponent.getJson();
93 | normalMessage = OtherUtils.fromJsonMessageToNormalMessage(jsonMessage);
94 | }
95 | }
96 |
97 | if(jsonMessage != null && normalMessage != null) {
98 | executeEvent(player,jsonMessage,normalMessage,event);
99 | return;
100 | }
101 | }
102 |
103 | for(WrappedChatComponent wrappedChatComponent : packet.getChatComponents().getValues()) {
104 | if(wrappedChatComponent != null) {
105 | String jsonMessage = wrappedChatComponent.getJson();
106 | String normalMessage = null;
107 | if(isPaper && OtherUtils.isChatNew()){
108 | normalMessage = LegacyComponentSerializer.legacyAmpersand().serialize(AdventureComponentConverter.fromWrapper(wrappedChatComponent));
109 | }else{
110 | normalMessage = OtherUtils.fromJsonMessageToNormalMessage(jsonMessage);
111 | }
112 |
113 | if(jsonMessage != null && normalMessage != null){
114 | executeEvent(player,jsonMessage,normalMessage,event);
115 | }
116 | return;
117 | }
118 | }
119 | }
120 | };
121 | }
122 |
123 | public void executeEvent(Player player,String jsonMessage,String normalMessage,PacketEvent event){
124 | ProtocolLibReceiveMessageEvent messageEvent = new ProtocolLibReceiveMessageEvent(player,jsonMessage,normalMessage);
125 | ConditionEvent conditionEvent = new ConditionEvent(plugin, player, messageEvent, EventType.PROTOCOLLIB_RECEIVE_MESSAGE, null);
126 | conditionEvent.addVariables(
127 | new StoredVariable("%json_message%",jsonMessage),
128 | new StoredVariable("%normal_message%",normalMessage.replace("§", "&")),
129 | new StoredVariable("%normal_message_without_color_codes%",ChatColor.stripColor(normalMessage))
130 | ).checkEvent();
131 |
132 | if(messageEvent.isCancelled()){
133 | event.setCancelled(true);
134 | }
135 | }
136 |
137 | }
138 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/managers/dependencies/ProtocolLibReceiveMessageEvent.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.managers.dependencies;
2 |
3 | import org.bukkit.entity.Player;
4 | import org.bukkit.event.Cancellable;
5 | import org.bukkit.event.Event;
6 | import org.bukkit.event.HandlerList;
7 |
8 |
9 | public class ProtocolLibReceiveMessageEvent extends Event implements Cancellable {
10 |
11 | private Player player;
12 | private String jsonMessage;
13 | private String normalMessage;
14 | private boolean cancelled;
15 | private static final HandlerList handlers = new HandlerList();
16 |
17 |
18 | public ProtocolLibReceiveMessageEvent(Player player, String jsonMessage, String normalMessage){
19 | this.player = player;
20 | this.jsonMessage = jsonMessage;
21 | this.normalMessage = normalMessage;
22 | this.cancelled = false;
23 | }
24 |
25 | public Player getPlayer() {
26 | return player;
27 | }
28 |
29 | public String getJsonMessage() {
30 | return jsonMessage;
31 | }
32 |
33 | public String getNormalMessage() {
34 | return normalMessage;
35 | }
36 |
37 | @Override
38 | public HandlerList getHandlers() {
39 | // TODO Auto-generated method stub
40 | return handlers;
41 | }
42 |
43 | public static HandlerList getHandlerList() {
44 | return handlers;
45 | }
46 |
47 | @Override
48 | public boolean isCancelled() {
49 | return cancelled;
50 | }
51 |
52 | @Override
53 | public void setCancelled(boolean cancelled) {
54 | this.cancelled = cancelled;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/CEEvent.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model;
2 |
3 | import ce.ajneb97.managers.RepetitiveManager;
4 | import ce.ajneb97.model.actions.ActionGroup;
5 | import org.bukkit.Bukkit;
6 |
7 | import java.util.List;
8 |
9 | public class CEEvent {
10 |
11 | private String name;
12 | private List conditions;
13 | private EventType eventType;
14 | private List actionGroups;
15 |
16 | private boolean oneTime;
17 |
18 | private String ignoreWithPermission;
19 |
20 | private long cooldown;
21 |
22 | private boolean enabled;
23 | private boolean ignoreIfCancelled;
24 | private boolean allowMathFormulasInConditions;
25 |
26 | private RepetitiveManager repetitiveManager;
27 |
28 | private CustomEventProperties customEventProperties;
29 |
30 | private List preventCooldownActivationActionGroups;
31 | private List preventOneTimeActivationActionGroups;
32 |
33 |
34 |
35 | public CEEvent(String name){
36 | this.name = name;
37 | }
38 |
39 | public String getName() {
40 | return name;
41 | }
42 |
43 | public void setName(String name) {
44 | this.name = name;
45 | }
46 |
47 | public List getConditions() {
48 | return conditions;
49 | }
50 |
51 | public void setConditions(List conditions) {
52 | this.conditions = conditions;
53 | }
54 |
55 | public EventType getEventType() {
56 | return eventType;
57 | }
58 |
59 | public void setEventType(EventType eventType) {
60 | this.eventType = eventType;
61 | }
62 |
63 | public List getActionGroups() {
64 | return actionGroups;
65 | }
66 |
67 | public void setActionGroups(List actionGroups) {
68 | this.actionGroups = actionGroups;
69 | }
70 |
71 | public boolean isOneTime() {
72 | return oneTime;
73 | }
74 |
75 | public void setOneTime(boolean oneTime) {
76 | this.oneTime = oneTime;
77 | }
78 |
79 | public String getIgnoreWithPermission() {
80 | return ignoreWithPermission;
81 | }
82 |
83 | public void setIgnoreWithPermission(String ignoreWithPermission) {
84 | this.ignoreWithPermission = ignoreWithPermission;
85 | }
86 |
87 | public long getCooldown() {
88 | return cooldown;
89 | }
90 |
91 | public void setCooldown(long cooldown) {
92 | this.cooldown = cooldown;
93 | }
94 |
95 | public boolean isEnabled() {
96 | return enabled;
97 | }
98 |
99 | public void setEnabled(boolean enabled) {
100 | this.enabled = enabled;
101 | }
102 |
103 | public boolean isIgnoreIfCancelled() {
104 | return ignoreIfCancelled;
105 | }
106 |
107 | public void setIgnoreIfCancelled(boolean ignoreIfCancelled) {
108 | this.ignoreIfCancelled = ignoreIfCancelled;
109 | }
110 |
111 | public List getPreventCooldownActivationActionGroups() {
112 | return preventCooldownActivationActionGroups;
113 | }
114 |
115 | public void setPreventCooldownActivationActionGroups(List preventCooldownActivationActionGroups) {
116 | this.preventCooldownActivationActionGroups = preventCooldownActivationActionGroups;
117 | }
118 |
119 | public List getPreventOneTimeActivationActionGroups() {
120 | return preventOneTimeActivationActionGroups;
121 | }
122 |
123 | public void setPreventOneTimeActivationActionGroups(List preventOneTimeActivationActionGroups) {
124 | this.preventOneTimeActivationActionGroups = preventOneTimeActivationActionGroups;
125 | }
126 |
127 | public boolean isAllowMathFormulasInConditions() {
128 | return allowMathFormulasInConditions;
129 | }
130 |
131 | public void setAllowMathFormulasInConditions(boolean allowMathFormulasInConditions) {
132 | this.allowMathFormulasInConditions = allowMathFormulasInConditions;
133 | }
134 |
135 | public void enable(){
136 | this.enabled = true;
137 | if(repetitiveManager != null && !repetitiveManager.isStarted()){
138 | repetitiveManager.start();
139 | }
140 | }
141 |
142 | public void disable(){
143 | this.enabled = false;
144 | if(repetitiveManager != null){
145 | repetitiveManager.end();
146 | }
147 | }
148 |
149 | public RepetitiveManager getRepetitiveManager() {
150 | return repetitiveManager;
151 | }
152 |
153 | public void setRepetitiveManager(RepetitiveManager repetitiveManager) {
154 | this.repetitiveManager = repetitiveManager;
155 | }
156 |
157 | public CustomEventProperties getCustomEventProperties() {
158 | return customEventProperties;
159 | }
160 |
161 | public void setCustomEventProperties(CustomEventProperties customEventProperties) {
162 | this.customEventProperties = customEventProperties;
163 | }
164 |
165 |
166 |
167 | public ActionGroup getActionGroup(String name){
168 | for(ActionGroup actionGroup : actionGroups){
169 | if(actionGroup.getName().equals(name)){
170 | return actionGroup;
171 | }
172 | }
173 | return null;
174 | }
175 | }
176 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/ConditionalType.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model;
2 |
3 | public enum ConditionalType {
4 | EQUALS("=="),
5 | NOT_EQUALS("!="),
6 | EQUALS_LEGACY("equals"),
7 | NOT_EQUALS_LEGACY("!equals"),
8 | EQUALS_IGNORE_CASE("equalsIgnoreCase"),
9 | NOT_EQUALS_IGNORE_CASE("!equalsIgnoreCase"),
10 | STARTS_WITH("startsWith"),
11 | NOT_STARTS_WITH("!startsWith"),
12 | CONTAINS("contains"),
13 | NOT_CONTAINS("!contains"),
14 | ENDS_WITH("endsWith"),
15 | NOT_ENDS_WITH("!endsWith"),
16 | MATCHES("matches"),
17 | NOT_MATCHES("!matches"),
18 | GREATER(">"),
19 | GREATER_EQUALS(">="),
20 | LOWER("<"),
21 | LOWER_EQUALS("<=");
22 |
23 | private String text;
24 | ConditionalType(String text) {
25 | this.text = text;
26 | }
27 |
28 | public String getText() {
29 | return text;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/CustomEventProperties.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model;
2 |
3 | import java.util.List;
4 |
5 | public class CustomEventProperties {
6 |
7 | private String eventPackage;
8 | private String playerVariable;
9 | private List variablesToCapture;
10 |
11 | public CustomEventProperties(String eventPackage, String playerVariable, List variablesToCapture) {
12 | this.eventPackage = eventPackage;
13 | this.playerVariable = playerVariable;
14 | this.variablesToCapture = variablesToCapture;
15 | }
16 |
17 | public String getEventPackage() {
18 | return eventPackage;
19 | }
20 |
21 | public void setEventPackage(String eventPackage) {
22 | this.eventPackage = eventPackage;
23 | }
24 |
25 | public String getPlayerVariable() {
26 | return playerVariable;
27 | }
28 |
29 | public void setPlayerVariable(String playerVariable) {
30 | this.playerVariable = playerVariable;
31 | }
32 |
33 | public List getVariablesToCapture() {
34 | return variablesToCapture;
35 | }
36 |
37 | public void setVariablesToCapture(List variablesToCapture) {
38 | this.variablesToCapture = variablesToCapture;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/EventType.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model;
2 |
3 | public enum EventType {
4 | PLAYER_RESPAWN,
5 | PLAYER_DEATH,
6 | PLAYER_ATTACK,
7 | PLAYER_KILL,
8 | PLAYER_DAMAGE,
9 | PLAYER_COMMAND,
10 | PLAYER_CHAT,
11 | PLAYER_PRE_JOIN,
12 | PLAYER_JOIN,
13 | PLAYER_LEAVE,
14 | PLAYER_LEVELUP,
15 | PLAYER_WORLD_CHANGE,
16 | PLAYER_ARMOR,
17 | PLAYER_TELEPORT,
18 | PLAYER_BED_ENTER,
19 | PLAYER_SWAP_HAND,
20 | PLAYER_FISH,
21 | PLAYER_OPEN_INVENTORY,
22 | PLAYER_CLOSE_INVENTORY,
23 | PLAYER_CLICK_INVENTORY,
24 | PLAYER_STATISTIC,
25 | PLAYER_SNEAK,
26 | PLAYER_RUN,
27 | PLAYER_REGAIN_HEALTH,
28 | PLAYER_CHANGE_AIR, //1.10+
29 | PLAYER_CHANGE_FOOD, //1.16+
30 | PLAYER_TAB_COMPLETE,
31 | BLOCK_INTERACT,
32 | BLOCK_BREAK,
33 | BLOCK_PLACE,
34 | ITEM_INTERACT,
35 | ITEM_CONSUME,
36 | ITEM_PICKUP,
37 | ITEM_CRAFT,
38 | ITEM_DROP,
39 | ITEM_MOVE,
40 | ITEM_SELECT,
41 | ITEM_ENCHANT,
42 | ITEM_REPAIR,
43 | REPETITIVE,
44 | REPETITIVE_SERVER,
45 | ENTITY_SPAWN,
46 | ENTITY_INTERACT,
47 | CONSOLE_COMMAND,
48 | SERVER_START,
49 | SERVER_STOP,
50 | CITIZENS_RIGHT_CLICK_NPC,
51 | WGEVENTS_REGION_ENTER,
52 | WGEVENTS_REGION_LEAVE,
53 | PROTOCOLLIB_RECEIVE_MESSAGE,
54 | CUSTOM,
55 | CALL
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/StoredVariable.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model;
2 |
3 | public class StoredVariable {
4 | private String name;
5 | private String value;
6 |
7 | public StoredVariable(String name, String value) {
8 | this.name = name;
9 | this.value = value;
10 | }
11 |
12 | public String getName() {
13 | return name;
14 | }
15 |
16 | public void setName(String name) {
17 | this.name = name;
18 | }
19 |
20 | public String getValue() {
21 | return value;
22 | }
23 |
24 | public void setValue(String value) {
25 | this.value = value;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/ToConditionGroup.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model;
2 |
3 | import java.util.List;
4 |
5 | public class ToConditionGroup {
6 | private String name;
7 | private List conditions;
8 |
9 | public ToConditionGroup(String name, List conditions) {
10 | this.name = name;
11 | this.conditions = conditions;
12 | }
13 |
14 | public String getName() {
15 | return name;
16 | }
17 |
18 | public void setName(String name) {
19 | this.name = name;
20 | }
21 |
22 | public List getConditions() {
23 | return conditions;
24 | }
25 |
26 | public void setConditions(List conditions) {
27 | this.conditions = conditions;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/actions/ActionGroup.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.actions;
2 |
3 | import java.util.List;
4 |
5 | public class ActionGroup {
6 | private String name;
7 | private List actions;
8 |
9 | public ActionGroup(String name, List actions) {
10 | this.name = name;
11 | this.actions = actions;
12 | }
13 |
14 | public String getName() {
15 | return name;
16 | }
17 |
18 | public void setName(String name) {
19 | this.name = name;
20 | }
21 |
22 | public List getActions() {
23 | return actions;
24 | }
25 |
26 | public void setActions(List actions) {
27 | this.actions = actions;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/actions/ActionTargeter.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.actions;
2 |
3 | public class ActionTargeter {
4 | private ActionTargeterType type;
5 | private String parameter;
6 |
7 | public ActionTargeter(ActionTargeterType type) {
8 | this.type = type;
9 | }
10 |
11 | public ActionTargeterType getType() {
12 | return type;
13 | }
14 |
15 | public void setType(ActionTargeterType type) {
16 | this.type = type;
17 | }
18 |
19 | public String getParameter() {
20 | return parameter;
21 | }
22 |
23 | public void setParameter(String parameter) {
24 | this.parameter = parameter;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/actions/ActionTargeterType.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.actions;
2 |
3 | public enum ActionTargeterType {
4 | TO_ALL,
5 | TO_TARGET,
6 | TO_WORLD,
7 | TO_RANGE,
8 | TO_PLAYER,
9 | TO_CONDITION,
10 | NORMAL;
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/actions/ActionType.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.actions;
2 |
3 | public enum ActionType {
4 | MESSAGE,
5 | CENTERED_MESSAGE,
6 | CONSOLE_MESSAGE,
7 | JSON_MESSAGE,
8 | MINI_MESSAGE,
9 | CONSOLE_COMMAND,
10 | PLAYER_COMMAND,
11 | PLAYER_COMMAND_AS_OP,
12 | PLAYER_SEND_CHAT,
13 | SEND_TO_SERVER,
14 | TELEPORT,
15 | REMOVE_ITEM,
16 | REMOVE_ITEM_SLOT,
17 | GIVE_POTION_EFFECT,
18 | REMOVE_POTION_EFFECT,
19 | KICK,
20 | CANCEL_EVENT,
21 | PLAYSOUND,
22 | PLAYSOUND_RESOURCE_PACK,
23 | STOPSOUND,
24 | ACTIONBAR,
25 | TITLE,
26 | FIREWORK,
27 | PARTICLE,
28 | GAMEMODE,
29 | DAMAGE,
30 | CLOSE_INVENTORY,
31 | CLEAR_INVENTORY,
32 | SET_ON_FIRE,
33 | FREEZE,
34 | HEAL,
35 | SET_FOOD_LEVEL,
36 | GIVE_ITEM,
37 | DROP_ITEM,
38 | SET_ITEM,
39 | SET_BLOCK,
40 | SUMMON,
41 | VECTOR,
42 | LIGHTNING_STRIKE,
43 | WAIT,
44 | WAIT_TICKS,
45 | KEEP_ITEMS,
46 | CANCEL_DROP,
47 | SET_DAMAGE,
48 | HIDE_JOIN_MESSAGE,
49 | HIDE_LEAVE_MESSAGE,
50 | SET_DEATH_MESSAGE,
51 | PREVENT_JOIN,
52 | SET_EVENT_XP,
53 | DISCORDSRV_EMBED,
54 | CALL_EVENT,
55 | EXECUTE_ACTION_GROUP,
56 | TAB_COMPLETE,
57 | API
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/actions/CEAction.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.actions;
2 |
3 | public class CEAction {
4 |
5 | private ActionType type;
6 | private String apiType; //Just for API events.
7 | private ActionTargeter targeter;
8 | private String actionLine;
9 |
10 | public CEAction(ActionType type, String actionLine, ActionTargeter targeter) {
11 | this.type = type;
12 | this.actionLine = actionLine;
13 | this.targeter = targeter;
14 | }
15 |
16 | public ActionType getType() {
17 | return type;
18 | }
19 |
20 | public void setType(ActionType type) {
21 | this.type = type;
22 | }
23 |
24 | public String getActionLine() {
25 | return actionLine;
26 | }
27 |
28 | public void setActionLine(String actionLine) {
29 | this.actionLine = actionLine;
30 | }
31 |
32 | public ActionTargeter getTargeter() {
33 | return targeter;
34 | }
35 |
36 | public void setTargeter(ActionTargeter targeter) {
37 | this.targeter = targeter;
38 | }
39 |
40 | public String getApiType() {
41 | return apiType;
42 | }
43 |
44 | public void setApiType(String apiType) {
45 | this.apiType = apiType;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/internal/CheckConditionsResult.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.internal;
2 |
3 | public class CheckConditionsResult {
4 |
5 | private boolean conditionsAccomplished;
6 | private String executeActionGroup;
7 |
8 | public CheckConditionsResult(boolean conditionsAccomplished, String executeActionGroup) {
9 | this.conditionsAccomplished = conditionsAccomplished;
10 | this.executeActionGroup = executeActionGroup;
11 | }
12 |
13 | public boolean isConditionsAccomplished() {
14 | return conditionsAccomplished;
15 | }
16 |
17 | public String getExecuteActionGroup() {
18 | if(executeActionGroup == null){
19 | return "default";
20 | }else{
21 | return executeActionGroup;
22 | }
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/internal/DebugSender.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.internal;
2 |
3 | import org.bukkit.command.CommandSender;
4 |
5 | public class DebugSender {
6 | private CommandSender sender;
7 | private String event;
8 | private String playerName;
9 |
10 | public DebugSender(CommandSender sender, String event, String playerName) {
11 | this.sender = sender;
12 | this.event = event;
13 | this.playerName = playerName;
14 | }
15 |
16 | public CommandSender getSender() {
17 | return sender;
18 | }
19 |
20 | public void setSender(CommandSender sender) {
21 | this.sender = sender;
22 | }
23 |
24 | public String getEvent() {
25 | return event;
26 | }
27 |
28 | public void setEvent(String event) {
29 | this.event = event;
30 | }
31 |
32 | public String getPlayerName() {
33 | return playerName;
34 | }
35 |
36 | public void setPlayerName(String playerName) {
37 | this.playerName = playerName;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/internal/PostEventVariableResult.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.internal;
2 |
3 | public class PostEventVariableResult {
4 | private String variable;
5 | private boolean replaced;
6 |
7 | public PostEventVariableResult(String variable, boolean replaced) {
8 | this.variable = variable;
9 | this.replaced = replaced;
10 | }
11 |
12 | public String getVariable() {
13 | return variable;
14 | }
15 |
16 | public void setVariable(String variable) {
17 | this.variable = variable;
18 | }
19 |
20 | public boolean isReplaced() {
21 | return replaced;
22 | }
23 |
24 | public void setReplaced(boolean replaced) {
25 | this.replaced = replaced;
26 | }
27 |
28 | public static PostEventVariableResult replaced(String variable){
29 | return new PostEventVariableResult(variable,true);
30 | }
31 |
32 | public static PostEventVariableResult noReplaced(){
33 | return new PostEventVariableResult(null,false);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/internal/SeparatorType.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.internal;
2 |
3 | public enum SeparatorType {
4 | AND,
5 | OR,
6 | NONE
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/internal/UpdateCheckerResult.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.internal;
2 |
3 | public class UpdateCheckerResult {
4 |
5 | private String latestVersion;
6 | private boolean error;
7 |
8 | public UpdateCheckerResult(String latestVersion, boolean error){
9 | this.latestVersion = latestVersion;
10 | this.error = error;
11 | }
12 |
13 | public String getLatestVersion() {
14 | return latestVersion;
15 | }
16 |
17 | public boolean isError() {
18 | return error;
19 | }
20 |
21 | public static UpdateCheckerResult noErrors(String latestVersion){
22 | return new UpdateCheckerResult(latestVersion,false);
23 | }
24 |
25 | public static UpdateCheckerResult error(){
26 | return new UpdateCheckerResult(null,true);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/internal/VariablesProperties.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.internal;
2 |
3 | import ce.ajneb97.model.CEEvent;
4 | import ce.ajneb97.model.StoredVariable;
5 | import org.bukkit.entity.Player;
6 | import org.bukkit.event.Event;
7 |
8 | import java.util.ArrayList;
9 |
10 | public class VariablesProperties {
11 |
12 | private ArrayList eventVariables;
13 | private Player player;
14 | private Player target;
15 | private Player toTarget;
16 | private boolean isPlaceholderAPI;
17 | private CEEvent event;
18 | private Event minecraftEvent;
19 |
20 | public VariablesProperties(ArrayList eventVariables, Player player, Player target, boolean isPlaceholderAPI, CEEvent event, Event minecraftEvent) {
21 | this.eventVariables = eventVariables;
22 | this.player = player;
23 | this.target = target;
24 | this.isPlaceholderAPI = isPlaceholderAPI;
25 | this.event = event;
26 | this.minecraftEvent = minecraftEvent;
27 | }
28 |
29 |
30 | public ArrayList getEventVariables() {
31 | return eventVariables;
32 | }
33 |
34 | public void setEventVariables(ArrayList eventVariables) {
35 | this.eventVariables = eventVariables;
36 | }
37 |
38 | public Player getPlayer() {
39 | return player;
40 | }
41 |
42 | public void setPlayer(Player player) {
43 | this.player = player;
44 | }
45 |
46 | public Player getTarget() {
47 | return target;
48 | }
49 |
50 | public void setTarget(Player target) {
51 | this.target = target;
52 | }
53 |
54 | public boolean isPlaceholderAPI() {
55 | return isPlaceholderAPI;
56 | }
57 |
58 | public void setPlaceholderAPI(boolean placeholderAPI) {
59 | isPlaceholderAPI = placeholderAPI;
60 | }
61 |
62 | public CEEvent getEvent() {
63 | return event;
64 | }
65 |
66 | public void setEvent(CEEvent event) {
67 | this.event = event;
68 | }
69 |
70 | public Event getMinecraftEvent() {
71 | return minecraftEvent;
72 | }
73 |
74 | public void setMinecraftEvent(Event minecraftEvent) {
75 | this.minecraftEvent = minecraftEvent;
76 | }
77 |
78 | public Player getToTarget() {
79 | return toTarget;
80 | }
81 |
82 | public void setToTarget(Player toTarget) {
83 | this.toTarget = toTarget;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/internal/WaitActionTask.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.internal;
2 |
3 | import org.bukkit.scheduler.BukkitTask;
4 |
5 | public class WaitActionTask {
6 | private String playerName;
7 | private String eventName;
8 | private BukkitTask task;
9 |
10 | public WaitActionTask(String playerName, String eventName, BukkitTask task) {
11 | this.playerName = playerName;
12 | this.eventName = eventName;
13 | this.task = task;
14 | }
15 |
16 | public String getPlayerName() {
17 | return playerName;
18 | }
19 |
20 | public void setPlayerName(String playerName) {
21 | this.playerName = playerName;
22 | }
23 |
24 | public String getEventName() {
25 | return eventName;
26 | }
27 |
28 | public void setEventName(String eventName) {
29 | this.eventName = eventName;
30 | }
31 |
32 | public BukkitTask getTask() {
33 | return task;
34 | }
35 |
36 | public void setTask(BukkitTask task) {
37 | this.task = task;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/player/EventData.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.player;
2 |
3 | public class EventData {
4 | private String name;
5 | private long cooldown; //Represents the millis time when the event was executed
6 | private boolean oneTime;
7 |
8 | public EventData(String name,long cooldown,boolean oneTime) {
9 | this.name = name;
10 | this.cooldown = cooldown;
11 | this.oneTime = oneTime;
12 | }
13 |
14 | public String getName() {
15 | return name;
16 | }
17 |
18 | public void setName(String name) {
19 | this.name = name;
20 | }
21 |
22 | public long getCooldown() {
23 | return cooldown;
24 | }
25 |
26 | public void setCooldown(long cooldown) {
27 | this.cooldown = cooldown;
28 | }
29 |
30 | public boolean isOneTime() {
31 | return oneTime;
32 | }
33 |
34 | public void setOneTime(boolean oneTime) {
35 | this.oneTime = oneTime;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/player/PlayerData.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.player;
2 |
3 | import org.bukkit.Bukkit;
4 |
5 | import java.util.ArrayList;
6 |
7 | public class PlayerData {
8 | private String uuid;
9 | private String name;
10 | private boolean modified;
11 | private ArrayList eventData;
12 |
13 | public PlayerData(String uuid, String name) {
14 | this.uuid = uuid;
15 | this.name = name;
16 | this.eventData = new ArrayList();
17 | this.modified = false;
18 | }
19 |
20 | public String getUuid() {
21 | return uuid;
22 | }
23 |
24 | public void setUuid(String uuid) {
25 | this.uuid = uuid;
26 | }
27 |
28 | public String getName() {
29 | return name;
30 | }
31 |
32 | public void setName(String name) {
33 | this.name = name;
34 | }
35 |
36 | public ArrayList getEventData() {
37 | return eventData;
38 | }
39 |
40 | public void setEventData(ArrayList eventData) {
41 | this.eventData = eventData;
42 | }
43 |
44 | public EventData getEventData(String eventName){
45 | for(EventData e : eventData){
46 | if(e.getName().equals(eventName)){
47 | return e;
48 | }
49 | }
50 | return null;
51 | }
52 |
53 | public void resetAll(){
54 | eventData.clear();
55 | }
56 |
57 | public void resetCooldown(String eventName){
58 | setCooldown(eventName,0);
59 | }
60 |
61 | public void setCooldown(String eventName,long currentMillis){
62 | EventData e = getEventData(eventName);
63 | if(e == null){
64 | e = new EventData(eventName,currentMillis,false);
65 | eventData.add(e);
66 | }else{
67 | e.setCooldown(currentMillis);
68 | }
69 | }
70 |
71 | public long getCooldown(String eventName){
72 | EventData e = getEventData(eventName);
73 | if(e == null){
74 | return 0;
75 | }else{
76 | return e.getCooldown();
77 | }
78 | }
79 |
80 | public void setOneTime(String eventName,boolean oneTime){
81 | EventData e = getEventData(eventName);
82 | if(e == null){
83 | e = new EventData(eventName,0,oneTime);
84 | eventData.add(e);
85 | }else{
86 | e.setOneTime(oneTime);
87 | }
88 | }
89 |
90 | public boolean isEventOneTime(String eventName){
91 | EventData e = getEventData(eventName);
92 | if(e == null){
93 | return false;
94 | }else{
95 | return e.isOneTime();
96 | }
97 | }
98 |
99 | public boolean isModified() {
100 | return modified;
101 | }
102 |
103 | public void setModified(boolean modified) {
104 | this.modified = modified;
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/verify/CEError.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.verify;
2 |
3 | import org.bukkit.entity.Player;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | public abstract class CEError {
9 |
10 | protected String event;
11 | protected String errorText;
12 |
13 | public CEError(String event,String errorText){
14 | this.event = event;
15 | this.errorText = errorText;
16 | }
17 |
18 | public List getFixedErrorText(){
19 | List sepText = new ArrayList();
20 | int currentPos = 0;
21 | for(int i=0;i= 35 && errorText.charAt(i) == ' ') {
23 | String m = errorText.substring(i-currentPos, i);
24 | currentPos = 0;
25 | sepText.add(m);
26 | }else {
27 | currentPos++;
28 | }
29 | if(i==errorText.length()-1) {
30 | String m = errorText.substring(i-currentPos+1, errorText.length());
31 | sepText.add(m);
32 | }
33 | }
34 | return sepText;
35 | }
36 |
37 | public abstract void sendMessage(Player player);
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/verify/CEErrorAction.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.verify;
2 |
3 | import ce.ajneb97.utils.JSONMessage;
4 | import org.bukkit.entity.Player;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | public class CEErrorAction extends CEError{
10 |
11 | private int actionLine;
12 | private String actionGroup;
13 |
14 | public CEErrorAction(String event, String errorText, int actionLine, String actionGroup) {
15 | super(event, errorText);
16 | this.actionLine = actionLine;
17 | this.actionGroup = actionGroup;
18 | }
19 |
20 | @Override
21 | public void sendMessage(Player player) {
22 | String message = "&c⚠ ";
23 | List hover = new ArrayList();
24 |
25 | JSONMessage jsonMessage = new JSONMessage(player,message+"&7Action &6"+actionLine+" &7on Action group &6"
26 | +actionGroup+" &7on Event &6"+event+" &7is not valid.");
27 | hover.add("&eTHIS IS AN ERROR!");
28 | hover.add("&fThe action defined for this event");
29 | hover.add("&fis probably not formatted correctly:");
30 | for(String m : getFixedErrorText()) {
31 | hover.add("&c"+m);
32 | }
33 | hover.add(" ");
34 | hover.add("&fRemember to use a valid actions from this list:");
35 | hover.add("&ahttps://ajneb97.gitbook.io/conditionalevents/actions");
36 | jsonMessage.hover(hover).send();
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/verify/CEErrorCondition.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.verify;
2 |
3 | import ce.ajneb97.utils.JSONMessage;
4 | import org.bukkit.entity.Player;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | public class CEErrorCondition extends CEError{
10 |
11 | private int conditionLine;
12 |
13 | public CEErrorCondition(String event, String errorText,int conditionLine) {
14 | super(event, errorText);
15 | this.conditionLine = conditionLine;
16 | }
17 |
18 | @Override
19 | public void sendMessage(Player player) {
20 | String message = "&e⚠ ";
21 | List hover = new ArrayList();
22 |
23 | JSONMessage jsonMessage = new JSONMessage(player,message+"&7Condition &6"+conditionLine+" &7on Event &6"+event+" &7is not valid.");
24 | hover.add("&eTHIS IS A WARNING!");
25 | hover.add("&fThe condition defined for this event");
26 | hover.add("&fis probably not formatted correctly:");
27 | for(String m : getFixedErrorText()) {
28 | hover.add("&c"+m);
29 | }
30 | hover.add(" ");
31 | hover.add("&fRemember to use a valid condition from this list:");
32 | hover.add("&ahttps://ajneb97.gitbook.io/conditionalevents/conditions");
33 | jsonMessage.hover(hover).send();
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/verify/CEErrorEventType.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.verify;
2 |
3 | import ce.ajneb97.utils.JSONMessage;
4 | import org.bukkit.entity.Player;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | public class CEErrorEventType extends CEError{
10 |
11 |
12 | public CEErrorEventType(String event, String errorText) {
13 | super(event, errorText);
14 | }
15 |
16 | @Override
17 | public void sendMessage(Player player) {
18 | String message = "&c⚠ ";
19 | List hover = new ArrayList();
20 |
21 | JSONMessage jsonMessage = new JSONMessage(player,message+"&7Event &6"+event+" &7has an invalid type.");
22 | hover.add("&eTHIS IS AN ERROR!");
23 | hover.add("&fThe type for this event is invalid, maybe");
24 | hover.add("&fyou misspelled it?:");
25 | for(String m : getFixedErrorText()) {
26 | hover.add("&c"+m);
27 | }
28 | hover.add(" ");
29 | hover.add("&fRemember to use a valid event types from this list:");
30 | hover.add("&ahttps://ajneb97.gitbook.io/conditionalevents/event-types");
31 | jsonMessage.hover(hover).send();
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/model/verify/CEErrorRandomVariable.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.model.verify;
2 |
3 | import ce.ajneb97.utils.JSONMessage;
4 | import org.bukkit.entity.Player;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | public class CEErrorRandomVariable extends CEError{
10 |
11 |
12 | public CEErrorRandomVariable(String event, String errorText) {
13 | super(event, errorText);
14 | }
15 |
16 | @Override
17 | public void sendMessage(Player player) {
18 | String message = "&c⚠ ";
19 | List hover = new ArrayList();
20 |
21 | JSONMessage jsonMessage = new JSONMessage(player,message+"&7Event &6"+event+" &7uses the %random_min_max% variable wrongly!");
22 | hover.add("&eTHIS IS AN ERROR!");
23 | hover.add("&fIt seems you are not using the random number");
24 | hover.add("&fvariable correctly:");
25 | for(String m : getFixedErrorText()) {
26 | hover.add("&c"+m);
27 | }
28 | hover.add(" ");
29 | hover.add("&fThe format of the random variable changed recently.");
30 | hover.add("&fUse the new one instead: &e%random_min_max%");
31 | jsonMessage.hover(hover).send();
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/tasks/PlayerDataSaveTask.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.tasks;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import org.bukkit.scheduler.BukkitRunnable;
5 |
6 | public class PlayerDataSaveTask {
7 |
8 | private ConditionalEvents plugin;
9 | private boolean end;
10 | public PlayerDataSaveTask(ConditionalEvents plugin) {
11 | this.plugin = plugin;
12 | this.end = false;
13 | }
14 |
15 | public void end() {
16 | end = true;
17 | }
18 |
19 | public void start(int minutes) {
20 | long ticks = minutes*60*20;
21 |
22 | new BukkitRunnable() {
23 | @Override
24 | public void run() {
25 | if(end) {
26 | this.cancel();
27 | }else {
28 | execute();
29 | }
30 | }
31 |
32 | }.runTaskTimerAsynchronously(plugin, 0L, ticks);
33 | }
34 |
35 | public void execute() {
36 | plugin.getConfigsManager().getPlayerConfigsManager().savePlayerData();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/utils/BlockUtils.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.utils;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import com.google.gson.Gson;
5 | import com.google.gson.JsonObject;
6 | import com.mojang.authlib.GameProfile;
7 | import com.mojang.authlib.properties.Property;
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.Material;
10 | import org.bukkit.SkullType;
11 | import org.bukkit.block.Block;
12 | import org.bukkit.block.Skull;
13 | import org.bukkit.block.data.BlockData;
14 | import org.bukkit.profile.PlayerProfile;
15 | import org.bukkit.profile.PlayerTextures;
16 |
17 | import java.lang.reflect.Field;
18 | import java.lang.reflect.InvocationTargetException;
19 | import java.net.MalformedURLException;
20 | import java.net.URL;
21 | import java.util.Base64;
22 | import java.util.Collection;
23 | import java.util.UUID;
24 |
25 | public class BlockUtils {
26 |
27 | public static String getHeadTextureData(Block block) {
28 | if(block == null) {
29 | return "";
30 | }
31 |
32 | Material material = block.getType();
33 | if(material.name().equals("PLAYER_HEAD") || material.name().equals("SKULL") || material.name().equals("PLAYER_WALL_HEAD")) {
34 | Skull skullBlock = (Skull) block.getState();
35 |
36 | ServerVersion serverVersion = ConditionalEvents.serverVersion;
37 | if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_21_R1)){
38 | if(skullBlock.getOwnerProfile() == null){
39 | return "";
40 | }
41 | PlayerTextures textures = skullBlock.getOwnerProfile().getTextures();
42 | if(textures.getSkin() == null){
43 | return "";
44 | }
45 |
46 | JsonObject skinJsonObject = new JsonObject();
47 | skinJsonObject.addProperty("url", textures.getSkin().toString());
48 | JsonObject texturesJsonObject = new JsonObject();
49 | texturesJsonObject.add("SKIN", skinJsonObject);
50 | JsonObject minecraftTexturesJsonObject = new JsonObject();
51 | minecraftTexturesJsonObject.add("textures", texturesJsonObject);
52 | return new String(Base64.getEncoder().encode(minecraftTexturesJsonObject.toString().getBytes()));
53 | }else{
54 | Field profileField;
55 | try {
56 | profileField = skullBlock.getClass().getDeclaredField("profile");
57 | profileField.setAccessible(true);
58 | GameProfile gameProfile = (GameProfile) profileField.get(skullBlock);
59 | if(gameProfile != null && gameProfile.getProperties() != null &&
60 | gameProfile.getProperties().containsKey("textures")) {
61 | Collection properties = gameProfile.getProperties().get("textures");
62 | for(Property p : properties) {
63 | if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_20_R2)){
64 | String pName = (String)p.getClass().getMethod("name").invoke(p);
65 | if(pName.equals("textures")){
66 | return (String)p.getClass().getMethod("value").invoke(p);
67 | }
68 | }else{
69 | if(p.getName().equals("textures")) {
70 | return p.getValue();
71 | }
72 | }
73 | }
74 | }
75 | } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException
76 | | InvocationTargetException | NoSuchMethodException e) {
77 | e.printStackTrace();
78 | }
79 | }
80 | }
81 |
82 | return "";
83 | }
84 |
85 | public static void setHeadTextureData(Block block,String texture,String owner){
86 | Skull skullBlock = (Skull) block.getState();
87 | if(OtherUtils.isLegacy()) {
88 | skullBlock.setSkullType(SkullType.PLAYER);
89 | skullBlock.setRawData((byte)1);
90 | }
91 |
92 | if(owner != null){
93 | skullBlock.setOwner(owner);
94 | skullBlock.update();
95 | return;
96 | }
97 |
98 | ServerVersion serverVersion = ConditionalEvents.serverVersion;
99 | if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_20_R2)){
100 | PlayerProfile profile = Bukkit.createPlayerProfile(UUID.randomUUID(),"conditionalevents");
101 | PlayerTextures textures = profile.getTextures();
102 | URL url;
103 | try {
104 | String decoded = new String(Base64.getDecoder().decode(texture));
105 | String decodedFormatted = decoded.replaceAll("\\s", "");
106 | JsonObject jsonObject = new Gson().fromJson(decodedFormatted, JsonObject.class);
107 | String urlText = jsonObject.get("textures").getAsJsonObject().get("SKIN")
108 | .getAsJsonObject().get("url").getAsString();
109 |
110 | url = new URL(urlText);
111 | } catch (Exception error) {
112 | error.printStackTrace();
113 | return;
114 | }
115 | textures.setSkin(url);
116 | profile.setTextures(textures);
117 | skullBlock.setOwnerProfile(profile);
118 | }else{
119 | GameProfile profile = new GameProfile(UUID.randomUUID(), "");
120 | profile.getProperties().put("textures", new Property("textures", texture));
121 | try {
122 | Field profileField = skullBlock.getClass().getDeclaredField("profile");
123 | profileField.setAccessible(true);
124 | profileField.set(skullBlock, profile);
125 | } catch (IllegalArgumentException | NoSuchFieldException | SecurityException | IllegalAccessException error) {
126 | error.printStackTrace();
127 | }
128 | }
129 |
130 | skullBlock.update();
131 | }
132 |
133 | public static String getBlockDataStringFromObject(BlockData blockData){
134 | String text = blockData.getAsString();
135 | int index = text.indexOf("[");
136 | if(index == -1){
137 | return "";
138 | }
139 | return text.substring(index+1,text.length()-1);
140 | }
141 |
142 | public static BlockData getBlockDataFromString(String blockDataString,Material material){
143 | String minecraftMaterial = material.getKey().getNamespace()+":"+material.getKey().getKey();
144 | String blockDataText = minecraftMaterial+"["+blockDataString+"]";
145 | return Bukkit.createBlockData(blockDataText);
146 | }
147 | }
148 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/utils/GlobalVariablesUtils.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.utils;
2 |
3 | import org.bukkit.Bukkit;
4 | import org.bukkit.ChatColor;
5 | import org.bukkit.Location;
6 | import org.bukkit.World;
7 | import org.bukkit.block.Block;
8 | import org.bukkit.entity.Player;
9 | import org.bukkit.inventory.ItemStack;
10 | import org.bukkit.inventory.meta.ItemMeta;
11 |
12 | import java.util.ArrayList;
13 | import java.util.List;
14 | import java.util.Random;
15 |
16 | public class GlobalVariablesUtils {
17 |
18 | public static String variablePlayer(Player finalPlayer){
19 | return finalPlayer.getName();
20 | }
21 |
22 | public static String variablePlayerBlockBelow(Player finalPlayer,String variable){
23 | int distance = Integer.parseInt(variable.replace("playerblock_below_", ""));
24 | Location l = finalPlayer.getLocation().clone().add(0, -distance, 0);
25 | return getBlockTypeInLocation(l);
26 | }
27 |
28 | public static String variablePlayerBlockAbove(Player finalPlayer,String variable){
29 | int distance = Integer.parseInt(variable.replace("playerblock_above_", ""));
30 | Location l = finalPlayer.getLocation().clone().add(0, distance, 0);
31 | return getBlockTypeInLocation(l);
32 | }
33 |
34 | public static String variablePlayerBlockInside(Player finalPlayer){
35 | Location l = finalPlayer.getLocation();
36 | return getBlockTypeInLocation(l);
37 | }
38 |
39 | public static String variablePlayerIsOutside(Player finalPlayer){
40 | Location l = finalPlayer.getLocation();
41 | Block block = getNextHighestBlock(l);
42 | if(block == null){
43 | return "true";
44 | }else{
45 | return "false";
46 | }
47 | }
48 |
49 | public static String variableRandomPlayer(){
50 | int random = new Random().nextInt(Bukkit.getOnlinePlayers().size());
51 | ArrayList players = new ArrayList<>(Bukkit.getOnlinePlayers());
52 | if(players.size() == 0) {
53 | return "none";
54 | }else {
55 | return players.get(random).getName();
56 | }
57 | }
58 |
59 | public static String variableRandomPlayerWorld(String variable){
60 | String worldName = variable.replace("random_player_", "");
61 | try {
62 | World world = Bukkit.getWorld(worldName);
63 | List players = world.getPlayers();
64 | if(players.size() == 0) {
65 | return "none";
66 | }else {
67 | int random = new Random().nextInt(players.size());
68 | return players.get(random).getName();
69 | }
70 | }catch(Exception e) {
71 | return "none";
72 | }
73 | }
74 |
75 | public static String variableRandomMinMax(String variable){
76 | String variableLR = variable.replace("random_", "");
77 | String[] variableLRSplit = variableLR.split("_");
78 | int num1 = Integer.valueOf(variableLRSplit[0]);
79 | int num2 = Integer.valueOf(variableLRSplit[1]);
80 | int numFinal = MathUtils.getRandomNumber(num1, num2);
81 | return numFinal+"";
82 | }
83 |
84 | public static String variableRandomWorld(String variable){
85 | String variableLR = variable.replace("randomword_", "");
86 | String[] variableLRSplit = variableLR.split("-");
87 | Random r = new Random();
88 | String word = variableLRSplit[r.nextInt(variableLRSplit.length)];
89 | return word;
90 | }
91 |
92 | public static String variablePlayerArmorName(Player finalPlayer,String variable){
93 | String armorType = variable.replace("playerarmor_name_", "");
94 | ItemStack item = getArmorItem(finalPlayer,armorType);
95 | String name = "";
96 | if(item != null && item.hasItemMeta()){
97 | ItemMeta meta = item.getItemMeta();
98 | if(meta.hasDisplayName()){
99 | name = ChatColor.stripColor(meta.getDisplayName());
100 | }
101 | }
102 | return name;
103 | }
104 |
105 | public static String variablePlayerArmorType(Player finalPlayer,String variable){
106 | String armorType = variable.replace("playerarmor_", "");
107 | ItemStack item = getArmorItem(finalPlayer,armorType);
108 | String material = "AIR";
109 | if(item != null) {
110 | material = item.getType().name();
111 | }
112 | return material;
113 | }
114 |
115 | public static String variableBlockAt(String variable){
116 | String variableLR = variable.replace("block_at_", "");
117 | String[] variableLRSplit = variableLR.split("_");
118 | Block block = getBlockFromFormat(variableLRSplit);
119 | if(block == null){
120 | return variable;
121 | }
122 | return block.getType().name();
123 | }
124 |
125 | public static String variableBlockDataAt(String variable){
126 | String variableLR = variable.replace("block_data_at_", "");
127 | String[] variableLRSplit = variableLR.split("_");
128 | Block block = getBlockFromFormat(variableLRSplit);
129 | if(block == null){
130 | return variable;
131 | }
132 |
133 | if(OtherUtils.isLegacy()){
134 | return block.getData()+"";
135 | }else{
136 | return BlockUtils.getBlockDataStringFromObject(block.getBlockData());
137 | }
138 | }
139 |
140 | private static Block getBlockFromFormat(String[] variableLRSplit) {
141 | try {
142 | int x = Integer.parseInt(variableLRSplit[0]);
143 | int y = Integer.parseInt(variableLRSplit[1]);
144 | int z = Integer.parseInt(variableLRSplit[2]);
145 | String worldName = "";
146 | for(int i = 3; i< variableLRSplit.length; i++) {
147 | if(i == variableLRSplit.length - 1) {
148 | worldName = worldName+ variableLRSplit[i];
149 | }else {
150 | worldName = worldName+ variableLRSplit[i]+"_";
151 | }
152 | }
153 | World world = Bukkit.getWorld(worldName);
154 | return world.getBlockAt(x,y,z);
155 | }catch(Exception e) {
156 | return null;
157 | }
158 | }
159 |
160 | public static String variableIsNearby(Player finalPlayer,String variable){
161 | String variableLR = variable.replace("is_nearby_", "");
162 | String[] variableLRSplit = variableLR.split("_");
163 | try {
164 | int x = Integer.valueOf(variableLRSplit[0]);
165 | int y = Integer.valueOf(variableLRSplit[1]);
166 | int z = Integer.valueOf(variableLRSplit[2]);
167 | String worldName = "";
168 | for(int i=3;i list) {
28 | hover = new BaseComponent[list.size()];
29 | for(int i=0;i 0) {
41 | return new BigDecimal(String.valueOf(value)).setScale(2, BigDecimal.ROUND_FLOOR).doubleValue();
42 | } else {
43 | return new BigDecimal(String.valueOf(value)).setScale(2, BigDecimal.ROUND_CEILING).doubleValue();
44 | }
45 | }catch(NumberFormatException e){
46 | return value;
47 | }
48 | }
49 |
50 | // org.apache.commons.lang3.math.NumberUtils
51 | public static boolean isParsable(String str) {
52 | if (str == null || str.isEmpty()) {
53 | return false;
54 | } else if (str.charAt(str.length() - 1) == '.') {
55 | return false;
56 | } else if (str.charAt(0) == '-') {
57 | return str.length() == 1 ? false : withDecimalsParsing(str, 1);
58 | } else {
59 | return withDecimalsParsing(str, 0);
60 | }
61 | }
62 |
63 | // org.apache.commons.lang3.math.NumberUtils
64 | private static boolean withDecimalsParsing(String str, int beginIdx) {
65 | int decimalPoints = 0;
66 |
67 | for(int i = beginIdx; i < str.length(); ++i) {
68 | boolean isDecimalPoint = str.charAt(i) == '.';
69 | if (isDecimalPoint) {
70 | ++decimalPoints;
71 | }
72 |
73 | if (decimalPoints > 1) {
74 | return false;
75 | }
76 |
77 | if (!isDecimalPoint && !Character.isDigit(str.charAt(i))) {
78 | return false;
79 | }
80 | }
81 |
82 | return true;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/utils/OtherUtils.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.utils;
2 | import ce.ajneb97.ConditionalEvents;
3 | import me.clip.placeholderapi.PlaceholderAPI;
4 | import net.md_5.bungee.api.chat.BaseComponent;
5 | import net.md_5.bungee.chat.ComponentSerializer;
6 | import org.bukkit.Bukkit;
7 | import org.bukkit.Color;
8 | import org.bukkit.entity.Player;
9 |
10 | public class OtherUtils {
11 |
12 | public static boolean isChatNew() {
13 | ServerVersion serverVersion = ConditionalEvents.serverVersion;
14 | if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_19_R1)){
15 | return true;
16 | }
17 | return false;
18 | }
19 |
20 | public static boolean isNew() {
21 | ServerVersion serverVersion = ConditionalEvents.serverVersion;
22 | if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_16_R1)){
23 | return true;
24 | }
25 | return false;
26 | }
27 |
28 | public static boolean isLegacy() {
29 | ServerVersion serverVersion = ConditionalEvents.serverVersion;
30 | if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_13_R1)){
31 | return false;
32 | }else {
33 | return true;
34 | }
35 | }
36 |
37 | public static Color getFireworkColorFromName(String colorName) {
38 | if(colorName.startsWith("#")){
39 | int rgbValue = Integer.parseInt(colorName.substring(1), 16);
40 | return Color.fromRGB(rgbValue);
41 | }
42 | try {
43 | return (Color) Color.class.getDeclaredField(colorName).get(Color.class);
44 | } catch (IllegalAccessException e) {
45 | e.printStackTrace();
46 | } catch (NoSuchFieldException e) {
47 | e.printStackTrace();
48 | }
49 | return null;
50 | }
51 |
52 | public static String fromJsonMessageToNormalMessage(String jsonMessage){
53 | try{
54 | BaseComponent[] base = ComponentSerializer.parse(jsonMessage);
55 | return BaseComponent.toLegacyText(base);
56 | }catch(Exception e){
57 | return null;
58 | }
59 | }
60 |
61 | public static String getFileExtension(String filePath) {
62 | int lastIndex = filePath.lastIndexOf(".");
63 | if (lastIndex > 0 && lastIndex < filePath.length() - 1) {
64 | return filePath.substring(lastIndex+1);
65 | } else {
66 | return "invalid";
67 | }
68 | }
69 |
70 | public static String replaceGlobalVariables(String text, Player player, ConditionalEvents plugin) {
71 | if(player == null){
72 | return text;
73 | }
74 | text = text.replace("%player%",player.getName());
75 | if(plugin.getDependencyManager().isPlaceholderAPI()) {
76 | text = PlaceholderAPI.setPlaceholders(player, text);
77 | }
78 |
79 | return text;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/utils/PlayerUtils.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.utils;
2 |
3 | import ce.ajneb97.ConditionalEvents;
4 | import org.bukkit.entity.Player;
5 | import org.bukkit.inventory.ItemStack;
6 | import org.bukkit.inventory.PlayerInventory;
7 |
8 | public class PlayerUtils {
9 |
10 | public static ItemStack getItemBySlot(Player player, String slot){
11 | PlayerInventory inventory = player.getInventory();
12 | switch(slot){
13 | case "HAND":
14 | return inventory.getItemInHand();
15 | case "OFF_HAND":
16 | return inventory.getItemInOffHand();
17 | case "HELMET":
18 | return inventory.getHelmet();
19 | case "CHESTPLATE":
20 | return inventory.getChestplate();
21 | case "LEGGINGS":
22 | return inventory.getLeggings();
23 | case "BOOTS":
24 | return inventory.getBoots();
25 | default:
26 | return inventory.getItem(Integer.parseInt(slot));
27 | }
28 | }
29 |
30 | public static void setItemBySlot(Player player, String slot, ItemStack item){
31 | PlayerInventory inventory = player.getInventory();
32 | switch(slot){
33 | case "HAND":
34 | inventory.setItemInHand(item);
35 | break;
36 | case "OFF_HAND":
37 | inventory.setItemInOffHand(item);
38 | break;
39 | case "HELMET":
40 | inventory.setHelmet(item);
41 | break;
42 | case "CHESTPLATE":
43 | inventory.setChestplate(item);
44 | break;
45 | case "LEGGINGS":
46 | inventory.setLeggings(item);
47 | break;
48 | case "BOOTS":
49 | inventory.setBoots(item);
50 | break;
51 | default:
52 | inventory.setItem(Integer.parseInt(slot),item);
53 | break;
54 | }
55 | }
56 |
57 | public static void updatePlayerInventory(Player player){
58 | ServerVersion serverVersion = ConditionalEvents.serverVersion;
59 | if(!serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_13_R1)) {
60 | //1.12-
61 | player.updateInventory();
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/utils/ServerVersion.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.utils;
2 |
3 | public enum ServerVersion {
4 | v1_8_R1,
5 | v1_8_R2,
6 | v1_8_R3,
7 | v1_9_R1,
8 | v1_9_R2,
9 | v1_10_R1,
10 | v1_11_R1,
11 | v1_12_R1,
12 | v1_13_R1,
13 | v1_13_R2,
14 | v1_14_R1,
15 | v1_15_R1,
16 | v1_16_R1,
17 | v1_16_R2,
18 | v1_16_R3,
19 | v1_17_R1,
20 | v1_18_R1,
21 | v1_18_R2,
22 | v1_19_R1,
23 | v1_19_R2,
24 | v1_19_R3,
25 | v1_20_R1,
26 | v1_20_R2,
27 | v1_20_R3,
28 | v1_20_R4,
29 | v1_21_R1,
30 | v1_21_R2,
31 | v1_21_R3,
32 | v1_21_R4;
33 |
34 | public boolean serverVersionGreaterEqualThan(ServerVersion version1,ServerVersion version2){
35 | return version1.ordinal() >= version2.ordinal();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/ce/ajneb97/utils/TimeUtils.java:
--------------------------------------------------------------------------------
1 | package ce.ajneb97.utils;
2 |
3 | import ce.ajneb97.managers.MessagesManager;
4 |
5 | public class TimeUtils {
6 |
7 | public static String getTime(long seconds, MessagesManager msgManager) {
8 | if(seconds == 0){
9 | return seconds+msgManager.getTimeSeconds();
10 | }
11 | long totalMin = seconds/60;
12 | long totalHour = totalMin/60;
13 | long totalDay = totalHour/24;
14 | String time = "";
15 | if(seconds > 59){
16 | seconds = seconds - 60*totalMin;
17 | }
18 | if(seconds > 0){
19 | time = seconds+msgManager.getTimeSeconds();
20 | }
21 | if(totalMin > 59){
22 | totalMin = totalMin - 60*totalHour;
23 | }
24 | if(totalMin > 0){
25 | time = totalMin+msgManager.getTimeMinutes()+" "+time;
26 | }
27 | if(totalHour > 24) {
28 | totalHour = totalHour - 24*totalDay;
29 | }
30 | if(totalHour > 0){
31 | time = totalHour+msgManager.getTimeHours()+" " + time;
32 | }
33 | if(totalDay > 0) {
34 | time = totalDay+msgManager.getTimeDays()+" " + time;
35 | }
36 |
37 | return time;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/resources/config.yml:
--------------------------------------------------------------------------------
1 | Config:
2 | update_notification: true
3 | data_save_time: 5
4 | debug_actions: true
5 | experimental:
6 | variable_replacement: false
7 | register_commands:
8 | - "hello"
9 | to_condition_groups:
10 | group1:
11 | - "%player_has_permission_conditionalevents.somepermission% == yes"
12 | Messages:
13 | prefix: '&4[&bConditionalEvents&4] '
14 | commandReload: '&aConfig Reloaded.'
15 | commandNoPermissions: '&cYou don''t have permissions to use this command.'
16 | commandResetError: '&cUse &7/ce reset /all'
17 | eventDoesNotExists: '&cThat event doesn''t exists on the config.'
18 | eventDataReset: '&aData reset for player &e%player% &aon event &e%event%&a!'
19 | eventDataResetAll: '&aAll data reset for player &e%player%&a!'
20 | eventDataResetForAllPlayers: '&aData reset for &eall players &aon event &e%event%&a!'
21 | eventDataResetAllForAllPlayers: '&aAll player data reset.'
22 | eventEnableError: '&cUse &7/ce enable '
23 | eventDisableError: '&cUse &7/ce disable '
24 | eventEnabled: '&aEvent &7%event% &aenabled.'
25 | eventDisabled: '&aEvent &7%event% &adisabled.'
26 | commandDebugError: '&cUse &7/ce debug '
27 | debugEnabled: '&aDebug now enabled for event &7%event%&a!'
28 | debugDisabled: '&aDebug disabled for event &7%event%&a!'
29 | debugEnabledPlayer: '&aDebug now enabled for event &7%event% &aand player &7%player%&a!'
30 | debugDisabledPlayer: '&aDebug disabled for event &7%event% &aand player &7%player%&a!'
31 | onlyPlayerCommand: "&cThis command can be only used by a player."
32 | playerDoesNotExists: '&cThat player doesn''t have any data.'
33 | seconds: s
34 | minutes: m
35 | hours: h
36 | days: d
37 | placeholderAPICooldownReady: "Ready!"
38 | placeholderAPICooldownNameError: "No event with that name!"
39 | commandCallError: '&cUse &7/ce call (optional)%variable1%=;%variableN%= (optional)player:'
40 | commandCallInvalidEvent: '&cYou can only execute a CALL event.'
41 | commandCallCorrect: '&aEvent &7%event% &asuccessfully executed.'
42 | commandCallCorrectPlayer: '&aEvent &7%event% &asuccessfully executed for player &7%player%&a.'
43 | commandCallFailed: '&cEvent &7%event% &ccould not be executed. Maybe a format error?'
44 | playerNotOnline: '&cThat player is not online.'
45 | commandItemError: "&cUse &7/ce item "
46 | savedItemDoesNotExists: "&cThat saved item doesn't exists."
47 | savedItemRemoved: "&aItem &7%name% &aremoved."
48 | mustHaveItemInHand: "&cYou must have an item on your hand."
49 | savedItemAlreadyExists: "&cA saved item with that name already exists."
50 | savedItemAdded: "&aItem &7%name% &asaved."
51 | commandInterruptError: '&cUse &7/ce interrupt (optional)'
52 | commandInterruptCorrect: '&aActions of event &7%event% &ainterrupted.'
53 | commandInterruptCorrectPlayer: '&aActions of event &7%event% &ainterrupted for player &7%player%&a.'
54 | Events:
55 | event1:
56 | type: player_join
57 | conditions:
58 | - '%player% == Ajneb'
59 | actions:
60 | default:
61 | - 'to_all: message: &e&l[ALERT] &f&lAjneb joined the game!'
62 | event2:
63 | type: block_interact
64 | one_time: true
65 | conditions:
66 | - '%block_x% == 20'
67 | - '%block_y% == 60'
68 | - '%block_z% == 20'
69 | - '%block_world% == lobby'
70 | - '%block% == STONE_BUTTON'
71 | - '%action_type% == RIGHT_CLICK'
72 | - '%player_has_permission_conditionalevents.event.event2% == no execute actions2'
73 | actions:
74 | default:
75 | - 'message: &aYou''ve received $500!'
76 | - 'console_command: eco give %player% 500'
77 | - 'playsound: ENTITY_PLAYER_LEVELUP;10;2'
78 | actions2:
79 | - 'message: &cYou need to have a rank to use this button.'
80 | one_time:
81 | - 'message: &cYou can claim this reward just once!'
82 | event3:
83 | type: player_attack
84 | conditions:
85 | - '%victim% == PLAYER'
86 | - '%item% == DIAMOND_SWORD'
87 | - '%item_name% == Super Sword'
88 | - '%random_1_10% >= 8'
89 | actions:
90 | default:
91 | - 'message: &aYour diamond sword poison effect was activated! &6%target:player_name% &ais now poisoned!'
92 | - 'to_target: give_potion_effect: POISON;120;1'
93 | - 'to_target: message: &cYou were poisoned by &e%player%&c!'
94 | event4:
95 | type: block_break
96 | ignore_with_permission: conditionalevents.ignore.event4
97 | conditions:
98 | - '%block_world% == spawn'
99 | actions:
100 | default:
101 | - 'cancel_event: true'
102 | - 'message: &cYou can''t break blocks on this world.'
103 | - 'playsound: BLOCK_NOTE_BLOCK_PLING;10;0.1'
104 | event5:
105 | type: player_command
106 | ignore_with_permission: conditionalevents.ignore.event5
107 | conditions:
108 | - '%main_command% equalsIgnoreCase //calc or %main_command% equalsIgnoreCase //solve or %main_command% equalsIgnoreCase //eval'
109 | actions:
110 | default:
111 | - 'cancel_event: true'
112 | - 'kick: &cWhat are you trying to do?'
113 | event6:
114 | type: repetitive
115 | repetitive_time: 10
116 | conditions:
117 | - '%player_world% == plotworld'
118 | - '%player_gamemode% != CREATIVE'
119 | actions:
120 | default:
121 | - 'gamemode: CREATIVE'
122 | - 'actionbar: &6Changing gamemode to creative.;100'
123 | event7:
124 | type: player_command
125 | conditions:
126 | - '%main_command% == /hello'
127 | actions:
128 | default:
129 | - 'cancel_event: true'
130 | - "message: &7You said hello to nearby players!"
131 | - 'to_range: 10;false: message: &e%player% &7says you hello!'
132 |
--------------------------------------------------------------------------------
/src/main/resources/events/more_events.yml:
--------------------------------------------------------------------------------
1 | Events:
2 | event8:
3 | type: player_command
4 | conditions:
5 | - "%main_command% == /youtube"
6 | actions:
7 | default:
8 | - 'cancel_event: true'
9 | - "message: &7Check the Youtube: &b"
10 | event9:
11 | type: player_command
12 | cooldown: 15
13 | prevent_cooldown_activation:
14 | - error1
15 | - error2
16 | conditions:
17 | - '%main_command% == /announce'
18 | - '%args_length% == 0 execute error1'
19 | - '%vault_eco_balance% < 500 execute error2'
20 | actions:
21 | default:
22 | - 'cancel_event: true'
23 | - 'to_all: centered_message: &f&m '
24 | - 'to_all: centered_message: &c&lAnnounce'
25 | - 'to_all: centered_message: &e%player% &7is making an announcement:'
26 | - 'to_all: centered_message: '
27 | - 'to_all: centered_message: &7%args_substring_1-100%'
28 | - 'to_all: centered_message: '
29 | - 'to_all: centered_message: &f&m '
30 | - 'console_command: eco take %player% 500'
31 | error1:
32 | - 'cancel_event: true'
33 | - 'message: &cYou have to use &7/announce &c.'
34 | error2:
35 | - 'cancel_event: true'
36 | - 'message: &cYou need $500 to use this command.'
37 | cooldown:
38 | - 'cancel_event: true'
39 | - 'message: &cYou must wait &7%time% &cbefore using this command again.'
--------------------------------------------------------------------------------
/src/main/resources/plugin.yml:
--------------------------------------------------------------------------------
1 | main: ce.ajneb97.ConditionalEvents
2 | version: 4.62.2
3 | name: ConditionalEvents
4 | api-version: 1.13
5 | softdepend: [PlaceholderAPI,Citizens,WorldGuardEvents,WorldGuard,ProtocolLib,DiscordSRV]
6 | author: Ajneb97
7 |
8 | commands:
9 | conditionalevents:
10 | description: Main command of ConditionalEvents
11 | aliases: ce
--------------------------------------------------------------------------------
/src/main/resources/saved_items.yml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajneb97/ConditionalEvents/465bb15d2d494f6ed37d756555c4e6525d9bfac7/src/main/resources/saved_items.yml
--------------------------------------------------------------------------------