Skip to content

Commit

Permalink
Add on language change events to API
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotcorreia committed Dec 10, 2019
1 parent 1282527 commit 4326fb9
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.rexcantor64.triton.api.events;

import com.rexcantor64.triton.api.language.Language;
import com.rexcantor64.triton.api.players.LanguagePlayer;
import net.md_5.bungee.api.plugin.Event;

/**
* This event is triggered when a player changes their language.
* To be used with BungeeCord.
*
* @since 2.4.0
*/
public class PlayerChangeLanguageBungeeEvent extends Event {
private final LanguagePlayer languagePlayer;
private final Language oldLanguage;
private Language newLanguage;
private boolean isCancelled;

public PlayerChangeLanguageBungeeEvent(LanguagePlayer languagePlayer, Language oldLanguage, Language newLanguage) {
this.languagePlayer = languagePlayer;
this.oldLanguage = oldLanguage;
this.newLanguage = newLanguage;
}

/**
* Check if the event is cancelled.
*
* @return whether the event is cancelled or not.
*/
public boolean isCancelled() {
return isCancelled;
}

/**
* Cancel the event.
* If cancelled, the language of the player isn't changed.
*
* @param cancelled Set whether the event is cancelled or not.
*/
public void setCancelled(boolean cancelled) {
isCancelled = cancelled;
}

/**
* Get the player that is changing languages.
*
* @return the player that is changing languages.
*/
public LanguagePlayer getLanguagePlayer() {
return languagePlayer;
}

/**
* Get the language the player is switching from.
*
* @return the language the player is switching from.
*/
public Language getOldLanguage() {
return oldLanguage;
}

/**
* Get the language the player is switching to.
*
* @return the language the player is switching to.
*/
public Language getNewLanguage() {
return newLanguage;
}

/**
* Set the language the player is switching to.
*
* @param newLanguage the language the player is switching to.
*/
public void setNewLanguage(Language newLanguage) {
this.newLanguage = newLanguage;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.rexcantor64.triton.api.events;

import com.rexcantor64.triton.api.language.Language;
import com.rexcantor64.triton.api.players.LanguagePlayer;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

/**
* This event is triggered when a player changes their language.
* To be used with Spigot.
*
* @since 2.4.0
*/
public class PlayerChangeLanguageSpigotEvent extends Event implements Cancellable {
private static final HandlerList HANDLERS = new HandlerList();
private final LanguagePlayer languagePlayer;
private final Language oldLanguage;
private Language newLanguage;
private boolean isCancelled;

public PlayerChangeLanguageSpigotEvent(LanguagePlayer languagePlayer, Language oldLanguage, Language newLanguage) {
this.languagePlayer = languagePlayer;
this.oldLanguage = oldLanguage;
this.newLanguage = newLanguage;
}

public static HandlerList getHandlerList() {
return HANDLERS;
}

/**
* Check if the event is cancelled.
*
* @return whether the event is cancelled or not.
*/
@Override
public boolean isCancelled() {
return isCancelled;
}

/**
* Cancel the event.
* If cancelled, the language of the player isn't changed.
*
* @param cancelled Set whether the event is cancelled or not.
*/
@Override
public void setCancelled(boolean cancelled) {
isCancelled = cancelled;
}

public HandlerList getHandlers() {
return HANDLERS;
}

/**
* Get the player that is changing languages.
*
* @return the player that is changing languages.
*/
public LanguagePlayer getLanguagePlayer() {
return languagePlayer;
}

/**
* Get the language the player is switching from.
*
* @return the language the player is switching from.
*/
public Language getOldLanguage() {
return oldLanguage;
}

/**
* Get the language the player is switching to.
*
* @return the language the player is switching to.
*/
public Language getNewLanguage() {
return newLanguage;
}

/**
* Set the language the player is switching to.
*
* @param newLanguage the language the player is switching to.
*/
public void setNewLanguage(Language newLanguage) {
this.newLanguage = newLanguage;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,19 @@ public interface LanguagePlayer {
void setLang(Language language);

/**
* Refresh the player's translated messages. This includes scoreboard, tab, bossbars, entities, etc. Does not affect chat.
* Refresh the player's translated messages. This includes scoreboard, tab, bossbars, entities, etc. Does not
* affect chat.
* This is automatically invoked when using {@link #setLang(Language)}.
*
* @since 1.0.0
*/
void refreshAll();

/**
* Get the UUID of the player.
*
* @return The UUID of the player.
* @since 2.4.0
*/
UUID getUUID();
}

0 comments on commit 4326fb9

Please sign in to comment.