generated from beanbeanjuice/SpigotPluginTemplate
-
-
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 #187 from beanbeanjuice/179-send-last-messages-dur…
…ing-switch Send Last Few Messages During Switch
- Loading branch information
Showing
10 changed files
with
103 additions
and
11 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
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
19 changes: 19 additions & 0 deletions
19
.../main/java/com/beanbeanjuice/simpleproxychat/utility/datastructures/BoundedArrayList.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,19 @@ | ||
package com.beanbeanjuice.simpleproxychat.utility.datastructures; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class BoundedArrayList<T> extends ArrayList<T> { | ||
|
||
private final int maximumSize; | ||
|
||
public BoundedArrayList(final int maximumSize) { | ||
this.maximumSize = maximumSize; | ||
} | ||
|
||
@Override | ||
public boolean add(T t) { | ||
if (super.size() >= maximumSize) super.remove(0); | ||
return super.add(t); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...pp/src/main/java/com/beanbeanjuice/simpleproxychat/utility/helper/LastMessagesHelper.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,34 @@ | ||
package com.beanbeanjuice.simpleproxychat.utility.helper; | ||
|
||
import com.beanbeanjuice.simpleproxychat.utility.config.Config; | ||
import com.beanbeanjuice.simpleproxychat.utility.config.ConfigDataKey; | ||
import com.beanbeanjuice.simpleproxychat.utility.datastructures.BoundedArrayList; | ||
|
||
public class LastMessagesHelper { | ||
|
||
private final Config config; | ||
private BoundedArrayList<String> boundedArrayList; | ||
|
||
public LastMessagesHelper(final Config config) { | ||
this.config = config; | ||
boundedArrayList = new BoundedArrayList<>(config.getAsInteger(ConfigDataKey.SEND_PREVIOUS_MESSAGES_ON_SWITCH_AMOUNT)); | ||
config.addReloadListener(this::reset); | ||
} | ||
|
||
private void reset() { | ||
BoundedArrayList<String> old = boundedArrayList; | ||
boundedArrayList = new BoundedArrayList<>(config.getAsInteger(ConfigDataKey.SEND_PREVIOUS_MESSAGES_ON_SWITCH_AMOUNT)); | ||
boundedArrayList.addAll(old); | ||
} | ||
|
||
public void addMessage(final String message) { | ||
boundedArrayList.add(message); | ||
} | ||
|
||
public BoundedArrayList<String> getBoundedArrayList() { | ||
if (!config.getAsBoolean(ConfigDataKey.SEND_PREVIOUS_MESSAGES_ON_SWITCH_ENABLED)) return new BoundedArrayList<>(0); | ||
|
||
return boundedArrayList; | ||
} | ||
|
||
} |
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