summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/User.java
blob: bca444dde0c9c18cbc131fbc5d90f2a4f44fccd0 (plain)
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
package com.earth2me.essentials;

import static com.earth2me.essentials.I18n.tl;
import com.earth2me.essentials.commands.IEssentialsCommand;
import com.earth2me.essentials.register.payment.Method;
import com.earth2me.essentials.register.payment.Methods;
import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.NumberUtil;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.ess3.api.IEssentials;
import net.ess3.api.MaxMoneyException;
import net.ess3.api.events.AfkStatusChangeEvent;
import net.ess3.api.events.UserBalanceUpdateEvent;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;


public class User extends UserData implements Comparable<User>, IReplyTo, net.ess3.api.IUser
{
	private static final Logger logger = Logger.getLogger("Essentials");
	private CommandSource replyTo = null;
	private transient UUID teleportRequester;
	private transient boolean teleportRequestHere;
	private transient Location teleportLocation;
	private transient boolean vanished;
	private transient final Teleport teleport;
	private transient long teleportRequestTime;
	private transient long lastOnlineActivity;
	private transient long lastThrottledAction;
	private transient long lastActivity = System.currentTimeMillis();
	private boolean hidden = false;
	private boolean rightClickJump = false;
	private transient Location afkPosition = null;
	private boolean invSee = false;
	private boolean recipeSee = false;
	private boolean enderSee = false;
	private transient long teleportInvulnerabilityTimestamp = 0;

	public User(final Player base, final IEssentials ess)
	{
		super(base, ess);
		teleport = new Teleport(this, ess);
		if (isAfk())
		{
			afkPosition = this.getLocation();
		}
		if (this.getBase().isOnline())
		{
			lastOnlineActivity = System.currentTimeMillis();
		}
	}

	User update(final Player base)
	{
		setBase(base);
		return this;
	}

	@Override
	public boolean isAuthorized(final IEssentialsCommand cmd)
	{
		return isAuthorized(cmd, "essentials.");
	}

	@Override
	public boolean isAuthorized(final IEssentialsCommand cmd, final String permissionPrefix)
	{
		return isAuthorized(permissionPrefix + (cmd.getName().equals("r") ? "msg" : cmd.getName()));
	}

	@Override
	public boolean isAuthorized(final String node)
	{
		final boolean result = isAuthorizedCheck(node);
		if (ess.getSettings().isDebug())
		{
			ess.getLogger().log(Level.INFO, "checking if " + base.getName() + " has " + node + " - " + result);
		}
		return result;
	}

	private boolean isAuthorizedCheck(final String node)
	{

		if (base instanceof OfflinePlayer)
		{
			return false;
		}

		try
		{
			return ess.getPermissionsHandler().hasPermission(base, node);
		}
		catch (Exception ex)
		{
			if (ess.getSettings().isDebug())
			{
				ess.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex);
			}
			else
			{
				ess.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage());
			}

			return false;
		}
	}

	@Override
	public void healCooldown() throws Exception
	{
		final Calendar now = new GregorianCalendar();
		if (getLastHealTimestamp() > 0)
		{
			final double cooldown = ess.getSettings().getHealCooldown();
			final Calendar cooldownTime = new GregorianCalendar();
			cooldownTime.setTimeInMillis(getLastHealTimestamp());
			cooldownTime.add(Calendar.SECOND, (int)cooldown);
			cooldownTime.add(Calendar.MILLISECOND, (int)((cooldown * 1000.0) % 1000.0));
			if (cooldownTime.after(now) && !isAuthorized("essentials.heal.cooldown.bypass"))
			{
				throw new Exception(tl("timeBeforeHeal", DateUtil.formatDateDiff(cooldownTime.getTimeInMillis())));
			}
		}
		setLastHealTimestamp(now.getTimeInMillis());
	}

	@Override
	public void giveMoney(final BigDecimal value) throws MaxMoneyException
	{
		giveMoney(value, (CommandSource)null);
	}

	@Override
	public void giveMoney(final BigDecimal value, final CommandSource initiator) throws MaxMoneyException
	{
		if (value.signum() == 0)
		{
			return;
		}
		setMoney(getMoney().add(value));
		sendMessage(tl("addedToAccount", NumberUtil.displayCurrency(value, ess)));
		if (initiator != null)
		{
			initiator.sendMessage(tl("addedToOthersAccount", NumberUtil.displayCurrency(value, ess), this.getDisplayName(), NumberUtil.displayCurrency(getMoney(), ess)));
		}
	}

	@Override
	public void payUser(final User reciever, final BigDecimal value) throws ChargeException, MaxMoneyException
	{
		if (value.signum() == 0)
		{
			return;
		}
		if (canAfford(value))
		{
			setMoney(getMoney().subtract(value));
			reciever.setMoney(reciever.getMoney().add(value));
			sendMessage(tl("moneySentTo", NumberUtil.displayCurrency(value, ess), reciever.getDisplayName()));
			reciever.sendMessage(tl("moneyRecievedFrom", NumberUtil.displayCurrency(value, ess), getDisplayName()));
		}
		else
		{
			throw new ChargeException(tl("notEnoughMoney"));
		}
	}

	@Override
	public void takeMoney(final BigDecimal value)
	{
		takeMoney(value, (CommandSource)null);
	}

	@Override
	public void takeMoney(final BigDecimal value, final CommandSource initiator)
	{
		if (value.signum() == 0)
		{
			return;
		}
		try
		{
			setMoney(getMoney().subtract(value));
		}
		catch (MaxMoneyException ex)
		{
			ess.getLogger().log(Level.WARNING, "Invalid call to takeMoney, total balance can't be more than the max-money limit.", ex);
		}
		sendMessage(tl("takenFromAccount", NumberUtil.displayCurrency(value, ess)));
		if (initiator != null)
		{
			initiator.sendMessage(tl("takenFromOthersAccount", NumberUtil.displayCurrency(value, ess), this.getDisplayName(), NumberUtil.displayCurrency(getMoney(), ess)));
		}
	}

	@Override
	public boolean canAfford(final BigDecimal cost)
	{
		return canAfford(cost, true);
	}

	public boolean canAfford(final BigDecimal cost, final boolean permcheck)
	{
		if (cost.signum() <= 0)
		{
			return true;
		}
		final BigDecimal remainingBalance = getMoney().subtract(cost);
		if (!permcheck || isAuthorized("essentials.eco.loan"))
		{
			return (remainingBalance.compareTo(ess.getSettings().getMinMoney()) >= 0);
		}
		return (remainingBalance.signum() >= 0);
	}

	public void dispose()
	{
		ess.runTaskAsynchronously(new Runnable()
		{
			@Override
			public void run()
			{
				_dispose();
			}
		});
	}

	private void _dispose()
	{
		if (!base.isOnline())
		{
			this.base = new OfflinePlayer(getConfigUUID(), ess.getServer());
		}
		cleanup();
	}

	@Override
	public Boolean canSpawnItem(final int itemId)
	{
		return !ess.getSettings().itemSpawnBlacklist().contains(itemId);
	}

	@Override
	public void setLastLocation()
	{
		setLastLocation(this.getLocation());
	}

	@Override
	public void setLogoutLocation()
	{
		setLogoutLocation(this.getLocation());
	}

	@Override
	public void requestTeleport(final User player, final boolean here)
	{
		teleportRequestTime = System.currentTimeMillis();
		teleportRequester = player == null ? null : player.getBase().getUniqueId();
		teleportRequestHere = here;
		if (player == null)
		{
			teleportLocation = null;
		}
		else
		{
			teleportLocation = here ? player.getLocation() : this.getLocation();
		}
	}

	public UUID getTeleportRequest()
	{
		return teleportRequester;
	}

	public boolean isTpRequestHere()
	{
		return teleportRequestHere;
	}

	public Location getTpRequestLocation()
	{
		return teleportLocation;
	}

	public String getNick(final boolean longnick)
	{
		final StringBuilder prefix = new StringBuilder();
		String nickname;
		String suffix = "";
		final String nick = getNickname();
		if (ess.getSettings().isCommandDisabled("nick") || nick == null || nick.isEmpty() || nick.equals(getName()))
		{
			nickname = getName();
		}
		else if (nick.equalsIgnoreCase(getName())) {
			nickname = nick;
		}
		else
		{
			nickname = ess.getSettings().getNicknamePrefix() + nick;
			suffix = "§r";
		}

		if (this.getBase().isOp())
		{
			try
			{
				final ChatColor opPrefix = ess.getSettings().getOperatorColor();
				if (opPrefix != null && opPrefix.toString().length() > 0)
				{
					prefix.insert(0, opPrefix.toString());
					suffix = "§r";
				}
			}
			catch (Exception e)
			{
			}
		}

		if (ess.getSettings().addPrefixSuffix())
		{
			//These two extra toggles are not documented, because they are mostly redundant #EasterEgg
			if (!ess.getSettings().disablePrefix())
			{
				final String ptext = ess.getPermissionsHandler().getPrefix(base).replace('&', '§');
				prefix.insert(0, ptext);
				suffix = "§r";
			}
			if (!ess.getSettings().disableSuffix())
			{
				final String stext = ess.getPermissionsHandler().getSuffix(base).replace('&', '§');
				suffix = stext + "§r";
				suffix = suffix.replace("§f§f", "§f").replace("§f§r", "§r").replace("§r§r", "§r");
			}
		}
		final String strPrefix = prefix.toString();
		String output = strPrefix + nickname + suffix;
		if (!longnick && output.length() > 16)
		{
			output = strPrefix + nickname;
		}
		if (!longnick && output.length() > 16)
		{
			output = FormatUtil.lastCode(strPrefix) + nickname;
		}
		if (!longnick && output.length() > 16)
		{
			output = FormatUtil.lastCode(strPrefix) + nickname.substring(0, 14);
		}
		if (output.charAt(output.length() - 1) == '§')
		{
			output = output.substring(0, output.length() - 1);
		}
		return output;
	}

	public void setDisplayNick()
	{
		if (base.isOnline() && ess.getSettings().changeDisplayName())
		{
			this.getBase().setDisplayName(getNick(true));
			if (ess.getSettings().changePlayerListName())
			{
				String name = getNick(false);
				try
				{
					this.getBase().setPlayerListName(name);
				}
				catch (IllegalArgumentException e)
				{
					if (ess.getSettings().isDebug())
					{
						logger.log(Level.INFO, "Playerlist for " + name + " was not updated. Name clashed with another online player.");
					}
				}
			}
		}
	}

	public String getDisplayName()
	{
		return super.getBase().getDisplayName() == null ? super.getBase().getName() : super.getBase().getDisplayName();
	}

	@Override
	public Teleport getTeleport()
	{
		return teleport;
	}

	public long getLastOnlineActivity()
	{
		return lastOnlineActivity;
	}

	public void setLastOnlineActivity(final long timestamp)
	{
		lastOnlineActivity = timestamp;
	}

	@Override
	public BigDecimal getMoney()
	{
		final long start = System.nanoTime();
		final BigDecimal value = _getMoney();
		final long elapsed = System.nanoTime() - start;
		if (elapsed > ess.getSettings().getEconomyLagWarning())
		{
			ess.getLogger().log(Level.INFO, "Lag Notice - Slow Economy Response - Request took over {0}ms!", elapsed / 1000000.0);
		}
		return value;
	}

	private BigDecimal _getMoney()
	{
		if (ess.getSettings().isEcoDisabled())
		{
			if (ess.getSettings().isDebug())
			{
				ess.getLogger().info("Internal economy functions disabled, aborting balance check.");
			}
			return BigDecimal.ZERO;
		}
		if (Methods.hasMethod())
		{
			try
			{
				final Method method = Methods.getMethod();
				if (!method.hasAccount(this.getName()))
				{
					throw new Exception();
				}
				final Method.MethodAccount account = Methods.getMethod().getAccount(this.getName());
				return BigDecimal.valueOf(account.balance());
			}
			catch (Exception ex)
			{
			}
		}
		return super.getMoney();
	}

	@Override
	public void setMoney(final BigDecimal value) throws MaxMoneyException
	{
		if (ess.getSettings().isEcoDisabled())
		{
			if (ess.getSettings().isDebug())
			{
				ess.getLogger().info("Internal economy functions disabled, aborting balance change.");
			}
			return;
		}
		final BigDecimal oldBalance = _getMoney();
		if (Methods.hasMethod())
		{
			try
			{
				final Method method = Methods.getMethod();
				if (!method.hasAccount(this.getName()))
				{
					throw new Exception();
				}
				final Method.MethodAccount account = Methods.getMethod().getAccount(this.getName());
				account.set(value.doubleValue());
			}
			catch (Exception ex)
			{
			}
		}
		super.setMoney(value, true);
		ess.getServer().getPluginManager().callEvent(new UserBalanceUpdateEvent(this.getBase(), oldBalance, value));
		Trade.log("Update", "Set", "API", getName(), new Trade(value, ess), null, null, null, ess);
	}

	public void updateMoneyCache(final BigDecimal value)
	{
		if (ess.getSettings().isEcoDisabled())
		{
			return;
		}
		if (Methods.hasMethod() && super.getMoney() != value)
		{
			try
			{
				super.setMoney(value, false);
			}
			catch (MaxMoneyException ex)
			{
				// We don't want to throw any errors here, just updating a cache
			}
		}
	}

	@Override
	public void setAfk(final boolean set)
	{
		final AfkStatusChangeEvent afkEvent = new AfkStatusChangeEvent(this, set);
		ess.getServer().getPluginManager().callEvent(afkEvent);
		if (afkEvent.isCancelled())
		{
			return;
		}

		this.getBase().setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : set);
		if (set && !isAfk())
		{
			afkPosition = this.getLocation();
		}
		else if (!set && isAfk())
		{
			afkPosition = null;
		}
		_setAfk(set);
	}

	public boolean toggleAfk()
	{
		setAfk(!isAfk());
		return isAfk();
	}

	@Override
	public boolean isHidden()
	{
		return hidden;
	}
	
	public boolean isHidden(final Player player)
	{
		return hidden || !player.canSee(getBase());
	}

	@Override
	public void setHidden(final boolean hidden)
	{
		this.hidden = hidden;
		if (hidden == true)
		{
			setLastLogout(getLastOnlineActivity());
		}
	}

	//Returns true if status expired during this check
	public boolean checkJailTimeout(final long currentTime)
	{
		if (getJailTimeout() > 0 && getJailTimeout() < currentTime && isJailed())
		{
			setJailTimeout(0);
			setJailed(false);
			sendMessage(tl("haveBeenReleased"));
			setJail(null);
			try
			{
				getTeleport().back();
			}
			catch (Exception ex)
			{
				try
				{
					getTeleport().respawn(null, TeleportCause.PLUGIN);
				}
				catch (Exception ex1)
				{
				}
			}
			return true;
		}
		return false;
	}

	//Returns true if status expired during this check
	public boolean checkMuteTimeout(final long currentTime)
	{
		if (getMuteTimeout() > 0 && getMuteTimeout() < currentTime && isMuted())
		{
			setMuteTimeout(0);
			sendMessage(tl("canTalkAgain"));
			setMuted(false);
			return true;
		}
		return false;
	}

	public void updateActivity(final boolean broadcast)
	{
		if (isAfk() && ess.getSettings().cancelAfkOnInteract())
		{
			setAfk(false);
			if (broadcast && !isHidden())
			{
				setDisplayNick();
				final String msg = tl("userIsNotAway", getDisplayName());
				if (!msg.isEmpty())
				{
					ess.broadcastMessage(this, msg);
				}
			}
		}
		lastActivity = System.currentTimeMillis();
	}

	public void checkActivity()
	{
		final long autoafkkick = ess.getSettings().getAutoAfkKick();
		if (autoafkkick > 0 && lastActivity > 0 && (lastActivity + (autoafkkick * 1000)) < System.currentTimeMillis()
			&& !isHidden() && !isAuthorized("essentials.kick.exempt") && !isAuthorized("essentials.afk.kickexempt"))
		{
			final String kickReason = tl("autoAfkKickReason", autoafkkick / 60.0);
			lastActivity = 0;
			this.getBase().kickPlayer(kickReason);


			for (Player player : ess.getServer().getOnlinePlayers())
			{
				final User user = ess.getUser(player);
				if (user.isAuthorized("essentials.kick.notify"))
				{
					user.sendMessage(tl("playerKicked", Console.NAME, getName(), kickReason));
				}
			}
		}
		final long autoafk = ess.getSettings().getAutoAfk();
		if (!isAfk() && autoafk > 0 && lastActivity + autoafk * 1000 < System.currentTimeMillis() && isAuthorized("essentials.afk.auto"))
		{
			setAfk(true);
			if (!isHidden())
			{
				setDisplayNick();
				final String msg = tl("userIsAway", getDisplayName());
				if (!msg.isEmpty())
				{
					ess.broadcastMessage(this, msg);
				}
			}
		}
	}

	public Location getAfkPosition()
	{
		return afkPosition;
	}

	@Override
	public boolean isGodModeEnabled()
	{
		return (super.isGodModeEnabled() && !ess.getSettings().getNoGodWorlds().contains(this.getLocation().getWorld().getName()))
			   || (isAfk() && ess.getSettings().getFreezeAfkPlayers());
	}

	public boolean isGodModeEnabledRaw()
	{
		return super.isGodModeEnabled();
	}

	@Override
	public String getGroup()
	{
		final String result = ess.getPermissionsHandler().getGroup(base);
		if (ess.getSettings().isDebug())
		{
			ess.getLogger().log(Level.INFO, "looking up groupname of " + base.getName() + " - " + result);
		}
		return result;
	}

	@Override
	public boolean inGroup(final String group)
	{
		final boolean result = ess.getPermissionsHandler().inGroup(base, group);
		if (ess.getSettings().isDebug())
		{
			ess.getLogger().log(Level.INFO, "checking if " + base.getName() + " is in group " + group + " - " + result);
		}
		return result;
	}

	@Override
	public boolean canBuild()
	{
		if (this.getBase().isOp())
		{
			return true;
		}
		return ess.getPermissionsHandler().canBuild(base, getGroup());
	}

	public long getTeleportRequestTime()
	{
		return teleportRequestTime;
	}

	public boolean isInvSee()
	{
		return invSee;
	}

	public void setInvSee(final boolean set)
	{
		invSee = set;
	}

	public boolean isEnderSee()
	{
		return enderSee;
	}

	public void setEnderSee(final boolean set)
	{
		enderSee = set;
	}

	@Override
	public void enableInvulnerabilityAfterTeleport()
	{
		final long time = ess.getSettings().getTeleportInvulnerability();
		if (time > 0)
		{
			teleportInvulnerabilityTimestamp = System.currentTimeMillis() + time;
		}
	}

	@Override
	public void resetInvulnerabilityAfterTeleport()
	{
		if (teleportInvulnerabilityTimestamp != 0
			&& teleportInvulnerabilityTimestamp < System.currentTimeMillis())
		{
			teleportInvulnerabilityTimestamp = 0;
		}
	}

	@Override
	public boolean hasInvulnerabilityAfterTeleport()
	{
		return teleportInvulnerabilityTimestamp != 0 && teleportInvulnerabilityTimestamp >= System.currentTimeMillis();
	}
	
	public boolean canInteractVanished()
	{
		return isAuthorized("essentials.vanish.interact");
	}

	@Override
	public boolean isVanished()
	{
		return vanished;
	}

	@Override
	public void setVanished(final boolean set)
	{
		vanished = set;
		if (set)
		{
			for (Player p : ess.getServer().getOnlinePlayers())
			{
				if (!ess.getUser(p).isAuthorized("essentials.vanish.see"))
				{
					p.hidePlayer(getBase());
				}
			}
			setHidden(true);
			ess.getVanishedPlayers().add(getName());
			if (isAuthorized("essentials.vanish.effect"))
			{
				this.getBase().addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false));
			}
		}
		else
		{
			for (Player p : ess.getServer().getOnlinePlayers())
			{
				p.showPlayer(getBase());
			}
			setHidden(false);
			ess.getVanishedPlayers().remove(getName());
			if (isAuthorized("essentials.vanish.effect"))
			{
				this.getBase().removePotionEffect(PotionEffectType.INVISIBILITY);
			}
		}
	}

	public boolean checkSignThrottle()
	{
		if (isSignThrottled())
		{
			return true;
		}
		updateThrottle();
		return false;
	}

	public boolean isSignThrottled()
	{
		final long minTime = lastThrottledAction + (1000 / ess.getSettings().getSignUsePerSecond());
		return (System.currentTimeMillis() < minTime);
	}

	public void updateThrottle()
	{
		lastThrottledAction = System.currentTimeMillis();
	}

	public boolean isFlyClickJump()
	{
		return rightClickJump;
	}

	public void setRightClickJump(boolean rightClickJump)
	{
		this.rightClickJump = rightClickJump;
	}

	@Override
	public boolean isIgnoreExempt()
	{
		return this.isAuthorized("essentials.chat.ignoreexempt");
	}

	public boolean isRecipeSee()
	{
		return recipeSee;
	}

	public void setRecipeSee(boolean recipeSee)
	{
		this.recipeSee = recipeSee;
	}

	@Override
	public void sendMessage(String message)
	{
		if (!message.isEmpty())
		{
			base.sendMessage(message);
		}
	}

	@Override
	public void setReplyTo(final CommandSource user)
	{
		replyTo = user;
	}

	@Override
	public CommandSource getReplyTo()
	{
		return replyTo;
	}

	@Override
	public int compareTo(final User other)
	{
		return FormatUtil.stripFormat(getDisplayName()).compareToIgnoreCase(FormatUtil.stripFormat(other.getDisplayName()));
	}

	@Override
	public boolean equals(final Object object)
	{
		if (!(object instanceof User))
		{
			return false;
		}
		return this.getName().equalsIgnoreCase(((User)object).getName());

	}

	@Override
	public int hashCode()
	{
		return this.getName().hashCode();
	}

	@Override
	public CommandSource getSource()
	{
		return new CommandSource(getBase());
	}

	@Override
	public String getName()
	{
		return this.getBase().getName();
	}
}