-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from Nookure/feature/freeze-chat-timer
Feature/freeze chat timer
- Loading branch information
Showing
34 changed files
with
599 additions
and
106 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
MAStaff-API/src/main/java/com/nookure/mast/api/event/BukkitListener.java
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,9 @@ | ||
package com.nookure.mast.api.event; | ||
|
||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
|
||
public interface BukkitListener<T> extends Listener { | ||
@EventHandler | ||
void handle(T event); | ||
} |
91 changes: 91 additions & 0 deletions
91
MAStaff-API/src/main/java/com/nookure/mast/api/manager/FreezeManager.java
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,91 @@ | ||
package com.nookure.mast.api.manager; | ||
|
||
import com.google.inject.Singleton; | ||
import es.angelillo15.mast.api.IStaffPlayer; | ||
import org.bukkit.OfflinePlayer; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
|
||
@Singleton | ||
public class FreezeManager { | ||
public HashMap<String, FreezeVector> frozenPlayers = new HashMap<>(); | ||
|
||
/** | ||
* Freeze the player | ||
* @param staff IStaffPlayer who freeze the player | ||
* @param target Player to freeze | ||
*/ | ||
public void freezePlayer(IStaffPlayer staff, Player target) { | ||
freezePlayer(staff, target, -1); | ||
} | ||
|
||
/** | ||
* Freeze the player | ||
* @param staff IStaffPlayer who freeze the player | ||
* @param target Player to freeze | ||
* @param time Time to freeze expire | ||
*/ | ||
public void freezePlayer(IStaffPlayer staff, Player target, long time) { | ||
frozenPlayers.put(target.getName(), new FreezeVector(staff, target, time)); | ||
} | ||
|
||
/** | ||
* Unfreeze the player | ||
* @param target Player | ||
*/ | ||
public void unfreezePlayer(Player target) { | ||
frozenPlayers.remove(target.getName()); | ||
} | ||
|
||
/** | ||
* Unfreeze the player | ||
* @param target Player | ||
*/ | ||
public void unfreezePlayer(String target) { | ||
frozenPlayers.remove(target); | ||
} | ||
|
||
/** | ||
* Check if the player is frozen | ||
* @param target Player | ||
* @return boolean | ||
*/ | ||
public boolean isFrozen(Player target) { | ||
return frozenPlayers.containsKey(target.getName()); | ||
} | ||
|
||
/** | ||
* Check if the player is frozen | ||
* @param target Player | ||
* @return boolean | ||
*/ | ||
public boolean isFrozen(String target) { | ||
return frozenPlayers.containsKey(target); | ||
} | ||
|
||
/** | ||
* Gets the frozen players list | ||
* @return ArrayList of OfflinePlayer | ||
*/ | ||
public ArrayList<OfflinePlayer> getFrozenPlayers() { | ||
ArrayList<OfflinePlayer> frozen = new ArrayList<>(); | ||
frozenPlayers.forEach((name, vector) -> frozen.add(vector.getTarget())); | ||
return frozen; | ||
} | ||
|
||
/** | ||
* Gets the frozen players list | ||
* @return ArrayList of FreezeVector with the frozen players | ||
*/ | ||
public ArrayList<FreezeVector> getFreezeVectors() { | ||
ArrayList<FreezeVector> frozen = new ArrayList<>(); | ||
frozenPlayers.forEach((name, vector) -> frozen.add(vector)); | ||
return frozen; | ||
} | ||
|
||
public FreezeVector getFreezeVector(Player target) { | ||
return frozenPlayers.get(target.getName()); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
MAStaff-API/src/main/java/com/nookure/mast/api/manager/FreezeVector.java
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,48 @@ | ||
package com.nookure.mast.api.manager; | ||
|
||
import es.angelillo15.mast.api.IStaffPlayer; | ||
import org.bukkit.OfflinePlayer; | ||
|
||
|
||
public class FreezeVector { | ||
private final IStaffPlayer staffPlayer; | ||
private final OfflinePlayer target; | ||
private long timeLeft; | ||
private boolean hasTalked = false; | ||
|
||
public FreezeVector(IStaffPlayer staffPlayer, OfflinePlayer target, long timeLeft) { | ||
this.staffPlayer = staffPlayer; | ||
this.target = target; | ||
this.timeLeft = timeLeft; | ||
} | ||
|
||
public IStaffPlayer getStaffPlayer() { | ||
return staffPlayer; | ||
} | ||
|
||
public OfflinePlayer getTarget() { | ||
return target; | ||
} | ||
|
||
/** | ||
* Get the time left to unfreeze the player | ||
* -1 disabled | ||
* -2 expired | ||
* @return long time left | ||
*/ | ||
public long getTimeLeft() { | ||
return timeLeft; | ||
} | ||
|
||
public void setTimeLeft(int timeLeft) { | ||
this.timeLeft = timeLeft; | ||
} | ||
|
||
public boolean hasTalked() { | ||
return hasTalked; | ||
} | ||
|
||
public void setHasTalked(boolean hasTalked) { | ||
this.hasTalked = hasTalked; | ||
} | ||
} |
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
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
13 changes: 0 additions & 13 deletions
13
MAStaff-API/src/main/java/es/angelillo15/mast/api/managers/freeze/FreezeVector.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.