-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Allows to fix the max number of riders (you can have several groups) * Add configurable cooldowns (actions and messages) * Now, items used can be consumed (your choice) * Add the permission playerrider.ride.keepitem * Add the permission playerrider.whip.keepitem * Add an option to prevent the rider to be hit by his victim
- Loading branch information
arboriginal
committed
Dec 4, 2018
1 parent
0b47190
commit 275ef47
Showing
5 changed files
with
283 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package me.arboriginal.PlayerRider; | ||
|
||
import java.util.HashMap; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
public class PRcooldown { | ||
public static HashMap<String, Long> cooldowns; | ||
public static HashMap<String, String> warnings; | ||
|
||
public PRcooldown() { | ||
cooldowns = new HashMap<String, Long>() { | ||
private static final long serialVersionUID = 1L; | ||
}; | ||
} | ||
|
||
public String id(String key, CommandSender player, CommandSender duck) { | ||
return key + "..." + player.getName() + "." + ((duck == null) ? ".." : duck.getName()); | ||
} | ||
|
||
public boolean isActive(String key, Player player) { | ||
return isActive(key, player, null, false); | ||
} | ||
|
||
public boolean isActive(String key, Player player, boolean warn) { | ||
return isActive(key, player, null, warn); | ||
} | ||
|
||
public boolean isActive(String key, Player player, Player duck) { | ||
return isActive(key, player, duck, false); | ||
} | ||
|
||
public boolean isActive(String key, Player player, Player duck, boolean warn) { | ||
Long now = getCurrentTime(), next = get(key, player, duck); | ||
|
||
if (next > now) { | ||
if (warn) PlayerRider.warn(key, player, duck, (int) Math.max(1, Math.floor((next - now) / 1000))); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public Long getCurrentTime() { | ||
return System.currentTimeMillis(); | ||
} | ||
|
||
public Long get(String key, Player player, Player duck) { | ||
key = id(key, player, duck); | ||
|
||
return cooldowns.containsKey(key) ? cooldowns.get(key) : 0; | ||
} | ||
|
||
public void clear(String key, Player player) { | ||
clear(key, player, null); | ||
} | ||
|
||
public void clear(String key, Player player, Player duck) { | ||
cooldowns.remove(id(key, player, duck)); | ||
} | ||
|
||
public void set(String key, Player player) { | ||
set(key, player, null); | ||
} | ||
|
||
public void set(String key, Player player, Player duck) { | ||
int delay = PlayerRider.config.getInt("cooldowns." + key) * 1000; | ||
|
||
if (delay > 0) { | ||
cooldowns.put(id(key, player, duck), getCurrentTime() + delay); | ||
} | ||
} | ||
} |
Oops, something went wrong.