-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHellmode.java
146 lines (122 loc) · 4.27 KB
/
Hellmode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package main;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class Hellmode extends JavaPlugin implements Listener {
/*
* all player information is saved inside config.yml
* more features and input arguments can be added in the future if needed
*
* current config file structure:
*
* <PLAYER DISPLAY NAME>
* hellmode: <boolean>
* lasttoggle <date and time represented as dd/MM/yyyy HH:mm:ss>
*/
public FileConfiguration config;
private SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
@Override
public void onEnable() {
getLogger().info("loading hellmode, created by EggyRepublic!");
config = this.getConfig();
getServer().getPluginManager().registerEvents(this, this);
loadConfiguration();
this.getCommand("hellmode").setExecutor(new Commands(this));
getLogger().info("successfully loaded hellmode!");
}
@Override
public void onDisable() {
getLogger().info("successfully unloaded hellmode, thank you com again");
this.saveConfig();
}
public void loadConfiguration() {
config.options().copyDefaults(true);
this.saveConfig();
}
//HELPER FUNCTIONS
public void toggleHellmode(Player p) {
if (!isHellmode(p)) {
//if not already Hellmode, turn it on by turning anti-regen on
//sets hellmode and lasttoggle fields in config
config.set(p.getDisplayName() + ".hellmode", true);
config.set(p.getDisplayName() + ".lasttoggle", formatter.format(new Date()));
this.saveConfig();
//turns on antiregen
antiregenOn(p);
} else {
//turning Hellmode off
//sets hellmode and lasttoggle fields in config
config.set(p.getDisplayName() + ".hellmode", false);
config.set(p.getDisplayName() + ".lasttoggle", formatter.format(new Date()));
this.saveConfig();
//turns off antiregen
antiregenOff(p);
}
}
/*
* checks configuration file for player's hellmode status (boolean)
* returns false if player not found
*/
public boolean isHellmode(Player p) {
return config.getBoolean(p.getDisplayName() + ".hellmode");
}
/*
* checks the last time a player have toggled hellmode and the current status in the config
*/
public String checkToggle(Player p) {
if (isHellmode(p)) {
return p.getDisplayName() + " last toggled on hellmode on " + config.getString(p.getDisplayName() + ".lasttoggle");
} else {
return p.getDisplayName() + " last toggled off hellmode on " + config.getString(p.getDisplayName() + ".lasttoggle");
}
}
//ASSORTED FEATURES
public void antiregenOn(Player p) {
p.sendMessage("toggled hellmode on for " + p.getName());
p.setSaturatedRegenRate(Integer.MAX_VALUE);
p.setUnsaturatedRegenRate(Integer.MAX_VALUE);
}
public void antiregenOff(Player p) {
p.sendMessage("toggled hellmode off for " + p.getName());
p.setSaturatedRegenRate(20);
p.setUnsaturatedRegenRate(80);
}
//EVENTS
@EventHandler
public void joinEvent(PlayerJoinEvent event) {
Player p = event.getPlayer();
p.sendMessage("hellmode: " + isHellmode(p));
p.sendMessage("hellmode enables anti-regen");
checkVar(p);
}
/*
* cancels all regeneration events
*/
@EventHandler
public void healEventBlock(EntityRegainHealthEvent event) {
Entity entity = event.getEntity();
if (entity instanceof Player) {
Player player = (Player) entity;
if (isHellmode(player)) {
event.setCancelled(true);
}
}
}
/*
* ensures consistency between player in game status and config file status
*/
public void checkVar(Player p) {
if (isHellmode(p)) {
antiregenOn(p);
} else {
antiregenOff(p);
}
}
}